Rate This Document
Findability
Accuracy
Completeness
Readability

Deploying Elasticsearch

Compiling and Decompressing the Elasticsearch Installation Package

  1. Compile the Elasticsearch installation package. For details, see Elasticsearch Porting Guide (CentOS & openEuler).
  2. 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.

  3. Create a soft link for subsequent version updates.
    1
    ln -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

  1. Edit the /etc/profile file.
    1
    vi /etc/profile
    
  2. 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
    
  3. Press Esc, type :wq!, and press Enter to save the file and exit.
  4. Make the environment variables take effect.
    1
    source /etc/profile
    

Copying the Configuration Directories

Go to the /usr/local/elasticsearch directory and copy the config 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.

  1. 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
    
  2. 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
    
  3. 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
    
  4. 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

  1. Synchronize the configurations.
    1. 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
      
    2. 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
      
  2. Create data and log directories.
    1. Create an ESMaster data directory on agent1 to agent3.
      1
      mkdir -p /usr/local/elasticsearch/esmaster
      
    2. Create an ESNode1 data directory on agent1 to agent3.
      1
      mkdir -p /data/data{1,2,3,4,5,6,7,8,9,10,11,12}/elastic
      
    3. Create ESMaster and ESNode1 data directories on agent1 to agent3.
      1
      mkdir -p /var/log/elastic-{9200,9201}
      
  3. Modify node parameters.
    1. 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.
      
    2. 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.
      
    3. 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.
      
    4. 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.
      

Starting and Stopping Elasticsearch

  1. Create an Elasticsearch user.
    1. Log in to agent1 to agent3 and create an elasticsearch user. By default, elasticsearch cannot be started by the root user.
      1
      useradd elasticsearch
      
    2. 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}
      
  2. 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
    
  3. 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.
      1
      ps aux | grep Elasticsearch
      
  4. Kill the Elasticsearch process to stop the Elasticsearch cluster.
    1
    kill -9 $(ps aux | grep Elasticsearch | grep -v 'grep --color=auto Elasticsearch' | awk '{print $2}')