Rocky 9 安装 Elasticsearch分布式集群基于非安全特性
一、 主机
| ip | 主机名 |
|---|---|
| 192.168.25.250 | ES01 |
| 192.168.25.130 | ES02 |
| 192.168.25.131 | ES03 |
二、系统初始化
所有主机执行:
systemctl disable firewalld --now
sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config
setenforce 0
swapoff -a && sed -i "s/^[^#]*swap*/#&/g" /etc/fstab
groupadd elasticsearch
useradd elasticsearch
useradd -g elasticsearch elasticsearch
echo "elasticsearch" | passwd --stdin elasticsearch
echo "elasticsearch ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers.d/elasticsearch
echo "
# 设置elasticsearch用户进程能打开的最大文件句柄
elasticsearch - nofile 65535
# 设置elasticsearch用户进程锁定使用物理内存
elasticsearch soft memlock unlimited
elasticsearch hard memlock unlimited
# 设置elasticsearch 用户进程创建的最大线程数
elasticsearch soft nproc 4096
elasticsearch hard nproc 4096
# 不限制elasticsearch用户创建文件的大小
elasticsearch soft fsize unlimited
elasticsearch hard fsize unlimited
" >> /etc/security/limits.conf
# 重新登录shell终端生效
echo "
# 设置个进程可创建的最大内存映射区域数量
vm.max_map_count=262144
# 设置tcp重传个数
net.ipv4.tcp_retries2=5
" >> /etc/sysctl.conf
# 立即生效
sysctl -p
hosts配置:
echo "192.168.25.250 ES01
192.168.25.130 ES02
192.168.25.131 ES03 " >> /etc/hosts
三、部署Elasticsearch
1. 下载Elasticsearch
所有主机执行:
mkdir /opt/es && cd /opt/es
wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-9.1.5-linux-x86_64.tar.gz
tar -zxvf elasticsearch-9.1.5-linux-x86_64.tar.gz
chown elasticsearch.elasticsearch * -R
su elasticsearch
cd elasticsearch-9.1.5
2. 配置修改
配置文档参考:https://www.elastic.co/docs/deploy-manage/deploy/self-managed/important-settings-configuration#_cluster_name_setting
2.1. JVM参数修改
所有主机执行:
config/jvm.options.d/custom_jvm.options:
# 统一内存堆栈大小,不可超过物理内存50%
-Xms2g
-Xmx2g# 使用G1 垃圾回收
-XX:+UseG1GC# es 运行时产生的临时可执行文件
-Djava.io.tmpdir=/home/elasticsearch/es/tmp# 指定gc参数及日志文件存放地址
-Xlog:gc*,gc+age=trace,safepoint:file=/home/elasticsearch/es/logs/gc.log:utctime,level,pid,tags:filecount=32,filesize=64m# JVM 内存溢出时,将日志文件写入指的目录下
-XX:HeapDumpPath=/home/elasticsearch/es/HeapDump
目录文件提前下载:
mkdir -pv /home/elasticsearch/es/tmp
mkdir -pv /home/elasticsearch/es/HeapDump
mkdir -pv /home/elasticsearch/es/data
mkdir -pv /home/elasticsearch/es/logs
2.2. elasticsearch配置修改
ES01:
config/elasticsearch.yml:
# 集群名称
cluster.name: elasticsearch-cluster# 节点角色
node.roles: [master, data]# 节点名称
node.name: ES01# 设置日志和数据存储目录,建议是设置到es目录外,应为es升级会删除数据
path.data: /home/elasticsearch/es/data
path.logs: /home/elasticsearch/es/logs# 锁定es必须使用物理内存
bootstrap.memory_lock: true# 设置网络接口和端口绑定
network.host: 0.0.0.0
http.port: 9200# 设置选举使用的9300端口绑定到本地所有接口上
transport.host: 0.0.0.0# 设置是否允许使用通配符删除索引
action.destructive_requires_name: false# 客户端通过http接口发送给 Elasticsearch 的请求体最大值
http.max_content_length: 100mb# 参与主节点选举的节点,所有节点加入后注释掉此项
cluster.initial_master_nodes: ["ES01","ES02","ES03"]# 节点发现
discovery.seed_hosts: ["192.168.25.250:9300", "192.168.25.130:9300", "192.168.25.131:9300"]# 关闭安全特性
xpack.security.enabled: false
ES02:
config/elasticsearch.yml:
# 集群名称
cluster.name: elasticsearch-cluster# 节点角色
node.roles: [master, data]# 节点名称
node.name: ES02# 设置日志和数据存储目录,建议是设置到es目录外,应为es升级会删除数据
path.data: /home/elasticsearch/es/data
path.logs: /home/elasticsearch/es/logs# 锁定es必须使用物理内存
bootstrap.memory_lock: true# 设置网络接口和端口绑定
network.host: 0.0.0.0
http.port: 9200# 设置选举使用的9300端口绑定到本地所有接口上
transport.host: 0.0.0.0# 设置是否允许使用通配符删除索引
action.destructive_requires_name: false# 客户端通过http接口发送给 Elasticsearch 的请求体最大值
http.max_content_length: 100mb# 节点发现
discovery.seed_hosts: ["192.168.25.250:9300", "192.168.25.130:9300", "192.168.25.131:9300"]# 关闭安全特性
xpack.security.enabled: false
ES03:
config/elasticsearch.yml
# 集群名称
cluster.name: elasticsearch-cluster# 节点角色
node.roles: [master, data]# 节点名称
node.name: ES03# 设置日志和数据存储目录,建议是设置到es目录外,应为es升级会删除数据
path.data: /home/elasticsearch/es/data
path.logs: /home/elasticsearch/es/logs# 锁定es必须使用物理内存
bootstrap.memory_lock: true# 设置网络接口和端口绑定
network.host: 0.0.0.0
http.port: 9200# 设置选举使用的9300端口绑定到本地所有接口上
transport.host: 0.0.0.0# 设置是否允许使用通配符删除索引
action.destructive_requires_name: false# 客户端通过http接口发送给 Elasticsearch 的请求体最大值
http.max_content_length: 100mb# 节点发现
discovery.seed_hosts: ["192.168.25.250:9300", "192.168.25.130:9300", "192.168.25.131:9300"]# 关闭安全特性
xpack.security.enabled: false
启动:
./bin/elasticsearch
查看集群状态
http://ip:9200/_cluster/health

