elasticsearch开机自启

时间:2019-08-27
本文章向大家介绍elasticsearch开机自启,主要包括elasticsearch开机自启使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。

linux下开机自启:

在/etc/init.d目录下新建文件elasticsearch

并敲入shell脚本:

#!/bin/sh
#chkconfig: 2345 80 05
#description: elasticsearch
 
export JAVA_HOME=/home/hadoop/jdk/jdk1.8.0_172
export JAVA_BIN=/home/hadoop/jdk/jdk1.8.0_172/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 hadoop<<!
    cd /opt/elasticsearch-5.1.1
    ./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 hadoop<<!
    cd /opt/elasticsearch-5.1.1
    ./bin/elasticsearch -d
!
    echo "elasticsearch startup"
    ;;  
*)
    echo "start|stop|restart"
    ;;  
esac

exit $?

前两行必须填写,且要注释掉

第一行为shell前行代码,目的告诉系统使用shell。

第二行分别代表运行级别,启动优先权,关闭优先权,且后面添加开机服务会用到

shell脚本中的Java,es路径,开启账户要注意,此处我是在root用户下使用的,但是es是安装在hadoop下面的

保存退出,并在/etc/init.d/下赋予执行权限

chmod +x elasticsearch

添加到开机启动任务

chkconfig --add elasticsearch

原文地址:https://www.cnblogs.com/ymdphp/p/11418257.html