1.标题获取安装文件
cd /opt/tools
wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-8.11.4-linux-x86_64.tar.gz
tar -zxvf elasticsearch-8.11.4-linux-x86_64.tar.gz
mv /opt/tools/elasticsearch-8.11.4 /opt/elasticsearch
#配置vm.max_map_count,要不然启动失败 sysctl -w vm.max_map_count=262144
2.创建elastic系统用户
useradd -r elastic
chown -R elastic:elastic /opt/elasticsearch
3. 配置config/elasticsearch.yml
sed -i ‘s/#node.name: node-1/node.name: node-1/’ /opt/elasticsearch/config/elasticsearch.yml
sed -i ‘s/#network.host: 192.168.0.1/network.host: 0.0.0.0/’ /opt/elasticsearch/config/elasticsearch.yml
echo ‘cluster.initial_master_nodes: [“node-1”]’ >> /opt/elasticsearch/config/elasticsearch.yml
echo ‘xpack.security.enabled: false’ >> /opt/elasticsearch/config/elasticsearch.yml
4.配置环境变量
cat >> /etc/profile << ‘EOF’
export ES_JAVA_HOME=/data/jypt/es/jdk-21.0.2
EOF
5.使/etc/profile配置立即生效
source /etc/profile
6.配置开机启动
cat >> /usr/lib/systemd/system/elasticsearch.service << ‘EOF’
[Unit]
Description=Elasticsearch
[Service]
User=elastic
LimitNOFILE=65536
LimitNPROC=65536
ExecStart=/data/jypt/es/elasticsearch-8.11.4/bin/elasticsearch
[Install]
WantedBy=multi-user.target
EOF
7.设置开机启动
systemctl enable elasticsearch
8.关闭开机启动
systemctl disable elasticsearch
9.堆内存配置
参考文章:https://blog.csdn.net/laoyang360/article/details/79998974
堆内存配置建议
将最小堆大小(Xms)和最大堆大小(Xmx)设置为彼此相等。
教育平台请用7点几的版本
Elasticsearch可用的堆越多,可用于缓存的内存就越多。但请注意,太多的堆内存可能会使您长时间垃圾收集暂停。
将Xmx设置为不超过物理内存的50%,以确保有足够的物理内存留给内核文件系统缓存。
配置文件路径:elasticsearch-8.1.0/config/jvm.options
生产环境建议默认配置,默认配置es一启动就占用了系统一半多的内存,占的太多了。
列如4GB的内存环境,就把这两个参数设置成:-Xms1g、-Xmx1g
大小建议:
宿主机内存大小的一半和31GB,取最小值。
默认配置,如下,以下是注掉的。
##-Xms4g
##-Xmx4g
配置时,将注释去掉,配置成想配置的内存,比如
##-Xms8g
##-Xmx8g
10.启动
systemctl start elasticsearch
关闭
systemctl stop elasticsearch
状态
systemctl status elasticsearch
重启
systemctl restart elasticsearch
11.检测
curl -XGET http://localhost:9200/_cluster/health?pretty
12. 开启安全认证功能
配置密码
修改配置
vi /opt/elasticsearch/config/elasticsearch.yml
修改如下配置
xpack.security.enabled: true
xpack.security.transport.ssl.enabled: true
如果不配置
xpack.security.transport.ssl.enabled: true
会报以下错误
bootstrap check failure [1] of [1]: Transport SSL must be enabled if security is enabled on a [basic] license. Please set [xpack.security.transport.ssl.enabled] to [true] or disable security by setting [xpack.security.enabled] to [false]
重启
systemctl restart elasticsearch
添加密码
修改内置用户密码-手动配置密码
/opt/elasticsearch/bin/elasticsearch-setup-passwords interactive
会为以下用户设置密码
[apm_system]
[kibana_system]
[kibana]
[logstash_system]
[beats_system]
[remote_monitoring_user]
[elastic]
根据指引自动生成数个密码。注意保存命令行输出。
/opt/elasticsearch/bin/elasticsearch-setup-passwords auto
CentOS 7 中 Elasticsearch 8 的 SSL 配置方法
在 CentOS 7 上安装并配置 Elasticsearch 8 时,如果遇到 invalid SSL configuration
错误,通常是因为 xpack.security.transport.ssl
或其他相关 SSL 参数未正确配置。以下是针对该问题的解决方案:
1. 创建证书
为了启用 SSL/TLS 加密通信,需要先创建自签名证书或导入已有的 CA 签名证书。
运行以下命令生成证书:
bin/elasticsearch-certutil ca
这将生成一个 CA 文件(默认名为 elastic-stack-ca.p12
)。
Enter password for elastic-stack-ca.p12 : btsqjz@2025
接着为集群中的每个节点生成证书:
bin/elasticsearch-certutil cert --ca elastic-stack-ca.p12
将生成的 .p12
文件分发至各个节点,并确保路径一致。
cd /config
sudo mkdir /certs
sudo chown elastic:elastic certs/elastic-certificates.p12
sudo chmod 660 certs/elastic-certificates.p12
2. 修改 elasticsearch.yml
配置文件
根据引用内容,需调整如下参数以支持 SSL/TLS:
xpack.security.enabled: true
xpack.security.transport.ssl.enabled: true
xpack.security.transport.ssl.verification_mode: certificate
xpack.security.transport.ssl.keystore.path: certs/elastic-certificates.p12
xpack.security.transport.ssl.truststore.path: certs/elastic-certificates.p12
4. 测试连接
验证集群健康状态是否正常:
curl -XGET -u elastic:<password> http://<node-ip>:9200/_cluster/health?pretty
curl -XGET -u elastic:sqjz@2025 http://localhost:9200/_cluster/health?pretty
返回结果应显示 "status": "green"
表明集群运行良好。
5.常见问题排查
错误提示:
invalid SSL configuration
可能原因包括但不限于:- 路径指定不正确;
- 密码未正确写入 keystore;
- 使用了过期或损坏的证书。
解决办法:
删除旧的 keystore 并重新初始化:rm -rf config/elasticsearch.keystore bin/elasticsearch-keystore create
随后重复上述步骤重新配置。