目录
一、ES8单节点部署
集群架构
主机名 | ip | 版本 |
---|---|---|
node01 | 10.0.0.14 | 8.10.4 |
node02 | 10.0.0.15 | 8.10.4 |
node03 | 10.0.0.16 | 8.10.4 |
1.环境准备
1.系统优化
略
2.es依赖配置
#修改文件打开数量上线,修改后需要断开会话
cat >> /etc/security/limits.d/es7.conf <<EOF
* soft nofile 65535
* hard nofile 131070
* hard nproc 8192
EOF
[root@node01 ~]# ulimit -Sn
65535
[root@node01 ~]# ulimit -Hn
131070
#调大内核虚拟内存映射值
cat >> /etc/sysctl.d/es.conf <<EOF
vm.swappiness=1
vm.max_map_count=524288
EOF
sysctl -q vm.max_map_count
sysctl -f /etc/sysctl.d/es.conf
sysctl -q vm.max_map_count
2.创建用户和目录
useradd -u 2024 es8
mkdir /es8/soft #安装目录
mkdir /es8/data #数据目录
mkdir /es8/logs #日志目录
3.下载解压安装包
3.1 下载es8
wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-8.10.4-linux-x86_64.tar.gz
3.2 解压安装
tar -xf elasticsearch-8.10.4-linux-x86_64.tar.gz -C /es8/soft
3.3 授权目录
chown -R es8.es8 /es8
4.修改配置文件
cluster.name: my-elk
node.name: node02
path.data: /es8/data
path.logs: /es8/logs
network.host: 0.0.0.0
http.port: 9200
注意:关于ssl等其他的配置,会默认开启。
5.使用system启动es
cat >> /usr/lib/systemd/system/es8.service << EOF
# /usr/lib/systemd/system/es8.service
[Unit]
Description=es2023
After=network.target
[Service]
Type=simple
ExecStart=/es8/soft/elasticsearch-8.10.4/bin/elasticsearch
User=elasticsearch
LimitNOFILE=131070
[Install]
WantedBy=multi-user.target
EOF
5.1 使用oracle-jdk启动(二选一)
5.1.1 部署jdk
tar -xf jdk-8u291-linux-x64.tar.gz -C /es8/soft
#添加环境变量
cat >> /etc/profile.d/jdk.sh << EOF
#!/bin/bash
export JAVA_HOME=/es8/soft/jdk1.8.0_291
export PATH=$PATH:$JAVA_HOME/bin
EOF
source /etc/profile.d/jdk.sh
cat >> /usr/lib/systemd/system/es8.service << EOF
[Unit]
Description=es2023
After=network.target
[Service]
Type=simple
Environment=JAVA_HOME=/es8/soft/jdk1.8.0_291 #oraclejdk
ExecStart=/es8/soft/elasticsearch-8.10.4/bin/elasticsearch
User=elasticsearch
LimitNOFILE=131070
[Install]
WantedBy=multi-user.target
EOF
6.查看日志
tail -f /es8/logs/my-elk.log
7.访问验证
8.重置elastic密码
8.1 重置随机密码
cd /es8/soft/elasticsearch-8.10.4/bin
./elasticsearch-reset-password -u elastic
登录成功
8.2 自定义密码
./elasticsearch-reset-password -u elastic -i
9.jvm内存调整
根据实际情况调整
vim /es8/soft/elasticsearch-8.10.4/config/jvm.options
9.1 重启验证
systemctl restart es8
ps -ef | grep elastic | grep Xms256m
二、ES8集群部署
1.环境准备
所有节点执行
1.系统优化
略
2.es依赖配置
#修改文件打开数量上线,修改后需要断开会话
cat >> /etc/security/limits.d/es7.conf <<EOF
* soft nofile 65535
* hard nofile 131070
* hard nproc 8192
EOF
ulimit -Sn
ulimit -Hn
#调大内核虚拟内存映射值
cat >> /etc/sysctl.d/es.conf <<EOF
vm.swappiness=1
vm.max_map_count=524288
EOF
sysctl -q vm.max_map_count
sysctl -f /etc/sysctl.d/es.conf
sysctl -q vm.max_map_count
2.创建用户和目录
useradd -u 2024 es8
mkdir /es8/soft -p #安装目录
mkdir /es8/data -p #数据目录
mkdir /es8/logs -p #日志目录
3.安装es8
3.1 解压指定目录
tar -xf elasticsearch-8.10.4-linux-x86_64.tar.gz -C /es8/soft
3.2 授权
chown -R es8.es8 /es8
4.集群配置文件
注意各节点的node.name和network.host不同,es-2和es-3节点无需配置discovery.seed_hosts和cluster.initial_master_nodes。network.host也可以填写0.0.0.0
4.1 node01
cluster.name: my-es8
node.name: node01
path.data: /es8/data
path.logs: /es8/logs
network.host: 0.0.0.0
http.port: 9200
action.destructive_requires_name: true
4.2 node02
ssl配置忽略
cluster.name: my-es8
node.name: node02
path.data: /es8/data
path.logs: /es8/logs
network.host: 0.0.0.0
http.port: 9200
discovery.seed_hosts: ["node01", "node02" ,"node03"]
cluster.initial_master_nodes: ["node02"]
4.3 node03
cluster.name: my-es8
node.name: node03
path.data: /es8/data
path.logs: /es8/logs
network.host: 0.0.0.0
http.port: 9200
5.node02生成token
systemctl start es8
[root@node02 bin]# ./elasticsearch-create-enrollment-token -s node
warning: ignoring JAVA_HOME=/es8/soft/jdk1.8.0_291; using bundled JDK
eyJ2ZXIiOiI4LjEwLjQiLCJhZHIiOlsiMTAuMC4wLjE1OjkyMDAiXSwiZmdyIjoiMTE0OWE4ZjI1MjRlZDY2ZDU1OTk1MjA1NTBhMGYyMWY2N2UzM2UzNDA0ZjNkNTk3MTg4OTJiMTg5NThhNWQxMiIsImtleSI6ImF6azIzWThCc3lDaWZzQXAwWTJrOlpQM19oSl9lUmMybzlrTDFrQ1pHdncifQ==
6.node01、node03加入集群
6.1 node01
[root@node01 bin]# su - es8
[es8@node01 soft]$ cd /es8/soft/elasticsearch-8.10.4/bin
[es8@node01 bin]$ ./elasticsearch --enrollment-token eyJ2ZXIiOiI4LjEwLjQiLCJhZHIiOlsiMTAuMC4wLjE1OjkyMDAiXSwiZmdyIjoiMTE0OWE4ZjI1MjRlZDY2ZDU1OTk1MjA1NTBhMGYyMWY2N2UzM2UzNDA0ZjNkNTk3MTg4OTJiMTg5NThhNWQxMiIsImtleSI6ImF6azIzWThCc3lDaWZzQXAwWTJrOlpQM19oSl9lUmMybzlrTDFrQ1pHdncifQ==
6.2 node03
[root@node03 bin]# su - es8
[es8@node03 soft]$ cd /es8/soft/elasticsearch-8.10.4/bin
[es8@node03 bin]$ ./elasticsearch --enrollment-token eyJ2ZXIiOiI4LjEwLjQiLCJhZHIiOlsiMTAuMC4wLjE1OjkyMDAiXSwiZmdyIjoiMTE0OWE4ZjI1MjRlZDY2ZDU1OTk1MjA1NTBhMGYyMWY2N2UzM2UzNDA0ZjNkNTk3MTg4OTJiMTg5NThhNWQxMiIsImtleSI6ImF6azIzWThCc3lDaWZzQXAwWTJrOlpQM19oSl9lUmMybzlrTDFrQ1pHdncifQ==
6.3 修改es集群配置
使用elasticsearch --enrollment-token命令加入集群后,默认配置文件discovery.seed_hosts: [“10.0.0.15:9300”],本案例中使用3节点组成es集群,3个节点即是master节点也是数据节点,接下来改为集群所有节点配置。集群初始化完成后取消cluster.initial_master_nodes配置
node01
[root@node01 ~]# egrep -v '^$|#' /es8/soft/elasticsearch-8.10.4/config/elasticsearch.yml
cluster.name: my-es8
node.name: node01
path.data: /es8/data
path.logs: /es8/logs
network.host: 0.0.0.0
http.port: 9200
xpack.security.enabled: true
xpack.security.enrollment.enabled: true
xpack.security.http.ssl:
enabled: true
keystore.path: certs/http.p12
xpack.security.transport.ssl:
enabled: true
verification_mode: certificate
keystore.path: certs/transport.p12
truststore.path: certs/transport.p12
discovery.seed_hosts: ["node01","node02","node03"]
node02
[root@node02 bin]# egrep -v '^$|#' ../config/elasticsearch.yml
cluster.name: my-es8
node.name: node02
path.data: /es8/data
path.logs: /es8/logs
network.host: 0.0.0.0
http.port: 9200
discovery.seed_hosts: ["node01", "node02" ,"node03"]
xpack.security.enabled: true
xpack.security.enrollment.enabled: true
xpack.security.http.ssl:
enabled: true
keystore.path: certs/http.p12
xpack.security.transport.ssl:
enabled: true
verification_mode: certificate
keystore.path: certs/transport.p12
truststore.path: certs/transport.p12
#cluster.initial_master_nodes: ["node02"] 注释初始化配置
node03
[root@node03 bin]# egrep -v '^$|#' /es8/soft/elasticsearch-8.10.4/config/elasticsearch.yml
cluster.name: my-es8
node.name: node03
path.data: /es8/data
path.logs: /es8/logs
network.host: 0.0.0.0
http.port: 9200
xpack.security.enabled: true
xpack.security.enrollment.enabled: true
xpack.security.http.ssl:
enabled: true
keystore.path: certs/http.p12
xpack.security.transport.ssl:
enabled: true
verification_mode: certificate
keystore.path: certs/transport.p12
truststore.path: certs/transport.p12
discovery.seed_hosts: ["node01","node02","node03"]
7.重启es集群
注:分别重启node01和node03
7.1 node01
cat >> /usr/lib/systemd/system/es8.service << EOF
# /usr/lib/systemd/system/es8.service
[Unit]
Description=es2024
After=network.target
[Service]
Type=simple
ExecStart=/es8/soft/elasticsearch-8.10.4/bin/elasticsearch
User=es8
LimitNOFILE=131070
[Install]
WantedBy=multi-user.target
EOF
systemctl daemon-reload
systemctl enable --now es8
7.2 node02
cat >> /usr/lib/systemd/system/es8.service << EOF
# /usr/lib/systemd/system/es8.service
[Unit]
Description=es2024
After=network.target
[Service]
Type=simple
ExecStart=/es8/soft/elasticsearch-8.10.4/bin/elasticsearch
User=es8
LimitNOFILE=131070
[Install]
WantedBy=multi-user.target
EOF
7.3 node03
cat >> /usr/lib/systemd/system/es8.service << EOF
# /usr/lib/systemd/system/es8.service
[Unit]
Description=es2024
After=network.target
[Service]
Type=simple
ExecStart=/es8/soft/elasticsearch-8.10.4/bin/elasticsearch
User=es8
LimitNOFILE=131070
[Install]
WantedBy=multi-user.target
EOF
systemctl daemon-reload
systemctl enable --now es8
7.4 查看集群日志
tail -f /es8/logs/my-es8.log
8.集群验证
8.1 查看集群状态
curl -X GET -u elastic:123456 -k https://10.0.0.15:9200/_cat/nodes?v
curl -X GET -u elastic:123456 -k https://10.0.0.15:9200/_cluster/health
8.2 创建索引分片
curl -XPUT -u elastic:123456 -k https://10.222.64.47:9200/test01
{
"settings":{
"number_of_shards": 5,
"number_of_replicas":2
}
}
可以看到五个分区两个副本
8.3 高可用验证
- 当前node-3为master节点,node-1、node-2为data节点
- 将node02关机
- 说明:当前集群状态为黄色,表示主节点可用,副本节点不完全可用
- 过一段时间观察,发现节点列表中看不到node-2,副本节点分配到了node-1和node-3,集群状态恢复到绿色。
重启node01节点