前回は『 OSS編~オーケストレーションツール Consul 04 KEY/VALUE DATA編~ 』と題して、オーケストレーションのConsulでKEY/VALUE DATA機能を試してみました。
今回は『OSS編~オーケストレーションツール Consul 05 Multiple Datacenters編~』と題して、オーケストレーションのConsulでMultiple Datacentersを試してみたいと思います。
Multiple Datacentersとは
ConsulではMultiple Datacentersに対応しています。
上記により複数のデータセンタをまたがってサーバを管理する事が出来ます。
※今回はVPNで繋がった環境で試しています。
1.consulの準備
データセンタ毎にconsulを準備します。
データセンタ01は 「dc1」という名前で起動します。
1$ consul agent -server -bootstrap-expect 1 -data-dir /tmp/consul -node=agent-one -dc dc12==> WARNING: BootstrapExpect Mode is specified as 1; this is the same as Bootstrap mode.3==> WARNING: Bootstrap mode enabled! Do not enable unless necessary4==> WARNING: It is highly recommended to set GOMAXPROCS higher than 15==> Starting Consul agent...6==> Starting Consul agent RPC...7==> Consul agent running!8 Node name: 'agent-one'9 Datacenter: 'dc1'10 Server: true (bootstrap: true)11 Client Addr: 127.0.0.1 (HTTP: 8500, HTTPS: -1, DNS: 8600, RPC: 8400)12 Cluster Addr: 172.16.1.46 (LAN: 8301, WAN: 8302)13 Gossip encrypt: false, RPC-TLS: false, TLS-Incoming: false14 Atlas: <disabled>データセンタ02は 「dc2」という名前で起動します。
1$ consul agent -server -bootstrap-expect 1 -data-dir /tmp/consul -node=agent-two -dc dc22==> WARNING: BootstrapExpect Mode is specified as 1; this is the same as Bootstrap mode.3==> WARNING: Bootstrap mode enabled! Do not enable unless necessary4==> WARNING: It is highly recommended to set GOMAXPROCS higher than 15==> Starting Consul agent...6==> Starting Consul agent RPC...7==> Consul agent running!8 Node name: 'agent-two'9 Datacenter: 'dc2'10 Server: true (bootstrap: true)11 Client Addr: 127.0.0.1 (HTTP: 8500, HTTPS: -1, DNS: 8600, RPC: 8400)12 Cluster Addr: 10.0.0.5 (LAN: 8301, WAN: 8302)13 Gossip encrypt: false, RPC-TLS: false, TLS-Incoming: false14 Atlas: <disabled>それぞれwanノードを確認してみます。
まだ、自分だけのリストなのが分かります。
1$ consul members -wan2Node Address Status Type Build Protocol3agent-one.dc1 172.16.1.46:8302 alive server 0.5.0 245$ consul members -wan6Node Address Status Type Build Protocol7agent-two.dc2 10.0.0.5:8302 alive server 0.5.0 2HTTP APIでも確認してみます。
1$ curl http://localhost:8500/v1/catalog/datacenters2["dc1"]34$ curl http://localhost:8500/v1/catalog/datacenters5["dc2"]2.join
それではjoinを実施してみます。
データセンタ02から01にjoinします。
1$ consul join -wan 「ipアドレス」2Successfully joined cluster by contacting 1 nodes.データセンタ01で確認してみます。
1$ consul members -wan2Node Address Status Type Build Protocol3agent-one.dc1 172.16.1.46:8302 alive server 0.5.0 24agent-two.dc2 10.0.0.5:8302 alive server 0.5.0 2データセンタ02でも確認してみます。
1$ consul members -wan2Node Address Status Type Build Protocol3agent-two.dc2 10.0.0.5:8302 alive server 0.5.0 24agent-one.dc1 172.16.1.46:8302 alive server 0.5.0 2HTTP APIでも確認してみます。
1$ curl http://localhost:8500/v1/catalog/datacenters2["dc1","dc2"]34$ curl http://localhost:8500/v1/catalog/nodes?dc=dc15[{"Node":"agent-one","Address":"172.16.1.46"}]67$ curl http://localhost:8500/v1/catalog/nodes?dc=dc28[{"Node":"agent-two","Address":"10.0.0.5"}]いかがでしたでしょうか?
次回もお楽しみに!!!