zoukankan      html  css  js  c++  java
  • elasticsearch 开机自启

    linux下开机自启:

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

    并敲入shell脚本:

    #!/bin/sh
    #chkconfig: 2345 80 05
    #description: elasticsearch
     
    export JAVA_HOME=/home/app/java/jdk1.8.0_201
    export JAVA_BIN=/home/app/java/jdk1.8.0_201/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 elsearch<<!
        cd /home/app/elasticsearch/elasticsearch-5.5.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 brian<<!
        cd /home/app/elasticsearch/elasticsearch-5.5.1
        ./bin/elasticsearch -d
    !
        echo "elasticsearch startup"
        ;;  
    *)
        echo "start|stop|restart"
        ;;  
    esac
    
    exit $?

    注意,

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

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

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

        shell脚本中的java、es路径、开启账户要注意。(我是在root用户下使用的,但是es是安装在brian下)

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

    chmod +x elasticsearch

    添加到开机启动任务

    chkconfig --add elasticsearch

    开机重启,ok

  • 相关阅读:
    剑指offer(第2版)刷题 Python版汇总
    git学习笔记
    Python中的lambda、map和filter
    算法题 22 折纸问题 (牛客网,今日头条)
    算法题 21 findNSum (好未来,LeetCode,牛客网)
    算法题 20 或与加
    Python的内存管理机制
    【算法题12 解码方法decode way】
    理解循环神经网络的来龙去脉
    机器学习资源个人汇总
  • 原文地址:https://www.cnblogs.com/chenyishi/p/11531994.html
Copyright © 2011-2022 走看看