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等文件,点击查看安装最后启动步骤

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

sunywz

~

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值