Elasticsearch集群部署

环境

CentOS Linux release 7.9.2009

elasticsearch 7.11.1

java 1.8

ip地址
192.168.1.151 es1
192.168.1.152 es2
192.168.1.153 es3

下载安装

wget https://mirrors.tuna.tsinghua.edu.cn/elasticstack/7.x/yum/7.11.1/elasticsearch-7.11.1-x86_64.rpm

rpm -irpm  -ivh elasticsearch-7.11.1-x86_64.rpm

主要文件
/etc/elasticsearch/elasticsearch.yml # els的配置文件
/etc/elasticsearch/jvm.options # JVM相关的配置,内存大小等等
/etc/elasticsearch/log4j2.properties # 日志系统定义
/var/lib/elasticsearch # 数据的默认存放位置

集群配置,三个节点都配置

vim /etc/elasticsearch/elasticsearch.yml
p# ======================== 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: es
#
# ------------------------------------ Node ------------------------------------
#
# Use a descriptive name for the node:
#结点名称
node.name: es1-151
#
# 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: /opt/elasticsearch/data
#
# Path to log files:
#
path.logs: /opt/elasticsearch/log
#
# ----------------------------------- 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):
# 设置ES绑定的IP,0.0.0.0 表示由系统指定
# 注意在安装有docker之类的地方,此处必需手动指定主机的IP地址
# 否则会发生注册之后,无法连接的问题。
#
network.host: 0.0.0.0
#
# 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 this node is started:
# The default list of hosts is ["127.0.0.1", "[::1]"]
# 主机发现,这里配置其他的节点主机名称或者IP
# 这个项目中不需要配置自己这台主机的IP,只需要提供其他节点的IP或主机名
# 
# 例如: discovery.seed_hosts: ["192.168.0.128", "192.168.0.129", "192.168.0.130"]
#
discovery.seed_hosts: ["192.168.1.152", "192.168.1.153"]
#
# Bootstrap the cluster using an initial set of master-eligible nodes:
#
# 可选选举为主节点的节点主机名
# 这里需要填入所有主机名称,这里填入了所有的节点
# 表示集群中任何一个节点都可以选举称为主节点
#
cluster.initial_master_nodes: ["192.168.1.151", "192.168.1.152", "192.168.1.153"]
#
# For more information, consult the discovery and cluster formation 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

JVM配置

vim /etc/elasticsearch/jvm.options
-Xms2g                                                  # JVM最大、最小使用内存,生产环境适当调整
-Xmx2g

启动和开机自启

systemctl enable elasticsearch.service
systemctl start elasticsearch
systemctl daemon-reload                                 # 可以省略

如果报错

ERROR: bootstrap checks failed memory locking requested for elasticsearch process but memory is not locked

编辑服务配置文件

vim /usr/lib/systemd/system/elasticsearch.service
LimitMEMLOCK=infinity

systemctl daemon-reload

测试

curl -XGET 'http://192.168.1.151:9200/_cat/nodes?pretty'
curl -XGET 'http://192.168.1.151:9200/_cat/nodes?v'

参考文献:

https://www.cnblogs.com/aubin/p/8012840.html

https://blog.csdn.net/q1009020096/article/details/111591154

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值