查看主节点:
curl http://localhost:9200/_cat/master?v
id host ip node
5X28PDTrSXiaikpy89RVrg 192.168.25.250 192.168.25.250 ES01
四、部署kibana
1. 下载kibana
cd /opt/es
sudo wget https://artifacts.elastic.co/downloads/kibana/kibana-9.1.5-linux-x86_64.tar.gz
sudo tar -zxvf kibana-9.1.5-linux-x86_64.tar.gz
sudo chown elasticsearch.elasticsearch kibana-9.1.5 -R
cd kibana-9.1.5
2.配置文件修改
config/kibana.yml:
# 接口地址和端口号
server.port: 5601
server.host: "0.0.0.0" # 允许所有IP访问
# 公网域名(若通过域名访问,建议配置,如 "https://kibana.example.com")
# server.publicBaseUrl: ""
# 限制客户端请求体大小(5MB,合理,避免大请求攻击)
server.maxPayload: 5242880
# Kibana服务名(自定义,便于识别)
server.name: "kibana-server"
# =================== System: Logging ===================
# 日志级别(info 适合生产,平衡信息量和性能)
logging.root.level: info
# 日志输出器(仅保留滚动文件配置,支持按大小轮转)
logging.appenders.default:type: rolling-filefileName: logs/kibana.log # 日志路径,当前路径下policy:type: size-limitsize: 100mb # 单文件100MBstrategy:type: numericmax: 10 # 保留10个历史文件(总约1GB)layout:type: json # JSON格式,便于日志分析
# =================== System: Other ===================
# 自定义数据目录
path.data: data # 数据路径(当前目录下的data)
# 性能指标采样间隔/ms
ops.interval: 5000
# 界面语言
i18n.locale: "zh-CN"
# PID文件路径(系统标准目录,更规范)
# pid.file: kibana.pid # pid文件路径
# =================== Saved Objects: Migrations ===================
# 迁移配置(生产环境优化)
migrations.batchSize: 500 # 单批迁移500个对象,降低内存压力
migrations.maxBatchSizeBytes: 90mb # 小于ES的http.max_content_length(默认100mb)
migrations.retryAttempts: 15 # 重试次数
./bin/kibana
由于关闭了安全特性,所以不需要密码就可以直接登录
访问kibana
http://ip:5601

