1.在/etc/systemd/system
目录下创建elasticsearch1.service
注意:如果您的系统使用的不是Systemd,请根据您的init系统调整命令(如Upstart或SysVinit)。
如果在同一台机器启动多个节点,就按照本文再创建elasticsearch2.service就行了。
下面是elasticsearch1.service脚本内容
把目录/opt/app/middles/es/elasticsearch-7.8.0/
替换成你的es安装目录
[Unit]
Description=es-node-1
Documentation=https://www.elastic.co/guide/en/elasticsearch/reference/current/index.html
Wants=network-online.target
After=network.target network-online.target
[Service]
Type=simple
User=es
Group=es
WorkingDirectory=/opt/app/middles/es/elasticsearch-7.8.0/
ExecStart=/opt/app/middles/es/elasticsearch-7.8.0/bin/elasticsearch -p /opt/app/middles/es/elasticsearch-7.8.0/elasticsearch.pid
ExecStop=/bin/kill -TERM $MAINPID
ExecReload=/bin/kill -HUP $MAINPID
Restart=always
RestartSec=10
# Set environment variables
Environment=ES_HOME=/opt/app/middles/es/elasticsearch-7.8.0/
Environment=ES_PATH_CONF=/opt/app/middles/es/elasticsearch-7.8.0/config
# Specifies the maximum file descriptor number that can be opened by this process
LimitNOFILE=65536
# Specifies the maximum number of processes
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
RuntimeDirectory=elasticsearch
RuntimeDirectoryMode=0755
[Install]
WantedBy=multi-user.target
2.重新加载
systemctl daemon-reload
3.常用命令
#设置开机启动
systemctl enable elasticsearch1.service
#启动es
systemctl start elasticsearch1.service
#停止es
systemctl stop elasticsearch1.service
#查看es状态
systemctl status elasticsearch1.service
标签:service,app,---,middles,elasticsearch,ElasticSearch,7.8,es
From: https://www.cnblogs.com/hujunwei/p/18049374