搭建ElasticSearch7.4.2集群

推荐阅读

Helm3(K8S 资源对象管理工具)视频教程:https://edu.csdn.net/course/detail/32506
Helm3(K8S 资源对象管理工具)博客专栏:https://blog.csdn.net/xzk9381/category_10895812.html

本文原文链接:https://blog.csdn.net/xzk9381/article/details/117465038,转载请注明出处。如有发现文章中的任何问题,欢迎评论区留言。

本次搭建的集群使用 7.4.2 版本,源码包可以到官网中下载

下载链接:https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.4.2-linux-x86_64.tar.gz

首先说一下搭建过程中使用的机器和角色分配:

IP 地址角色备注
10.19.74.53Master、Ingest
10.19.74.54Master、Data
10.19.74.55Master、Data
10.19.74.56Data、Ingest

由于机器有限,所以每个机器中均启动两个 ES 节点,实际使用中可以将每个角色分配到单独的机器中。

一、服务器环境初始化

在安装集群之前,首先对集群的环境进行配置。

1. 创建用户

管理 ES 集群最好使用非 root 用户,这里我们创建一个 es 用户,并将其家目录设置在 /opt 目录下:

useradd es -m /opt/es

将 elasticsearch-7.4.2-linux-x86_64.tar.gz 压缩包拷贝到 es 用户的家目录下并解压缩,将解压后的文件和目录的属主和属组均设置为 es:

chown -R es.es elasticsearch-7.4.2
2. 优化系统和内核

ES 集群对于系统性能要求比较高,所以需要对系统和内核做一些调优。

首先是在 /etc/sysctl.conf 文件中添加如下配置项,配置完成后使用 sysctl -p 生效:

# 设置系统最大打开文件描述符数量
fs.file-max=655360
# 设置一个进程拥有虚拟内存区域的大小
vm.max_map_count=655360
# 尽量减少 swap 内存交换的使用,但是不是禁用
vm.swappiness=1

接下来在 /etc/security/limits.conf 文件中添加如下内容:

# 设置最大文件打开数
* soft nofile 265535
* hard nofile 265535
# 设置最大用户进程数
* soft nproc 216384
* hard nproc 232768
# 设置最大锁定内存空间
es soft memlock unlimited
es hard memlock unlimited

在 /etc/security/limits.d/20-nproc.conf 文件中添加如下内容:

# 修改用户最大线程数
es		soft	nproc	unlimited
root	soft	nproc	unlimited

如果有条件的,建议卸载 swap 内存交换分区:

swapoff -a ; sed -i '/ swap / s/^\(.*\)$/#\1/g' /etc/fstab

二、搭建 Master 节点

根据我们的规划,需要在 10.19.74.53 - 10.19.74.55 这三台机器中启动 Master 节点,所以这里以 10.19.74.53 机器为例进行演示,其他两台机器操作步骤一样:

注意,所有步骤都使用 es 用户来执行

首先将 /opt/es 目录下解压后的源码包复制到当前路径下,并重命名为 esmaster。编辑 esmaster/config/elasticsearch.yml 文件,修改如下内容:

# ---------------------------------- Cluster -----------------------------------
# 集群名称,所有节点必须保持一致
cluster.name: skywalking-es-cluster
# ------------------------------------ Node ------------------------------------
# 当前节点的名称,一般命名规则是:业务-角色-ip地址
node.name: master-10.19.74.53
#
# Add custom attributes to the node, node.ingest set true only on client node
#node.attr.rack: r1
# 这里将 node.master 设置为 true,代表当前节点为 master 角色
node.master: true
node.voting_only: false
node.data: false
node.ingest: false
node.ml: false
xpack.ml.enabled: true
#
# ----------------------------------- Paths ------------------------------------
# 设置日志路径和数据存储路径
path.data: /opt/es/data/esmaster
path.logs: /opt/es/log/esmaster
#
# ----------------------------------- Memory -----------------------------------
bootstrap.memory_lock: true
#
# ---------------------------------- Network -----------------------------------
#
# 设置当前节点的 IP 地址
network.host: 10.19.74.53
# 设置 api 端口
http.port: 9201
# 设置数据通信端口
transport.port: 9301
#
# --------------------------------- Discovery ----------------------------------
#
# 这里填写所有的 Master 节点和 data 节点
discovery.seed_hosts:
  - 10.19.74.53:9301
  - 10.19.74.54:9301
  - 10.19.74.55:9301
  - 10.19.74.54:9300
  - 10.19.74.55:9300
  - 10.19.74.56:9300

# Bootstrap the cluster using an initial set of master-eligible nodes:
# 设置集群的 master 节点的 node.name 名称,也可以是 ip 地址或者域名
cluster.initial_master_nodes:
  - master-10.19.74.53
  - master-10.19.74.54
  - master-10.19.74.55
#
# ---------------------------------- Gateway -----------------------------------
#
# Block initial recovery after a full cluster restart until N nodes are started:
gateway.recover_after_nodes: 3
#
# ---------------------------------- Various -----------------------------------
#
# Require explicit names when deleting indices:
#action.destructive_requires_name: true
#
# ---------------------------------- x-pack ------------------------------------
#x-pack setting
xpack.monitoring.collection.enabled: true

