一、需要

最近在看es相干的常识,此处简略记录一下es集群的搭建步骤。因为本地机器无限,此处模仿一下在同一台机器上搭建三个节点的集群。

二、前置条件

1、es不能应用root用户启动,因而须要创立一个用户。

2、本地的多个es节点之间不能应用雷同的datalog目录。

3、集群之间的脑裂问题,集群本人保护。

三、搭建步骤

1、下载es

# 下载wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.12.0-linux-x86_64.tar.gz# 解压tar -zxvf elasticsearch-7.12.0-linux-x86_64.tar.gz# 重命名mv elasticsearch-7.12.0 es01# 复制2份cp -r es01/ es02cp -r es01/ es03

2、创立 es 用户并给es目录受权

# 创立es用户useradd es# 设置es用户的明码passwd es# 扭转上一步下载的 es01、es02和es03目录的所有者为刚创立的es用户chown -R es es01chown -R es es02chown -R es es03# 创立数据目录和日志目录mkdir data && mkdir logcd data mkdir es01mkdir es02mkdir es03cd logmkdir es01mkdir es02mkdir es03
⚠️ 因为 es 用 root 用户启动会报错,所以此处须要新建一个用户,而后用新建的用户启动es。

3、批改es的配置文件

配置文件属性节点01节点02节点03解释
es0[1,2,3]/config/<br/>elasticsearch.ymles01es02es03es01、es02、es03示意同一台机器上的3个目录
cluster.namees-clusteres-clusteres-cluster集群的名称,组成集群的集群名称必须统一。
node.namees01es01es01节点名称,集群中的每个节点的名字必须要惟一。
path.data/home/es/<br/>es/data/es01/home/es/<br/>es/data/es02/home/es/<br/>es/data/es03数据目录
path.logs/home/es/<br/>es/log/es01/home/es/<br/>es/log/es02/home/es/<br/>es/log/es03日志目录
network.hostlocalhostlocalhostlocalhost监听地址,能够写本地ip,通过此地址能够拜访到es
http.port920092019202监听端口
transport.port920592069207集群之间通信接口,比方集群选举
discovery.<br/>seed_hosts:["localhost:9095", "localhost:9096", "localhost:9097"]["localhost:9095", "localhost:9096", "localhost:9097"]["localhost:9095", "localhost:9096", "localhost:9097"]有资格成为主节点的地址列表
cluster.<br/>initial_master_nodes["es01", "es02", "es03"]["es01", "es02", "es03"]["es01", "es02", "es03"]初始的候选master节点列表。必须和node.name的值统一。
node.mastertruetruetruetrue:示意能够被选举成为master节点.
node.datatruetruetruetrue: 示意能够存储数据。
http.cors.enabledtruetruetruetrue: 示意容许跨域。
http.cors.allow-origin***示意反对所有域名
es0[1,2,3]/config/<br/>jvm.options
-Xms512m-Xms512m-Xms512m依据本人的状况设置,不要超过本机物理内存的一半,最大不要超过30g
-Xmx512m-Xmx512m-Xmx512m...

重要的属性:

  1. cluster.initial_master_nodes

    链接:https://www.elastic.co/guide/en/elasticsearch/reference/7.12/modules-discovery-bootstrap-cluster.html

         链接:https://www.elastic.co/guide/en/elasticsearch/reference/7.12/important-settings.html#initial_master_nodes

4、es01目录下 elasticsearch.yml 的一个残缺的配置

cluster.name: es-clusternode.name: es01path.data: /home/es/es/data/es01path.logs: /home/es/es/log/es01network.host: localhosthttp.port: 9200transport.port: 9205discovery.seed_hosts: ["localhost:9205", "localhost:9206", "localhost:9207"]cluster.initial_master_nodes: ["es01", "es02", "es03"]node.master: truenode.data: truehttp.cors.enabled: truehttp.cors.allow-origin: "*"

5、启动es集群

#!/bin/bash# -d 后盾启动 -p 指定pid保留在那个文件中 /home/es/es/es01/pid01/home/es/es/es01/bin/elasticsearch -d -p pid01/home/es/es/es02/bin/elasticsearch -d -p pid02/home/es/es/es03/bin/elasticsearch -d -p pid03

6、查看集群是否启动

curl http://localhost:9202/_cat/nodes?v

curl http://localhost:9202/_cat/health?v

四、参考链接

1、https://www.elastic.co/cn/downloads/elasticsearch.

2、https://www.elastic.co/guide/en/elasticsearch/reference/current/important-settings.html#discovery-settings

3、https://www.elastic.co/guide/en/elasticsearch/reference/7.12/modules-discovery-bootstrap-cluster.html.

4、https://www.elastic.co/guide/en/elasticsearch/reference/7.12/important-settings.html#initial_master_nodes

5、https://www.elastic.co/guide/en/elasticsearch/reference/7.12/modules-discovery-settings.html

6、https://www.elastic.co/guide/en/elasticsearch/reference/7.12/jvm-options.html