openEuler 下部署 Elasticsearch

Elasticsearch(简称 ES)是分布式搜索与分析引擎,广泛用于日志分析、全文检索等场景。本文基于 openEuler 22.03 LTS 系统,从环境准备、单节点部署、集群搭建、功能验证到运维优化,提供可落地的部署指南。

一、环境准备

  1. 系统基础配置
    openEuler 默认配置需调整以适配 ES 的资源要求:
    bash
    运行

切换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

  1. 下载 Elasticsearch 安装包

选择与 openEuler 架构匹配的 ES 版本(以 7.17.10 为例,适配 openEuler 22.03):

bash

运行

下载安装包(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 用户启动,需创建系统用户:
    bash
    运行

创建用户组与用户

groupadd elasticsearch

useradd -g elasticsearch elasticsearch

授权目录权限

chown -R elasticsearch:elasticsearch /usr/local/elasticsearch

  1. 配置 ES 核心参数

编辑 ES 配置文件/usr/local/elasticsearch/config/elasticsearch.yml:

yaml

集群名称(自定义)

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"

  1. 启动 ES 服务

bash

运行

切换到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
    yaml
    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"

  1. 依次启动所有节点

bash

运行

su elasticsearch

cd /usr/local/elasticsearch

./bin/elasticsearch -d

  1. 验证集群状态

bash

运行

查看集群健康状态(返回"status":"green"则正常)

curl http://192.168.1.10:9200/_cat/health?v

四、功能验证

  1. 创建测试索引
    bash
    运行

创建名为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"

  1. 查看节点信息

bash

运行

查看集群节点列表

curl http://localhost:9200/_cat/nodes?v

五、运维优化(openEuler 适配)

  1. 内存优化
    编辑/usr/local/elasticsearch/config/jvm.options,调整 JVM 堆内存(建议为物理内存的 50%,不超过 32GB):
    ini
    -Xms4g
    -Xmx4g
  2. 开机自启配置
    创建 systemd 服务文件/etc/systemd/system/elasticsearch.service:
    ini

    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

启用自启:

bash

运行

systemctl daemon-reload

systemctl enable elasticsearch

systemctl start elasticsearch

  1. 常见问题解决

启动失败提示内存不足:检查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 完成日志采集。

相关推荐
智商网输送线配件1 小时前
2026 自动化流水线配件采购难题破解:小批量混批与非标定制的供应链实测
大数据·人工智能·自动化·智商网·流水线设备配件
辛迪聊物业数字化2 小时前
智慧物业管理平台架构实践:从SaaS物业云到商管系统的全模块落地
大数据·微服务·php
SelectDB2 小时前
快手基于 Apache Doris 千亿多模态检索的实践
大数据·数据库·数据分析
SelectDB2 小时前
StarRocks 迁移至 Apache Doris 完整指南:三步完成结构、数据与业务平滑切换
大数据·数据库·数据分析
mmsx2 小时前
Android 地图十万要素不卡顿:空间网格 + 渐进式加载的移动端实践
android·大数据·opengl
宁波鹿语心理3 小时前
注意缺陷多动障碍儿童及家庭的心理支持:理解特质,重建价值
大数据
跨境数据猎手3 小时前
反向海淘是什么:2026从系统架构到业务落地
大数据·产品运营·需求分析
TDengine (老段)3 小时前
TDengine 常见问题 TOP7
大数据·数据库·时序数据库·常见问题·tdengine·涛思数据
探数API小喇叭3 小时前
天气 API 接口思路:拆解一套包含 4 个子接口的轻量化气象服务
大数据·api·天气预报
方向研究4 小时前
硬盘健康信息监测
大数据