大数据学习初级入门教程(十) —— Elasticsearch 7.6.2 完全分布式集群的安装、配置、启动和测试

在前两篇文章《大数据学习初级入门教程(八) —— Elasticsearch 7.6.2 单节点的安装、启动和测试》和《大数据学习初级入门教程(九) —— Elasticsearch 7.6.2 伪分布式集群的安装、配置、启动和测试》中,已经对 ES 集群的单节点安装和伪分布式集群安装做了安装、配置、启动和测试,这篇文章主要对 ES 完全分布式集群安装进行详细的图文说明。

由于前两篇把部署和启动 ES 相关的操作都已说明,这里将不再细说,直接按步就搬的搭建集群。

一、环境说明

服务器:

CentOS release 6.9 (Final) x64,节点主机名分别为:node19、node18、node11

操作用户默认是 root

Java 环境:

java version "1.8.0_172"
Java(TM) SE Runtime Environment (build 1.8.0_172-b11)
Java HotSpot(TM) 64-Bit Server VM (build 25.172-b11, mixed mode)

ElasticSearch 版本:

elasticsearch-7.6.2-linux-x86_64.tar.gz

二、创建用户

分别用 root 用户登录三台服务器,创建新用户 elastic。

# adduser elastic

# passwd elastic

三、修改系统配置

修改 /etc/security/limits.conf 文件,增加配置:

*               soft    nofile          65535
*               hard    nofile          65535
*               soft    nproc           4096
*               hard    nproc           4096

修改 etc/security/limits.d/90-nproc.conf 文件:

*          soft    nproc     4096
root       soft    nproc     unlimited

注意:修改以上配置后,别忘了重启服务器。

可以通过下面命令测试重启后配置是否生效:

[elastic@node19 elasticsearch-7.6.2]$ ulimit -Hn
65535
[elastic@node19 elasticsearch-7.6.2]$ ulimit -Sn
65535
[elastic@node19 elasticsearch-7.6.2]$ ulimit -Hu
4096
[elastic@node19 elasticsearch-7.6.2]$ ulimit -Su
4096
[elastic@node19 elasticsearch-7.6.2]$ 

修改 /etc/sysctl.conf 文件,增加配置 vm.max_map_count=262144,并执行命令 sysctl -p 使之配置生效。

四、切换用户

# su elastic

五、上传安装包

上传 ES 安装包到目录 /home/elastic 下,这里先只操作一台服务器 node19。

六、解压安装包

$ cd /home/elastic/

$ tar -zxvf elasticsearch-7.6.2-linux-x86_64.tar.gz 

七、修改 ES 配置

修改 ES 实例节点的配置,路径为:/home/elastic/elasticsearch-7.6.2/config/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
# 设置集群名称,集群内所有节点的名称必须一致
cluster.name: myes762
#
# ------------------------------------ Node ------------------------------------
#
# Use a descriptive name for the node:
#
#node.name: node-1
# 设置节点名称,集群内节点名称必须唯一
node.name: es19
#
# Add custom attributes to the node:
#
#node.attr.rack: r1
#
# 表示该节点会不会作为主节点,true表示会;false表示不会
node.master: true
# 当前节点是否用于存储数据,是:true、否:false
node.data: true
#
# ----------------------------------- 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:
#
# 需要锁住物理内存,是:true、否:false
#bootstrap.memory_lock: true
# 系统调用过滤器检查,是:true、否:false
bootstrap.system_call_filter: 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.
#
# Set the bind address to a specific IP (IPv4 or IPv6):
#
#network.host: 192.168.0.1
# 监听地址,用于访问该es
network.host: node19
#
# Set a custom port for HTTP:
#
#http.port: 9200
# es对外提供的http端口,默认 9200
http.port: 9200
#
# For more information, consult the network module documentation.
#
# TCP的默认监听端口,默认 9300
transport.tcp.port: 9300
#
# 是否支持跨域,是:true,在使用head插件时需要此配置
http.cors.enabled: true
# “*” 表示支持所有域名
http.cors.allow-origin: "*"
#
# --------------------------------- Discovery ----------------------------------
#
discovery.zen.minimum_master_nodes: 2
#
# 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]"]
#
#discovery.seed_hosts: ["host1", "host2"]
# es7.x 之后新增的配置,写入候选主节点的设备地址,在开启服务后可以被选为主节点
discovery.seed_hosts: ["node19:9300", "node18:9300", "node11:9300"]
# 判断结点是否脱离时间配置
discovery.zen.fd.ping_timeout: 60s
# 判断结点是否脱离次数配置
discovery.zen.fd.ping_retries: 5
#
# Bootstrap the cluster using an initial set of master-eligible nodes:
#
#cluster.initial_master_nodes: ["node-1", "node-2"]
# es7.x 之后新增的配置,初始化一个新的集群时需要此配置来选举master
cluster.initial_master_nodes: ["es19", "es18", "es11"]
#
# 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

八、拷贝 ES 目录到其它机器

直接把 ES 目录 /home/elastic/elasticsearch-7.6.2 拷贝到另外两台机器 node18 和 node 11。

$ scp -r elasticsearch-7.6.2 elastic@node18:/home/elastic/

$ scp -r elasticsearch-7.6.2 elastic@node11:/home/elastic/

九、修改配置

参考第七步修改第 1 个实例节点的配置,修改第 2、3 节点的配置文件,主要变如下:

node18:

# 设置节点名称,集群内节点名称必须唯一
node.name: es18

# 监听地址,用于访问该es
network.host: node18

node11:

# 设置节点名称,集群内节点名称必须唯一
node.name: es11

# 监听地址,用于访问该es
network.host: node11

十、启动集群

依次启动 3 个 ES 实例节点,这里用后台启动方式。

$ ./bin/elasticsearch -d

可以通过查看日志,看看是否启动中有错误:

$ tail -f logs/myes762.log

如果各个节点日志看到下面的信息,说明集群启动基本没问题:

可以通过浏览器访问各个节点测试:

也可以通过访问 http://192.168.220.19:9200/_cat/nodes 查看集群状态:

可以看到 ES 集群 myes762当前的 master 节点为 es18。

到此,完全分布式 ES 集群搭建的基本操作完成了,如果有其它机器,也可以按照上面的步骤,继续扩充集群。

十一、集群启动脚本

es762_start.sh:

#!/bin/bash
echo "ES762 集群启动开始..."
 
for host in node19 node18 node11
do
 
echo "--------------------------------"
echo $host "节点 es 启动开始..."
ssh $host "/home/elastic/elasticsearch-7.6.2/bin/elasticsearch -d >/dev/null 2>&1 &"
echo $host "节点 es 启动结束."
 
done
 
echo "ES762 集群启动结束."

这里,简单写个脚本,用于集群的启动,便于操作。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值