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

相关推荐
奔波霸的伶俐虫29 分钟前
liunx磁盘挂载和jar启动命令
linux·运维·服务器
都市前线31 分钟前
格雷希尔: G80P系列在制动卡钳行业自动化应用
运维·自动化
wwwlyj12332132 分钟前
slab分配器(3):slab内存申请和释放
linux
JiMoKuangXiangQu1 小时前
Linux 网络:skb 数据管理
linux·网络·skb
做程序员的第一天1 小时前
ubuntu下在pycharm中配置已有的虚拟环境
linux·ubuntu·pycharm
开源优测1 小时前
使用pytest-xdist让自动化并行测试变得轻松简单
运维·自动化·pytest
唐青枫2 小时前
Linux fgrep 命令使用详解
linux
亭墨2 小时前
linux0.11内核源码修仙传第六章——中断初始化
linux·c语言·驱动开发·学习·面试
Ljw...2 小时前
序列化和反序列化(Linux)
linux·开发语言·网络·c++·tcp/ip·序列化反序列化
aiprtem3 小时前
LVGL组件设计之模拟桌面
linux·c语言·网络·物联网