ElasticSearch5.4.3 offline construction

 

1. Introduction to ElasticSearch

ElasticSearch is a Lucene-based search server. It provides a distributed multi-user capable full-text search engine based on a RESTful web interface. Developed in Java and released as open source under the terms of the Apache License, Elasticsearch is the current popular enterprise search engine. Designed for use in cloud computing, it can achieve real-time search, stable, reliable, fast, and easy to install and use.

We build a website or application and want to add a search function, but it is very difficult to create a search job. We want our search solution to be fast, we want a zero configuration and a completely free search mode, we want to be able to simply use JSON to index data over HTTP, we want our search server to be always available, we want to be able to Starting with one and scaling to hundreds, we want real-time search, we want simple multi-tenancy, we want to build a cloud solution. So we use Elasticsearch to solve all these problems and many more that may arise.

2. Deployment preparation

2.1. Environmental preparation

2.2. Node configuration information

IP address

CPU name

192.168.23.1

risen01

192.168.23.2

risen02

192.168.23.3

risen03

 

2.3. Node resource configuration information

IP address

Role

192.168.23.1

Candidate master node

192.168.23.2

data node

192.168.23.3

data node

 

3. Cluster configuration and startup

3.1 Installation package upload and decompression

Operation node: risen01

Operating user: root

1. Upload the installation packages elasticsearch-5.4.3.tar.gz and jdk-8u161-linux-x64.tar.gz to the ~/packages directory under the risen01 node. The result is as shown in the figure:

2. Unzip the JDK installation package and elasticsearch installation package to /usr/local

Operation node: risen01

Operating user: root

Unzip the JDK command:

tar -zxvf ~/packeages/jdk-8u161-linux-x64.tar.gz -C /usr/local

Unzip the es command:

tar -zxvf ~/packages/elasticsearch-5.4.3.tar.gz -C /usr/local

3.2. Preparation before startup

Operation nodes: risen01, risen02, risen03

Operating user: root

1. Create a new elasticsearch directory in the /data directory to store es data

2. Create a new elasticsearch directory in the /log directory to store es logs

3.3, modify the configuration file

3.3.1. Specify JDK1.8 for es5

Operation node: risen01

Operating user: bigdata

Modify the elasticsearch startup file under /usr/local/elasticsearch-5.4.3/bin, and add the following line of code under #!/bin/bash:

export JAVA_HOME=/usr/local/jdk1.8.0_161

3.3.2. Modify es5 configuration file

Operation node: risen01

Operating user: bigdata

Note: Strictly abide by the indented spaces in the configuration file, and attribute values ​​do not support uppercase letters. At the same time, many configuration items have changed a lot between ES5 and ES2 versions. The specific and reasonable configuration still depends on the overall resources of the cluster and business needs. and the amount of data and other factors are considered comprehensively.

Modify the elasticsearch.yml configuration file in the /usr/local/elasticsearch-5.4.3/config directory. Let's introduce the specific configuration of the cluster in detail:

#集群名称
cluster.name:risen-cluster

#节点名称
node.name: master

#这里我们选择risen01只作为master并不作为数据存储节点
node.master: true
node.data: false

# 设置es的日志目录
path.logs: /log/elasticsearch

# 设置es的数据目录
path.data: /data/elasticsearch

# 当JVM开始写入交换空间时(swapping)ElasticSearch性能会低下,你应该保证它不会写入交换空间

# 设置这个属性为true来锁定内存,同时也要允许elasticsearch的进程可以锁住内存
bootstrap.memory_lock: false

#Centos6不支持SecComp,而默认为true会进行检测导致启动失败
bootstrap.system_call_filter: false

#同时设置bind_host和publish_host上面两个参数
network.host: 192.168.23.1

#设置节点间交互的tcp端口,默认是9300
transport.tcp.port: 9300

#设置是否压缩tcp传输时的数据,默认为false,不压缩
transport.tcp.compress: true

#设置对外服务的http端口,默认为9200
http.port: 9200

#使用http协议对外提供服务,默认为true,开启
http.enabled: false

# 使用head等插件监控集群信息,需要打开以下配置项
http.cors.enabled: true
http.cors.allow-origin: "*"
http.cors.allow-credentials: true

#一个集群中的N个节点启动后,才允许进行恢复处理
gateway.recover_after_nodes: 1 

#Recovery Throttling
# 下面这些配置允许在初始化恢复,副本分配,再平衡,或者添加和删除节点时控制节点间的分片分配
# 设置一个节点的并行恢复数
# 1.初始化数据恢复时,并发恢复线程的个数,默认为4
cluster.routing.allocation.node_initial_primaries_recoveries: 4 

