1、ES启动报错:不能使用root用户

[root@weshare bin]# ./elasticsearch
[2019-10-02T19:40:42,296][WARN ][o.e.b.ElasticsearchUncaughtExceptionHandler] [] uncaught exception in thread [main]
org.elasticsearch.bootstrap.StartupException: java.lang.RuntimeException:can not run elasticsearch as root
at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:125) ~[elasticsearch-6.1.1.jar:6.1.1]
at org.elasticsearch.bootstrap.Elasticsearch.execute(Elasticsearch.java:112) ~[elasticsearch-6.1.1.jar:6.1.1]
at org.elasticsearch.cli.EnvironmentAwareCommand.execute(EnvironmentAwareCommand.java:86) ~[elasticsearch-6.1.1.jar:6.1.1]
at org.elasticsearch.cli.Command.mainWithoutErrorHandling(Command.java:124) ~[elasticsearch-cli-6.1.1.jar:6.1.1]
at org.elasticsearch.cli.Command.main(Command.java:90) ~[elasticsearch-cli-6.1.1.jar:6.1.1]
at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:92) ~[elasticsearch-6.1.1.jar:6.1.1]
at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:85) ~[elasticsearch-6.1.1.jar:6.1.1]
Caused by: java.lang.RuntimeException: can not run elasticsearch as root
at org.elasticsearch.bootstrap.Bootstrap.initializeNatives(Bootstrap.java:104) ~[elasticsearch-6.1.1.jar:6.1.1]
at org.elasticsearch.bootstrap.Bootstrap.setup(Bootstrap.java:171) ~[elasticsearch-6.1.1.jar:6.1.1]
at org.elasticsearch.bootstrap.Bootstrap.init(Bootstrap.java:322) ~[elasticsearch-6.1.1.jar:6.1.1]
at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:121) ~[elasticsearch-6.1.1.jar:6.1.1]
... 6 more

解决方法:新建其他用户,并把ES安装目录赋给该用户,切换该用户,启动ES

详细过程:创建一个用户来专门启动 ES

groupadd esgroup 创建ES用户组

useradd es-admin 创建ES用户

passwd es-admin 给用户赋密码

abc123456 密码

chown -R esgroup:es-admin elasticsearch-7.2.0 更改ES安装文件夹及内部文件的所属用户为es-admin ,elasticsearch-7.2.0为你ES的安装目录名称

su es-admin 切换到es-admin用户再启动

cd elasticsearch-7.2.0/bin 进入你的ES目录下的bin目录

./elasticsearch 启动ES

2、ES启动报错:jdk的安全策略问题

[2019-07-25T18:17:30,305][INFO ][o.e.b.BootstrapChecks    ] [node-1] bound or publishing to a non-loopback address, enforcing bootstrap checks
ERROR: [1] bootstrap checks failed
[1]: granting the all permission effectively disables security

解决方法:把jre中的java.policy删掉,启动成功

3、ES启动报错:系统能打开的最大文件数量太小

max file descriptors [65535] for elasticsearch process is too low, increase to at least [65536]

解决方法:修改文件改动默认配置,命令:sudo vim /etc/security/limits.conf

修改为:

root soft nofile 65536

root hard nofile 65536

user1 soft nofile 65536 #user1为普通用户,可以改为 ,即所有普通用户

user1 hard nofile 65536 #user1为普通用户,可以改为,即所有普通用户

(注意,重启之后配置才能生效)

4、ES启动报错:使用虚拟内存过小

max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]

解决方法:修改文件改动默认配置,命令:sudo vim /etc/sysctl.conf

增加这一行:vm.max_map_count=655360

刷新配置:sysctl -p

(注意,重启之后配置才能生效)

5、ES启动报错:内存不足

解决方法:vi jvm.options (jvm.options在ES安装目录的config里面)

es 5.x版本默认启动内存需要4g ,对于一些低内存的虚拟机或者云服务器可能无法启动,需要修改默认内存参数

默认是:

-Xms4g
-Xmx4g

可以修改为:

-Xms1g
-Xmx1g

6、ES启动报错:外网不能访问

Caused by: java.net.BindException: Cannot assign requested address

解决方法:配置外网

cd elasticsearch-7.2.0/config
vi elasticsearch.yml

network.host: 192.168.0.1 修改为本机IP 0.0.0.0

7、ES启动报错:没有执行权限

./elasticsearch: Permission denied

解决方法:

授权执行命令 chmod +x bin/elasticsearch

-----------------------------看到以下标识这段话启动正常了---------------------------

license [44e05c9c-2cb2-4e07-9cc4-627142e154b1] mode [basic] - valid

此时在服务器上执行: curl ip:port

如:curl 127.0.0.1:9200

{
"name" : "weshare002",
"cluster_name" : "elasticsearch",
"cluster_uuid" : "5wRNqjWBR0ia6qzExFr7-A",
"version" : {
"number" : "7.2.0",
"build_flavor" : "default",
"build_type" : "tar",
"build_hash" : "508c38a",
"build_date" : "2019-06-20T15:54:18.811730Z",
"build_snapshot" : false,
"lucene_version" : "8.0.0",
"minimum_wire_compatibility_version" : "6.8.0",
"minimum_index_compatibility_version" : "6.0.0-beta1"
},
"tagline" : "You Know, for Search"
}