elasticsearch开机自启动

  1. cd /etc/init.d 进入目录
  2. 创建文件es,把下面内容粘贴进去
#!/bin/bash
#
#chkconfig: 345 63 37
#description: elasticsearch
#processname: elasticsearch

ES_HOME=/usr/local/elasticsearch

case $1 in
  start)
    su - es -c "$ES_HOME/bin/elasticsearch -d -p pid"
    echo "elasticsearch is started"
    ;;
  stop)
    pid=`cat $ES_HOME/pid`
    kill -9 $pid
    echo "elasticsearch is stopped"
    ;;
  restart)
    pid=`cat $ES_HOME/pid`
    kill -9 $pid
    echo "elasticsearch is stopped"
    sleep 1
    su - es -c "$ES_HOME/bin/elasticsearch -d -p pid"
    echo "elasticsearch is started"
    ;;
  *)
    echo "start|stop|restart"
    ;;
esac
exit 0
  1. 给脚本添加权限chmod 755 es
  2. 添加服务到开机项 chkconfig --add es
  3. 设置为开机启动 chkconfig es on
  4. 测试 service es start

你可能感兴趣的:(elasticsearch开机自启动)