夜间模式暗黑模式
字体
阴影
滤镜
圆角
主题色
Centos8将Elasticsearch做成systemctl服务

一、添加elasticsearch基本信息的配置文件

vim /etc/sysconfig/elasticsearch-1   #elasticsearch-1 这个名字任意定义,因为我服务器中有多个es所以加-1进行命名。

将下列内容添加到elasticsearch-1中

#es的目录文件地址
ES_HOME=/data/es-cluster/elasticsearch-7.9.2-1
#Java的目录文件地址(这里我就用es7中自带的jdk)
JAVA_HOME=/data/es-cluster/elasticsearch-7.9.2-1/jdk
#es中的config文件的地址  
ES_PATH_CONF=/data/es-cluster/elasticsearch-7.9.2-1/config
#运行es进程的地址(这里需要注意由于es启动的时候非root用户启动 所以你配置的目录es用户要有写如的权限)
PID_DIR=/data/es-cluster/elasticsearch-7.9.2-1/run/elasticsearch-1
ES_STARTUP_SLEEP_TIME=5

二、编写控制elasticsearch启动的service文件

vim /usr/lib/systemd/system/elasticsearch-1.service   #elasticsearch-1.service这个名字根据喜好定义,后续需要这个名字来进行启动关闭。

将下列内容添加到elasticsearch-1.service中

[Unit]
Description=Elasticsearch
Documentation=http://www.elastic.co
Wants=network-online.target
After=network-online.target

[Service]
Environment=ES_HOME=/data/es-cluster/elasticsearch-7.9.2-1
Environment=ES_PATH_CONF=/data/es-cluster/elasticsearch-7.9.2-1/config
Environment=PID_DIR=/data/es-cluster/elasticsearch-7.9.2-1/run/elasticsearch-1
EnvironmentFile=/etc/sysconfig/elasticsearch-1
WorkingDirectory=/data/es-cluster/elasticsearch-7.9.2-1
#启动的用户
User=es
#启动的用户组
Group=es
#启动线程地址
ExecStart=/data/es-cluster/elasticsearch-7.9.2-1/bin/elasticsearch -p ${PID_DIR}/elasticsearch.pid

#下列这些如无特殊情况,不需要进行修改直接进行复制就行
StandardOutput=journal
StandardError=inherit

# Specifies the maximum file descriptor number that can be opened by this process
LimitNOFILE=65536

# Specifies the maximum number of process
LimitNPROC=4096

# Specifies the maximum size of virtual memory
LimitAS=infinity

# Specifies the maximum file size
LimitFSIZE=infinity

# Disable timeout logic and wait until process is stopped
TimeoutStopSec=0

# SIGTERM signal is used to stop the Java process
KillSignal=SIGTERM

# Send the signal only to the JVM rather than its control group
KillMode=process

# Java process is never killed
SendSIGKILL=no

# When a JVM receives a SIGTERM signal it exits with code 143
SuccessExitStatus=143
 
[Install]
WantedBy=multi-user.target

添加可执行权限

chmod +x /usr/lib/systemd/system/elasticsearch-1.service

重新加载systemctl服务配置文件

systemctl daemon-reload

三、服务开启关闭自启动

启动

systemctl start elasticsearch-1.service

关闭

systemctl stop elasticsearch-1.service

重启

systemctl restart elasticsearch-1.service

开机自启动

systemctl enable elasticsearch-1.service
暂无评论

发送评论 编辑评论


				
上一篇
下一篇