编写脚本
- 说明:需指定JDK环境,要不然会默认使用es自带的JDK,自带的版本太新,去除了GC。
vim /etc/init.d/elasticsearch #!/bin/sh #chkconfig: 2345 80 05 export JAVA_HOME=/data/app/jdk-13.0.1 export PATH=$JAVA_HOME/bin:$PATH export ES_HOME=/data/elasticsearch/ export PATH=$ES_HOME/bin:$PATH case $1 in start) cd $ES_HOME ./bin/elasticsearch -d -p pid exit ! echo "elasticsearch is started" ;; stop) pid=`ps -ef | grep "Elasticsearch" |grep -v "grep" | awk '{print $2}'` kill -15 $pid echo "elasticsearch is stopped" ;; restart) pid=`ps -ef | grep "Elasticsearch" |grep -v "grep" | awk '{print $2}'` kill -15 $pid echo "elasticsearch is stopped" sleep 1 cd $ES_HOME ./bin/elasticsearch -d -p pid exit ! echo "elasticsearch is started" ;; *) echo "start|stop|restart" ;; esac exit 0
添加到开机启动任务
chmod +x /etc/init.d/elasticsearch chkconfig --add elasticsearch service elasticsearch restart
评论