Linux环境部署Elasticsearch 6.x和常见问题

介绍

Elasticsearch(ES)是一个基于Lucene构建的开源、分布式、RESTful接口的全文搜索引擎。 Elasticsearch还是一个分布式文档数据库,其中每个字段均可被索引,而且每个字段的数据均可被搜索,ES能够横向扩展至数以百计的服务器存储以及处理PB级的数据。

本文内容基于Elastic 技术栈6.x版本;

准备工作

1
2
3
4
5
6
# lasticsearch-6-3-2

wget https://www.elastic.co/cn/downloads/past-releases/elasticsearch-6-3-2

# or
wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-6.3.2.tar.gz

下载到指定目录~/path/,解压

1
tar -zxvf elasticsearch-6.3.2.tar.gz

由于elasticsearch 不允许使用root用户启动
创建一个用于启动elasticsearch 的用户

1
2
useradd  elastic 
passwd elastic

输入密码,并确认,完成特定用户创建

并为该用户授权elasticsearch相关目录

1
chown -R elastic:elastic elasticsearch*

切换到用户elastic ,创建elasticsearch目录软连接指向elastic用户的根目录

1
2
cd ~
ln -s /path/to/elasticsearch ./elasticsearch

进入该目录

1
cd ./elasticsearch

执行

1
./bin/elasticsearch

启动elasticsearch

后台启动 (daemonize)

1
./bin/elasticsearch  -d

常见问题

启动错误提示1:

1
2
3
4
5
6
7
8
9
10
11

ERROR: [4] bootstrap checks failed
[1]: max file descriptors [4096] for elasticsearch process is too low, increase to at least [65536]
[2]: max number of threads [1024] for user [elastic] 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]
[4]: system call filters failed to install; check the logs and fix your configuration or disable system call filters at your own risk


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

Make sure to increase the limit on the number of open files descriptors for the user running Elasticsearch to 65,536 or higher. For the .zip and .tar.gz packages, set ulimit -n 65536 as root before starting Elasticsearch, or set nofile to 65536 in /etc/security/limits.conf .

解决:切换到root用户,编辑limits.conf 添加相关配置

1
vi /etc/security/limits.conf

添加如下内容:

1
2
3
4
* soft nofile 65536
* hard nofile 131072
* soft nproc 2048
* hard nproc 4096

启动错误提示2:

1
[2]: max number of threads [1024] for user [elastic] is too low, increase to at least [4096]

对于第二条错误同意需要切换到root用户,进入limits.d目录下修改配置文件。

1
vi /etc/security/limits.d/90-nproc.conf

修改如下内容:

1
* soft nproc 1024

#修改为

1
* soft nproc 4096

错误提示3

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

第三条错误需要切换到root用户修改配置sysctl.conf
vi /etc/sysctl.conf

添加下面配置:

1
vm.max_map_count=655360

并执行命令:

1
sysctl -p

错误提示4:

1
[4]: system call filters failed to install; check the logs and fix your configuration or disable system call filters at your own risk

原因:
这是在因为Centos6不支持SecComp,而ES 6.x默认bootstrap.system_call_filter为true进行检测,所以导致检测失败,失败后直接导致ES不能启动。

解决:
在elasticsearch.yml中配置bootstrap.system_call_filter为false,注意要在Memory下面:

1
2
bootstrap.memory_lock: false
bootstrap.system_call_filter: false

操作完成,现在所有的机器都能访问Linux服务器的HTTP服务了。

监控健康状况
http://[es_host]:9200/_cat/health?v
监控节点情况
http://[es_host]:9200/_cat/nodes?v
监控索引情况
http://[es_host]:9200/_cat/indices?v