ElasticSearch Installation

ElasticSearch Installation

Basic Info

OS Version: CentOS 7.3
Java Version: 1.8.0_151
ElasticSearch Version: 5.5.0

About ElasticSearch Version

Disable SELinux and Firewall

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
## Disable SELinux
[root@localhost ~]# vim /etc/selinux/config
# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
# enforcing - SELinux security policy is enforced.
# permissive - SELinux prints warnings instead of enforcing.
# disabled - No SELinux policy is loaded.
SELINUX=disabled ## change to disabled
# SELINUXTYPE= can take one of three two values:
# targeted - Targeted processes are protected,
# minimum - Modification of targeted policy. Only selected processes are protected.
# mls - Multi Level Security protection.
#SELINUXTYPE=targeted ## comment it
## Need to reboot system
[root@localhost ~]# sestatus
SELinux status: disabled
## Disable SELinux
[root@localhost ~]# systemctl disable firewalld.service
## Need to reboot system
[root@localhost ~]# systemctl status firewalld.service
● firewalld.service - firewalld - dynamic firewall daemon
Loaded: loaded (/usr/lib/systemd/system/firewalld.service; disabled; vendor preset: enabled)
Active: inactive (dead)
Docs: man:firewalld(1)

Install ElasticSearch

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
[root@localhost ~]# cd /opt/software
[root@localhost software]# wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-5.5.0.tar.gz
[root@localhost software]# ls | grep elasticsearch
elasticsearch-5.5.0.tar.gz
[root@localhost software]# tar -zxvf elasticsearch-5.5.0.tar.gz
## 將elasticsearch資料夾設定給啓動Elasticsearch的user
[root@localhost software]# chown -R datacenter:datacenter elasticsearch-5.5.0
[root@localhost software]# cd elasticsearch-5.5.0/
[root@localhost elasticsearch-5.5.0]# ll
total 224
drwxr-xr-x. 2 datacenter datacenter 4096 Jan 9 22:16 bin
drwxr-xr-x. 2 datacenter datacenter 75 Jan 9 22:46 config
drwxr-xr-x. 2 datacenter datacenter 4096 Jun 30 2017 lib
-rw-r--r--. 1 datacenter datacenter 11358 Jun 30 2017 LICENSE.txt
drwxr-xr-x. 13 datacenter datacenter 236 Jun 30 2017 modules
-rw-r--r--. 1 datacenter datacenter 194187 Jun 30 2017 NOTICE.txt
drwxr-xr-x. 2 datacenter datacenter 6 Jun 30 2017 plugins
-rw-r--r--. 1 datacenter datacenter 9548 Jun 30 2017 README.textile
## 建立Data與Log要放置的資料夾,與config/elasticsearch.yml中的屬性對應
[root@localhost elasticsearch-5.5.0]# mkdir data logs
## 新增ElasticSearch的環境變量
[root@localhost elasticsearch-5.5.0]# vim /etc/profile
export ES_HOME="/opt/software/elasticsearch-5.5.0"
export PATH="$ES_HOME/bin:$PATH"
[root@localhost elasticsearch-5.5.0]# source /etc/profile

Configure ElasticSearch

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
[root@localhost elasticsearch-5.5.0]# cd config/
[root@localhost config]# ls
elasticsearch.yml jvm.options log4j2.properties
[root@localhost config]# ll
total 16
-rw-rw----. 1 datacenter datacenter 2851 Jan 9 22:46 elasticsearch.yml
-rw-rw----. 1 datacenter datacenter 3117 Jun 30 2017 jvm.options
-rw-rw----. 1 datacenter datacenter 4456 Jun 30 2017 log4j2.properties
## 修改以下設定
[root@localhost config]# vim elasticsearch.yml
# ---------------------------------- Cluster -----------------------------------
#
# Use a descriptive name for your cluster:
#
cluster.name: es_cluster
#
# ------------------------------------ Node ------------------------------------
#
# Use a descriptive name for the node:
#
node.name: es_001_84
# ----------------------------------- Paths ------------------------------------
#
# Path to directory where to store the data (separate multiple locations by comma):
#
path.data: $ES_HOME/data
#
# Path to log files:
#
path.logs: $ES_HOME/logs
# ---------------------------------- Network -----------------------------------
#
# Set the bind address to a specific IP (IPv4 or IPv6):
#
network.host: 10.103.67.84
#
# Set a custom port for HTTP:
#
http.port: 9200
# ----------------------------------- Memory -----------------------------------
#
# Lock the memory on startup:
#
# CentOS 6需要新增以下兩行配置,ElasticSearch才能正常啓動
bootstrap.memory_lock: false
bootstrap.system_call_filter: false
#

