【原创】Ubuntu 18.04 x64 使用 Docker 安装 ES 6.7.0 集群

安装准备

1、相关环境

Ubuntu 18.04 x64

Docker 19.03

ElasticSearch 6.7.0

Kibana 6.7.0

2、安装规划

使用 Docker 安装三个节点的 Elasticsearch 集群并安装对应版本的 Kibana。

3、安装用户

全程使用一个具有 sudo 权限的普通用户 jiangzl 完成,不建议直接使用 root 安装。

安装步骤

1、创建网络

sudo docker network create elk

用于同一网络的服务连接,如 ES 集群节点间的网络发现,Kibana 连接到 ES 集群都很方便。

2、安装 ElasticSearch

  • 拉取镜像

sudo docker pull elasticsearch:6.7.0
  • 创建相关目录

在 Ubuntu /home/{username} 目录下创建 elasticsearch 根目录

cd ~
mkdir -p elk/elasticsearch

创建配置文件目录,存放 ES 配置文件

cd elk/elasticsearch
mkdir config 

创建数据文件目录,用于存储 ES 数据

mkdir data1 data2 data3

创建插件目录,用于存放 ES 插件

mkdir plugins1 plugins2 plugins3
  • 添加配置

cd config 
vi elasticsearch1.yml

在 $ES_HOME/config 下分别添加三个配置文件 elasticsearch1.yml,elasticsearch2.yml,elasticsearch3.yml,内容如下所示:

elasticsearch1.yml

cluster.name: elasticsearch-cluster
node.name: es-node1
network.bind_host: 0.0.0.0
network.publish_host: ES01
http.port: 9201
transport.tcp.port: 9301
http.cors.enabled: true
http.cors.allow-origin: "*"
node.master: true 
node.data: true  
discovery.zen.ping.unicast.hosts: ["ES01:9301", "ES02:9301", "ES03:9301"]
discovery.zen.minimum_master_nodes: 1

elasticsearch2.yml

cluster.name: elasticsearch-cluster
node.name: es-node2
network.bind_host: 0.0.0.0
network.publish_host: ES02
http.port: 9201
transport.tcp.port: 9301
http.cors.enabled: true
http.cors.allow-origin: "*"
node.master: true 
node.data: true  
discovery.zen.ping.unicast.hosts: ["ES01:9301", "ES02:9301", "ES03:9301"]
discovery.zen.minimum_master_nodes: 1

elasticsearch3.yml

cluster.name: elasticsearch-cluster
node.name: es-node3
network.bind_host: 0.0.0.0
network.publish_host: ES03
http.port: 9201
transport.tcp.port: 9301
http.cors.enabled: true
http.cors.allow-origin: "*"
node.master: true 
node.data: true  
discovery.zen.ping.unicast.hosts: ["ES01:9301", "ES02:9301", "ES03:9301"]
discovery.zen.minimum_master_nodes: 1

配置示例截图如下:

  • 运行 ES 容器

ES01:

sudo docker run \
-e ES_JAVA_OPTS="-Xms2g -Xmx2g" -d \
-p 9201:9201 -p 9301:9301 \
--net elk \
-v ~/elk/elasticsearch/config/elasticsearch1.yml:/usr/share/elasticsearch/config/elasticsearch.yml \
-v ~/elk/elasticsearch/plugins1:/usr/share/elasticsearch/plugins \
-v ~/elk/elasticsearch/data1:/usr/share/elasticsearch/data \
--name ES01 elasticsearch:6.7.0

ES02:

sudo docker run \
-e ES_JAVA_OPTS="-Xms2g -Xmx2g" -d \
--net elk \
-p 9202:9201 -p 9302:9301 \
-v ~/elk/elasticsearch/config/elasticsearch2.yml:/usr/share/elasticsearch/config/elasticsearch.yml \
-v ~/elk/elasticsearch/plugins2:/usr/share/elasticsearch/plugins \
-v ~/elk/elasticsearch/data2:/usr/share/elasticsearch/data \
--name ES02 elasticsearch:6.7.0

ES03:

sudo docker run \
-e ES_JAVA_OPTS="-Xms2g -Xmx2g" -d  \
--net elk \
-p 9203:9201 -p 9303:9301 \
-v ~/elk/elasticsearch/config/elasticsearch3.yml:/usr/share/elasticsearch/config/elasticsearch.yml \
-v ~/elk/elasticsearch/plugins3:/usr/share/elasticsearch/plugins \
-v ~/elk/elasticsearch/data3:/usr/share/elasticsearch/data \
--name ES03 elasticsearch:6.7.0

注:如果在 Ubuntu 上运行 docker ES 容器时报错如下:

sudo docker logs ES01
...
ERROR: [1] bootstrap checks failed
[1]: max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]
...

原因:

Ubuntu 主机默认的最大虚拟内存太小

解决方案:

修改配置文件 sysctl.conf

sudo vi /etc/sysctl.conf

添加下面配置:

vm.max_map_count=655360

并执行命令:

