elasticsearch配置集群

1、elasticsearch.yml

1.1、这里是该集群的群名 我是直接去掉注释

cluster.name: my-application

1.2、你当前机器在集群中的结点名字,这里我也是直接去掉注释,就是皮

node.name: node-1

1.3、设置此机器master是否可以成为master

node.master: true

1.4、设置此机器是否可以是数据结点

node.data: true

1.5、es数据存储路径,一般该路径,就你解压安装的路径/data,data文件本身就存在的了

path.data: /opt/es/elasticsearch-6.3.1/data

1.6、es日志输出路径,一般该路径,就你解压安装的路径/logs,logs文件本身就存在的了

path.logs: /opt/es/elasticsearch-6.3.1/logs

1.7、设置你对外可以被访问的ip地址

network.host: 192.168.154.4

1.8、设置服务访问端口

http.port: 9200

1.9、设置结点点通讯的tcp端口,因为不涉及客户,所有到达应用层即可

transport.tcp.port: 9300

1.10、设置集群中其他的兄弟姐妹结点

discovery.zen.ping.unicast.hosts: [“192.168.154.3”]

1.11、设置最小的master结点数 根据参考推荐一般设置为nodes / 2 + 1 ,此次集群只有两天机器,所以设置# # 为2/2+1=2

discovery.zen.minimum_master_nodes: 2

1.12、本人的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:
#
# 1、这里是该集群的群名 我是直接去掉注释
cluster.name: my-application
#
# ------------------------------------ Node ------------------------------------
#
# Use a descriptive name for the node:
# 2、你当前机器在集群中的结点名字,这里我也是直接去掉注释,就是皮
node.name: node-1
#
# Add custom attributes to the node:
#
# node.attr.rack: r1
# 3、设置此机器master是否可以成为master
node.master: true
# 4、设置此机器是否可以是数据结点
node.data: true
#
# ----------------------------------- Paths ------------------------------------
#
# Path to directory where to store the data (separate multiple locations by comma):
#
# 5、es数据存储路径,一般该路径,就你解压安装的路径/data,data文件本身就存在的了
path.data: /opt/es/elasticsearch-6.3.1/data
#
# Path to log files:
# 
# 6、es日志输出路径,一般该路径,就你解压安装的路径/logs,logs文件本身就存在的了
path.logs: /opt/es/elasticsearch-6.3.1/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):
#
# 7、设置你对外可以被访问的ip地址
network.host: 192.168.154.4
#
# Set a custom port for HTTP:
#
# 8、设置服务访问端口
http.port: 9200
# 9、设置结点点通讯的tcp端口,因为不涉及客户,所有到达应用层即可
transport.tcp.port: 9300
#
# For more information, consult the network module documentation.a
#
# --------------------------------- 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]"]
#
# 10、设置集群中其他的兄弟姐妹结点
discovery.zen.ping.unicast.hosts: ["192.168.154.3"]
#
# Prevent the "split brain" by configuring the majority of nodes (total number of master-eligible nodes / 2 + 1):
#
# 11、设置最小的master结点数 根据参考推荐一般设置为nodes / 2 + 1 ,此次集群只有两天机器,所以设置# # 为2/2+1=2
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

2、配置完运行

在./elasticsearch/bin目录下以非root的用户执行 ./elasticsearch
开始运行,首先也要确定是否已经开启过es了,若有先关闭,再打开
关闭es:
1、执行:ps -ef|grep elastic
2、得到进程id 执行:kill -9 psid

2.1、es启动警告

在集群配置中打开其中一台es,es会警告说找不到集群的其他结点,因为其他结点还未启动,第一台启动的机器会不停地向兄弟结点发送心跳。如下图:
在这里插入图片描述

2.2、当集群的机器都启动时,会选举去master

在这里插入图片描述

2.3、可以在浏览器访问并看到集群名字和各自结点名

在这里插入图片描述

3、总结

小小总结,es集群没有中间商赚差价,他本身就是集群的。

4、注意

discovery.zen.minimum_master_nodes:2 若是设置为半数+1,但是集群中启动机器数量不足原定半数+1,则会出现错误 。这时解决方案是调 discovery.zen.minimum_master_nodes: 2 的参数。比如这里discovery.zen.minimum_master_nodes: 2参数为2,若是集群就启动一台机器,则需改2为1。

原创文章 59 获赞 21 访问量 2万+

猜你喜欢

转载自blog.csdn.net/weixin_44185736/article/details/105625487