@Author:By Runsen
原文:https://maoli.blog.csdn.net/article/details/104312880
本文准备搭建三节点 elasticsearch集群,elasticsearch版本:6.5.4,因此这里准备了三台 Linux CentOS 7机器,只需要简单通过Vmware克隆两台CentOS 7机器,并分别设置静态ip即可。
三台 CentOS 7分别启动elasticsearch
NodeName | Web端口 |
---|---|
node-1 | 192.168.92.90:9200 |
node-2 | 192.168.92.91:9200 |
node-3 | 192.168.92.93:9200 |
并将三台Centos7主机名分别设置nodenode01,node02和node03,区别三台centos7机器
#node01主机名设置:
[elsearch@localhost ~]$ hostnamectl set-hostname node01
node01
[elsearch@node01 ~]$ ifconfig
ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.92.90 netmask 255.255.255.0 broadcast 192.168.92.255
inet6 fe80::b889:1772:c306:ef8f prefixlen 64 scopeid 0x20<link>
inet6 fe80::72e0:4da:118d:13d9 prefixlen 64 scopeid 0x20<link>
ether 00:0c:29:07:43:5a txqueuelen 1000 (Ethernet)
RX packets 829 bytes 158380 (154.6 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 634 bytes 116833 (114.0 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
#node02主机名设置:
[elsearch@localhost ~]$ hostnamectl set-hostname node02
node02
[elsearch@node02 ~]$ ifconfig
ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.92.91 netmask 255.255.255.0 broadcast 192.168.92.255
inet6 fe80::b889:1772:c306:ef8f prefixlen 64 scopeid 0x20<link>
ether 00:0c:29:84:99:62 txqueuelen 1000 (Ethernet)
RX packets 2195 bytes 323930 (316.3 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 466 bytes 52037 (50.8 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
#node03主机名设置:
[elsearch@localhost ~]$ hostnamectl set-hostname node03
node03
[elsearch@node03 ~]$ ifconfig
ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.92.92 netmask 255.255.255.0 broadcast 192.168.92.255
inet6 fe80::22a3:7ced:1761:de8e prefixlen 64 scopeid 0x20<link>
inet6 fe80::b889:1772:c306:ef8f prefixlen 64 scopeid 0x20<link>
inet6 fe80::72e0:4da:118d:13d9 prefixlen 64 scopeid 0x20<link>
ether 00:0c:29:c9:f0:22 txqueuelen 1000 (Ethernet)
RX packets 859 bytes 141277 (137.9 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 619 bytes 147363 (143.9 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
下面在三台Centos7机器上对应的elasticsearch.yml
配置集群
[elsearch@node01 elasticsearch-6.5.4]$ vim config/elasticsearch.yml
#node01的配置:
cluster.name: es-itcast-cluster
node.name: node01
#设置node01为主节点
node.master: true
node.data: true
network.host: 0.0.0.0
http.port: 9200
discovery.zen.ping.unicast.hosts: ["192.168.92.90","192.168.92.91","192.168.92.92"] discovery.zen.minimum_master_nodes: 2
http.cors.enabled: true
http.cors.allow-origin: "*"
[elsearch@node02 elasticsearch-6.5.4]$ vim config/elasticsearch.yml
#node02的配置:
cluster.name: es-itcast-cluster
node.name: node02
node.master: true
node.data: true
network.host: 0.0.0.0
http.port: 9200
discovery.zen.ping.unicast.hosts: ["192.168.92.90","192.168.92.91","192.168.92.92"] discovery.zen.minimum_master_nodes: 2
http.cors.enabled: true
http.cors.allow-origin: "*"
[elsearch@node03 elasticsearch-6.5.4]$ vim config/elasticsearch.yml
#node03的配置:
cluster.name: es-itcast-cluster
node.name: node03
node.master: false
node.data: true
network.host: 0.0.0.0
http.port: 9200
discovery.zen.ping.unicast.hosts: ["192.168.92.90","192.168.92.91","192.168.92.92"]
discovery.zen.minimum_master_nodes: 2
http.cors.enabled: true
http.cors.allow-origin: "*"
#分别启动3个节点 bin/elasticsearch
[elsearch@node01 ~]# curl 127.0.0.1:9200
{
"name": "node01",
"cluster_name": "es-itcast-cluster",
"cluster_uuid": "_na_",
"version": {
"number": "6.5.4",
"build_flavor": "default",
"build_type": "tar",
"build_hash": "d2ef93d",
"build_date": "2018-12-17T21:17:40.758843Z",
"build_snapshot": false,
"lucene_version": "7.5.0",
"minimum_wire_compatibility_version": "5.6.0",
"minimum_index_compatibility_version": "5.0.0"
},
"tagline": "You Know, for Search"
}
[elsearch@node02 ~]# curl 127.0.0.1:9200
{
"name": "node02",
"cluster_name": "es-itcast-cluster",
"cluster_uuid": "_na_",
"version": {
"number": "6.5.4",
"build_flavor": "default",
"build_type": "tar",
"build_hash": "d2ef93d",
"build_date": "2018-12-17T21:17:40.758843Z",
"build_snapshot": false,
"lucene_version": "7.5.0",
"minimum_wire_compatibility_version": "5.6.0",
"minimum_index_compatibility_version": "5.0.0"
},
"tagline": "You Know, for Search"
}
[elsearch@node03 ~]# curl 127.0.0.1:9200
{
"name" : "node03",
"cluster_name" : "es-itcast-cluster",
"cluster_uuid" : "_na_",
"version" : {
"number" : "6.5.4",
"build_flavor" : "default",
"build_type" : "tar",
"build_hash" : "d2ef93d",
"build_date" : "2018-12-17T21:17:40.758843Z",
"build_snapshot" : false,
"lucene_version" : "7.5.0",
"minimum_wire_compatibility_version" : "5.6.0",
"minimum_index_compatibility_version" : "5.0.0"
},
"tagline" : "You Know, for Search"
}
访问任何一个节点,判断是否健康:http://192.168.92.90:9200/_cluster/health?pretty
在elasticsearch-head界面管理工具,我们可以看见创建了三节点集群配置成功,
解决方法:查看9300端口是否开放
停止firewall
systemctl stop firewalld.service
解决方法:将在三节点中node.master:true设置2个,设置一个无法体现选举的设置思想。
google 超级久,两个节点的 日志和data 目录没在一个地方
可我没有指定 日志和data 目录,在浪费1个小时多,找到解决方法:删除elasticsearch安装目录的data文件夹