# 2.添加删除节点或负载均衡时并发恢复线程的个数,默认为2
cluster.routing.allocation.node_concurrent_recoveries: 2

# 设置恢复时的吞吐量(例如:100mb,默认为0无限制.如果机器还有其他业务在跑的话还是限制一下的好)
indices.recovery.max_bytes_per_sec: 20mb

# 注意: 合理的设置以上参数能有效的提高集群节点的数据恢复以及初始化速度
#Discovery

# 设置这个参数来保证集群中的节点可以知道其它N个有master资格的节点.默认为1,对于大的集群来说,可以设置大一点的值(2-4)
discovery.zen.minimum_master_nodes: 1

# 这是一个集群中的主节点的初始列表,当节点(主节点或者数据节点)启动时使用这个列表进行探测
discovery.zen.ping.unicast.hosts:["risen01:9300","risen02:9300","rien03:9300"]

# es保护机制是否允许删除索引或者正则
action.destructive_requires_name: true

action.auto_create_index: false

3.3.3. Distributing other node machines

Operation node: risen01

Operating user: root

Excuting an order:

scp -r /usr/local/elasticsearch-5.4.3/ root@risen02:/usr/local/
scp -r /usr/local/elasticsearch-5.4.3/ root@risen03:/usr/local/

3.3.4. Modify data node permissions

Operation nodes: risen02, risen03

Operating user: root

Excuting an order:

chown -R bigdata.bigdata /usr/local/elasticsearch-5.4.3

Create a new data node log directory and data directory and modify the permissions:

The result is shown in the figure:

3.3.5. Modify the data node configuration file

Operation nodes: risen02, risen03

Operating user: bigdata

(1) Modify the risen02 ElasticSearch configuration file

vim /usr/local/elasticsearch-5.4.3/config/elasticsearch.yml, modify the content:

node.name: slave1
node.master: false
node.data: true
network.host: 192.168.23.2

(2) Modify the risen03 ElasticSearch configuration file

vim /usr/local/elasticsearch-5.4.3/config/elasticsearch.yml, modify the content:

node.name: slave2
node.master: false
node.data: true
network.host: 192.168.23.3

The other contents remain unchanged, and the cluster configuration can be adjusted again according to actual needs to improve performance.

3.3.6. Modify permissions

Operation nodes: risen01, risen02, risen03

Operating user: root

Note: elasticsearch startup does not support root startup, so it needs to be started by other users. Here we use the bigdata user created at the beginning (each machine has already created the bigdata user in advance), and empower the bigdata user

chown -R bigdata.bigdata /log/elasticsearch
chown -R bigdata.bigdata /data/elasticsearch
chown -R bigdata.bigdata /usr/lcoal/elasticsearch-5.4.3
chown -R bigdata.bigdata /usr/lcoal/jdk1.8.0_161

3.4, start the cluster

1. Startup steps

Operation nodes: risen01, risen02, risen03

Operating user: bigdata

Note: There may be environmental problems when starting for the first time. Please check whether the solution at the end of [Errors and Warnings] can be helpful.

risen01 operation: enter /usr/local/elasticsearch-5.4.3 and execute: bin/elasticsearch, the result is as shown in the figure:

risen02 operation: enter /usr/local/elasticsearch-5.4.3 and execute: bin/elasticsearch, the result is as shown in the figure:

At this point, you will find that the risen01 startup interface appears as shown in the following figure:

This means that the new risen02 node has been added to the cluster, and risen01 has been automatically detected. risen03 operation: enter /usr/local/elasticsearch-5.4.3, execute: bin/elasticsearch, the result is as shown in the figure:

At the same time, it will be found that the information of the node added above appears on the risen01 startup interface. If the startup is successful, risen01 will automatically detect it.

2. Running in the background, all our nodes have been started at this point. After each node is successfully started, add -d to the start command to run in the background. The command:

bin/elasticsearch -d

3. Then execute the view node information command on any node:

curl risen01:9200/_cat/nodes?v

The result is shown in the figure:

It can be seen that our node configuration is as expected.

4. Visualization plug-in installation

4.1, head plug-in installation

Note: Since the head plugin service of es5 requires grunt to start, and to install grunt, you must install npm and node commands

4.1.1. Preparation before installation

4.1.2, install the compilation environment

Operating Nodes: Networked Machines and risen01

Operating user: root

Excuting an order:

yum install -y gcc gcc-c++ make

4.1.3, install npm and node

Operation node: risen01

Operating user: root

