Elasticsearch(002):分布式集群搭建、管理之ES集群搭建与配置---2019最新版

在JDK环境配置好的情况,我们接下来的安装和配置Elasticsearch集群了。

我们后续的文章采用的Es的版本都是6.5.4版本。

1. 下载ES、Kibana、LogStash的安装包

elasticsearch-6.5.4.tar.gz
kibana-6.5.4-linux-x86_64.tar.gz
logstash-6.5.4.tar.gz

2. 将上述的安装包上传到服务器应的安装目录上

名称    服务路径(不存在文件使用mkdir命令进行创建即可)
es  --->  /usr/es/node-01
es  --->  /usr/es/node-02
es  --->  /usr/es/node-03
kibana  --->  /usr/kibana
logstash  --->  /usr/logstashll

3. 分别解压上述文件

tar -zxvf elasticsearch-6.5.4.tar.gz
tar -zxvf kibana-6.5.4-linux-x86_64.tar.gz
tar -zxvf logstash-6.5.4.tar.gz

4. 分别配置每个节点的ES配置

整体的方案是以同一台服务器三个不同的端口来模拟3个ES节点组成一个高可用高并发的集群为例。

这里以node-01节点为例,其他两个节点进行类似操作

  1. 修改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.0.1
#
# 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: 
#
# 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

修改后的内容(我写注释都是进行了修改,依照此进行修改即可)

# ======================== 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
#配置集群名称 三台服务器保持一致
cluster.name: adam-es-server
#
# ------------------------------------ Node ------------------------------------
#
# Use a descriptive name for the node:
#
#node.name: node-1
#配置单一节点名称,每个节点唯一标识
node.name: node-01
#
# Add custom attributes to the node:
#
#node.attr.rack: r1
#
#指定该节点是否有资格被选举成为master结点,默认是true,如果原来的master宕机会重新选举新的master。
node.master: true
#指定该节点是否存储索引数据,默认为true
node.data: true
node.ingest: true  #默认true
# ----------------------------------- Paths ------------------------------------
#
# Path to directory where to store the data (separate multiple locations by comma):
#
#path.data: /path/to/data
# 配置ES数据储存的路径,根据自己的实际路径进行调整
path.data: /usr/es/node-01/elasticsearch-6.5.4/data
#
# Path to log files:
#
#path.logs: /path/to/logs
# 配置ES日志数据储存的路径,根据自己的实际路径进行调整
path.logs: /usr/es/node-01/elasticsearch-6.5.4/logs
#
# ----------------------------------- Memory -----------------------------------
#
# Lock the memory on startup:
#
#bootstrap.memory_lock: true
# 设置为true可以锁住ES使用的内存,避免内存与swap分区交换数据
bootstrap.memory_lock: false
#
# 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.0.1
# 设置绑定的ip地址,0.0.0.0表示任何网络均可连接。身生产环境不推荐这样配置,推荐配置成具体的ip
network.host: 0.0.0.0
#
# Set a custom port for HTTP:
#
#http.port: 9200
#端口:三个节点分别是9200 9201 9202
http.port: 9200
#
# For more information, consult the network module documentation.
#
#集群结点之间通信端口
transport.tcp.port: 9300
# --------------------------------- 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"]
#设置集群中master节点的初始列表
discovery.zen.ping.unicast.hosts: ["0.0.0.0:9300", "0.0.0.0:9301", "0.0.0.0:9302"]
#
# Prevent the "split brain" by configuring the majority of nodes (total number of master-eligible nodes / 2 + 1):
#
#discovery.zen.minimum_master_nodes: 
#主结点数量的最少值 ,此值的公式为:(master_eligible_nodes / 2) + 1 ,比如:有3个符合要求的主结点,那么这里要设置为2
discovery.zen.minimum_master_nodes: 2
#单机允许的最大存储结点数,通常单机启动一个结点建议设置为1,开发环境如果单机启动多个节点可设置大于1.
node.max_local_storage_nodes: 2
#
# 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
# 下面两行配置为haad插件配置,三台服务器一致。
http.cors.enabled: true
http.cors.allow-origin: /.*/

5. 创建新用户提供给ES使用

由于ES不能使用root账号使用,不然启动会报错,Exception in thread "main" java.lang.RuntimeException: don't run elasticsearch as root.
所以我们必须新建一个用户给ES使用。

#添加es用户
useradd es
#给es用户授权目录权限
chown es:es -R /usr/es/

6. 启动es服务

切换到es用户,使用命令依次启动node-01、node-02、node-03

su es
# 进入bin目录
./elasticsearch # 添加 -d 表示后台启动

在浏览器中输入http://192.168.91.131:9200/ http://192.168.91.131:9201/ http://192.168.91.131:9202/发现能够正常返回节点信息

到此集群的安装到此大功告成!!

发布了158 篇原创文章 · 获赞 147 · 访问量 27万+

猜你喜欢

转载自blog.csdn.net/weixin_39723544/article/details/103238833