1. 程式人生 > >docker 部署elasticsearch叢集

docker 部署elasticsearch叢集

[[email protected] ~]# docker images
REPOSITORY                                      TAG                 IMAGE ID            CREATED             SIZE
docker.elastic.co/elasticsearch/elasticsearch   5.6.3               865b21b970de        14 months ago       657MB
elasticsearch                                   5.6.3               865b21b970de        14 months ago       657MB
docker.elastic.co/elasticsearch/elasticsearch   5.6.2               59b11c02b218        14 months ago       657MB

[[email protected] es_docker]# cat es1.yml 
cluster.name: "dali"
node.name: node1
node.master: true
node.data: true
xpack.security.enabled: false
network.host: 0.0.0.0
discovery.zen.minimum_master_nodes: 1
discovery.zen.ping.unicast.hosts: ["172.17.0.2", "172.17.0.3"]
[[email protected] es_docker]# ls
es1.yml  es2.yml
[
[email protected]
es_docker]# cat es2.yml cluster.name:
"dali" node.name: node2 node.master: false node.data: true xpack.security.enabled: false network.host: 0.0.0.0 discovery.zen.minimum_master_nodes: 1 #discovery.zen.ping.unicast.hosts: es1 discovery.zen.ping.unicast.hosts: ["172.17.0.2", "172.17.0.3
"]

docker run -d --name es1 -p 9200:9200 -p 9300:9300 -v /root/es_docker/es1.yml:/usr/share/elasticsearch/config/elasticsearch.yml elasticsearch:5.6.3
docker run -d --name es2 -p 9201:9200 -p 9301:9300 -v /root/es_docker/es2.yml:/usr/share/elasticsearch/config/elasticsearch.yml elasticsearch:5.6.3

[[email protected] es_docker]# curl -XGET 'http://192.168.204.130:9200/_cluster/state/nodes?pretty'
{
  "cluster_name" : "dali",
  "nodes" : {
    "JzKMNUXiRnS4RBJrwhn7fQ" : {
      "name" : "node1",
      "ephemeral_id" : "tbAY947pQVeNIJK1vSns1Q",
      "transport_address" : "172.17.0.2:9300",
      "attributes" : {
        "ml.max_open_jobs" : "10",
        "ml.enabled" : "true"
      }
    },
    "q3su9zqhR6q7CBAAeJYErA" : {
      "name" : "node2",
      "ephemeral_id" : "O90SzWzdQgegLgD2ghsZxQ",
      "transport_address" : "172.17.0.3:9300",
      "attributes" : {
        "ml.max_open_jobs" : "10",
        "ml.enabled" : "true"
      }
    }
  }
}

更改配置模擬容器不在一個server上

[[email protected] es_docker]# cat es1.yml 
cluster.name: "dali"
node.name: node1
node.master: true
node.data: true
xpack.security.enabled: false
network.host: 0.0.0.0
discovery.zen.minimum_master_nodes: 1
discovery.zen.ping.unicast.hosts: ["192.168.204.130:9300", "192.168.204.130:9301"]
#discovery.zen.ping.unicast.hosts: ["172.17.0.2", "172.17.0.3"]
#discovery.zen.ping.unicast.hosts: es1
[[email protected] es_docker]# cat es2.yml 
cluster.name: "dali"
node.name: node2
node.master: false
node.data: true
xpack.security.enabled: false
network.host: 0.0.0.0
discovery.zen.minimum_master_nodes: 1
#discovery.zen.ping.unicast.hosts: es1
discovery.zen.ping.unicast.hosts: ["192.168.204.130:9300", "192.168.204.130:9301"]

檢視叢集status

[[email protected] es_docker]# curl -XGET 'http://192.168.204.130:9200/_cluster/state/nodes?pretty'
{
  "cluster_name" : "dali",
  "nodes" : {
    "JzKMNUXiRnS4RBJrwhn7fQ" : {
      "name" : "node1",
      "ephemeral_id" : "ChICyr0LQ36Vmpo5G4IB8w",
      "transport_address" : "172.17.0.2:9300",
      "attributes" : {
        "ml.max_open_jobs" : "10",
        "ml.enabled" : "true"
      }
    },
    "q3su9zqhR6q7CBAAeJYErA" : {
      "name" : "node2",
      "ephemeral_id" : "cEmXAm9cQ8SIPQZlJBKuug",
      "transport_address" : "172.17.0.3:9300",
      "attributes" : {
        "ml.max_open_jobs" : "10",
        "ml.enabled" : "true"
      }
    }
  }
}