openEuler 下部署 Elasticsearch
【摘要】 Elasticsearch(简称 ES)是分布式搜索与分析引擎,广泛用于日志分析、全文检索等场景。本文基于 openEuler 22.03 LTS 系统,从环境准备、单节点部署、集群搭建、功能验证到运维优化,提供可落地的部署指南。一、环境准备1. 系统基础配置openEuler 默认配置需调整以适配 ES 的资源要求:# 切换root用户su root# 1. 关闭防火墙(测试环境,生产环境...
Elasticsearch(简称 ES)是分布式搜索与分析引擎,广泛用于日志分析、全文检索等场景。本文基于 openEuler 22.03 LTS 系统,从环境准备、单节点部署、集群搭建、功能验证到运维优化,提供可落地的部署指南。
一、环境准备
1. 系统基础配置
openEuler 默认配置需调整以适配 ES 的资源要求:
# 切换root用户
su root
# 1. 关闭防火墙(测试环境,生产环境需开放9200/9300端口)
systemctl stop firewalld
systemctl disable firewalld
# 2. 临时关闭SELinux(永久关闭需修改/etc/selinux/config)
setenforce 0
# 3. 调整虚拟内存(ES要求vm.max_map_count≥262144)
sysctl -w vm.max_map_count=262144
echo "vm.max_map_count=262144" >> /etc/sysctl.conf
sysctl -p
# 4. 安装依赖包
dnf install -y java-11-openjdk-devel wget
2. 下载 Elasticsearch 安装包
选择与 openEuler 架构匹配的 ES 版本(以 7.17.10 为例,适配 openEuler 22.03):
# 下载安装包(x86_64架构)
wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.17.10-linux-x86_64.tar.gz
# 若为ARM64架构,替换为对应包:
# wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.17.10-linux-aarch64.tar.gz
# 解压包
tar -zxvf elasticsearch-7.17.10-linux-x86_64.tar.gz
mv elasticsearch-7.17.10 /usr/local/elasticsearch
二、单节点部署
1. 创建 ES 专属用户
ES 不允许 root 用户启动,需创建系统用户:
# 创建用户组与用户
groupadd elasticsearch
useradd -g elasticsearch elasticsearch
# 授权目录权限
chown -R elasticsearch:elasticsearch /usr/local/elasticsearch
2. 配置 ES 核心参数
编辑 ES 配置文件
/usr/local/elasticsearch/config/elasticsearch.yml:# 集群名称(自定义)
cluster.name: es-cluster
# 节点名称(自定义)
node.name: es-node-1
# 数据存储路径
path.data: /usr/local/elasticsearch/data
# 日志存储路径
path.logs: /usr/local/elasticsearch/logs
# 绑定IP(0.0.0.0允许所有IP访问)
network.host: 0.0.0.0
# HTTP端口(默认9200)
http.port: 9200
# 集群初始化主节点(单节点为自身)
cluster.initial_master_nodes: ["es-node-1"]
3. 启动 ES 服务
# 切换到elasticsearch用户
su elasticsearch
# 后台启动ES
cd /usr/local/elasticsearch
./bin/elasticsearch -d
# 验证启动状态(返回JSON信息则成功)
curl http://localhost:9200
三、集群部署(3 节点示例)
以
节点1(192.168.1.10)、节点2(192.168.1.11)、节点3(192.168.1.12)为例,在单节点基础上调整配置:1. 所有节点统一配置elasticsearch.yml
cluster.name: es-cluster
# 各节点名称需唯一(如es-node-1、es-node-2、es-node-3)
node.name: es-node-1
path.data: /usr/local/elasticsearch/data
path.logs: /usr/local/elasticsearch/logs
network.host: 0.0.0.0
http.port: 9200
# 集群节点发现列表(所有节点IP)
discovery.seed_hosts: ["192.168.1.10", "192.168.1.11", "192.168.1.12"]
# 初始化主节点(所有节点名称)
cluster.initial_master_nodes: ["es-node-1", "es-node-2", "es-node-3"]
2. 依次启动所有节点
su elasticsearch
cd /usr/local/elasticsearch
./bin/elasticsearch -d
3. 验证集群状态
# 查看集群健康状态(返回"status":"green"则正常)
curl http://192.168.1.10:9200/_cat/health?v
四、功能验证
1. 创建测试索引
# 创建名为test_index的索引
curl -X PUT "http://localhost:9200/test_index"
# 插入测试数据
curl -X POST "http://localhost:9200/test_index/_doc/1" -H "Content-Type: application/json" -d '{"name":"openEuler","version":"22.03"}'
# 查询数据
curl -X GET "http://localhost:9200/test_index/_search"
2. 查看节点信息
# 查看集群节点列表
curl http://localhost:9200/_cat/nodes?v
五、运维优化(openEuler 适配)
1. 内存优化
编辑
/usr/local/elasticsearch/config/jvm.options,调整 JVM 堆内存(建议为物理内存的 50%,不超过 32GB):-Xms4g
-Xmx4g
2. 开机自启配置
创建 systemd 服务文件
/etc/systemd/system/elasticsearch.service:[Unit]
Description=Elasticsearch
After=network.target
[Service]
User=elasticsearch
Group=elasticsearch
WorkingDirectory=/usr/local/elasticsearch
ExecStart=/usr/local/elasticsearch/bin/elasticsearch
Restart=always
[Install]
WantedBy=multi-user.target
启用自启:
systemctl daemon-reload
systemctl enable elasticsearch
systemctl start elasticsearch
3. 常见问题解决
- 启动失败提示内存不足:检查
vm.max_map_count是否配置,或调整 JVM 堆内存; - 集群节点无法发现:确认防火墙开放 9300 端口(ES 节点通信端口),执行
firewall-cmd --add-port=9300/tcp --permanent; - 权限错误:重新执行
chown -R elasticsearch:elasticsearch /usr/local/elasticsearch。
总结
openEuler 下部署 ES 的核心是系统参数适配(虚拟内存、用户权限)+ ES 配置优化(集群发现、资源限制)。单节点适合测试场景,生产环境建议 3 节点以上集群保证高可用。后续可结合 Kibana 实现数据可视化,或接入 Filebeat 完成日志采集。
【声明】本内容来自华为云开发者社区博主,不代表华为云及华为云开发者社区的观点和立场。转载时必须标注文章的来源(华为云社区)、文章链接、文章作者等基本信息,否则作者和本社区有权追究责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱:
cloudbbs@huaweicloud.com
- 点赞
- 收藏
- 关注作者
评论(0)