概述:
在上一篇中已经介绍了如何安装ElasticSearch6.x 以及其运行环境,这篇主要介绍下ElasticSearch运行过程中碰到的问题,如何解决 和 ElasticSearch-Head插件安装使用。
运行碰到的问题:
1、org.elasticsearch.bootstrap.StartupException: java.lang.RuntimeException: can not run elasticsearch as root异常
说明:
ElasticSearch不能运行在root账户下
解决:
创建一个单独的用户来使用ElasticSearch,做法如下:
adduser test #用户名这里为 test,可以自己指定
操作详情:
创建完新用户 test后,运行:
su test #切换到新建用户 test下
然后执行./bin/elasticsearch命令,尝试运行ElasticSearch
2、Exception in thread "main" java.nio.file.AccessDeniedException: /usr/local/elasticsearch-6.5.2/config/jvm.options
说明:
ElasticSearch没有访问权限
解决:
切换到root用户下:
su #切换到root
#输入root密码
chown test /usr/local/elasticsearch-6.5.2/ -R #将文件夹及其子目录拥有者设为test用户
su test #切换到test用户下
再次执行 ./bin/elasticsearch命令,该问题应该已经解决
3、max virtual memory areas vm.max_map_count [65530] is too low, increase to at least[262144]
说明:
ElasticSearch用户拥有的内存权限太小,至少需要262144
解决:
切换到root用户,执行:
sysctl -w vm.max_map_count=262144
#查看结果:
sysctl -a|grep vm.max_map_count
#显示:
vm.max_map_count=262144
上述方法修改后,如果重启虚拟机将失效,解决办法如下:
#在/etc/sysctl.conf文件最添加一行:
vm.max_map_count=262144
#再执行命令
sysctl -p
4、max number of threads [3712] for user [test] is too low
说明:
启动检查未通过,ElasticSearch用户的最大线程数太低
解决:
切换到root用户,修改limits.d目录下的配置文件:
新建一个配置文件,比如 test-limits.config
vim /etc/security/limits.d/test-limits.conf
加入内容如下:
* soft nofile 65536
* hard nofile 131072
* soft nproc 4096
* hard nproc 4096
配置:
1、JVM配置
说明:
可以通过配置,设置ElasticSearch需要最小最大使用内存
方法:
打开ElasticSearch目录下 ./config/jvm.options文件
设置-Xms, -Xmx,初始默认为1g
# Xms represents the initial size of total heap space
# Xmx represents the maximum size of total heap space
-Xms1g #最小使用内存
-Xmx1g #最大使用内存
2、节点配置:
可以在 ./config/elasticsearch.yml文件配置节点名称,host, port等相关信息,这里主要配置了host信息:
# Set the bind address to a specific IP (IPv4 or IPv6):
#
network.host: 192.168.61.197
#
# Set a custom port for HTTP:
#
#http.port: 9200
运行 验证:
通过命令,运行ElasticSearch:
./bin/elasticsearch
在浏览器中输入,可以查看节点信息
信息如下:
{
name: "node-2",
cluster_name: "elastice",
cluster_uuid: "D4Bh0Bj4SYOWTZQPYlWWwA",
version: {
number: "6.5.2",
build_flavor: "default",
build_type: "tar",
build_hash: "9434bed",
build_date: "2018-11-29T23:58:20.891072Z",
build_snapshot: false,
lucene_version: "7.5.0",
minimum_wire_compatibility_version: "5.6.0",
minimum_index_compatibility_version: "5.0.0"
},
tagline: "You Know, for Search"
}
Head插件安装:
ElasticSearch-Head作为ElasticSearch的一个插件,是一个易于使用的ElasticSearch客户端工具,具体安装方法有多种,可以参照Head git说明进行操作:
https://github.com/mobz/elasticsearch-head
笔者这里采用的是安装Chrome插件方式进行安装,只需要在Chrome市场下载Head插件进行安装即可,比较方便。
Head插件安装好后,连接服务器地址,展示效果如下:
该结果仅作为示例,这是笔者之前配置安装的ElasticSearch集群,以及多个分片和复制分片结果,如果想要知道更多,可以接着看下一篇