编写开机启动脚本
#!/bin/sh
#chkconfig: 2345 80 05
#description: elasticsearch
#jdk相关路径
export JAVA_HOME=/var/local/java/jdk1.8.0_241
export JAVA_BIN=/var/local/java/jdk1.8.0_241/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)
#es的启动账号名
su elsearch<<!
#es的安装路径
cd /var/local/elasticsearch-6.2.4/
./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 es<<!
cd /var/local/elasticsearch-6.2.4/
./bin/elasticsearch -d
!
echo "elasticsearch startup"
;;
*)
echo "start|stop|restart"
;;
esac
exit $?
脚本中的各种路径需要根据自己服务器修改。
为启动脚本增加执行权限:
chmod +x /etc/init.d/elastisearch
1
配置开机启动es:
chkconfig --add elastisearch
1
重启机器:
reboot
1
检查ES是否启动:
jps
1