日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > linux >内容正文

linux

【Linux环境】Elasticsearch 启动停止服务的2类方法【及 java.nio.file.AccessDeniedException: xx/pid 问题解决】(含启停shell脚本)

發布時間:2024/10/6 linux 25 豆豆
生活随笔 收集整理的這篇文章主要介紹了 【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.sh

elasticsearch.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.sh

2.2 測試

  • 我們不啟動,先停止一下試試 😃
  • [root@tcloud elasticsearch]# ./elasticsearch.sh stop ============停止ElasticSearch================ ./elasticsearch.sh: line 16: kill: (831717) - No such process
  • 啟動停止一起測試
  • # 啟動 [root@tcloud elasticsearch]# ./elasticsearch.sh start ============啟動ElasticSearch================# 驗證是否啟動成功 [root@tcloud elasticsearch]# ps -ef | grep elastic root 2082 16917 0 16:25 pts/2 00:00:00 su elasticsearch elastic+ 2083 2082 0 16:25 pts/2 00:00:00 bash elastic+ 17031 1 9 17:30 ? 00:00:22 /usr/local/java/bin/java -Xms256m -Xmx256m -XX:+UseConcMarkSweepGC -XX:CMSInitiatingOccupancyFraction=75 -XX:+UseCMSInitiatingOccupancyOnly -XX:+AlwaysPreTouch -Xss1m -Djava.awt.headless=true -Dfile.encoding=UTF-8 -Djna.nosys=true -XX:-OmitStackTraceInFastThrow -Dio.netty.noUnsafe=true -Dio.netty.noKeySetOptimization=true -Dio.netty.recycler.maxCapacityPerThread=0 -Dlog4j.shutdownHookEnabled=false -Dlog4j2.disable.jmx=true -Djava.io.tmpdir=/tmp/elasticsearch.6IpCYVwq -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=data -XX:ErrorFile=logs/hs_err_pid%p.log -XX:+PrintGCDetails -XX:+PrintGCDateStamps -XX:+PrintTenuringDistribution -XX:+PrintGCApplicationStoppedTime -Xloggc:logs/gc.log -XX:+UseGCLogFileRotation -XX:NumberOfGCLogFiles=32 -XX:GCLogFileSize=64m -Des.path.home=/usr/local/elasticsearch -Des.path.conf=/usr/local/elasticsearch/config -Des.distribution.flavor=default -Des.distribution.type=tar -cp /usr/local/elasticsearch/lib/* org.elasticsearch.bootstrap.Elasticsearch -d -p /usr/local/elasticsearch/pid elastic+ 17053 17031 0 17:30 ? 00:00:00 /usr/local/elasticsearch/modules/x-pack-ml/platform/linux-x86_64/bin/controller root 17979 2848 0 17:34 pts/1 00:00:00 grep --color=auto elastic# 停止并驗證【還有一個elasticsearch的線程 但實際上已經關閉了】 [root@tcloud elasticsearch]# ./elasticsearch.sh stop ============停止ElasticSearch================ [root@tcloud elasticsearch]# ps -ef | grep elastic root 2082 16917 0 16:25 pts/2 00:00:00 su elasticsearch elastic+ 2083 2082 0 16:25 pts/2 00:00:00 bash root 18118 2848 0 17:35 pts/1 00:00:00 grep --color=auto elastic

    3. 總結

    elasticsearch.sh 這個腳本修改后可以用到很多服務的啟動停止上,比如大數據集群、多個jar文件等。

    總結

    以上是生活随笔為你收集整理的【Linux环境】Elasticsearch 启动停止服务的2类方法【及 java.nio.file.AccessDeniedException: xx/pid 问题解决】(含启停shell脚本)的全部內容,希望文章能夠幫你解決所遇到的問題。

    如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。