1.编写es启停脚本,如下:
注意替换es目录(/home/caster/elasticsearch-7.9.3)以及es启动用户(es)
#!/bin/bash
source /etc/profile
case "$1" in
start)
su es<<!
cd /home/caster/elasticsearch-7.9.3
./bin/elasticsearch -d
!
echo "elasticsearch startup"
;;
stop)
es_pid=`ps aux|grep elasticsearch | grep -v 'grep elasticsearch' | awk '{print $2}'`
kill $es_pid
echo "elasticsearch stopped"
;;
restart)
es_pid=`ps aux|grep elasticsearch | grep -v 'grep elasticsearch' | awk '{print $2}'`
kill -9 $es_pid
echo "elasticsearch stopped"
su es<<!
cd /home/caster/elasticsearch-7.9.3
./bin/elasticsearch -d
!
echo "elasticsearch startup"
;;
*)
echo "start|stop|restart"
;;
esac
exit $?
2.将脚本添加到开启自启动模块
-
放置脚本到指定目录并赋予脚本执行权限: chmod +x /etc/init.d/es
/etc/init.d目录 -
添加到自启动: chkconfig --add es
添加查看结果 - 重启机器查看es是否会自启动
reboot 并查看es是否自启动
网友评论