最近在看es
相关的知识,此处简单记录一下es集群的搭建步骤。因为本地机器有限,此处模拟一下在同一台机器上搭建三个节点的集群。
1、es
不能使用root
用户启动,因此需要创建一个用户。
2、本地的多个es节点之间不能使用相同的data
和log
目录。
3、集群之间的脑裂问题,集群自己维护。
# 下载
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/ es02
cp -r es01/ es03
# 创建es用户
useradd es
# 设置es用户的密码
passwd es
# 改变上一步下载的 es01、es02和es03目录的所有者为刚创建的es用户
chown -R es es01
chown -R es es02
chown -R es es03
# 创建数据目录和日志目录
mkdir data && mkdir log
cd data
mkdir es01
mkdir es02
mkdir es03
cd log
mkdir es01
mkdir es02
mkdir es03
️ 因为 es 用 root 用户启动会报错,所以此处需要新建一个用户,然后用新建的用户启动es。
配置文件
属性
节点01
节点02
节点03
解释
es0[1,2,3]/config/
elasticsearch.yml
es01
es02
es03
es01、es02、es03表示同一台机器上的3个目录
cluster.name
es-cluster
es-cluster
es-cluster
集群的名称,组成集群的集群名称必须一致。
node.name
es01
es01
es01
节点名称,集群中的每个节点的名字必须要唯一。
path.data
/home/es/
es/data/es01
/home/es/
es/data/es02
/home/es/
es/data/es03
数据目录
path.logs
/home/es/
es/log/es01
/home/es/
es/log/es02
/home/es/
es/log/es03
日志目录
network.host
localhost
localhost
localhost
监听地址,可以写本地ip,通过此地址可以访问到es
http.port
9200
9201
9202
监听端口
transport.port
9205
9206
9207
集群之间通讯接口,比如集群选举
discovery.
seed_hosts:
[“localhost:9095”, “localhost:9096”, “localhost:9097”]
[“localhost:9095”, “localhost:9096”, “localhost:9097”]
[“localhost:9095”, “localhost:9096”, “localhost:9097”]
有资格成为主节点的地址列表
cluster.
initial_master_nodes
[“es01”, “es02”, “es03”]
[“es01”, “es02”, “es03”]
[“es01”, “es02”, “es03”]
初始的候选master节点列表。必须和node.name的值一致。
node.master
true
true
true
true:表示可以被选举成为master节点.
node.data
true
true
true
true: 表示可以存储数据。
http.cors.enabled
true
true
true
true: 表示允许跨域。
http.cors.allow-origin
*
*
*
表示支持所有域名
es0[1,2,3]/config/
jvm.options
-Xms512m
-Xms512m
-Xms512m
根据自己的情况设置,不要超过本机物理内存的一半,最大不要超过30g
-Xmx512m
-Xmx512m
-Xmx512m
…
重要的属性:
cluster.initial_master_nodes
cluster.name: es-cluster
node.name: es01
path.data: /home/es/es/data/es01
path.logs: /home/es/es/log/es01
network.host: localhost
http.port: 9200
transport.port: 9205
discovery.seed_hosts: ["localhost:9205", "localhost:9206", "localhost:9207"]
cluster.initial_master_nodes: ["es01", "es02", "es03"]
node.master: true
node.data: true
http.cors.enabled: true
http.cors.allow-origin: "*"
#!/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
curl http://localhost:9202/_cat/nodes?v
curl http://localhost:9202/_cat/health?v
1、https://www.elastic.co/cn/downloads/elasticsearch.
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
手机扫一扫
移动阅读更方便
你可能感兴趣的文章