环境准备
- Linux服务器一台(文章中使用系统的是CentOS 7)
- 保证能够连接外网
集群搭建
安装Docker和Docker Compse
使用
yum
安装docker
1
yum -y install docker
安装企业版附加包
1
yum -y install epel-release
安装python-pip(python的一个软件包管理工具)
1
yum -y install python-pip
更新pip
1
pip install --upgrade pip
安装docker-compose
1
pip install docker-compose
验证是否安装成功
1
docker-compose --version
准备工作(必做)
创建用于挂载数据和日志文件的目录,我这里直接在root目录下进行操作了。
1
2
3
4创建用于 数据/日志/配置文件 的目录
mkdir -p /root/elasticsearch/data/{node0,node1,node2}
mkdir -p /root/elasticsearch/logs/{node0,node1,node2}
mkdir -p /root/elasticsearch/config/{node0,node1,node2}修改创建的数据和日志文件挂载目录的权限,否则运行容器的时候会因为权限报错
1
2
3
4我这里图省事,直接777了
chmod 777 /root/elasticsearch/data/* -R
chmod 777 /root/elasticsearch/logs/* -R
chmod 777 /root/elasticsearch/config/* -R修改系统
vm.max_map_count
参数,否则运行会报错1
2echo vm.max_map_count=262144 >> /etc/sysctl.conf
sysctl -p
安装
下载Elasticsearch镜像
1
2我这里使用的是6.6.1的版本
docker pull elasticsearch:6.6.1编写docker-compose.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77version: '3'
services:
elasticsearch-node0:
image: elasticsearch:6.6.1
container_name: elasticsearch-node0
privileged: true
environment:
- cluster.name=elasticsearch-cluster
- node.name=node0
- node.master=true
- node.data=true
- bootstrap.memory_lock=true
- http.cors.enabled=true
- http.cors.allow-origin=*
- "discovery.zen.ping.unicast.hosts=elasticsearch-node0,elasticsearch-node1,elasticsearch-node2"
- "discovery.zen.minimum_master_nodes=2"
ulimits:
memlock:
soft: -1
hard: -1
volumes:
- ./data/node0:/usr/share/elasticsearch/data
- ./logs/node0:/usr/share/elasticsearch/logs
- ./config/node0:/usr/share/elasticsearch/config
ports:
- 9200:9200
- 9300:9300
elasticsearch-node1:
image: elasticsearch:6.6.1
container_name: elasticsearch-node1
privileged: true
environment:
- cluster.name=elasticsearch-cluster
- node.name=node1
- node.master=true
- node.data=true
- bootstrap.memory_lock=true
- http.cors.enabled=true
- http.cors.allow-origin=*
- "discovery.zen.ping.unicast.hosts=elasticsearch-node0,elasticsearch-node1,elasticsearch-node2"
- "discovery.zen.minimum_master_nodes=2"
ulimits:
memlock:
soft: -1
hard: -1
volumes:
- ./data/node1:/usr/share/elasticsearch/data
- ./logs/node1:/usr/share/elasticsearch/logs
- ./config/node0:/usr/share/elasticsearch/config
ports:
- 9201:9200
- 9301:9300
elasticsearch-node2:
image: elasticsearch:6.6.1
container_name: elasticsearch-node2
privileged: true
environment:
- cluster.name=elasticsearch-cluster
- node.name=node2
- node.master=true
- node.data=true
- bootstrap.memory_lock=true
- http.cors.enabled=true
- http.cors.allow-origin=*
- "discovery.zen.ping.unicast.hosts=elasticsearch-node0,elasticsearch-node1,elasticsearch-node2"
- "discovery.zen.minimum_master_nodes=2"
ulimits:
memlock:
soft: -1
hard: -1
volumes:
- ./data/node2:/usr/share/elasticsearch/data
- ./logs/node2:/usr/share/elasticsearch/logs
- ./config/node0:/usr/share/elasticsearch/config
ports:
- 9202:9200
- 9302:9300启动
1
2
3
4启动,启动需要一些时间
docker-compose up -d
重启:docker-compose restart
删除容器: docker-compose rm查看日志
1
2若启动失败,查看日志排错
docker-compose logs
集群信息查看
我这里使用的head
,一款Elasticsearch
的web-ui工具
安装HEAD
安装git(如果已安装可以省略)
1
yum -y install git
安装nodejs(如果已安装可以省略)
1
yum -y install nodejs
拉取HEAD项目(本质是一个前端项目)
1
git clone https://github.com/mobz/elasticsearch-head.git
下载完毕,进入下载的目录中并安装相关依赖
1
2
3cd elasticsearch-head
安装过程可能需要一些时间
npm install运行
1
npm run start
访问
http://{你安装所在机器的IP}:9100
可以看到三个节点,OK!