elasticsearch安裝和配置,elasticsearch啟動報錯:can not run elasticsearch as root


elasticsearch安裝和配置

elasticsearch啟動報錯:can not run elasticsearch as root

elasticsearch啟動報錯:ERROR: [3] bootstrap checks failed
[1]: max file descriptors [4096] for elasticsearch process is too low, increase to at least [65535]      
[2]: max number of threads [3818] for user [es] is too low, increase to at least [4096]                        
[3]: max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]

 

================================

©Copyright 蕃薯耀 2021-02-20

https://www.cnblogs.com/fanshuyao/

 

一、elasticsearch解壓安裝
1、解壓elasticsearch

cd /java/es6/
tar -zxvf elasticsearch-6.8.13.tar.gz

 

2、修改文件夾名稱和移動位置

mv elasticsearch-6.8.13 /java/elasticsearch6

 

3、進入配置文件目錄

cd /java/elasticsearch6/config

[root@host-12 java]# cd /java/elasticsearch6/config
[root@host-12 config]# ll
總用量 32
-rw-r-----. 1 631 503 2853 10月 16 17:04 elasticsearch.yml
-rw-r-----. 1 631 503 3885 10月 16 17:04 jvm.options
-rw-r-----. 1 631 503 13085 10月 16 17:17 log4j2.properties
-rw-r-----. 1 631 503 473 10月 16 17:17 role_mapping.yml
-rw-r-----. 1 631 503 197 10月 16 17:17 roles.yml
-rw-r-----. 1 631 503 0 10月 16 17:17 users
-rw-r-----. 1 631 503 0 10月 16 17:17 users_roles

 


4、創建數據和日志目錄

mkdir -p /java/elasticsearch6/esdata

mkdir -p /java/elasticsearch6/eslogs

 

5、修改配置文件:

vi /java/elasticsearch6/config/elasticsearch.yml

 

修改內容:

#集群名稱
cluster.name: myes6
#節點名稱
node.name: node-11
#數據目錄
path.data: /java/elasticsearch6/esdata
#日志目錄
path.logs: /java/elasticsearch6/eslogs
# 是否鎖定內存在啟動時
bootstrap.memory_lock: false
#centos6.x操作系統不支持SecComp,默認bootstrap.system_call_filter為true進行檢測,所以導致檢測失敗,失敗后直接導致ES不能啟動。
#如果不配置,會出現錯誤:system call filters failed to install; check the logs and fix your configuration or disable system call filters at your own risk
bootstrap.system_call_filter: false
#IP地址
network.host: 192.168.170.11
#端口號
http.port: 9200
#集群發現
discovery.zen.ping.unicast.hosts: ["192.168.170.11", "192.168.170.12", "192.168.170.13"]

 


二、elasticsearch設置環境變量

1、配置elasticsearch運行的環境變量,簡化命令,配置后,不用拼寫完整路徑:

vi /etc/profile

 

2、在文件的最后加上:

ELASTICSEARCH_HOME=/java/elasticsearch6/
PATH=$PATH:$ELASTICSEARCH_HOME/bin
export ELASTICSEARCH_HOME PATH

 

3、讓環境變量配置立即生效:

source /etc/profile

 

三、啟動elasticsearch

/java/elasticsearch6/bin/elasticsearch

如果設置環境變量,則可以:

elasticsearch

 

elasticsearch啟動時報錯:can not run elasticsearch as root

不能使用root啟動

Caused by: java.lang.RuntimeException: can not run elasticsearch as root
at org.elasticsearch.bootstrap.Bootstrap.initializeNatives(Bootstrap.java:103) ~[elasticsearch-6.8.13.jar:6.8.13]
at org.elasticsearch.bootstrap.Bootstrap.setup(Bootstrap.java:170) ~[elasticsearch-6.8.13.jar:6.8.13]
at org.elasticsearch.bootstrap.Bootstrap.init(Bootstrap.java:333) ~[elasticsearch-6.8.13.jar:6.8.13]
at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:159) ~[elasticsearch-6.8.13.jar:6.8.13]
... 6 more

 

增加es用戶:

groupadd es

useradd es -g es

passwd es

新的 密碼:
重新輸入新的 密碼:
passwd:所有的身份驗證令牌已經成功更新。

#設置文件夾的權限

cd /java

chown -R es:es elasticsearch6

 

切換為es用戶:

su es

 

再次啟動:

/java/elasticsearch6/bin/elasticsearch


