elasticsearch8 linux版以服务的方式启动

1.创建系统服务文件

对于使用 systemd 作为系统初始化系统的 Linux 发行版(如 CentOS 7 及以上、Ubuntu 16.04 及以上),需要创建一个 systemd 服务文件。以 root 用户或具有 sudo 权限的用户身份执行以下操作:

bash 复制代码
sudo vim /etc/systemd/system/elasticsearch.service

在打开的文件中输入以下内容:

bash 复制代码
[Unit]
Description=Elasticsearch
Documentation=https://www.elastic.co
Wants=network-online.target
After=network-online.target

[Service]
User=elasticsearch
Group=elasticsearch
ExecStart=/usr/share/elasticsearch/bin/elasticsearch
Restart=always
TimeoutStopSec=60
LimitNOFILE=65536
LimitNPROC=4096

[Install]
WantedBy=multi-user.target

注意事项

  • ExecStart 字段指定了 Elasticsearch 的启动脚本路径,如果你将 Elasticsearch 安装在其他目录,请相应修改该路径。
  • UserGroup 字段指定了 Elasticsearch 运行时使用的用户和用户组。确保该用户和用户组已经存在,并且对 Elasticsearch 安装目录有适当的权限。

2. 重新加载 systemd 管理器配置

创建或修改服务文件后,需要重新加载 systemd 管理器的配置,使新的服务文件生效:

bash 复制代码
sudo systemctl daemon-reload

3. 启动 Elasticsearch 服务

使用以下命令启动 Elasticsearch 服务:

bash 复制代码
sudo systemctl start elasticsearch

4. 验证服务是否启动成功

可以使用以下命令检查 Elasticsearch 服务的运行状态:

bash 复制代码
sudo systemctl status elasticsearch

如果服务启动成功,你会看到类似以下的输出:

bash 复制代码
● elasticsearch.service - Elasticsearch
   Loaded: loaded (/etc/systemd/system/elasticsearch.service; disabled; vendor preset: enabled)
   Active: active (running) since Mon 2024-01-01 12:00:00 CST; 1min ago
     Docs: https://www.elastic.co
 Main PID: 12345 (elasticsearch)
    Tasks: 100 (limit: 4915)
   Memory: 1.5G
   CGroup: /system.slice/elasticsearch.service
           └─12345 /usr/share/elasticsearch/jdk/bin/java -Xshare:auto -Des.networkaddress.cache.ttl=60 -Des.networkaddress.cache.negative.ttl=10 -XX:+AlwaysPreTouch -Xss1m -Djava.awt.headless=true -Dfile.encoding=UTF-8 -Djna.nosys=true -XX:-OmitStackTraceInFastThrow -Dio.netty.noUnsafe=true -Dio.netty.noKeySetOptimization=true -Dio.netty.recycler.maxCapacityPerThread=0 -Dio.netty.allocator.numDirectArenas=0 -Dlog4j.shutdownHookEnabled=false -Dlog4j2.disable.jmx=true -Djava.io.tmpdir=/tmp/elasticsearch-1234567890 -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=data -XX:ErrorFile=logs/hs_err_pid%p.log -Xmx1g -Xms1g -Des.path.home=/usr/share/elasticsearch -Des.path.conf=/etc/elasticsearch -Des.distribution.flavor=default -Des.distribution.type=tar -cp /usr/share/elasticsearch/lib/* org.elasticsearch.bootstrap.Elasticsearch

Jan 01 12:00:00 your-server systemd[1]: Started Elasticsearch.

5. 设置服务开机自启

如果你希望 Elasticsearch 服务在系统启动时自动启动,可以使用以下命令:

bash 复制代码
sudo systemctl enable elasticsearch

这样,每次系统启动时,Elasticsearch 服务都会自动启动。

相关推荐
甲鱼9298 小时前
MySQL 实战手记:日志管理与主从复制搭建全指南
运维
Johny_Zhao1 天前
OpenClaw安装部署教程
linux·人工智能·ai·云计算·系统运维·openclaw
YuMiao2 天前
gstatic连接问题导致Google Gemini / Studio页面乱码或图标缺失问题
服务器·网络协议
chlk1232 天前
Linux文件权限完全图解:读懂 ls -l 和 chmod 755 背后的秘密
linux·操作系统
舒一笑2 天前
Ubuntu系统安装CodeX出现问题
linux·后端
改一下配置文件2 天前
Ubuntu24.04安装NVIDIA驱动完整指南(含Secure Boot解决方案)
linux
碳基沙盒2 天前
OpenClaw 多 Agent 配置实战指南
运维
深紫色的三北六号3 天前
Linux 服务器磁盘扩容与目录迁移:rsync + bind mount 实现服务无感迁移(无需修改配置)
linux·扩容·服务迁移
SudosuBash3 天前
[CS:APP 3e] 关于对 第 12 章 读/写者的一点思考和题解 (作业 12.19,12.20,12.21)
linux·并发·操作系统(os)
哈基咪怎么可能是AI3 天前
为什么我就想要「线性历史 + Signed Commits」GitHub 却把我当猴耍 🤬🎙️
linux·github