0%

ubuntu下搭建elasticsearch集群

在Ubuntu 18.04.1 LTS搭建一个简单的elasticsearch集群demo,具体情况如下:

集群名称:elasticsearch-cluster-demo
主节点:1个 node-master-one
数据节点:2个 node-data-one、node-data-two
客户端节点:1个 node-client-one

elasticsearch 安装

elasticsearch 的安装可以点击参考文章:
ubuntu下安装elasticsearch

拷贝几个es安装包文件夹,进行相应节点的命名,再进行后续的修改配置。

基本集群配置

node-master-one

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
# 集群名称
cluster.name: elasticsearch-cluster-demo
#
# 节点信息
node.name: node-master-one
node.master: true
node.data: false
#
# Path to directory where to store the data (separate multiple locations by comma):
# es data 存储路径
path.data: /home/environment/elasticsearch-cluster/elasticsearch-master-one/data
#
# Path to log files:
# log存储路径
path.logs: /home/environment/elasticsearch-cluster/elasticsearch-master-one/logs
#
# Set the bind address to a specific IP (IPv4 or IPv6):
# 网路监听
network.host: 0.0.0.0
http.port: 9200
transport.tcp.port: 9300
#
# Pass an initial list of hosts to perform discovery when new node is started:
# The default list of hosts is ["127.0.0.1", "[::1]"]
# 可以发现当前节点的主节点ip:port
discovery.zen.ping.unicast.hosts: ["127.0.0.1:9300"]
#
# Prevent the "split brain" by configuring the majority of nodes (total number of master-eligible nodes / 2 + 1):
# 集群最小主节点个数
#discovery.zen.minimum_master_nodes: 2
#
# 设置跨域问题,方便使用elasticsearch-head来检测集群状态
http.cors.enabled: true
http.cors.allow-origin: /.*/

node-data-one

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
# 集群名称
cluster.name: elasticsearch-cluster-demo
#
# 节点信息
node.name: node-data-one
node.master: false
node.data: true
#
# Path to directory where to store the data (separate multiple locations by comma):
# es data 存储路径
path.data: /home/environment/elasticsearch-cluster/elasticsearch-data-one/data
#
# Path to log files:
# log存储路径
path.logs: /home/environment/elasticsearch-cluster/elasticsearch-data-one/logs
#
# Set the bind address to a specific IP (IPv4 or IPv6):
# 网路监听
network.host: 0.0.0.0
http.port: 9210
transport.tcp.port: 9310
#
# Pass an initial list of hosts to perform discovery when new node is started:
# The default list of hosts is ["127.0.0.1", "[::1]"]
# 可以发现当前节点的主节点ip:port
discovery.zen.ping.unicast.hosts: ["127.0.0.1:9300"]
#
# Prevent the "split brain" by configuring the majority of nodes (total number of master-eligible nodes / 2 + 1):
# 集群最小主节点个数
#discovery.zen.minimum_master_nodes: 2
#
# 设置跨域问题,方便使用elasticsearch-head来检测集群状态
http.cors.enabled: true
http.cors.allow-origin: /.*/

node-data-two

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
# 集群名称
cluster.name: elasticsearch-cluster-demo
#
# 节点信息
node.name: node-data-two
node.master: false
node.data: true
#
# Path to directory where to store the data (separate multiple locations by comma):
# es data 存储路径
path.data: /home/environment/elasticsearch-cluster/elasticsearch-data/two/data
#
# Path to log files:
# log存储路径
path.logs: /home/environment/elasticsearch-cluster/elasticsearch-data-two/logs
#
# Set the bind address to a specific IP (IPv4 or IPv6):
# 网路监听
network.host: 0.0.0.0
http.port: 9211
transport.tcp.port: 9311
#
# Pass an initial list of hosts to perform discovery when new node is started:
# The default list of hosts is ["127.0.0.1", "[::1]"]
# 可以发现当前节点的主节点ip:port
discovery.zen.ping.unicast.hosts: ["127.0.0.1:9300"]
#
# Prevent the "split brain" by configuring the majority of nodes (total number of master-eligible nodes / 2 + 1):
# 集群最小主节点个数
#discovery.zen.minimum_master_nodes: 2
#
# 设置跨域问题,方便使用elasticsearch-head来检测集群状态
http.cors.enabled: true
http.cors.allow-origin: /.*/

node-client-one

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
# 集群名称
cluster.name: elasticsearch-cluster-demo
#
# 节点信息
node.name: node-client-one
node.master: false
node.data: false
#
# Path to directory where to store the data (separate multiple locations by comma):
# es data 存储路径
path.data: /home/environment/elasticsearch-cluster/elasticsearch-client-one/data
#
# Path to log files:
# log存储路径
path.logs: /home/environment/elasticsearch-cluster/elasticsearch-client-one/logs
#
# Set the bind address to a specific IP (IPv4 or IPv6):
# 网路监听
network.host: 0.0.0.0
http.port: 9220
transport.tcp.port: 9320
#
# Pass an initial list of hosts to perform discovery when new node is started:
# The default list of hosts is ["127.0.0.1", "[::1]"]
# 可以发现当前节点的主节点ip:port
discovery.zen.ping.unicast.hosts: ["127.0.0.1:9300"]
#
# Prevent the "split brain" by configuring the majority of nodes (total number of master-eligible nodes / 2 + 1):
# 集群最小主节点个数
#discovery.zen.minimum_master_nodes: 2
#
# 设置跨域问题,方便使用elasticsearch-head来检测集群状态
http.cors.enabled: true
http.cors.allow-origin: /.*/

集群状态检测

当对每一个es节点的配置修改完以后,便可以启动每个节点,在主节点启动后,便可以使用elasticsearch-head来检测es的集群状态,也可以通过查看es的日志来查看节点自动加入集群的情况。

elasticsearch-head项目托管在github上,安装方式可见项目主页的README.txtile文件。项目地址如下:

https://github.com/mobz/elasticsearch-head

安装成功后,在接入输入要连接的集群的某一个主节点的ip与端口,连接成功后即可看见该集群的状态,如下图所示:

cluster-health