另外两个节点也按照上面的内容进行配置,修改 IP 地址和节点名称即可。

编辑 esmaster/config/jvm.options 文件,修改如下内容:

-Xms31g
-Xmx31g

最后创建数据目录和日志目录:

mkdir -p /opt/es/{data/esmaster,log/esmaster}

三、搭建 Data 节点

搭建 Data 节点和搭建 Master 节点的过程一致,这里以 10.19.74.54 机器为例。首先是将解压后的源码包复制一份到当前路径下并重命名为 esdatanode,接下来修改 esdatanode/config/elasticsearch.yml 文件,内容如下:

# ---------------------------------- Cluster -----------------------------------
cluster.name: skywalking-es-cluster
# ------------------------------------ Node ------------------------------------
node.name: data-10.19.74.54
#
# Add custom attributes to the node, node.ingest set true only on client node
#node.attr.rack: r1
node.master: false
node.voting_only: false
node.data: true
node.ingest: false
node.ml: false
xpack.ml.enabled: true
#
# ----------------------------------- Paths ------------------------------------
path.data: /opt/es/data/esdatanode
path.logs: /opt/es/log/esdatanode
#
# ----------------------------------- Memory -----------------------------------
bootstrap.memory_lock: true
#
# ---------------------------------- Network -----------------------------------
#
network.host: 10.19.74.54
http.port: 9200
transport.port: 9300
#
# --------------------------------- Discovery ----------------------------------
#
discovery.seed_hosts:
  - 10.19.74.53:9301
  - 10.19.74.54:9301
  - 10.19.74.55:9301
  - 10.19.74.54:9300
  - 10.19.74.55:9300
  - 10.19.74.56:9300

# Bootstrap the cluster using an initial set of master-eligible nodes:
cluster.initial_master_nodes:
  - master-10.19.74.53
  - master-10.19.74.54
  - master-10.19.74.55
#
# ---------------------------------- Gateway -----------------------------------
#
# Block initial recovery after a full cluster restart until N nodes are started:
gateway.recover_after_nodes: 3
#
# ---------------------------------- Various -----------------------------------
#
# Require explicit names when deleting indices:
#action.destructive_requires_name: true
#
# ---------------------------------- x-pack ------------------------------------
#x-pack setting
xpack.monitoring.collection.enabled: true

内容基本与 Master 节点一致,只需要修改节点 IP 地址、节点名称和节点角色即可,其他 data 节点的配置方式一致(注意使用 es 用户配置)。

接下来修改 jvm.option 文件,配置与 Master 节点一致。

最后创建数据目录和日志目录:

mkdir -p /opt/es/{data/esdatanode,log/esdatanode}

本文原文链接:https://blog.csdn.net/xzk9381/article/details/117465038,转载请注明出处。如有发现文章中的任何问题,欢迎评论区留言。

四、搭建 Ingest 节点

根据我们的规划,Ingest 部署在 10.19.74.53 和 10.19.74.56 节点中,这里以 10.19.74.53 为例。首先是将解压后的源码包复制一份到当前路径下并重命名为 esclient,接下来修改 esclient/config/elasticsearch.yml 文件,内容如下:

# ---------------------------------- Cluster -----------------------------------
cluster.name: skywalking-es-cluster
# ------------------------------------ Node ------------------------------------
node.name: ingest-10.19.74.53
#
# Add custom attributes to the node, node.ingest set true only on client node
#node.attr.rack: r1
node.master: false
node.voting_only: false
node.data: false
node.ingest: true
node.ml: false
xpack.ml.enabled: true
#
# ----------------------------------- Paths ------------------------------------
path.data: /opt/es/data/esclient
path.logs: /opt/es/log/esclient
#
# ----------------------------------- Memory -----------------------------------
bootstrap.memory_lock: true
#
# ---------------------------------- Network -----------------------------------
#
network.host: 10.19.74.53
http.port: 9202
transport.port: 9302
#
# --------------------------------- Discovery ----------------------------------
#
discovery.seed_hosts:
  - 10.19.74.53:9301
  - 10.19.74.54:9301
  - 10.19.74.55:9301
  - 10.19.74.54:9300
  - 10.19.74.55:9300
  - 10.19.74.56:9300

# Bootstrap the cluster using an initial set of master-eligible nodes:
cluster.initial_master_nodes:
  - master-10.19.74.53
  - master-10.19.74.54
  - master-10.19.74.55
#
# ---------------------------------- Gateway -----------------------------------
#
# Block initial recovery after a full cluster restart until N nodes are started:
gateway.recover_after_nodes: 3
#
# ---------------------------------- Various -----------------------------------
#
# Require explicit names when deleting indices:
#action.destructive_requires_name: true
#
# ---------------------------------- x-pack ------------------------------------
#x-pack setting
xpack.monitoring.collection.enabled: true

还是主要修改节点 IP 地址、节点名称和节点角色即可,另一个 ingest 节点的配置方式一致。内存配置也和 master 和 data 节点保持一致。

