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/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
  • 相关阅读:
    File类与字节流
    字符流
    二进制文件的读写与小结
    下拉列表框与线性、帧布局管理器
    android第二章控件2
    第一章
    安卓时间
    2017《Java技术》 预留作业2 胡开辉
    2017 《JAVA技术》 胡开辉
    ESB产品对比
  • 原文地址:https://www.cnblogs.com/ymdphp/p/11418257.html
Copyright © 2011-2022 走看看