Elasticsearch7.6.2集群搭建

服务器环境

有三台CentOS7服务器,IP分别是:
10.18.0.159
10.18.0.161
10.18.0.162

首先关闭三台服务器的防火墙

1.查看防火墙状态:

systemctl stop firewalld

可以看到目前处于运行状态
在这里插入图片描述
2. 关闭防火墙

systemctl stop firewalld

3.再次检查防火墙状态
在这里插入图片描述
4.永久关闭防火墙

[root@localhost local]# systemctl disable firewalld

5.创建ES用户
es不能够通过root用户启动,所以要专门创建用户用于启动es

# 创建用户, 为了方便记忆选择创建用户名为:es,也可以使用其他名称
[root@localhost local]# useradd es
# 设置用户密码
[root@localhost ~]# passwd es

6.优化系统参数

vi /etc/sysctl.conf
# 修改Linux文件打开最大数,否则启动es会报错
fs.file-max=65536
# 
vm.max_map_count = 262144

添加线程,不然会在启动的时候报错

 vi /etc/security/limits.conf
*        soft  nofile  65535
*        hard  nofile  131072
*        soft  nproc   2048
*        hard  nproc   4096

报错信息如下:

[1]: max number of threads [1024] for user [leyou] is too low, increase to at least [4096]

安装Elasticsearch

下载Elasticsearch
https://www.elastic.co/cn/downloads/past-releases/elasticsearch-7-6-2

上传服务器并解压

[root@localhost local]# tar -zxvf elasticsearch-7.6.2-linux-x86_64.tar.gz

编辑 elasticsearch.yml,三台服务器均需配置

[es@localhost config]$ vi /usr/local/elasticsearch-7.6.2/config/elasticsearch.yml 

# ---------------------------------- Cluster -----------------------------------
#
# Use a descriptive name for your cluster:
#
# 集群名称,同一个集群内的集群名称应当相同,我这里3台es都是 es-common
cluster.name: es-common
#
# ------------------------------------ Node ------------------------------------
#
# Use a descriptive name for the node:
#
# 节点名称不可重复,我这里三台ES的名称分别是 node-159、node-161、node-162
node.name: node-161
# 当前节点是否参选主节点,true表示会;false表示不会
node.master: true
# 当前节点是否用于存储数据,是:true、否:false
node.data: true
#
# ----------------------------------- Paths ------------------------------------
#
# 数据位置
path.data: /usr/local/elasticsearch-7.6.2/esdata
#
# 日志位置
path.logs: /usr/local/elasticsearch-7.6.2/eslog
#
# ----------------------------------- Memory -----------------------------------

# ---------------------------------- Network -----------------------------------
#
# Set the bind address to a specific IP (IPv4 or IPv6):
#
network.host: 0.0.0.0
#
# Set a custom port for HTTP:
#
#http.port: 9200
#
# For more information, consult the network module documentation.
#
# --------------------------------- Discovery ----------------------------------
# es7.x 之后新增的配置,写入候选主节点的设备地址,在开启服务后可以被选为主节点
discovery.seed_hosts: ["10.18.0.161", "10.18.0.159","10.18.0.162"]

# es7.x 之后新增的配置,初始化一个新的集群时需要此配置来选举master
cluster.initial_master_nodes: ["node-161","node-159", "node-162"]
#
#
# ---------------------------------- 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: "*"

如果服务器内存不够大,需要设置es启动内存为物理内存的一半以上,进行一下修改

vi jvm.options
# 根据自身服务器情况进行设置
-Xms512m
-Xmx512m

将elasticsearch目录设置es用户权限

[es@localhost config]$ chown -R es:es /usr/local/elasticsearch-7.6.2
# 查看权限设置结果
[es@localhost local]$ ll /usr/local/
total 459736
drwxr-xr-x.  2 root root         6 Apr 11  2018 bin
drwxr-xr-x. 11 es   es         182 Jan  8 20:26 elasticsearch-7.6.2
-rw-r--r--.  1 root root 296477546 Jan  8 06:45 elasticsearch-7.6.2-linux-x86_64.tar.gz
drwxr-xr-x.  2 root root         6 Apr 11  2018 etc
drwxr-xr-x.  2 root root         6 Apr 11  2018 games
drwxr-xr-x.  2 root root         6 Apr 11  2018 include
drwxr-xr-x.  9   10  143       219 Jan 15  2020 java
drwxr-xr-x.  2 root root         6 Apr 11  2018 lib
drwxr-xr-x.  2 root root         6 Apr 11  2018 lib64
drwxr-xr-x.  2 root root         6 Apr 11  2018 libexec
-rw-r--r--.  1 root root 174287938 Jan  8 07:32 openjdk-8u41-b04-linux-x64-14_jan_2020.tar.gz
drwxr-xr-x.  2 root root         6 Apr 11  2018 sbin
drwxr-xr-x.  5 root root        49 Jan  5 09:18 share
drwxr-xr-x.  2 root root         6 Apr 11  2018 src

使用es用户分别启动三台ES

[es@localhost local]$ cd /usr/local/elasticsearch-7.6.2/bin
#  -d 后台启动
[es@localhost bin]$ ./elasticsearch -d

查看是否启动成功
访问 http://10.18.0.162:9200/, 看到下图中信息表示已启动成功
在这里插入图片描述
查看集群信息
访问:http://10.18.0.162:9200/_cat/nodes?pretty

下图中 * 表示该节点是master节点,其他均为follower节点
在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值