Elasticsearch7.8 CentOs开机自启
时间: 2023-12-20 13:00:46 浏览: 84
Elasticsearch 开机自启脚本
要在CentOS上实现Elasticsearch 7.8开机自启动,你可以创建一个启动脚本并将其放置在`/etc/init.d/`目录中。以下是一个示例脚本:
```shell
#!/bin/sh
#chkconfig: 2345 80 05
#description: elasticsearch
case "$1" in
start)
su es<<!
cd /home/soft/elasticsearch/elasticsearch-7.8.0/
./bin/elasticsearch -d
!
echo "Elasticsearch started"
;;
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 es<<!
cd /home/soft/elasticsearch/elasticsearch-7.8.0/
./bin/elasticsearch -d
!
echo "Elasticsearch started"
;;
*)
echo "Usage: start|stop|restart"
;;
esac
exit $?
```
将上述脚本保存为`elasticsearch`,然后使用以下命令将其复制到`/etc/init.d/`目录中:
```shell
sudo cp elasticsearch /etc/init.d/
```
接下来,你需要设置脚本的权限:
```shell
sudo chmod +x /etc/init.d/elasticsearch
```
最后,你可以使用以下命令来启动、停止或重启Elasticsearch:
```shell
sudo service elasticsearch start # 启动
sudo service elasticsearch stop # 停止
sudo service elasticsearch restart # 重启
```
这样,Elasticsearch 7.8就能在CentOS开机时自动启动了。<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* [Elasticsearch 开机自启脚本](https://download.csdn.net/download/weixin_40344051/12922702)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"]
- *2* *3* [Linux搭建elasticsearch-7.8.0单机版本](https://blog.csdn.net/zhuocailing3390/article/details/125985525)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"]
[ .reference_list ]
阅读全文