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
http://fanshuyao.iteye.com/
一、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
http://fanshuyao.iteye.com/