Deploy Elasticsearch

2017-11-20 16:31:50
ElasticSearch deploy doc
  • env

    1
    2
    3
    4
    5
    6
    7
    8
    [root@localhost ~]# cat /etc/issue
    CentOS release 6.8 (Final)
    Kernel \r on an \m

    [root@localhost ~]# java -version
    java version "1.8.0_112"
    Java(TM) SE Runtime Environment (build 1.8.0_112-b15)
    Java HotSpot(TM) 64-Bit Server VM (build 25.112-b15, mixed mode)
  • download es, create es user

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    curl -L -O  https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-6.0.0.tar.gz

    tar -xzf elasticsearch-6.0.0.tar.gz
    sudo useradd es
    mv elasticsearch-6.0.0 /usr/local/elasticsearch
    chown es.es /usr/local/elasticsearch -R

    #add es.conf to /etc/security/limits.d/es.conf
    [root@localhost ~]# cat /etc/security/limits.d/es.conf
    es soft memlock unlimited
    es hard memlock unlimited
    es soft nofile 204800
    es hard nofile 204800
    es soft nproc 4096

    #add option to /etc/sysctl.conf
    vm.max_map_count=655360
    sysctl -p
  • conf

    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
    [root@localhost ~]# cat /usr/local/elasticsearch/config/elasticsearch.yml |grep -v ^#
    cluster.name: es-ws-v6
    node.name: node-1
    node.master: true
    node.data: true
    path.data: /usr/local/elasticsearch/data
    path.logs: /usr/local/elasticsearch/logs
    bootstrap.memory_lock: true
    bootstrap.system_call_filter: false
    network.host: 172.16.56.193
    network.publish_host: 172.16.56.193
    discovery.zen.ping.unicast.hosts: ["172.16.56.194","172.16.56.195"]
    discovery.zen.minimum_master_nodes: 2


    [root@localhost ~]# cat /usr/local/elasticsearch/config/elasticsearch.yml |grep -v ^#
    cluster.name: es-ws-v6
    node.name: node-2
    node.master: true
    node.data: true
    path.data: /usr/local/elasticsearch/data
    path.logs: /usr/local/elasticsearch/logs
    bootstrap.memory_lock: true
    bootstrap.system_call_filter: false
    network.host: 172.16.56.194
    network.publish_host: 172.16.56.194
    discovery.zen.ping.unicast.hosts: ["172.16.56.193","172.16.56.195"]
    discovery.zen.minimum_master_nodes: 2


    [root@localhost ~]# cat /usr/local/elasticsearch/config/elasticsearch.yml |grep -v ^#
    cluster.name: es-ws-v6
    node.name: node-3
    node.master: true
    node.data: true

    path.data: /usr/local/elasticsearch/data
    path.logs: /usr/local/elasticsearch/logs
    bootstrap.memory_lock: true
    bootstrap.system_call_filter: false
    network.host: 172.16.56.195
    network.publish_host: 172.16.56.195
    discovery.zen.ping.unicast.hosts: ["172.16.56.193", "172.16.56.194"]
    discovery.zen.minimum_master_nodes: 2

    if you need to extend,only to keep cluster.name with es-ws-v6 ,now we add new node with config/elasticsearch

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    [root@localhost ~]# cat /usr/local/elasticsearch/config/elasticsearch.yml |grep -v ^#
    cluster.name: es-ws-v6
    node.name: node-4
    node.master: true
    node.data: true

    path.data: /usr/local/elasticsearch/data
    path.logs: /usr/local/elasticsearch/logs
    bootstrap.memory_lock: true
    bootstrap.system_call_filter: false
    network.host: 172.16.56.196
    network.publish_host: 172.16.56.196
    discovery.zen.ping.unicast.hosts: ["172.16.56.195"]
    discovery.zen.minimum_master_nodes: 2
  • start es and check cluster health,service script look here

    1
    2
    3
    4
    5
    6
    #start es
    su es
    cd /usr/local/elasticsearch
    bin/elasticsearch -d -p es.pid
    # check health
    curl http://172.16.56.193:9200/_cluster/health
  • restart es cluster service

    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
    #Disable shard allocation.
    curl -XPUT '172.16.56.193:9200/_cluster/settings?pretty' -H 'Content-Type: application/json' -d'
    {
    "persistent": {
    "cluster.routing.allocation.enable": "none"
    }
    }
    '

    #Stop indexing and perform a synced flush.
    curl -XPOST '172.16.56.193:9200/_flush/synced?pretty'

    #kill all node
    sudo -i service elasticsearch stop
    #If you are running Elasticsearch as a daemon:
    ps aux |grep elasticsearch |awk '{print $2}' |xargs kill

    #Start each upgraded node.
    #you can use _cat/health and _cat/nodes to monitor nodes joining the cluster:
    #If you have dedicated master nodes, start them first and wait for them to form a cluster
    #and elect a master before proceeding with your data nodes. You can check progress by looking at the logs.

    curl -XGET '172.16.56.193:9200/_cat/nodes?pretty'
    curl -XGET '172.16.56.193:9200/_cat/health?pretty'


    #Wait for all nodes to join the cluster and report a status of yellow.

    #Reenable allocation
    curl -XPUT '172.16.56.193:9200/_cluster/settings?pretty' -H 'Content-Type: application/json' -d'
    {
    "transient": {
    "cluster.routing.allocation.enable": "all"
    }
    }
    '

ref
Elasticsearch Reference
Elasticsearch 集群指南
ELASTICSEARCH集群部署文档


您的鼓励是我写作最大的动力

俗话说,投资效率是最好的投资。 如果您感觉我的文章质量不错,读后收获很大,预计能为您提高 10% 的工作效率,不妨小额捐助我一下,让我有动力继续写出更多好文章。