Elasticsearch-03 CentOS7 / Windows上部署Elasticsearch5.6.16集群模式

版权声明:【show me the code ,change the world】 https://blog.csdn.net/yangshangwei/article/details/89392662

概述

Elasticsearch-01CentOS7单节点部署ES5.6.16中我们学习了ES单节点的部署,这里我们来看下ES集群是如何部署的吧

CentOS上部署ES集群

集群组成

  • 节点数量: 3个 (1个Master 2个Slave)
  • OS: CentOS 7
  • IP: 192.168.91.128
  • port : master-9200 slave01-8200 slave02-7200

方便起见,先按照伪集群模式部署吧,在同一台主机上使用不同的端口来区分不同的节点,当然了你也可以使用3台虚机,那是最好不过的了


关键配置信息

必须保证集群名相同,如果节点处于同一局域网同一网段,es会自动去发现其他的节点。

elasticsearch.yml

Master


# 绑定的服务器IP,可设置为本机IP
network.host: 192.168.91.128
#启动的端口,默认9200  
http.port: 9200
 
#跨域设置
http.cors.enabled: true
http.cors.allow-origin: "*"
 
#集群信息
cluster.name: artisan
node.name: master
node.master: true

其他配置,也可以按需修改


Slave01:

#host 和 端口
network.host: 192.168.91.128
http.port: 8200

#集群信息
cluster.name: artisan
node.name: slave01
#默认的通讯接口是9300,用来发现master信息
discovery.zen.ping.unicast.hosts: ["192.168.91.128:9300"]

Slave02:

#host 和 端口
network.host: 192.168.91.128
http.port: 7200

#集群信息
cluster.name: artisan
node.name: slave02
#默认的通讯接口是9300,用来发现master信息
discovery.zen.ping.unicast.hosts: ["192.168.91.128:9300"]

Master节点搭建

修改elasticsearch.yml中的配置

# ======================== Elasticsearch Configuration =========================
#
# NOTE: Elasticsearch comes with reasonable defaults for most settings.
#       Before you set out to tweak and tune the configuration, make sure you
#       understand what are you trying to accomplish and the consequences.
#
# The primary way of configuring a node is via this file. This template lists
# the most important settings you may want to configure for a production cluster.
#
# Please consult the documentation for further information on configuration options:
# https://www.elastic.co/guide/en/elasticsearch/reference/index.html
#
# ---------------------------------- Cluster -----------------------------------
#
# Use a descriptive name for your cluster:
#
#cluster.name: my-application
#
# ------------------------------------ Node ------------------------------------
#
# Use a descriptive name for the node:
#
#node.name: node-1
#
# Add custom attributes to the node:
#
#node.attr.rack: r1
#
# ----------------------------------- Paths ------------------------------------
#
# Path to directory where to store the data (separate multiple locations by comma):
#
#path.data: /path/to/data
#
# Path to log files:
#
#path.logs: /path/to/logs
#
# ----------------------------------- Memory -----------------------------------
#
# Lock the memory on startup:
#
#bootstrap.memory_lock: true
#
# Make sure that the heap size is set to about half the memory available
# on the system and that the owner of the process is allowed to use this
# limit.
#
# Elasticsearch performs poorly when the system is swapping the memory.
#
# ---------------------------------- Network -----------------------------------
#
# Set the bind address to a specific IP (IPv4 or IPv6):
#
network.host: 192.168.91.128
#
# Set a custom port for HTTP:
#
http.port: 9200
#
# For more information, consult the network module documentation.
#
# --------------------------------- Discovery ----------------------------------
#
# 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]"]
#
#discovery.zen.ping.unicast.hosts: ["host1", "host2"]
#
# Prevent the "split brain" by configuring the majority of nodes (total number of master-eligible nodes / 2 + 1):
#
#discovery.zen.minimum_master_nodes: 3
#
# For more information, consult the zen discovery module documentation.
#
# ---------------------------------- Gateway -----------------------------------
#
# Block initial recovery after a full cluster restart until N nodes are started:
#
#gateway.recover_after_nodes: 3
#
# For more information, consult the gateway module documentation.
#
# ---------------------------------- Various -----------------------------------
#
# Require explicit names when deleting indices:
#
#action.destructive_requires_name: true
#
#跨域设置
http.cors.enabled: true
http.cors.allow-origin: "*"
#集群信息
cluster.name: artisan
node.name: master
node.master: true

通过head插件访问集群信息
在这里插入图片描述

可以看到 节点名字已经变成了master, 并且前面的五角星表示为master节点(指挥官) 。


