elasticsearch 集群部署

1. 环境准备

IP 主机名 安装软件 操作系统
192.168.2.20 master es,jdk1.8 ubuntu18.04
192.168.2.21 slave1 es,jdk1.8 ubuntu18.04
192.168.2.22 slave2 es,jdk1.8 ubuntu18.04

我们部署ELK 5.X 本文介绍多机 集群部署,也就是每个机器上跑一个es组成的集群

配置文件

root@master:~# egrep -v '#|^$' /opt/elasticsearch/config/elasticsearch.yml 
cluster.name: es-cluster
node.name: master
path.data: /opt/elasticsearch/data
path.logs: /opt/elasticsearch/logs
bootstrap.memory_lock: false
network.host: 0.0.0.0
http.port: 9200
discovery.zen.ping.unicast.hosts: ["master", "slave1","slave2"]
discovery.zen.minimum_master_nodes: 1

root@slave1:~# egrep -v '#|^$' /opt/elasticsearch/config/elasticsearch.yml 
cluster.name: es-cluster
node.name: slave1
path.data: /opt/elasticsearch/data
path.logs: /opt/elasticsearch/logs
bootstrap.memory_lock: false
network.host: 0.0.0.0
http.port: 9200
discovery.zen.ping.unicast.hosts: ["master", "slave1","slave2"]
discovery.zen.minimum_master_nodes: 1

root@slave2:~# egrep -v '#|^$' /opt/elasticsearch/config/elasticsearch.yml
cluster.name: es-cluster
node.name: slave2
path.data: /opt/elasticsearch/data
path.logs: /opt/elasticsearch/logs
bootstrap.memory_lock: false
network.host: 0.0.0.0
http.port: 9200
discovery.zen.ping.unicast.hosts: ["master", "slave1","slave2"]
discovery.zen.minimum_master_nodes: 1

3. 集群启动

/opt/elasticsearch/bin/elasticsearch # 前台运行
# /opt/elasticsearch/bin/elasticsearch & # 后台运行
root@master:~# /opt/elasticsearch/bin/elasticsearch
root@slave1:~# /opt/elasticsearch/bin/elasticsearch
root@slave2:~# /opt/elasticsearch/bin/elasticsearch

查看集群状态

curl master:9200/_cluster/stats|json
curl master:9200/_cat/nodes?v

查看node节点

root@master:~# curl master:9200
{
  "name" : "master",
  "cluster_name" : "es-cluster",
  "cluster_uuid" : "qNGJCGblQAGp3vhiiAWz8g",
  "version" : {
    "number" : "5.6.16",
    "build_hash" : "3a740d1",
    "build_date" : "2019-03-13T15:33:36.565Z",
    "build_snapshot" : false,
    "lucene_version" : "6.6.1"
  },
  "tagline" : "You Know, for Search"
}

root@master:~# curl master:9200/_cat/nodes?v
ip           heap.percent ram.percent cpu load_1m load_5m load_15m node.role master name
192.168.2.21           13          89   0    0.06    0.08     0.02 mdi       -      slave1
192.168.2.20           15          59   2    1.90    1.85     1.74 mdi       *      master
192.168.2.22           12          98   0    0.13    0.21     0.08 mdi       -      slave2
查看集群信息
root@master:~# curl master:9200/_cluster/stats|json
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  1742  100  1742    0     0  62214      0 --:--:-- --:--:-- --:--:-- 62214
{
  "_nodes": {
    "total": 3,
    "successful": 3,
    "failed": 0
  },
  "cluster_name": "es-cluster",
  "timestamp": 1570599426453,
  "status": "green",
  "indices": {
    "count": 0,
    "shards": {},
    "docs": {
      "count": 0,
      "deleted": 0
    },
    "store": {
      "size_in_bytes": 0,
      "throttle_time_in_millis": 0
    },
    "fielddata": {
      "memory_size_in_bytes": 0,
      "evictions": 0
    },
    "query_cache": {
      "memory_size_in_bytes": 0,
      "total_count": 0,
      "hit_count": 0,
      "miss_count": 0,
      "cache_size": 0,
      "cache_count": 0,
      "evictions": 0
    },
    "completion": {
      "size_in_bytes": 0
    },
    "segments": {
      "count": 0,
      "memory_in_bytes": 0,
      "terms_memory_in_bytes": 0,
      "stored_fields_memory_in_bytes": 0,
      "term_vectors_memory_in_bytes": 0,
      "norms_memory_in_bytes": 0,
      "points_memory_in_bytes": 0,
      "doc_values_memory_in_bytes": 0,
      "index_writer_memory_in_bytes": 0,
      "version_map_memory_in_bytes": 0,
      "fixed_bit_set_memory_in_bytes": 0,
      "max_unsafe_auto_id_timestamp": -9223372036854776000,
      "file_sizes": {}
    }
  },
  "nodes": {
    "count": {
      "total": 3,
      "data": 3,
      "coordinating_only": 0,
      "master": 3,
      "ingest": 3
    },
    "versions": [
      "5.6.16"
    ],
    "os": {
      "available_processors": 16,
      "allocated_processors": 16,
      "names": [
        {
          "name": "Linux",
          "count": 3
        }
      ],
      "mem": {
        "total_in_bytes": 24938258432,
        "free_in_bytes": 4462952448,
        "used_in_bytes": 20475305984,
        "free_percent": 18,
        "used_percent": 82
      }
    },
    "process": {
      "cpu": {
        "percent": 0
      },
      "open_file_descriptors": {
        "min": 221,
        "max": 294,
        "avg": 245
      }
    },
    "jvm": {
      "max_uptime_in_millis": 1229725,
      "versions": [
        {
          "version": "1.8.0_112",
          "vm_name": "Java HotSpot(TM) 64-Bit Server VM",
          "vm_version": "25.112-b15",
          "vm_vendor": "Oracle Corporation",
          "count": 3
        }
      ],
      "mem": {
        "heap_used_in_bytes": 889373360,
        "heap_max_in_bytes": 6302990336
      },
      "threads": 127
    },
    "fs": {
      "total_in_bytes": 2948701765632,
      "free_in_bytes": 2916082200576,
      "available_in_bytes": 2766081945600,
      "spins": "true"
    },
    "plugins": [],
    "network_types": {
      "transport_types": {
        "netty4": 3
      },
      "http_types": {
        "netty4": 3
      }
    }
  }
}