安装 Elasticsearch 集群

官方文档: https://www.elastic.co/guide/en/elasticsearch/reference/5.1/index.html
Server 1: 192.168.56.200
Server 2: 192.168.56.201

  1)添加 elasticsearch 用户
    ~#useradd -b /home -M -s /sbin/nologin -U elasticsearch
  2)安装JDK
    ~#tar xzf jdk-8u112-linux-x64.tar.gz
    ~#mv jdk1.8.0_112/ /srv/
    ~#echo "JAVA_HOME=/srv/jdk1.8.0_112" >> /etc/environment
    ~#vim /etc/profile #在 export PATH 之前添加下行
      pathmunge $JAVA_HOME/bin
    ~#reboot
    ~#java -version
  3)修改系统参数、主机名
    ~#echo "vm.max_map_count=262144" >> /etc/sysctl.conf
    ~#vim /etc/security/limits.conf #添加以下四行
      * soft nofile 1000000
      * hard nofile 1000000
      elasticsearch soft memlock unlimited
      elasticsearch hard memlock unlimited
    ~#vim /etc/hosts #添加以下两行
      192.168.56.200 node200
      192.168.56.201 node201
    ~#hostnamectl set-hostname node200
    ~#reboot
    ~#ulimit -a
  4)安装ES
    ~#mkdir /data/elasticsearch/data
    ~#mkdir /data/elasticsearch/logs
    ~#chown -R elasticsearch:elasticsearch /data/elasticsearch
    ~#tar xzf elasticsearch-5.0.1.tar.gz
    ~#mv elasticsearch-5.0.1 /srv/
    ~#vim /srv/elasticsearch-5.0.1/config/elasticsearch.yml #修改以下配置
      cluster.name: ESCluster #同一集群中所有节点的 claster.name 必须一致
      node.name: node200
      path.data: /data/elasticsearch/data
      path.logs: /data/elasticsearch/logs
      bootstrap.memory_lock: true
      network.host: 192.168.56.200
      http.port: 9200
      discovery.zen.ping.unicast.hosts: ["node200", "node201"] #集群中所有节点的主机名(自动加入集群、自动选举Master)
      discovery.zen.minimum_master_nodes: 2
    ~#vim /srv/elasticsearch-5.0.1/config/jvm.options #修改以下配置
      -Xms1g #参考文档 https://www.elastic.co/guide/en/elasticsearch/guide/current/heap-sizing.html
      -Xmx1g
    ~#chown -R elasticsearch:elasticsearch /srv/elasticsearch-5.0.1/config
  5)启动 Elasticsearch 服务(node200)
    ~#sudo -u elasticsearch /srv/elasticsearch-5.0.1/bin/elasticsearch -d
    ~#curl http://192.168.56.200:9200/ #看到以下输出代表 Elasticsearch 已正确运行
      {
        "name" : "node200",
        "cluster_name" : "ESCluster",
        "cluster_uuid" : "qLPhdOwRQW6vcxRLv0utrw",
        "version" : {
          "number" : "5.0.1",
          "build_hash" : "080bb47",
          "build_date" : "2016-11-11T22:08:49.812Z",
          "build_snapshot" : false,
          "lucene_version" : "6.2.1"
        },
        "tagline" : "You Know, for Search"
      }
  6)在 201 机器上重复以上1、2、3、4四个步骤(需要修改以下三点不同的地方),安装第二个ES节点。
    hostnamectl set-hostname node201
    node.name: node201
    network.host: 192.168.56.201
  7)启动 Elasticsearch 服务(node201)
    ~#sudo -u elasticsearch /srv/elasticsearch-5.0.1/bin/elasticsearch -d
    ~#curl http://192.168.56.201:9200/ #看到以下输出代表 Elasticsearch 已正确运行
      {
        "name" : "node201",
        "cluster_name" : "ESCluster",
        "cluster_uuid" : "qLPhdOwRQW6vcxRLv0utrw",
        "version" : {
          "number" : "5.0.1",
          "build_hash" : "080bb47",
          "build_date" : "2016-11-11T22:08:49.812Z",
          "build_snapshot" : false,
          "lucene_version" : "6.2.1"
        },
        "tagline" : "You Know, for Search"
      }
  8)查看集群状态
    ~#curl -XGET http://192.168.56.200:9200/_cluster/health?pretty
    ~#curl -XGET http://192.168.56.200:9200/_cluster/state?pretty

发表评论

电子邮件地址不会被公开。 必填项已用*标注