elasticsearch自启服务
1 创建服务文件
[root@node1 ~]
#!/bin/sh
export JAVA_HOME=/usr/local/jdk1.8.0_181
export JAVA_BIN=/usr/local/jdk1.8.0_181/bin
export PATH=$PATH:$JAVA_HOME/bin
export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
export JAVA_HOME JAVA_BIN PATH CLASSPATH
case "$1" in
start)
su esuser<<!
cd /usr/local/elasticsearch
./bin/elasticsearch -d
!
echo "elasticsearch startup"
;;
stop)
es_pid=`ps aux|grep elasticsearch | grep -v 'grep elasticsearch' | awk '{print $2}'`
kill -9 $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 esuser<<!
cd /usr/local/elasticsearch
./bin/elasticsearch -d
!
echo "elasticsearch startup"
;;
*)
echo "start|stop|restart"
;;
esac
exit $?
2 将脚本生成系统服务
[root@node1 ~]
[root@node1 ~]
[root@node1 ~]