【Linux环境】Elasticsearch 启动停止服务的2类方法【及 java.nio.file.AccessDeniedException: xx/pid 问题解决】(含启停shell脚本)
生活随笔
收集整理的這篇文章主要介紹了
【Linux环境】Elasticsearch 启动停止服务的2类方法【及 java.nio.file.AccessDeniedException: xx/pid 问题解决】(含启停shell脚本)
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
我使用的是騰訊的云服務器1核心2G內存,安裝的有MySQL數據庫,elasticsearch 啟動后剩余的內存就捉襟見肘了,為了運行其他服務,需要停止 elasticsearch 服務,這個時候我才發現 elasticsearch 根本就不希望大家停止掉自己【沒有停止服務的命令】這里總結一下啟動和停止服務的方法:
1. 直接啟動與停止
啟動:
# 切換到 elasticsearch 用戶 [root@tcloud ~]# su elasticsearch# 一般啟動 bash-4.2$ /usr/local/elasticsearch/bin/elasticsearch# 后臺啟動 bash-4.2$ /usr/local/elasticsearch/bin/elasticsearch -d停止:
# 一般啟動 Ctrl c 【很多非后臺啟動的服務都是這樣停止的】 [root@tcloud bin]# [2021-08-03T17:11:25,733][INFO ][o.e.x.m.j.p.NativeController] Native controller process has stopped - no new native processes can be started [2021-08-03T17:11:25,735][INFO ][o.e.n.Node ] [M_rq0Xz] stopping ... [2021-08-03T17:11:25,743][INFO ][o.e.x.w.WatcherService ] [M_rq0Xz] stopping watch service, reason [shutdown initiated] [2021-08-03T17:11:25,955][INFO ][o.e.n.Node ] [M_rq0Xz] stopped [2021-08-03T17:11:25,955][INFO ][o.e.n.Node ] [M_rq0Xz] closing ... [2021-08-03T17:11:25,976][INFO ][o.e.n.Node ] [M_rq0Xz] closed# 后臺啟動 # 查詢 elasticsearch 的相關線程【多個】 [root@tcloud bin]# ps -ef | grep elastic # 停止所有 elasticsearch 相關線程【多個】 [root@tcloud bin]# kill -9 ***2. 使用PID啟動與停止【當然也可以不用shell腳本 直接使用命令】
2.1 配置
前邊的方法停止的時候查詢到的線程ID是多個,這里只用停掉PID即可,我們編寫一個shell腳本來實現啟動和停止:
# 添加 pid [root@tcloud ~]# vim /usr/local/elasticsearch/pid# 寫入pid值# 我寫的是 831717 # 將 pid 文件轉到 elasticsearch 用戶下【這個很重要】 [root@tcloud elasticsearch]# chown -R elasticsearch ./pid [root@tcloud elasticsearch]# chgrp -R elasticsearch ./pid # 添加 elasticsearch.sh 腳本文件 [root@tcloud ~]# vim /usr/local/elasticsearch/elasticsearch.shelasticsearch.sh 文件的內容如下:
#!/bin/bashif [ $# -ne 1 ] thenecho "args number is error!!!"exit ficase $1 in "start")echo "============啟動ElasticSearch================"su elasticsearch -c "sh ${ELASTICSEARCH_HOME}/bin/elasticsearch -d -p ${ELASTICSEARCH_HOME}/pid";; "stop")echo "============停止ElasticSearch================"kill `cat ${ELASTICSEARCH_HOME}/pid`;; *)echo "args info is error!!!";; esac # 給 shell 腳本賦權限 [root@tcloud ~]# chmod +x /usr/local/elasticsearch/elasticsearch.sh2.2 測試
3. 總結
elasticsearch.sh 這個腳本修改后可以用到很多服務的啟動停止上,比如大數據集群、多個jar文件等。
總結
以上是生活随笔為你收集整理的【Linux环境】Elasticsearch 启动停止服务的2类方法【及 java.nio.file.AccessDeniedException: xx/pid 问题解决】(含启停shell脚本)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Redis 远程字典服务及shell全部
- 下一篇: Java【前端动态添加一条记】【后端使用