Slave1节点搭建

复制一份,然后修改配置文件

[root@localhost ~]# su - elastic 
Last login: Thu Apr 18 08:47:46 PDT 2019 on pts/1
[elastic@localhost ~]$ pwd
/home/elastic
[elastic@localhost ~]$ ll
total 33108
drwxr-xr-x. 9 elastic elastic     4096 Apr 18 03:30 elasticsearch-5.6.16
-rw-r--r--. 1 root    root    33894983 Apr 18 03:27 elasticsearch-5.6.16.tar.gz
[elastic@localhost ~]$ 
[elastic@localhost ~]$ 
[elastic@localhost ~]$ mkdir elasticsearch-5.6.16-salve
[elastic@localhost ~]$ cp elasticsearch-5.6.16.tar.gz elasticsearch-5.6.16-salve/
[elastic@localhost ~]$ cd elasticsearch-5.6.16-salve/
[elastic@localhost elasticsearch-5.6.16-salve]$ ll
total 33104
-rw-r--r--. 1 elastic elastic 33894983 Apr 18 18:28 elasticsearch-5.6.16.tar.gz
[elastic@localhost elasticsearch-5.6.16-salve]$ tar -xvzf elasticsearch-5.6.16.tar.gz 

[elastic@localhost elasticsearch-5.6.16-salve]$ cp -r  elasticsearch-5.6.16  elasticsearch-slave01
[elastic@localhost elasticsearch-5.6.16-salve]$ cp -r  elasticsearch-5.6.16  elasticsearch-slave02


[elastic@localhost elasticsearch-5.6.16-salve]$ cd elasticsearch-slave01

[elastic@localhost elasticsearch-slave01]$ vim config/elasticsearch.yml 



elasticsearch.yml 追加如下配置

#host 和 端口
network.host: 192.168.91.128
http.port: 8200

#集群信息
cluster.name: artisan
node.name: slave01
#默认的通讯接口是9300,找到集群的信
discovery.zen.ping.unicast.hosts: ["192.168.91.128:9300"]

Slave2节点搭建

[elastic@localhost elasticsearch-5.6.16-salve]$ cd elasticsearch-slave02

elasticsearch.yml 追加如下配置

#host 和 端口
network.host: 192.168.91.128
http.port: 7200

#集群信息
cluster.name: artisan
node.name: slave02
#默认的通讯接口是9300,用来发现master信息
discovery.zen.ping.unicast.hosts: ["192.168.91.128:9300"]

我这里用的虚机的内存太小了,无法启动两个及两个以上的节点, 为了验证配置的正确性,windows上部署下吧


Windows 部署 ES集群

三个节点:

在这里插入图片描述


elasticsearch.yml配置修改

elasticsearch.yml的配置如下:

和centos中的配置一样,仅仅是IP不同

master:

# 绑定的服务器IP,可设置为本机IP
network.host: 127.0.0.1
#启动的端口,默认9200  
http.port: 9200
 
#跨域设置
http.cors.enabled: true
http.cors.allow-origin: "*"
 
#集群信息
cluster.name: artisan
node.name: master
node.master: true

在这里插入图片描述


salve01:

#host 和 端口
network.host: 127.0.0.1
http.port: 8200

#集群信息
cluster.name: artisan
node.name: slave01
#默认的通讯接口是9300,用来发现master信息
discovery.zen.ping.unicast.hosts: ["127.0.0.1:9300"]

在这里插入图片描述


slave02:

#host 和 端口
network.host: 127.0.0.1
http.port: 7200

#集群信息
cluster.name: artisan
node.name: slave02
#默认的通讯接口是9300,用来发现master信息
discovery.zen.ping.unicast.hosts: ["127.0.0.1:9300"]

在这里插入图片描述


启动服务

双击H:\elasticsearch-5.6.16-slave02\bin\elasticsearch.bat
在这里插入图片描述

通过head 插件查看 集群信息
在这里插入图片描述

配置OK


注意事项

found existing node {master}{xdHjXCdET_e7M0G_MYNiTQ}{WbXaI8HtRDCbFEzS8VtdIg}{127.0.0.1}{127.0.0.1:9300} with the same id but is a different node instance];

如果配到了这种错误,很明显id重复了,如果配置没有问题,看下你是不是直接copy的已经存在的节点data目录中的数据重复导致的。 建议解压一个新的压缩包,重新配置,避免上述错误。

猜你喜欢

转载自blog.csdn.net/yangshangwei/article/details/89392662
今日推荐