ERROR: [3] bootstrap checks failed
[1]: max file descriptors [4096] for elasticsearch process is too low, increase to at least [65535]
[2]: max number of threads [3818] for user [es] is too low, increase to at least [4096]
[3]: max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]
[2021-02-04T16:28:09,472][INFO ][o.e.n.Node ] [node-11] stopping ...
[2021-02-04T16:28:09,546][INFO ][o.e.n.Node ] [node-11] stopped
[2021-02-04T16:28:09,546][INFO ][o.e.n.Node ] [node-11] closing ...
[2021-02-04T16:28:09,576][INFO ][o.e.n.Node ] [node-11] closed

切換到Root用戶:

su root

 

[1][2]解決(切換到root用戶):

vi /etc/security/limits.conf

 

文件后面添加下面的內容:

# soft表示為超過這個值就會有warnning
# hard則表示不能超過這個值
* soft nofile 65536
* hard nofile 131072
* soft nproc 2048
* hard nproc 4096

 

如果[1]方法沒有解決[2],可以再執行下面的解決[2](切換到root用戶):
【20-nproc.conf】這個文件可能每個人都不一樣,可以進入目錄查看具體的文件

vi /etc/security/limits.d/20-nproc.conf

 

Centos7默認就是:4096,不需要再修改,如果不是,請修改

* soft nproc 4096
root soft nproc unlimited

 

[3]解決(切換到root用戶):

vi /etc/sysctl.conf

 

增加內容:

vm.max_map_count=655360

保存后,執行命令:

sysctl -p


最后重啟Linux系統(必須),不重啟不生效

切換為es用戶:

su es

 

再次啟動:

/java/elasticsearch6/bin/elasticsearch

或后台啟動:

/java/elasticsearch6/bin/elasticsearch -d


后台啟動可以通過jsp查看有沒有進程。
[root@host-11 ~]# jps
992 QuorumPeerMain
1490 Elasticsearch
1551 Jps


啟動成功后,進行驗證:
[node-11] publish_address {192.168.170.11:9200}, bound_addresses {192.168.170.11:9200}
[node-11] license [bf28e518-3560-4e69-a605-4e97b2055ba7] mode [basic] - valid


進行驗證:
瀏覽器打開:

http://192.168.170.11:9200/

或者在Linux命令窗口驗證:

curl http://192.168.170.11:9200/

返回結果:
{
"name" : "node-11",
"cluster_name" : "myes6",
"cluster_uuid" : "xDGeM7glQECODLuS32Qo9A",
"version" : {
"number" : "6.8.13",
"build_flavor" : "default",
"build_type" : "tar",
"build_hash" : "be13c69",
"build_date" : "2020-10-16T09:09:46.555371Z",
"build_snapshot" : false,
"lucene_version" : "7.7.3",
"minimum_wire_compatibility_version" : "5.6.0",
"minimum_index_compatibility_version" : "5.0.0"
},
"tagline" : "You Know, for Search"
}

查看集群狀態:

http://192.168.170.11:9200/_cluster/stats?pretty

 

查看單個節點狀態:

http://192.168.170.11:9200/_nodes/node-11/process?pretty

 

查看ES集群健康狀態

http://192.168.170.11:9200/_cluster/health?pretty

{
"cluster_name" : "myes6", //集群名稱
"status" : "green", //集群的狀態紅綠燈,綠:健康,黃:亞健康,紅:病態
"timed_out" : false,
"number_of_nodes" : 2, //節點數
"number_of_data_nodes" : 2, //數據節點數
"active_primary_shards" : 12,
"active_shards" : 24,
"relocating_shards" : 0,
"initializing_shards" : 0,
"unassigned_shards" : 0,
"delayed_unassigned_shards" : 0,
"number_of_pending_tasks" : 0,
"number_of_in_flight_fetch" : 0,
"task_max_waiting_in_queue_millis" : 0,
"active_shards_percent_as_number" : 100.0
}

查看指定索引庫的健康狀態

http://192.168.170.11:9200/_cluster/health/stu?pretty

 

多個索引:

http://192.168.170.11:9200/_cluster/health/index_name1,index_name2?pretty

 

查看集群的主節點:
瀏覽器打開:

http://192.168.170.12:9200/_cat/master?v

 

或者在Linux命令窗口驗證:

curl 192.168.170.12:9200/_cat/master?v

 

輸出內容:
id host ip node
CDH9HpfRRmaAN3VBbj4Vow 192.168.170.11 192.168.170.11 node-11

 

(如果文章對您有所幫助,歡迎捐贈,^_^)

 

================================

©Copyright 蕃薯耀 2021-02-20

https://www.cnblogs.com/fanshuyao/


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM