下载地址:https://github.com/elastic/elasticsearch
import ”github.com/olivere/elastic“
1. 第一次启动时报错,
[WARN ][o.e.b.ElasticsearchUncaughtExceptionHandler] [node-1] 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:127) ~[elasticsearch-5.4.1.jar:5.4.1]
at org.elasticsearch.bootstrap.Elasticsearch.execute(Elasticsearch.java:114) ~[elasticsearch-5.4.1.jar:5.4.1]
at org.elasticsearch.cli.EnvironmentAwareCommand.execute(EnvironmentAwareCommand.java:67) ~[elasticsearch-5.4.1.jar:5.4.1]
at org.elasticsearch.cli.Command.mainWithoutErrorHandling(Command.java:122) ~[elasticsearch-5.4.1.jar:5.4.1]
at org.elasticsearch.cli.Command.main(Command.java:88) ~[elasticsearch-5.4.1.jar:5.4.1]
at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:91) ~[elasticsearch-5.4.1.jar:5.4.1]
at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:84) ~[elasticsearch-5.4.1.jar:5.4.1]
Caused by: java.lang.RuntimeException: can not run elasticsearch as root
at org.elasticsearch.bootstrap.Bootstrap.initializeNatives(Bootstrap.java:106) ~[elasticsearch-5.4.1.jar:5.4.1]
at org.elasticsearch.bootstrap.Bootstrap.setup(Bootstrap.java:194) ~[elasticsearch-5.4.1.jar:5.4.1]
at org.elasticsearch.bootstrap.Bootstrap.init(Bootstrap.java:350) ~[elasticsearch-5.4.1.jar:5.4.1]
at org.elasticsearch.bootstrap.Elasticsearch.init(Elasticsearch.java:123) ~[elasticsearch-5.4.1.jar:5.4.1]
... 6 more
原因:elasticsearch自5版本之后,处于安全考虑,不允许使用root用户运行。
2.切换回普通用户后 ,启动报错Exception in thread "main" java.nio.file.AccessDeniedException: /usr/local/elasticsearch/elasticsearch-6.2.2-` 1/config/jvm.options
elasticsearch用户没有该文件夹的权限,执行下面的命令:
chown -R name(普通用户的名字):name /usr/local/elasticsearch/
3. 再次启动还是报错max file descriptors [4096] for elasticsearch process is too low, increase to at least [65536]每个进程最大同时打开文件数太小
max number of threads [3818] for user [es] is too low, increase to at least [4096]最大线程个数太低
max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]最大虚拟内存太小
解决办法:修改配置 /etc/security/limits.conf,在配置中增加如下:
* soft nofile 65536
* hard nofile 131072
* soft nproc 4096
* hard nproc 4096
vm.max_map_count = 262144
并执行命令:
sysctl -p
用户退出后重新登录生效或者执行 source /etc/profile (更新配置)
在一般情况下,上面的问题基本解决了。可是用 ulimit -Hn 和ulimit -Sn查看 发现配置无法生效,启动后再次报错。翻阅资料得知。可能是我在其他文件中把值给写死了。
最终解决:创建一个普通用户: useradd name(用户名) -g group(所属组名) -p pwd(密码)
然后配置生效了
将elasticsearch 安装目录权限修改一下
chown -R name(普通用户的名字):name /usr/local/elasticsearch/
切换至普通用户再运行elasticsearch就可以了
然后在浏览器输入 http://ip:9200 出现如下说明你成功了。
{
"name" : "node-1",
"cluster_name" : "my-application",
"cluster_uuid" : "4PAg9qiARJK2renoARXchg",
"version" : {
"number" : "6.6.2",
"build_flavor" : "default",
"build_type" : "tar",
"build_hash" : "3bd3e59",
"build_date" : "2019-03-06T15:16:26.864148Z",
"build_snapshot" : false,
"lucene_version" : "7.6.0",
"minimum_wire_compatibility_version" : "5.6.0",
"minimum_index_compatibility_version" : "5.0.0"
},
"tagline" : "You Know, for Search"
}