最后创建数据目录和日志目录:

mkdir -p /opt/es/{data/esclient,log/esclient}

五、启动 ES 集群

启动 ES 集群需要使用 es 用户执行,分别进入各个节点角色的目录中的 bin 目录下,执行如下命令即可启动:

./elasticsearch -d

六、检查集群状态

在浏览器中输入如下地址即可查看集群各个节点的状态:

http://10.19.74.53:9202/_cat/nodes?v

返回的结果如下:

ip          heap.percent ram.percent cpu load_1m load_5m load_15m node.role master name
10.19.74.55           69          97  23    3.28    3.36     3.18 d         -      data-10.19.74.55
10.19.74.54           60          92  10    4.11    3.90     3.48 m         *      master-10.19.74.54
10.19.74.53           36          65   0    0.01    0.02     0.05 i         -      ingest-10.19.74.53
10.19.74.53           46          65   0    0.01    0.02     0.05 m         -      master-10.19.74.53
10.19.74.55           13          97  23    3.28    3.36     3.18 m         -      master-10.19.74.55
10.19.74.54           64          92  10    4.11    3.90     3.48 d         -      data-10.19.74.54
10.19.74.56           63          96  17    2.98    3.31     3.36 i         -      ingest-10.19.74.56
10.19.74.56           16          96  17    2.98    3.31     3.36 d         -      data-10.19.74.56

也可以直接访问 http://10.19.74.53:9202 获取集群的信息,返回的结果如下:

{
  "name" : "ingest-10.19.74.53",
  "cluster_name" : "skywalking-es-cluster",
  "cluster_uuid" : "zXpOHN29Q5yiJ7MOMY9S7g",
  "version" : {
    "number" : "7.4.2",
    "build_flavor" : "default",
    "build_type" : "tar",
    "build_hash" : "2f90bbf7b93631e52bafb59b3b049cb44ec25e96",
    "build_date" : "2019-10-28T20:40:44.881551Z",
    "build_snapshot" : false,
    "lucene_version" : "8.2.0",
    "minimum_wire_compatibility_version" : "6.8.0",
    "minimum_index_compatibility_version" : "6.0.0-beta1"
  },
  "tagline" : "You Know, for Search"
}

返回以上信息就代表集群已经部署成功,这里我们规划了两个 ingest 节点,所以可以使用其中一个 ingest 来接收 filebeat 或者 logstash 发送过来的数据,另一个 ingest 节点可以作为 Kibana 连接集群的入口。

七、搭建 Kibana

接下来就是搭建 Kibana 服务,这里使用的 Kibana 版本也是 7.4.2。

下载地址为:https://artifacts.elastic.co/downloads/kibana/kibana-7.4.2-linux-x86_64.tar.gz

在 10.19.74.53 机器中下载安装包并解压到 /opt/es 目录下重命名为 kibana。修改 kibana/config/kibana.yml 文件,内容如下:

# Kibana is served by a back end server. This setting specifies the port to use.
server.port: 5601

# Specifies the address to which the Kibana server will bind. IP addresses and host names are both valid values.
# The default is 'localhost', which usually means remote machines will not be able to connect.
# To allow connections from remote users, set this parameter to a non-loopback address.
server.host: "10.19.74.53"

# Enables you to specify a path to mount Kibana at if you are running behind a proxy.
# Use the `server.rewriteBasePath` setting to tell Kibana if it should remove the basePath
# from requests it receives, and to prevent a deprecation warning at startup.
# This setting cannot end in a slash.
server.basePath: "/es7/kibana"

# Specifies whether Kibana should rewrite requests that are prefixed with
# `server.basePath` or require that they are rewritten by your reverse proxy.
# This setting was effectively always `false` before Kibana 6.3 and will
# default to `true` starting in Kibana 7.0.
server.rewriteBasePath: true

# The maximum payload size in bytes for incoming server requests.
server.maxPayloadBytes: 1048576

# The Kibana server's name.  This is used for display purposes.
server.name: "10.19.74.31"

# The URLs of the Elasticsearch instances to use for all your queries.
elasticsearch.hosts: ["http://10.19.74.53:9202"]

# Set the value of this setting to true to suppress all logging output.
logging.silent: false

# Set the value of this setting to true to suppress all logging output other than error messages.
logging.quiet: false

# Set the value of this setting to true to log all events, including system usage information
# and all requests.
#logging.verbose: false

# Set the interval in milliseconds to sample system and process performance
# metrics. Minimum is 100ms. Defaults to 5000.
ops.interval: 5000

# Specifies locale to be used for all localizable strings, dates and number formats.
# Supported languages are the following: English - en , by default , Chinese - zh-CN .
i18n.locale: "zh-CN"

修改完成后,进入 kibana/bin 目录下,执行如下命令启动 kibana 即可:

nohup ./kibana &

本文原文链接:https://blog.csdn.net/xzk9381/article/details/117465038,转载请注明出处。如有发现文章中的任何问题,欢迎评论区留言。

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

店伙计

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值