脚本:
vi /etc/init.d/elasticsearch
脚本内容: ES_HOME的路径替换为自己的
#!/bin/bash
#chkconfig: 2345 80 90
#description: elasticsearch
export ES_HOME=/usr/local/elasticsearch-8.8.0
case "$1" in
start)
su es<<!
cd $ES_HOME
./bin/elasticsearch -d -p pid
!
echo "elasticsearch startup"
;;
stop)
kill -9 `cat $ES_HOME/pid`
echo "elasticsearch stopped"
;;
restart)
kill -9 `cat $ES_HOME/pid`
echo "elasticsearch stopped"
su es<<!
cd $ES_HOME
./bin/elasticsearch -d -p pid
!
echo "elasticsearch startup"
;;
*)
echo "start|stop|restart"
;;
esac
exit $?
赋权
chmod 777 /etc/init.d/elasticsearch
注册服务
chkconfig --add elasticsearch
开机自启
chkconfig elasticsearch on
systemctl enable elasticsearch
操作命令
systemctl start elasticsearch # 【启动服务】
systemctl stop elasticsearch # 【停止服务】
systemctl restart elasticsearch # 【重启服务】