elasticsearch在CentOS环境下开机启动
实验环境:
OS版本:CentOS-7-x86_64-Minimal-1708;ES版本:elasticsearch-7.4.0.
具体步骤:
在/etc/init.d/目录创建es文件
vi /etc/init.d/es文件内容:
#!/bin/bash # #chkconfig: 345 63 37 #description: elasticsearch #processname: elasticsearch-7.4.0 ES_HOME=/usr/local//usr/local/elasticsearch-7.4.0 case $1 in start) su - es_user -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_user -c "$ES_HOME/bin/elasticsearch -d -p pid" echo "elasticsearch is started" ;; *) echo "start|stop|restart" ;; esac exit 0
修改上面文件的权限,执行命令
chmod 777 /etc/init.d/es
添加和删除服务并设置启动方式(chkconfig具体使用另行百度)
chkconfig --add es chkconfig --del es
启动和关闭服务
service es start // 启动服务 service es stop // 关闭服务 service es restart // 重启服务
设置服务的启动方式
chkconfig es on // 设置开机启动 chkconfig es off // 关闭开机启动