Elasticsearch-分布式集群搭建

关于分布式与单机的区别及优势我们不一一赘述了,在redis,nginx,mysql中,我都有说过。但是分布式ES的特性还是需要详细了解的,于是我在网上找到了一个不错的博文,比我讲得好,所以直接引用过来:

Elasticsearch 分布式特性(集群、节点、分片)
所以这里我们直接进行搭建分布式ES。

1.按照前面的章节安装的ES进行克隆出3台服务器,分别修改ip,主机名:

#### elasticsearch-1
eth0:10.0.0.221
eth1:172.16.1.221


#### elasticsearch-2
eth0:10.0.0.222
eth1:172.16.1.222


#### elasticsearch-3
eth0:10.0.0.223
eth1:172.16.1.223

2.当克隆以后,清空es中的data目录,这里面包含了原先的索引库数据。

[root@elasticsearch-1 ~]# cd /application/elasticsearch-7.6.1/data/
[root@elasticsearch-1 data]# ll
total 0
drwxrwxr-x 3 esuser esuser 15 Mar 26 09:19 nodes
[root@elasticsearch-1 data]# rm -rf nodes/
 

3.分别修改Elasticsearch.yml文件:

#### elasticsearch-1

------- Cluster -------
cluster.name: elasticsearch-cluster
node.name: es-node1               ######只有这里不一样

------- Network -------
http.cors.enabled: true
http.cors.allow-origin: "*"
node.master: true
node.data: true

------ Discovery ------
discovery.seed_hosts: ["172.16.1.221", "172.16.1.222","172.16.1.223"]
cluster.initial_master_nodes: ["es-node1"]

#### elasticsearch-2

------- Cluster -------
cluster.name: elasticsearch-cluster
node.name: es-node2               ######只有这里不一样

------- Network -------
http.cors.enabled: true
http.cors.allow-origin: "*"
node.master: true
node.data: true

------ Discovery ------
discovery.seed_hosts: ["172.16.1.221", "172.16.1.222","172.16.1.223"]
cluster.initial_master_nodes: ["es-node1"]

#### elasticsearch-3

------- Cluster -------
cluster.name: elasticsearch-cluster
node.name: es-node3               ######只有这里不一样

------- Network -------
http.cors.enabled: true
http.cors.allow-origin: "*"
node.master: true
node.data: true

------ Discovery ------
discovery.seed_hosts: ["172.16.1.221", "172.16.1.222","172.16.1.223"]
cluster.initial_master_nodes: ["es-node1"]

最后对比一下三台服务器的配置

####elasticsearch-2####
[root@elasticsearch-1 config]# more elasticsearch.yml |grep ^[^#]
cluster.name: elasticsearch-cluster
node.name: es-node1
path.data: /application/elasticsearch-7.6.1/data
path.logs: /application/elasticsearch-7.6.1/logs
network.host: 0.0.0.0
http.cors.enabled: true
http.cors.allow-origin: "*"
node.master: true
node.data: true
discovery.seed_hosts: ["172.16.1.221", "172.16.1.222","172.16.1.223"]
cluster.initial_master_nodes: ["es-node1"]
[root@elasticsearch-1 config]# 



####elasticsearch-2####
[root@elasticsearch-2 config]# more elasticsearch.yml |grep ^[^#]
cluster.name: elasticsearch-cluster
node.name: es-node2
path.data: /application/elasticsearch-7.6.1/data
path.logs: /application/elasticsearch-7.6.1/logs
network.host: 0.0.0.0
http.cors.enabled: true
http.cors.allow-origin: "*"
node.master: true
node.data: true
discovery.seed_hosts: ["172.16.1.221", "172.16.1.222","172.16.1.223"]
cluster.initial_master_nodes: ["es-node1"]
[root@elasticsearch-2 config]# 


####elasticsearch-3####
[root@elasticsearch-3 config]# more elasticsearch.yml |grep ^[^#]
cluster.name: elasticsearch-cluster
node.name: es-node3
path.data: /application/elasticsearch-7.6.1/data
path.logs: /application/elasticsearch-7.6.1/logs
network.host: 0.0.0.0
http.cors.enabled: true
http.cors.allow-origin: "*"
node.master: true
node.data: true
discovery.seed_hosts: ["172.16.1.221", "172.16.1.222","172.16.1.223"]
cluster.initial_master_nodes: ["es-node1"]
[root@elasticsearch-3 config]# 

4.启动三台服务器(需要切换到esuser用户)

[root@elasticsearch-1 elasticsearch-7.6.1]# su esuser
[esuser@elasticsearch-1 elasticsearch-7.6.1]$ bin/elasticsearch

5.分别在浏览器上访问测试分布式集群(10.0.0.221:9200,10.0.0.222:9200,10.0.0.223:9200)

启动es出现错误,需要配置jvm等文件,点击查看安装最后启动步骤

猜你喜欢

转载自blog.csdn.net/qq_31776219/article/details/114691462