当前位置: 首页 > article >正文

【elasticsearch 7 或8 的安装及配置SSL 操作指引】

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
    

随后重复上述步骤重新配置。


http://www.lryc.cn/news/2387851.html

相关文章:

  • GitHub 趋势日报 (2025年05月23日)
  • MongoDB索引:原理、实践与优化指南
  • SQL实战之索引优化(单表、双表、三表、索引失效)
  • [7-1] ADC模数转换器 江协科技学习笔记(14个知识点)
  • SSM整合:Spring+SpringMVC+MyBatis完美融合实战指南
  • Spring Boot分页查询进阶:整合Spring Data REST实现高效数据导航
  • 阿里云 Serverless 助力海牙湾构建弹性、高效、智能的 AI 数字化平台
  • 升级node@22后运行npm install报错 distutils not found
  • 一个开源的多播放源自动采集在线影视网站
  • 【PhysUnits】10 减一操作(sub1.rs)
  • 深度检测与动态透明度控制 - 基于Babylon.js的遮挡检测实现解析
  • Linux下使用socat将TCP服务转为虚拟串口设备
  • docker push 报错 denied: requested access to the resource is denied
  • epub→pdf | which 在线转换??好用!!
  • PBX、IP PBX、FXO 、FXS 、VOIP、SIP 的概念解析以及关系
  • MySQL数据高效集成到金蝶云星空的技术分享
  • git 命令之-git cherry-pick
  • 如何在STM32CubeMX下为STM32工程配置调试打印功能
  • Linux系统 - 基本概念
  • kerberos在无痕浏览器 获取用户信息失败 如何判断是否无痕浏览器
  • 在h5端实现录音发送功能(兼容内嵌微信小程序) recorder-core
  • PDF电子发票数据提取至Excel
  • 【身份证识别表格】把大量手机拍摄的身份证信息转换成EXCEL表格的数据,拍的身份证照片转成excel表格保存,基于WPF和腾讯OCR的实现方案
  • FPGA高速接口 mipi lvds cameralink hdml 千兆网 sdi
  • Linux路径解析指南:逻辑路径 vs 实际路径详解
  • Azure 公有云基础架构与核心服务:从基础到实践指南
  • 【运维_日常报错解决方案_docker系列】一、docker系统不起来
  • C# 数组与字符串:全面解析与应用实践
  • 前端vue中使用signalr
  • Stable Diffusion底模对应的VAE推荐