Start ElasticSearch

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
## 切換至啓動Elasticsearch的user
[root@localhost config]# su - detacenter
[datacenter@localhost ~]$ cd $ES_HOME
[datacenter@localhost bin]$ cd bin
[datacenter@localhost bin]$ ./elasticsearch -help
starts elasticsearch
Option Description
------ -----------
-E <KeyValuePair> Configure a setting
-V, --version Prints elasticsearch version information and exits
-d, --daemonize Starts Elasticsearch in the background
-h, --help show help
-p, --pidfile <Path> Creates a pid file in the specified path on start
-q, --quiet Turns off standard ouput/error streams logging in console
-s, --silent show minimal output
-v, --verbose show verbose output
## 啓動Elasticsearch,會出現一些錯誤
[datacenter@localhost bin]$ ./elasticsearch
## ...
[2018-01-09T23:01:25,705][INFO ][o.e.n.Node ] [es_001_84] initialized
[2018-01-09T23:01:25,706][INFO ][o.e.n.Node ] [es_001_84] starting ...
[2018-01-09T23:01:25,852][INFO ][o.e.t.TransportService ] [es_001_84] publish_address {10.103.67.84:9300}, bound_addresses {10.103.67.84:9300}
[2018-01-09T23:01:25,861][INFO ][o.e.b.BootstrapChecks ] [es_001_84] bound or publishing to a non-loopback or non-link-local address, enforcing bootstrap checks
ERROR: [2] bootstrap checks failed
[1]: max file descriptors [4096] for elasticsearch process is too low, increase to at least [65536]
[2]: max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]
[2018-01-09T23:01:25,891][INFO ][o.e.n.Node ] [es_001_84] stopping ...
[2018-01-09T23:01:25,919][INFO ][o.e.n.Node ] [es_001_84] stopped
[2018-01-09T23:01:25,920][INFO ][o.e.n.Node ] [es_001_84] closing ...
[2018-01-09T23:01:25,933][INFO ][o.e.n.Node ] [es_001_84] closed

Fix Error

1
2
3
4
5
6
7
8
9
10
11
12
13
## Error Message: [1]: max file descriptors [4096] for elasticsearch process is too low, increase to at least [65536]
[root@localhost ~]# vim /etc/security/limits.conf
* soft nofile 65536
* hard nofile 65536
## 需要進行登出入讓設定生效
## Error Message: [2]: max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]
[root@localhost ~]# vim /etc/sysctl.conf
## 新增下列一行
vm.max_map_count=262144
[root@localhost ~]# sysctl -p
vm.max_map_count = 262144

Start ElasticSearch again

1
2
3
4
5
6
7
8
9
10
[datacenter@localhost bin]$ ./elasticsearch
## ...
[2018-01-10T01:39:36,813][INFO ][o.e.n.Node ] [es_001_84] initialized
[2018-01-10T01:39:36,813][INFO ][o.e.n.Node ] [es_001_84] starting ...
[2018-01-10T01:39:37,031][INFO ][o.e.t.TransportService ] [es_001_84] publish_address {10.103.67.84:9300}, bound_addresses {10.103.67.84:9300}
[2018-01-10T01:39:37,043][INFO ][o.e.b.BootstrapChecks ] [es_001_84] bound or publishing to a non-loopback or non-link-local address, enforcing bootstrap checks
[2018-01-10T01:39:40,143][INFO ][o.e.c.s.ClusterService ] [es_001_84] new_master {es_001_84}{_sZKX65KQKaZdmpa-kBfvA}{nWkvPXL_Qi609Zq3vfJW5g}{10.103.67.84}{10.103.67.84:9300}, reason: zen-disco-elected-as-master ([0] nodes joined)
[2018-01-10T01:39:40,169][INFO ][o.e.h.n.Netty4HttpServerTransport] [es_001_84] publish_address {10.103.67.84:9200}, bound_addresses {10.103.67.84:9200}
[2018-01-10T01:39:40,169][INFO ][o.e.n.Node ] [es_001_84] started
[2018-01-10T01:39:40,172][INFO ][o.e.g.GatewayService ] [es_001_84] recovered [0] indices into cluster_state

Test service

1
2
3
4
5
6
7
8
9
10
11
12
13
14
[datacenter@localhost ~]$ curl -XGET '10.103.67.84:9200/?pretty'
{
"name" : "es_001_84",
"cluster_name" : "es_cluster",
"cluster_uuid" : "sf6PJarSQMC4AIH02fNKtg",
"version" : {
"number" : "5.5.0",
"build_hash" : "260387d",
"build_date" : "2017-06-30T23:16:05.735Z",
"build_snapshot" : false,
"lucene_version" : "6.6.0"
},
"tagline" : "You Know, for Search"
}