es实战-开机自启动

2021-01-07  本文已影响0人  caster

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.将脚本添加到开启自启动模块

上一篇 下一篇

猜你喜欢

热点阅读