https://hub.docker.com/_/elasticsearch/
https://www.docker.elastic.co/r/elasticsearch
https://hub.docker.com/r/sebp/elk/
# docker run # --net=host
---ok---
docker run -d -p 9200:9200 -p 9300:9300 --name elasticsearch --restart=always -v /etc/localtime:/etc/localtime:ro -e "node.name=01" -e "cluster.name=cluster" -e "cluster.initial_master_nodes=01" -v /data/file/logs/elasticsearch:/usr/share/elasticsearch/logs elasticsearch:7.12.1
docker run -d -p 9200:9200 -p 9300:9300 --name elasticsearch --restart=always -v /etc/localtime:/etc/localtime:ro -v /data/docker/monitor/elasticsearch/elasticsearch.ini:/usr/share/elasticsearch/config/elasticsearch.yml:ro -v /data/file/logs/elasticsearch:/usr/share/elasticsearch/logs elasticsearch:7.12.1
--test---
docker run -d -p 9200:9200 -p 9300:9300 --name elasticsearch --restart=always -v /etc/localtime:/etc/localtime:ro -e "discovery.type:node" -e "http.host:0.0.0.0" -e "transport.host:127.0.0.1" -e "cluster.name:cluster" -e "node.name:node-1" -e "network.host:0.0.0.0" -e "discovery.seed_hosts:127.0.0.1" -e "cluster.initial_master_nodes: ["node-1"]" -e "bootstrap.memory_lock:true" -e "ES_JAVA_OPTS:-Xms800m -Xmx800m" elasticsearch:7.9.0
docker run -d -p 9200:9200 -p 9300:9300 --name elasticsearch --restart=always -v /etc/localtime:/etc/localtime:ro -v /data/docker/monitor/elasticsearch/elasticsearch-5.6.16.ini:/usr/share/elasticsearch/config/elasticsearch.yml:ro -v /data/file/logs/elasticsearch:/usr/share/elasticsearch/logs elasticsearch:5.6.16
node.name=es01 cluster.name=es-docker-cluster discovery.seed_hosts=es02,es03 cluster.initial_master_nodes=es01,es02,es03 bootstrap.memory_lock=true "ES_JAVA_OPTS=-Xms512m -Xmx512m"
cluster.name: elk node.name: elk01 node.master: true node.data: true cluster.initial_master_nodes: ["elk01"] path.data: /elk/es/data path.logs: /elk/es/logs bootstrap.memory_lock: false bootstrap.system_call_filter: false network.host: 0.0.0.0 http.port: 9200 #discovery.zen.ping.unicast.hosts: ["192.168.146.128"] #discovery.zen.minimum_master_nodes: 2 #discovery.zen.ping_timeout: 150s #discovery.zen.fd.ping_retries: 10 #client.transport.ping_timeout: 60s http.cors.enabled: true http.cors.allow-origin: "*" # 配置文件含义 cluster.name 集群名称,各节点配成相同的集群名称。 node.name 节点名称,各节点配置不同。 node.master 指示某个节点是否符合成为主节点的条件。 node.data 指示节点是否为数据节点。数据节点包含并管理索引的一部分。 path.data 数据存储目录。 path.logs 日志存储目录。 bootstrap.memory_lock 内存锁定,是否禁用交换。 bootstrap.system_call_filter 系统调用过滤器。 network.host 绑定节点IP。 http.port 端口。 discovery.zen.ping.unicast.hosts 提供其他 Elasticsearch 服务节点的单点广播发现功能。 discovery.zen.minimum_master_nodes 集群中可工作的具有Master节点资格的最小数量,官方的推荐值是(N/2)+1,其中N是具有master资格的节点的数量。 discovery.zen.ping_timeout 节点在发现过程中的等待时间。 discovery.zen.fd.ping_retries 节点发现重试次数。 http.cors.enabled 是否允许跨源 REST 请求,用于允许head插件访问ES。 http.cors.allow-origin 允许的源地址。 # 设置JVM堆大小 vim /usr/elk/elasticsearch-7.8.1/config/jvm.options -Xms1g ----修改成 -Xms2g -Xmx1g ----修改成 -Xms2g #一般设置为虚拟机内存的一半,最少为2G,推荐设置为4G
应用: monitor -> 添加服务: elasticsearch
镜像: docker.elastic.co/elasticsearch/elasticsearch:7.12.0
环境变量:
discovery.type = node
http.host = 0.0.0.0
transport.host = 127.0.0.1
cluster.name = cluster
bootstrap.memory_lock = true
ES_JAVA_OPTS = -Xms512m -Xmx512m
discovery.zen.ping.unicast.hosts = elasticsearch
卷:
/data/db/elasticsearch:/usr/share/elasticsearch/data
/data/file/logs/elasticsearch:/usr/share/elasticsearch/logs
/data/file:/data/file
/etc/localtime:/etc/localtime:ro
端口:9200-9200 9300-9300
保存ip: 升级或替换 不变
主机名: 使用容器名称
进一步安装:
whereis elasticsearch # 查看安装位置
插件:
bin/elasticsearch-plugin install ingest-attachment
安装中文分词插件: https://github.com/medcl/elasticsearch-analysis-ik/releases
bin/elasticsearch-plugin install https://github.com/medcl/elasticsearch-analysis-ik/releases/download/v7.9.1/elasticsearch-analysis-ik-7.9.1.zip
测试ik分词器:
curl -XGET -H 'Content-Type: application/json' 'http://localhost:9200/_analyze?pretty' -d '{
"analyzer" : "ik_max_word",
"text": "中华人民共和国国歌"
}'修改下权限:
chmod -R 777 /data/db/elasticsearch
chmod -R 777 /data/file/logs/elasticsearch
常规命令:
curl localhost:9200 # 测试
curl -X GET "localhost:9200/_cat/nodes?v&pretty" # 查看节点情况
curl 'localhost:9200/_cat/indices?v' # 通过下面的命令可以查看所有的索引
curl 'localhost:9200/_cat/health?v' # 查询集群的健康状态
curl -XPUT 'localhost:9200/customer'//创建索引,插入数据
curl -XPUT 'localhost:9200/customer/external/1'-d '
{
"name": "John Doe"
}'
curl 'localhost:9200/customer/external/1'//查询数据
curl -XDELETE 'localhost:9200/customer'//删除索引==============================
下载head插件
cd /home
wget https://github.com/mobz/elasticsearch-head/archive/master.zip
or
cd /data/file/soft/src/elk/elasticsearch-head-master
安装node:
wget https://npm.taobao.org/mirrors/node/latest/node-v10.6.0-linux-x64.tar.gz
tar -zxvf node-v10.6.0-linux-x64.tar.gz
or
cd /data/file/soft/src/node/10.6.0
vi /etc/profile
NODE_HOME=/data/file/soft/src/node/10.6.0
PATH=$PATH:$NODE_HOME/bin
NODE_PATH=$NODE_HOME/lib/node_modules
source /etc/profile
安装grunt:
grunt是基于Node.js的项目构建工具,可以进行打包压缩、测试、执行等等的工作,head插件就是通过grunt启动
cd /data/file/soft/src/elk/elasticsearch-head-master
npm install -g grunt-cli # 执行后会生成node_modules文件夹
grunt -version # 检查是否安装成功
cd /data/file/soft/src/elk/elasticsearch-head-master
vi Gruntfile.js:
===> connect:
port:9100,
base: '.',
keepalice: true,
hostname: '*'
vi _site/app.js:
"http://localhost:9200"; ===> "http://具体ip:9200";
运行head:
npm install phantomjs-prebuilt@2.1.14 --ignore-scripts # 解决phantomjs失败
grunt server
访问测试: http://xxx:9100
集群健康状态哪里显示未连接:
vim /data/docker/elk/elasticsearch.yml
cluster.name: "cluster"
node.name: node-1
network.host: 0.0.0.0 # 当前节点的IP地址
http.port: 9200 # 对外提供服务的端口
# minimum_master_nodes need to be explicitly set when bound on a public IP
# set to 1 to allow single node clusters
# Details: https://github.com/elastic/elasticsearch/pull/17288
discovery.zen.minimum_master_nodes: 2 # 为了避免脑裂,集群节点数最少为 半数+1
# 增加参数,使head插件可以访问es
http.cors.enabled: true # elasticsearch中启用CORS
http.cors.allow-origin: "*" # 允许访问的IP地址段,* 为所有IP都可以访问
======================================
grafana 添加数据源:
elasticsearch查看所有index:
curl 'localhost:9200/_cat/indices?v'
======================================
1. master 节点配置
# 集群名称 cluster.name: sys-log # 节点名称,要唯一 node.name: es-node-1 # 单一角色配置 master node.master: true node.data: false node.ingest: false # 服务端口号 http.port: 9200 # 集群通信端口 transport.port: 9300 # 数据存放目录 path.data: /data/node # 日志存放位置 path.logs: /data/logs # es绑定的ip地址,根据自己机器ip进行修改 network.host: 192.168.1.1 # 启动初始化,有很多帖子说这里要配置成当前主机,后果是通过初始化多台主机,会让他们形成多个es集群而不是组成一个。 正确的配置:候选节点数组,初始化时就只有一个集群了 cluster.initial_master_nodes: ["es-node-1","es-node-2","es-node-3","es-node-4"] discovery.seed_hosts: ["192.168.1.1","192.168.1.2","192.168.1.3","192.168.1.4"] # 生产必须为true,内存锁定检查,目的是内存地址直接映射,减少一次copy时间 bootstrap.memory_lock: true # 系统过滤检查,防止数据损坏,考虑集群安全,生产设置成false bootstrap.system_call_filter: false # 设置这个参数来保证集群中的节点可以知道其它N个有master资格的节点。默认为1,对于大的集群来说,可以设置大一点的值(2-4) #discovery.zen.minimum_master_nodes: 2 #discovery.zen.fd.ping_timeout: 1m #discovery.zen.fd.ping_retries: 5 # 自动创建内置安全账户索引,后续做监控,配置下 action.destructive_requires_name: true action.auto_create_index: .security,.monitoring*,.watches,.triggered_watches,.watcher-history* xpack.monitoring.enabled: true xpack.graph.enabled: false xpack.watcher.enabled: false xpack.ml.enabled: false # 是否支持跨域 http.cors.enabled: true # * 表示支持所有域名 http.cors.allow-origin: "*" # 集群身份认证与用户鉴权 xpack.security.enabled: true xpack.license.self_generated.type: basic xpack.security.transport.ssl.enabled: true # 集群内部安全通信-节点CA认证 xpack.security.transport.ssl.verification_mode: certificate xpack.security.transport.ssl.keystore.path: certs/elastic-certificates.p12 xpack.security.transport.ssl.truststore.path: certs/elastic-certificates.p12
2. data 节点配置
# 集群名称 cluster.name: sys-log # 节点名称,要唯一 node.name: es-node-2 # 单一角色配置 master node.master: false node.data: true node.ingest: false # 服务端口号 http.port: 9200 # 集群通信端口 transport.port: 9300 # 数据存放目录 path.data: /data/node # 日志存放位置 path.logs: /data/logs # es绑定的ip地址,根据自己机器ip进行修改 network.host: 192.168.1.2 # 启动初始化,有很多帖子说这里要配置成当前主机,后果是通过初始化多台主机,会让他们形成多个es集群而不是组成一个。 正确的配置:候选节点数组,初始化时就只有一个集群了 cluster.initial_master_nodes: ["es-node-1","es-node-2","es-node-3","es-node-4"] discovery.seed_hosts: ["192.168.1.1","192.168.1.2","192.168.1.3","192.168.1.4"] # 生产必须为true,内存锁定检查,目的是内存地址直接映射,减少一次copy时间 bootstrap.memory_lock: true # 系统过滤检查,防止数据损坏,考虑集群安全,生产设置成false bootstrap.system_call_filter: false # 设置这个参数来保证集群中的节点可以知道其它N个有master资格的节点。默认为1,对于大的集群来说,可以设置大一点的值(2-4) #discovery.zen.minimum_master_nodes: 2 #discovery.zen.fd.ping_timeout: 1m #discovery.zen.fd.ping_retries: 5 # 自动创建内置安全账户索引,后续做监控,配置下 action.destructive_requires_name: true action.auto_create_index: .security,.monitoring*,.watches,.triggered_watches,.watcher-history* xpack.monitoring.enabled: true xpack.graph.enabled: false xpack.watcher.enabled: false xpack.ml.enabled: false # 是否支持跨域 http.cors.enabled: true # * 表示支持所有域名 http.cors.allow-origin: "*" # 集群身份认证与用户鉴权 xpack.security.enabled: true xpack.license.self_generated.type: basic xpack.security.transport.ssl.enabled: true # 集群内部安全通信-节点CA认证 xpack.security.transport.ssl.verification_mode: certificate xpack.security.transport.ssl.keystore.path: certs/elastic-certificates.p12 xpack.security.transport.ssl.truststore.path: certs/elastic-certificates.p12
3. ingest节点配置
# 集群名称 cluster.name: sys-log # 节点名称,要唯一 node.name: es-node-3 # 单一角色配置 master node.master: false node.data: false node.ingest: true # 服务端口号 http.port: 9200 # 集群通信端口 transport.port: 9300 # 数据存放目录 path.data: /data/node # 日志存放位置 path.logs: /data/logs # es绑定的ip地址,根据自己机器ip进行修改 network.host: 192.168.1.3 # 启动初始化,有很多帖子说这里要配置成当前主机,后果是通过初始化多台主机,会让他们形成多个es集群而不是组成一个。 正确的配置:候选节点数组,初始化时就只有一个集群了 cluster.initial_master_nodes: ["es-node-1","es-node-2","es-node-3","es-node-4"] discovery.seed_hosts: ["192.168.1.1","192.168.1.2","192.168.1.3","192.168.1.4"] # 生产必须为true,内存锁定检查,目的是内存地址直接映射,减少一次copy时间 bootstrap.memory_lock: true # 系统过滤检查,防止数据损坏,考虑集群安全,生产设置成false bootstrap.system_call_filter: false # 设置这个参数来保证集群中的节点可以知道其它N个有master资格的节点。默认为1,对于大的集群来说,可以设置大一点的值(2-4) #discovery.zen.minimum_master_nodes: 2 #discovery.zen.fd.ping_timeout: 1m #discovery.zen.fd.ping_retries: 5 # 自动创建内置安全账户索引,后续做监控,配置下 action.destructive_requires_name: true action.auto_create_index: .security,.monitoring*,.watches,.triggered_watches,.watcher-history* xpack.monitoring.enabled: true xpack.graph.enabled: false xpack.watcher.enabled: false xpack.ml.enabled: false # 是否支持跨域 http.cors.enabled: true # * 表示支持所有域名 http.cors.allow-origin: "*" # 集群身份认证与用户鉴权 xpack.security.enabled: true xpack.license.self_generated.type: basic xpack.security.transport.ssl.enabled: true # 集群内部安全通信-节点CA认证 xpack.security.transport.ssl.verification_mode: certificate xpack.security.transport.ssl.keystore.path: certs/elastic-certificates.p12 xpack.security.transport.ssl.truststore.path: certs/elastic-certificates.p12
4. coordinator节点配置
# 集群名称 cluster.name: sys-log # 节点名称,要唯一 node.name: es-node-5 node.master: false node.data: false node.ingest: false # 服务端口号 http.port: 9200 # 集群通信端口 transport.port: 9300 path.data: /data/node # 日志存放位置 path.logs: /data/logs # es绑定的ip地址,根据自己机器ip进行修改 network.host: 192.168.1.5 # 启动初始化,当前主机 cluster.initial_master_nodes: ["es-node-1","es-node-2","es-node-3","es-node-4"] discovery.seed_hosts: ["192.168.1.1","192.168.1.2","192.168.1.3"] # 生产必须,内存锁定检查 bootstrap.memory_lock: true # 系统过滤检查,防止数据损坏 bootstrap.system_call_filter: false # 设置这个参数来保证集群中的节点可以知道其它N个有master资格的节点。默认为1,对于大的集群来说,可以设置大一点的值(2-4) #discovery.zen.minimum_master_nodes: 2 #discovery.zen.fd.ping_timeout: 1m #discovery.zen.fd.ping_retries: 5 # 自动创建内置安全账户索引 action.destructive_requires_name: true action.auto_create_index: .security,.monitoring*,.watches,.triggered_watches,.watcher-history* xpack.monitoring.enabled: true xpack.graph.enabled: false xpack.watcher.enabled: false xpack.ml.enabled: false # 是否支持跨域 http.cors.enabled: true # * 表示支持所有域名 http.cors.allow-origin: "*" # 集群身份认证与用户鉴权 xpack.security.enabled: true xpack.license.self_generated.type: basic xpack.security.transport.ssl.enabled: true # 集群内部安全通信-节点CA认证 xpack.security.transport.ssl.verification_mode: certificate xpack.security.transport.ssl.keystore.path: certs/elastic-certificates.p12 xpack.security.transport.ssl.truststore.path: certs/elastic-certificates.p12
5. data+ingest节点配置
# 集群名称 cluster.name: sys-log # 节点名称,要唯一 node.name: es-node-4 node.master: false node.data: true node.ingest: true # 服务端口号 http.port: 9200 # 集群通信端口 transport.port: 9300 path.data: /data/node # 日志存放位置 path.logs: /data/logs # es绑定的ip地址,根据自己机器ip进行修改 network.host: 192.168.1.4 # 启动初始化,当前主机 cluster.initial_master_nodes: ["es-node-1","es-node-2","es-node-3","es-node-4"] discovery.seed_hosts: ["192.168.1.1","192.168.1.2","192.168.1.3"] # 生产必须,内存锁定检查 bootstrap.memory_lock: true # 系统过滤检查,防止数据损坏 bootstrap.system_call_filter: false # 设置这个参数来保证集群中的节点可以知道其它N个有master资格的节点。默认为1,对于大的集群来说,可以设置大一点的值(2-4) #discovery.zen.minimum_master_nodes: 2 #discovery.zen.fd.ping_timeout: 1m #discovery.zen.fd.ping_retries: 5 # 自动创建内置安全账户索引 action.destructive_requires_name: true action.auto_create_index: .security,.monitoring*,.watches,.triggered_watches,.watcher-history* xpack.monitoring.enabled: true xpack.graph.enabled: false xpack.watcher.enabled: false xpack.ml.enabled: false # 是否支持跨域 http.cors.enabled: true # * 表示支持所有域名 http.cors.allow-origin: "*" # 集群身份认证与用户鉴权 xpack.security.enabled: true xpack.license.self_generated.type: basic xpack.security.transport.ssl.enabled: true # 集群内部安全通信-节点CA认证 xpack.security.transport.ssl.verification_mode: certificate xpack.security.transport.ssl.keystore.path: certs/elastic-certificates.p12 xpack.security.transport.ssl.truststore.path: certs/elastic-certificates.p12
6.master + data + ingest 节点配置
# 官方默认角色 # 集群名称 cluster.name: sys-log # 节点名称,要唯一 node.name: es-node-6 node.master: true node.data: true # 服务端口号 http.port: 9200 # 集群通信端口 transport.port: 9300 path.data: /data/node # 日志存放位置 path.logs: /data/logs # es绑定的ip地址,根据自己机器ip进行修改 network.host: 192.168.1.6 # 启动初始化,当前主机 cluster.initial_master_nodes: ["es-node-1","es-node-2","es-node-3","es-node-4"] discovery.seed_hosts: ["192.168.1.1","192.168.1.2","192.168.1.3"] # 生产必须,内存锁定检查 bootstrap.memory_lock: true # 系统过滤检查,防止数据损坏 bootstrap.system_call_filter: false # 设置这个参数来保证集群中的节点可以知道其它N个有master资格的节点。默认为1,对于大的集群来说,可以设置大一点的值(2-4) #discovery.zen.minimum_master_nodes: 2 #discovery.zen.fd.ping_timeout: 1m #discovery.zen.fd.ping_retries: 5 # 自动创建内置安全账户索引 action.destructive_requires_name: true action.auto_create_index: .security,.monitoring*,.watches,.triggered_watches,.watcher-history* xpack.monitoring.enabled: true xpack.graph.enabled: false xpack.watcher.enabled: false xpack.ml.enabled: false # 是否支持跨域 http.cors.enabled: true # * 表示支持所有域名 http.cors.allow-origin: "*" # 集群身份认证与用户鉴权 xpack.security.enabled: true xpack.license.self_generated.type: basic xpack.security.transport.ssl.enabled: true # 集群内部安全通信-节点CA认证 xpack.security.transport.ssl.verification_mode: certificate xpack.security.transport.ssl.keystore.path: certs/elastic-certificates.p12 xpack.security.transport.ssl.truststore.path: certs/elastic-certificates.p12
7. CA证书生成并配置
-先生成CA证书,并copy到es的config目录
---生成elastic-stack-ca.p12
bin/elasticsearch-certutil ca
---生成elastic-certificates.p12
bin/elasticsearch-certutil cert --ca elastic-stack-ca.p12
8. es集群内置账号初始化
bin/elasticsearch-setup-passwords interactive # 请记住初始化的用户名和密码
http://ip:9200/ ,这里换成您自己的ip
9. 集成 kibana 配置
# 也可以使用kibana登录验证
vi /usr/local/server/kibana/config/kibana.yml
server.port: 80
server.host: "0.0.0.0"
server.name: "kibana"
# 这里可以配置多个
elasticsearch.hosts: ["http://192.168.1.1:9200"]
kibana.index: ".kibana"
kibana.defaultAppId: "home"
#中文显示
i18n.locale: "zh-CN"
# 初始化kibana用户名
elasticsearch.username: "kibana"
# 初始化密码,修改成自己的
elasticsearch.password: "123456"
# 启动kibana,/data/logs/这个目录必须存在
nohup /usr/local/server/kibana/bin/kibana --allow-root >/data/logs/log.log 2>&1 &
======================================
https://www.toutiao.com/i6867108571407090190/
https://github.com/hangxin1940/docker-elasticsearch-cn