elasticsearch开机自启

▼魔方 西西 提交于 2019-11-28 18:06:39

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

 

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!