elasticsearch设置执行脚本并添加开机启动

发布时间:2019-04-09 15:29:19 作者:阿拓 阅读量:76

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

  1. #!/bin/sh
  2. #chkconfig: 2345 80 05
  3. #description: elasticsearch
  4. export JAVA_HOME=/usr/java/jdk1.8.0_112
  5. export JAVA_BIN=/usr/java/jdk1.8.0_112/bin
  6. export PATH=$PATH:$JAVA_HOME/bin
  7. export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
  8. export JAVA_HOME JAVA_BIN PATH CLASSPATH
  9. case "$1" in
  10. start)
  11. su lyt<<!
  12. cd /home/lyt/dev-repo/elk5/elasticsearch-5.6.9
  13. ./bin/elasticsearch -d
  14. !
  15. echo "elasticsearch startup"
  16. ;;
  17. stop)
  18. es_pid=`ps aux|grep elasticsearch | grep -v 'grep elasticsearch' | awk '{print $2}'`
  19. kill -9 $es_pid
  20. echo "elasticsearch stopped"
  21. ;;
  22. restart)
  23. es_pid=`ps aux|grep elasticsearch | grep -v 'grep elasticsearch' | awk '{print $2}'`
  24. kill -9 $es_pid
  25. echo "elasticsearch stopped"
  26. su lyt<<!
  27. cd /home/lyt/dev-repo/elk5/elasticsearch-5.6.9
  28. ./bin/elasticsearch -d
  29. !
  30. echo "elasticsearch startup"
  31. ;;
  32. *)
  33. echo "start|stop|restart"
  34. ;;
  35. esac
  36. exit $?

保存退出,赋予执行权限

chmod +x elasticsearch

添加到开机启动任务

chkconfig -add elasticsearch
如果不设置开机启动的话,也可以使用service elasticsearch start/stop/restart来操作

我要评论

Powered By ZTsky Blog 版权所有 © 2015-2019. All right reserved. 鄂ICP备15021472号
Catfish(鲶鱼) Blog V 2.0.63