我在想本机搭建一套ELK环境,本来想着应该很简单,网上教程也很多,结果教程都或多或少有点问题,踩了不少的坑,折腾了好几天才解决。干脆根据自己安装经验,写篇教程,让大家少走点弯路。也欢迎大佬来拍砖。
宿主机是centos7.0的虚拟机,IP地址为:192.168.3.140
需要部署以下容器:
镜像 | 容器名称 | 说明 |
---|---|---|
elasticsearch:5.6.4 | es1 | elasticsearch的master节点 |
elasticsearch:5.6.4 | es2 | elasticsearch的数据节点 |
mobz/elasticsearch-head:5 | es_head | elasticsearch的head插件 |
kibana:5.6.4 | kibana | kibana节点 |
logstash:5.6.4 | logstash | logstash节点 |
redis:latest | redis-cache | redis节点 |
Pull相关Docker镜像:
docker pull elasticsearch:5.6.4
docker pull mobz/elasticsearch-head:5
docker pull kibana:5.6.4
docker pull logstash:5.6.4
docker pull redis:latest
1、工作目录准备
master节点目录:/data/elasticsearch/data
数据节点:/data/elasticsearch/data
2、创建两个配置文件
/data/elasticsearch/config/es1.yml
network.bind_host: 0.0.0.0
cluster.name: elasticsearch_cluster
node.name: master
node.master: true
node.data: true
http.cors.enabled: true
http.cors.allow-origin: "*"
network.host: 0.0.0.0
discovery.zen.minimum_master_nodes: 1
/data/elasticsearch/config/es2.yml
network.bind_host: 0.0.0.0
cluster.name: elasticsearch_cluster
node.name: node2
node.master: false
node.data: true
http.cors.enabled: true
http.cors.allow-origin: "*"
network.host: 0.0.0.0
discovery.zen.minimum_master_nodes: 1
discovery.zen.ping.unicast.hosts: es1
3、启动
可以先用命令行启动:
docker run -d --name es1 -p 9200:9200 -p 9300:9300 -v /data/elasticsearch/config/es1.yml:/usr/share/elasticsearch/config/elasticsearch.yml: -v /data/elasticsearch/data:/usr/share/elasticsearch/data elasticsearch:5.6.4
docker run -d --name es2 --link es1:es1 -p 9201:9200 -p 9301:9300 -v /root/es_docker/es2.yml:/usr/share/elasticsearch/config/elasticsearch.yml -v /data/elasticsearch/data2:/usr/share/elasticsearch/data elasticsearch:5.6.4
docker-compose.yml文件:
version: '2.0'
services:
elasticsearch-central:
image: elasticsearch:5.6.4
container_name: es1
volumes:
- /data/elasticsearch/data:/usr/share/elasticsearch/data
- /data/elasticsearch/config/es1.yml:/usr/share/elasticsearch/config/elasticsearch.yml
environment:
- ES_CLUSTERNAME=elasticsearch
command: elasticsearch
ports:
- "9200:9200"
- "9300:9300"
elasticsearch-data:
image: elasticsearch:5.6.4
container_name: es2
volumes:
- /data/elasticsearch/data2:/usr/share/elasticsearch/data
- /data/elasticsearch/config/es2.yml:/usr/share/elasticsearch/config/elasticsearch.yml
environment:
- ES_CLUSTERNAME=elasticsearch
command: elasticsearch
ports:
- "9200:9200"
- "9300:9300"
links:
- elasticsearch-central:elasticsearch
在docker-compose.yml目录下执行以下命令,启动elasticsearch:
docker-compose up
通过docker ps查看容器是否启动,也可以通过docker logs -f -t –tail=10 容器名,查看容器启动日志。
查看集群健康状态:
http://192.168.3.140:9200/_cat/health?v
4、安装注意问题
1)启动时报:
max virtual memory areas vm.max_map_count [65530] likely too low, increase to at least [262144]
修改/etc/sysctl.conf文件就可以了,问题是,修改哪里的sysctl.conf文件。
开始我想修改elasticsearch容器里面配置文件,但是发现报错容器根本起不来,而且即使起来了,发现容器里面根本没有/etc/sysctl.conf这个文件。
其实Docker容器是继承宿主机的虚拟内存大小配置,只需修改宿主机对应文件即可。
[root@localhost ~]# cat /etc/sysctl.conf | grep -v "vm.max_map_count" > /tmp/system_sysctl.conf
[root@localhost ~]# echo "vm.max_map_count=262144" >> /tmp/system_sysctl.conf
[root@localhost ~]# mv /tmp/system_sysctl.conf /etc/sysctl.conf
mv:是否覆盖"/etc/sysctl.conf"? y
[root@localhost ~]# cat /etc/sysctl.conf
# System default settings live in /usr/lib/sysctl.d/00-system.conf.
# To override those settings, enter new settings here, or in an /etc/sysctl.d/.conf file
#
# For more information, see sysctl.conf(5) and sysctl.d(5).
vm.max_map_count=262144
[root@localhost ~]# sysctl -p
vm.max_map_count = 262144
2)配置文件修改
从网上复制的配置文件,可能存在问题。可以重新start容器,docker start 容器 -a 或者docker logs -f -t –tail=10 容器名,看启动信息,分析具体出错的原因。
下一篇讲解安装head插件安装。