修改配置文件elasticsearch文件下的config文件夹下的elasticserach.yml文件
编辑elasticsearch.yml

vim /elasticsearch.yml

配置说明

cluster.name: aubin-cluster     #必须相同 
# 集群名称(不能重复)
node.name: els1(必须不同)
# 节点名称,仅仅是描述名称,用于在日志中区分(自定义)
#指定了该节点可能成为 master 节点,还可以是数据节点
    node.master: true
    node.data: true
path.data: /opt/data
# 数据的默认存放路径(自定义)
path.logs: /opt/logs 
# 日志的默认存放路径 
network.host: 192.168.0.1 
# 当前节点的IP地址 
http.port: 9200 
# 对外提供服务的端口
transport.tcp.port: 9300
#9300为集群服务的端口 
discovery.zen.ping.unicast.hosts: ["172.18.68.11", "172.18.68.12","172.18.68.13"] 
# 集群个节点IP地址,也可以使用域名,需要各节点能够解析 
discovery.zen.minimum_master_nodes: 2 
# 为了避免脑裂,集群节点数最少为 半数+1

配置如图,同理每个elasticsearch配置原理都一样
Linux Centos7搭建Elasticsearch集群详细教程1.png
Linux Centos7搭建Elasticsearch集群详细教程2.png
参考配置

# ======================== 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: aubin-cluster
#
# ------------------------------------ Node ------------------------------------
#
# Use a descriptive name for the node:
#
node.name: es1
#
# Add custom attributes to the node:
#
#node.attr.rack: r1
#
# ----------------------------------- Paths ------------------------------------
#
# Path to directory where to store the data (separate multiple locations by comma):
#
node.master: true
node.data: true
path.data: /opt/data

#path.data: /path/to/data
#
# Path to log files:
#
path.logs: /opt/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.153.134
#
# Set a custom port for HTTP:
#
http.port: 9200
transport.tcp.port: 9300
#
# 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: ["192.168.153.139"]
#
# Prevent the "split brain" by configuring the majority of nodes (total number of master-eligible nodes / 2 + 1):
#
discovery.zen.minimum_master_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

这里需要创建/opt/data/opt/logs文件夹,注意:清空datalogs数据

mkdir /opt

进入opt

cd /opt

创建data

mkdir data

创建logs

mkdir logs

给/opt中的datalogs

chmod 777 data

赋权限logs

chmod 777 logs

然后进入到elasticsearch/bin目录下切换用户(注意:root用户启动报错)

启动elasticsearch

./elasticsearch

访问:192.168.153.134:9200/_cat/nodes?v
Linux Centos7搭建Elasticsearch集群详细教程3.png

Last modification:October 23, 2019
如果觉得这篇技术文章对你有用,请随意赞赏