Deploying Elasticsearch
Compiling and Decompressing the Elasticsearch Installation Package
- Compile the Elasticsearch installation package. For details, see Elasticsearch Porting Guide (CentOS & openEuler).
- Place the Elasticsearch installation package to the /usr/local directory on the agent1 node and decompress it.
1 2
mv elasticsearch-6.7.1.tar.gz /usr/local tar -zxvf elasticsearch-6.7.1.tar.gz
If the installation package name is not elasticsearch-6.7.1.tar.gz, replace it with the actual one.
- Create a soft link for subsequent version updates.
1ln -s elasticsearch-6.7.1 elasticsearch
If the software directory name is not elasticsearch-6.7.1, replace it with the actual one.
Adding Elasticsearch to Environment Variables
- Edit the /etc/profile file.
1vi /etc/profile - Press i to enter the insert mode and add environment variables at the end of the file.
1 2
export ES_HOME=/usr/local/elasticsearch export PATH=$ES_HOME/bin:$PATH
- Press Esc, type :wq!, and press Enter to save the file and exit.
- Make the environment variables take effect.
1source /etc/profile
Copying the Configuration Directories
Go to the directory and copy the directory to the configuration directories of the ESMaster and ESNode1 instances.
1 2 3 | cd /usr/local/elasticsearch cp -r config config0 cp -r config config1 |
- config0: configuration directory of the ESMaster instance
- config1: configuration directory of the ESNode1 instance
Modifying the Elasticsearch Configuration Files
All Elasticsearch configuration files are stored in the $ES_HOME/config{0,1} directory.
- Modify the config0/elasticsearch.yml file.
1 2 3 4 5 6 7 8 9 10 11 12 13 14
cluster.name: my-application # Cluster name, which can be changed. node.name: node-{ip}-9200 # Instance name. Ensure that each instance name is unique in the cluster. path.data: /data/data1/elastic,/data/data2/elastic,/data/data3/elastic,/data/data4/elastic,/data/data5/elastic,/data/data6 # Data directory of the ESMaster instance. path.logs: /var/log/elastic-9200 # Log directory of the ESMaster instance. bootstrap.memory_lock: false network.host: $agent1 # You can enter the IP address of agent1. http.port: 9200 # Port of the ESMaster instance. transport.tcp.port: 9300 discovery.zen.ping.unicast.hosts: ["agent1:9300","agent1:9301","agent2:9300","agent2:9301", "agent3:9300","agent3:9301"] discovery.zen.minimum_master_nodes: 1 node.max_local_storage_nodes: 5 node.master: true node.data: true xpack.ml.enabled: false
- Modify the config1/elasticsearch.yml file.
1 2 3 4 5 6 7 8 9 10 11 12 13 14
cluster.name: my-application # Cluster name, which can be changed. node.name: node-{ip}-9201 # Instance name. Ensure that each instance name is unique in the cluster. path.data: /data/data7/elastic,/data/data8/elastic,/data/data9/elastic,/data/data10/elastic,/data/data11/elastic,/data/data12/elastic # Data directory of the ESMaster instance. path.logs: /var/log/elastic-9201 # Log directory of the ESMaster instance. bootstrap.memory_lock: false network.host: agent1 # You can enter the IP address of agent1. http.port: 9201 # Port of the ESMaster instance. transport.tcp.port: 9301 discovery.zen.ping.unicast.hosts: ["agent1:9300","agent1:9301","agent2:9300","agent2:9301", "agent3:9300","agent3:9301"] discovery.zen.minimum_master_nodes: 1 node.max_local_storage_nodes: 5 node.master: true node.data: true xpack.ml.enabled: false
- Modify the config{0,1}/jvm.options file. The memory of the ESMaster instance does not need to be too large. Set it based on site requirements.
1 2
-Xms31g -Xmx31g
- Modify the bin/elasticsearch-env file. Add the following configuration to the beginning of the script:
1 2
export JAVA_HOME=/usr/local/jdk8u252-b09 export PATH=${JAVA_HOME}/bin:${PATH}
Synchronizing the Configurations to Other Nodes
- Synchronize the configurations.
- Copy elasticsearch-6.7.1 to the /usr/local directory of agent2 and agent3.
1 2
scp -r /usr/local/elasticsearch-6.7.1 root@agent2:/usr/local scp -r /usr/local/elasticsearch-6.7.1 root@agent3:/usr/local
- Log in to agent2 and agent3 and create a soft link for elasticsearch-6.7.1.
1 2
cd /usr/local ln -s elasticsearch-6.7.1 elasticsearch
- Copy elasticsearch-6.7.1 to the /usr/local directory of agent2 and agent3.
- Create data and log directories.
- Create an ESMaster data directory on agent1 to agent3.
1mkdir -p /usr/local/elasticsearch/esmaster
- Create an ESNode1 data directory on agent1 to agent3.
1mkdir -p /data/data{1,2,3,4,5,6,7,8,9,10,11,12}/elastic
- Create ESMaster and ESNode1 data directories on agent1 to agent3.
1mkdir -p /var/log/elastic-{9200,9201}
- Create an ESMaster data directory on agent1 to agent3.
- Modify node parameters.
- On agent2, modify config0/elasticsearch.yml.
1 2
node.name: node-{ip}-9200 # Instance name. Ensure that each instance name is unique in the cluster. network.host: agent2 # You can enter the IP address of agent2.
- Modify config1/elasticsearch.yml.
1 2
node.name: node-{ip}-9201 # Instance name. Ensure that each instance name is unique in the cluster. network.host: agent2 # You can enter the IP address of agent2.
- On agent3, modify config0/elasticsearch.yml.
1 2
node.name: node-{ip}-9200 # Instance name. Ensure that each instance name is unique in the cluster. network.host: agent3 # You can enter the IP address of agent3.
- Modify config1/elasticsearch.yml.
1 2
node.name: node-{ip}-9201 # Instance name. Ensure that each instance name is unique in the cluster. network.host: agent3 # You can enter the IP address of agent3.
- On agent2, modify config0/elasticsearch.yml.
Starting and Stopping Elasticsearch
- Create an Elasticsearch user.
- Log in to agent1 to agent3 and create an elasticsearch user. By default, elasticsearch cannot be started by the root user.
1useradd elasticsearch - Change the owner of the elasticsearch directories.
1 2 3
chown -R elasticsearch:elasticsearch /usr/local/elasticsearch chown -R elasticsearch:elasticsearch /data/data{1,2,3,4,5,6,7,8,9,10,11,12}/elastic chown -R elasticsearch:elasticsearch /var/log/elastic-{9200,9201}
- Log in to agent1 to agent3 and create an elasticsearch user. By default, elasticsearch cannot be started by the root user.
- On agent1 to agent3, modify /etc/security/limits.conf.
1 2 3 4
elasticsearch soft nofile 190000 elasticsearch hard nofile 190000 elasticsearch soft nproc 190000 elasticsearch hard nproc 190000
- On agent1 to agent3, start the Elasticsearch cluster in the ${ES_HOME} directory as the elasticsearch user.
1 2 3
sysctl -w vm.max_map_count=655360 sudo -u elasticsearch ES_PATH_CONF=/usr/local/elasticsearch/config0/ bin/elasticsearch -p /usr/local/elasticsearch/es-{ip}-9200.pid -d sudo -u elasticsearch ES_PATH_CONF=/usr/local/elasticsearch/config1/ bin/elasticsearch -p /usr/local/elasticsearch/es-{ip}-9201.pid -d
- If your permission is insufficient, add the permission.
1 2
chmod -R 777 /usr/local/elasticsearch chmod -R 777 /data/data{1,2,3,4,5,6,7,8,9,10,11,12}/elastic
- Check the Elasticsearch startup status.
1ps aux | grep Elasticsearch
- If your permission is insufficient, add the permission.
- Kill the Elasticsearch process to stop the Elasticsearch cluster.
1kill -9 $(ps aux | grep Elasticsearch | grep -v 'grep --color=auto Elasticsearch' | awk '{print $2}')
Parent topic: Deployment Guide (CentOS & openEuler)