elasticsearch设置开机自启
1,进入cd /etc/init.d 目录
cd /etc/init.d
2,编辑脚本内容:
vim /etc/init.d/elasticsearch
3,复制以下内容
注意注意:jdk相关路径-es的启动账号名-es的安装路径
都修改为自己的!!!
#!/bin/sh
#chkconfig: 2345 80 05
#description: elasticsearch
#jdk相关路径
export JAVA_HOME=/usr/java/jdk1.8
export JAVA_BIN=/usr/java/jdk1.8/bin
export PATH=$PATH:$JAVA_HOME/bin
export CLASSPATH=.:$JAVA_HOME/jre/lib/ext:$JAVA_HOME/lib/tools.jar
export JAVA_HOME JAVA_BIN PATH CLASSPATH
case "$1" in
start)
#es的启动账号名
su test<<!
#es的安装路径
cd /usr/local/elasticsearch-6.8.0
./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 test<<!
cd /usr/local/elasticsearch-6.8.0
./bin/elasticsearch -d
!
echo "elasticsearch startup"
;;
*)
echo "start|stop|restart"
;;
esac
exit $?
退出保存即可!!
为启动脚本增加执行权限:
chmod +x elasticsearch
配置开机启动es:
chkconfig --add elasticsearch
重启机器:
reboot
检查ES是否启动:
[root@localhost init.d]# jps
2226 Jps
1986 Elasticsearch
以上表示开机自启动成功,可以访问了!!!