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 服务都会自动启动。

相关推荐
FreeBuf_18 分钟前
微软365 PDF导出功能存在本地文件包含漏洞,可泄露敏感服务器数据
服务器·microsoft·pdf
lixzest1 小时前
C++ Lambda 表达式详解
服务器·开发语言·c++·算法
ajassi20001 小时前
开源 python 应用 开发(三)python语法介绍
linux·python·开源·自动化
o不ok!1 小时前
Linux面试问题-软件测试
linux·运维·服务器
DaxiaLeeSuper1 小时前
Prometheus+Grafana+node_exporter监控linux服务器资源的方案
linux·grafana·prometheus
尽兴-2 小时前
如何将多个.sql文件合并成一个:Windows和Linux/Mac详细指南
linux·数据库·windows·sql·macos
kfepiza2 小时前
Netplan 中 bridges、bonds、ethernets、vlans 之间的关系 笔记250711
linux·tcp/ip·shell
小小不董3 小时前
深入理解oracle ADG和RAC
linux·服务器·数据库·oracle·dba
狄加山6753 小时前
Cadence模块复用
服务器·硬件架构·硬件工程·信号处理·智能硬件