Elasticsearch安装与集群配置

环境

1、操作系统:centos6.5

2、jdk:jdk-8u121-linux-x64.tar.gz

3、elasticsearch: 5.4

4、3台:192.168.100.x-x

安装jdk

1、下载jdk-8u121-linux-x64.tar.gz

1
2
tar -zxf jdk-8u121-linux-x64.tar.gz
mv jdk1.8.0_121/ jdk1.8

2、配置java环境变量

1
vi + /etc/profile

加入

1
2
3
4
JAVA_HOME=/opt/jdk1.8
CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
PATH=$JAVA_HOME/bin:$PATH
export PATH

执行

1
2
source /etc/profile
java --version

安装ElasticSearch

1、官网:https://www.elastic.co/downloads/elasticsearch

文件:https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-5.4.0.tar.gz

当然可以下载rpm包安装(rpm -ivh)

查看默认的配置文件目录如下

1
2
# whereis elasticsearch 
elasticsearch: /etc/elasticsearch /usr/share/elasticsearch

好,这里不做详细介绍,继续手动安装

2、添加Linux用户

在root用户下

1
2
useradd es
passwd es

3、解压安装

1
2
3
4
5
tar zxf elasticsearch-5.4.0.tar.gz
chown -R es:es elasticsearch-5.4.0
su es
cd elasticsearch-5.4.0/bin
./elasticsearch -d

出现error

1
2
3
4
5
6
Java HotSpot(TM) 64-Bit Server VM warning: INFO: os::commit_memory(0x0000000085330000, 2060255232, 0) failed; error='Cannot allocate memory' (errno=12)
#
# There is insufficient memory for the Java Runtime Environment to continue.
# Native memory allocation (mmap) failed to map 2060255232 bytes for committing reserved memory.
# An error report file with more information is saved as:
# /opt/elasticsearch-5.4.0/bin/hs_err_pid2306.log

es默认的启动jvm堆设置问题,默认是2g,修改一下

1
2
cd .. && cd config
vi jvm.options

-Xms2g修改为-Xms128m

-Xmx2g修改为-Xmx128m

保存

1
2
cd .. && cd bin
./elasticsearch

报Error

1
2
3
4
5
6
7
8
9
...

ERROR: bootstrap checks failed
max file descriptors [4096] for elasticsearch process is too low, increase to at least [65536]
max number of threads [1024] for user [es] is too low, increase to at least [2048]
max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]
system call filters failed to install; check the logs and fix your configuration or disable system call filters at your own risk

...

原因:

a、无法创建足够多的文件描述符,设置大一点,vi /etc/security/limits.conf

b、最大线程数不够,修改,vi /etc/security/limits.d/90-nproc.conf

c、最大虚拟内存太小,修改 vi /etc/sysctl.conf

d、Centos6不支持SecComp,而新的ES默认bootstrap.system_call_filter为true,所以导致检查失败

​ 修改: 在elasticsearch.yml中设置bootstrap.system_call_filter: false;

vi /etc/security/limits.conf 添加:

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

vi /etc/security/limits.d/90-nproc.conf 修改

1
* soft nproc 1024修改为* soft 2048

vi /etc/sysctl.conf 添加

1
vm.max_map_count=655360

执行sysctl -p

vi config/elasticsearch.yml

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

最后重启虚拟机,执行./elasticsearch -d,验证

1
2
3
4
5
6
7
8
9
10
11
12
13
14
[[email protected] bin]$ curl -X GET http://localhost:9200/
{
"name" : "jo7WMM2",
"cluster_name" : "elasticsearch",
"cluster_uuid" : "uf3mrhh8THqwSZKzAJo9QA",
"version" : {
"number" : "5.4.0",
"build_hash" : "780f8c4",
"build_date" : "2017-04-28T17:43:27.229Z",
"build_snapshot" : false,
"lucene_version" : "6.5.0"
},
"tagline" : "You Know, for Search"
}

4、安装所有插件(安装后竟然需要验证了,赶紧卸载)

1
2
./elasticsearch-plugin install x-pack
./elasticsearch-plugin remove x-pack

elsticsearch配置说明

如果使用yum或rpm方式安装Elasticsearch默认的配置文件地址是:/etc/elasticsearch/elasticsearch.yml,详细的配置说明可以参考Configuring Elasticsearch。另外还有一个系统配置存放在/etc/sysconfig/elasticsearch,可设置的内容包含如下参数:

ES_USER The user to run as, defaults to elasticsearch.
ES_GROUP The group to run as, defaults to elasticsearch.
JAVA_HOME Set a custom Java path to be used.
MAX_OPEN_FILES Maximum number of open files, defaults to 65536.
MAX_LOCKED_MEMORY Maximum locked memory size. Set to unlimited if you use thebootstrap.memory_lock option in elasticsearch.yml.
MAX_MAP_COUNT Maximum number of memory map areas a process may have. If you use mmapfsas index store type, make sure this is set to a high value. For more information, check the linux kernel documentation about max_map_count. This is set via sysctl before starting elasticsearch. Defaults to 262144.
LOG_DIR Log directory, defaults to /var/log/elasticsearch.
DATA_DIR Data directory, defaults to /var/lib/elasticsearch.
CONF_DIR Configuration file directory (which needs to include elasticsearch.ymland log4j2.properties files), defaults to /etc/elasticsearch.
ES_JAVA_OPTS Any additional JVM system properties you may want to apply.
RESTART_ON_UPGRADE Configure restart on package upgrade, defaults to false. This means you will have to restart your elasticsearch instance after installing a package manually. The reason for this is to ensure, that upgrades in a cluster do not result in a continuous shard reallocation resulting in high network traffic and reducing the response times of your cluster.

另外,一些默认安装的文件路径如下:

Type Description Default Location Setting
home Elasticsearch home directory or $ES_HOME /usr/share/elasticsearch
bin Binary scripts including elasticsearch to start a node and elasticsearch-plugin to install plugins /usr/share/elasticsearch/bin
conf Configuration files including elasticsearch.yml /etc/elasticsearch path.conf
conf Environment variables including heap size, file descriptors. /etc/sysconfig/elasticsearch
data The location of the data files of each index / shard allocated on the node. Can hold multiple locations. /var/lib/elasticsearch path.data
logs Log files location. /var/log/elasticsearch path.logs
plugins Plugin files location. Each plugin will be contained in a subdirectory. /usr/share/elasticsearch/plugins
repo Shared file system repository locations. Can hold multiple locations. A file system repository can be placed in to any subdirectory of any directory specified here. Not configured path.repo
script Location of script files. /etc/elasticsearch/scripts path.scripts
坚持技术分享,您的支持将鼓励我继续创作!