Description: Because my networked machine has already installed its own npm and node commands, I will now demonstrate how to install it on risen01

(1) Unzip the node-v6.11.0-linux-x64.tar.xz package, command:

xz -d ~/packages/node-v6.11.0-linux-x64.tar.xz

At this point, a compressed package of /node-v6.11.0-linux-x64.tar will be generated.

(2) Unzip the /node-v6.11.0-linux-x64.tar package, command:

tar -xvf node-v6.11.0-linux-x64.tar -C /usr/local/node/

(3) Environment variable settings

Modify the /etc/profile file as shown in the following figure:

Then execute the command:

source /etc/profile

Verify that the environment variable is added successfully

If the above picture appears, the installation is successful.

4.1.4, install grunt

Operating Nodes: Networked Machines

Operating user: root

(1) Upload the downloaded elasticsearch-head plugin to any directory on the networked machine, then unzip and rename it to head

(2) Enter the head directory and execute the command:

npm install -g grunt --registry=https://registry.npm.taobao.org

The result is shown below:

(3) Copy the node_modules directory under /root/.nvm/versions/node/v9.5.0/lib/ to the head directory

(4) Modify the Gruntfile.js file in the head directory, and add new properties in connect:

hostname:’192.168.23.1’,

save and exit

Note: The port 9100 here is the port for accessing the head. In order to avoid port conflicts, it can be modified

The result is shown in the figure:

(5) Package the elasticsearch-head plugin and execute the command:

zip -q -r head.zip head/*

(6) Download the packaged head.zip plugin on the networked machine to the local, upload it to the /usr/local/elasticsearch-5.4.3 directory of risen01 and unzip it (do not put it in the plugins directory, es5 and es2 There are big changes between)

(7) Enter the /usr/local/elasticsearch-5.4.3/head directory to execute the command to start the head plugin:

node_modules/grunt/bin/grunt server

The following screenshot errors may occur:

Reason for error: missing many grunt dependencies

Solution: Return to the networked machine and then enter the head directory to install dependencies one by one (command:

npm install grunt-contrib-clean --registry=https://registry.npm.taobao.org
npm install grunt-contrib-watch --registry=https://registry.npm.taobao.org
npm install grunt-contrib-connect --registry=https://registry.npm.taobao.org
npm install grunt-contrib-copy --registry=https://registry.npm.taobao.org
npm install grunt-contrib-jasmine --registry=https://registry.npm.taobao.org
npm install grunt-contrib-concat --registry=https://registry.npm.taobao.org

), you will find that many new dependency packages appear in the node_modules directory, but at this time the grunt directory in the previous node_modules directory is overwritten, then re-execute the command npm install -g grunt --registry=https://registry.npm .taobao.org, and then merge the two node_modules into one. Package the entire head again and upload it to risen01, replace the previous head package and restart

The result is shown in the figure:

Start the plugin successfully!

To run in the background, just add the & symbol after the execution command.

4.1.5, head visualization plug-in results

5. Errors and warnings

5.1, the kernel version is too low

Warning content:

seccomp unavailable: requires kernel 3.5+ with CONFIG_SECCOMP and CONFIG_SECCOMP_FILTER

Warning screenshot:

Warning solution: Modify the configuration in elasticsearch.yml and add the following two properties under Memory:

bootstrap.memory_lock: false
bootstrap.system_call_filter: false

5.2. Overall screenshot of error reporting

5.3. The problem of unable to create local files, the maximum number of files that users can create is too small

Error content:

[4]ERROR: bootstrap checks failed

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

Error solution: switch to the root user, edit the limits.conf configuration file, and add the following to vim /etc/security/limits.conf:

* soft nofile 65536
* hard nofile 131072
* soft nproc 2048
* hard nproc 4096

save and exit

5.4. The problem of unable to create local threads, the maximum number of threads that users can create is too small

Error content:

[2]max number of threads [1024] for user [bigdata] likely too low, increase to at least [2048]

Error solution: switch to the root user, enter the limits.d directory, modify the 90-nproc.conf configuration file, vi /etc/security/limits.d/90-nproc.conf

Find the following:

* soft nproc 1024

change into

* soft nproc 2048

save and exit

5.5, the maximum virtual memory is too small

报错内容:[3]max virtual memory areas vm.max_map_count [65530] likely too low, increase to at least [262144]

Error solution: switch to the root user, modify the configuration file sysctl.conf, and add the following configuration to vi /etc/sysctl.conf:

vm.max_map_count=655360

Save and exit and execute the command:

sysctl -p

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324896608&siteId=291194637