sysctl -p

然后重新启动 elasticsearch,即可启动成功。

sudo docker restart ES01 ES02 ES03
  • 验证安装

a、验证端口访问是否正常

http://localhost:9201/
http://localhost:9202/
http://localhost:9203/

b、查看集群各节点是否正常

http://localhost:9201/_cat/nodes

3、安装 Kibana

  • 拉取镜像

sudo docker pull kibana:6.7.0
  • 运行容器

sudo docker run -d --name kibana --net elk -p 5601:5601 kibana:6.7.0

此时应该会报错,原因是还没有配置 Elasticsearch 集群的信息,kibana 生成的默认配置文件 kibana.yml 中 elasticsearch.hosts: [ “http://elasticsearch:9200/” ],因此需要更新此项配置

sudo docker logs kibana

{"type":"log","@timestamp":"2020-08-27T06:13:14Z","tags":["warning","elasticsearch","admin"],"pid":1,"message":"Unable to revive connection: http://elasticsearch:9200/"}
{"type":"log","@timestamp":"2020-08-27T06:13:14Z","tags":["warning","elasticsearch","admin"],"pid":1,"message":"No living connections"}
{"type":"log","@timestamp":"2020-08-27T06:13:15Z","tags":["warning","elasticsearch","admin"],"pid":1,"message":"Unable to revive connection: http://elasticsearch:9200/"}
{"type":"log","@timestamp":"2020-08-27T06:13:15Z","tags":["warning","elasticsearch","admin"],"pid":1,"message":"No living connections"}
{"type":"log","@timestamp":"2020-08-27T06:13:15Z","tags":["warning","task_manager"],"pid":1,"message":"PollError No Living connections"}
{"type":"log","@timestamp":"2020-08-27T06:13:16Z","tags":["warning","elasticsearch","admin"],"pid":1,"message":"Unable to revive connection: http://elasticsearch:9200/"}
{"type":"log","@timestamp":"2020-08-27T06:13:16Z","tags":["warning","elasticsearch","admin"],"pid":1,"message":"No living connections"}
{"type":"log","@timestamp":"2020-08-27T06:13:17Z","tags":["warning","elasticsearch","admin"],"pid":1,"message":"Unable to revive connection: http://elasticsearch:9200/"}
{"type":"log","@timestamp":"2020-08-27T06:13:17Z","tags":["warning","elasticsearch","admin"],"pid":1,"message":"No living connections"}
{"type":"log","@timestamp":"2020-08-27T06:13:17Z","tags":["warning","elasticsearch","admin"],"pid":1,"message":"Unable to revive connection: http://elasticsearch:9200/"}
{"type":"log","@timestamp":"2020-08-27T06:13:17Z","tags":["warning","elasticsearch","admin"],"pid":1,"message":"No living connections"}
{"type":"log","@timestamp":"2020-08-27T06:13:17Z","tags":["warning","elasticsearch","admin"],"pid":1,"message":"Unable to revive connection: http://elasticsearch:9200/"}
{"type":"log","@timestamp":"2020-08-27T06:13:17Z","tags":["warning","elasticsearch","admin"],"pid":1,"message":"No living connections"}

进入容器

sudo docker exec -it kibana bash
  • 更新配置

cd config
vi kibana.yml

elasticsearch.hosts 更新为如下配置即可

#
# ** THIS IS AN AUTO-GENERATED FILE **
#
# Default Kibana configuration for docker target
server.name: kibana
server.host: "0"
elasticsearch.hosts: [ "http://ES01:9201", "http://ES02:9201", "http://ES03:9201" ]
# xpack.monitoring.ui.container.elasticsearch.enabled: true

保存退出

exit

提交新的 Image

sudo docker commit kibana kibana_v0.1

停止旧容器

sudo docker stop kibana

删除旧容器

sudo docker rm kibana

重新运行 Kibana

sudo docker run -d --name kibana --net elk -p 5601:5601 kibana_v0.1
  • 验证 Kibana

安装完成!

附录

常用命令

sudo docker start ES01 ES02 ES03 kibana    # 启动 ES 集群及 Kibana
sudo docker stop ES01 ES02 ES03 kibana    # 停止 ES 集群及 Kibana
sudo docker restart ES01 ES02 ES03 kibana    # 重启 ES 集群及 Kibana

注: ES01、ES02、ES03 分别代表 elasticsearch 三个容器的容器名称(container name),kibana 代表 Kibana 容器的容器名称,这些名称均是在运行容器(sudo docker run)时通过 –name 参数指定的。

参考:

https://www.elastic.co/guide/en/elasticsearch/reference/6.7/docker.html

https://blog.csdn.net/belonghuang157405/article/details/83301937

https://blog.csdn.net/weixin_42047790/article/details/90677996

https://www.cnblogs.com/fbtop/p/11005469.html

https://www.cnblogs.com/lisongyu/p/12602539.html

You may also like...

发表评论

电子邮件地址不会被公开。 必填项已用*标注

%d 博主赞过: