Elasticsearch部署问题

ray-zhuang-ToTlbvvI_uc-unsplash.jpg

问题

Elasticsearch启动报错:Exception in thread “main” java.nio.file.AccessDeniedException

编辑 / etc/sudoers 文件:

1
vim /etc/sudoers

在下面添加一行:

1
2
es    ALL=(ALL)       ALL 
# es是我要赋予权限的用户名

没有权限

1
2
chown -R smarthome:smarthome /home/smarthome/elasticsearch/
chmod 777 /home/smarthome/elasticsearch

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

文件权限不足

在 / etc/security/limits.conf 中添加如下内容

1
2
3
4
vi /etc/security/limits.conf
#添加以下内容
es hard nofile 65536
es soft nofile 65536
1
2
ulimit -Hn
ulimit -Sn

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

虚拟内存分配不足

1
2
sysctl -w vm.max_map_count=262144
sysctl -a|grep vm.max_map_count

然后在 /etc/sysctl.conf 文件最后添加一行

1
vm.max_map_count=262144

输入命令:sysctl -p立即生效

OpenJDK 64-Bit Server VM warning: Option UseConcMarkSweepGC was deprecated in version 9.0 and will likely be removed in a future release.

修改 jvm.options 文件配置vim /etc/elasticsearch/jvm.options,将

1
-XX:+UseConcMarkSweepGC 改为 -XX:+UseG1GC

索引

创建索引

1
2
3
4
# PUT请求

http://127.0.0.1:9200/my-index-001

删除索引

1
2
3
4
5
6
7
8
9
# 删除单个
# DELETE请求

http://127.0.0.1:9200/my-index-001
# 删除多个
# DELETE请求

http://127.0.0.1:9200/my-index-001,my-index-002
# 通配符需要开启

查询索引

1
2
3
# GET请求

http://127.0.0.1:9200/_alias

maybe these locations are not writable or multiple nodes were started without increasing

这个错误的原因是因为之前用root用户启动了es,之后切换用户运行就会报这个错误

解决

删除ES配置目录下data目录中的nodes文件,然后用非ROOT用户启动就能解决了

参考