Last active
August 29, 2015 14:06
-
-
Save foostan/900261af5bdba03a31d0 to your computer and use it in GitHub Desktop.
オーケストレーションツールとしてのConsulの使い方 ref: http://qiita.com/foostan/items/954f73173ea34eb361da
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
docker pull foostan/consul |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
git clone https://github.com/foostan/docker-consul.git | |
cd docker-consul | |
vagrant up |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
root@client1:/# consul agent -data-dir=/tmp/consul -join 172.17.0.2 & | |
==> WARNING: It is highly recommended to set GOMAXPROCS higher than 1 | |
==> Starting Consul agent... | |
==> Starting Consul agent RPC... | |
==> Joining cluster... | |
Join completed. Synced with 1 initial agents | |
==> Consul agent running! | |
Node name: 'client1' | |
Datacenter: 'dc1' | |
Server: false (bootstrap: false) | |
Client Addr: 127.0.0.1 (HTTP: 8500, DNS: 8600, RPC: 8400) | |
Cluster Addr: 172.17.0.6 (LAN: 8301, WAN: 8302) | |
Gossip encrypt: false, RPC-TLS: false, TLS-Incoming: false | |
-以下省略- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
root@client2:/# consul agent -data-dir=/tmp/consul -join 172.17.0.2 & | |
==> WARNING: It is highly recommended to set GOMAXPROCS higher than 1 | |
==> Starting Consul agent... | |
==> Starting Consul agent RPC... | |
==> Joining cluster... | |
Join completed. Synced with 1 initial agents | |
==> Consul agent running! | |
Node name: 'client2' | |
Datacenter: 'dc1' | |
Server: false (bootstrap: false) | |
Client Addr: 127.0.0.1 (HTTP: 8500, DNS: 8600, RPC: 8400) | |
Cluster Addr: 172.17.0.5 (LAN: 8301, WAN: 8302) | |
Gossip encrypt: false, RPC-TLS: false, TLS-Incoming: false | |
-以下省略- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
root@server1:/# consul members | |
Node Address Status Type Build Protocol | |
client2 172.17.0.5:8301 alive client 0.4.0 2 | |
server1 172.17.0.2:8301 alive server 0.4.0 2 | |
server2 172.17.0.3:8301 alive server 0.4.0 2 | |
client1 172.17.0.6:8301 alive client 0.4.0 2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
root@server1:/# consul exec "hostname" | |
server1: server1 | |
server1: | |
==> server1: finished with exit code 0 | |
client1: client1 | |
client1: | |
client2: client2 | |
client2: | |
server2: server2 | |
server2: | |
==> client1: finished with exit code 0 | |
==> client2: finished with exit code 0 | |
==> server2: finished with exit code 0 | |
4 / 4 node(s) completed / acknowledged |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
root@server1:/# consul exec -node="client1" "hostname" | |
client1: client1 | |
client1: | |
==> client1: finished with exit code 0 | |
1 / 1 node(s) completed / acknowledged |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
root@client1:/# consul watch -type=key -key=foo "curl -s -X GET localhost:8500/v1/kv/foo?raw" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
root@server1:/# curl -X PUT -d "foo" localhost:8500/v1/kv/foo | |
true | |
root@server1:/# curl -X PUT -d "bar" localhost:8500/v1/kv/foo | |
true | |
root@server1:/# curl -X PUT -d "bazz" localhost:8500/v1/kv/foo | |
true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
foobarbazz | |
(実際はfoo bar bazz が順番に表示される) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
root@client1:/# consul watch -type=event -name="deploy" "echo deploy" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
root@server1:/# consul event -name="deploy" | |
Event ID: b38a8748-84d9-8235-8e4d-441935999af9 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
vagrant@vagrant-ubuntu-trusty-64:~$ docker run -h server1 -i -t foostan/consul | |
root@server1:/# |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
consul watch -type=service -service=consul "echo change services" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
root@server2:/# consul leave |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
root@server2:/# consul agent -data-dir=/tmp/consul -server -join 172.17.0.2 & |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
root@client1:/# consul watch -type=checks "echo change checks" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
root@client1:/# consul watch -type=nodes "echo change nodes" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
vagrant@vagrant-ubuntu-trusty-64:~$ docker run -h server2 -i -t foostan/consul | |
root@server2:/# |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
vagrant@vagrant-ubuntu-trusty-64:~$ docker run -h client1 -i -t foostan/consul | |
root@client1:/# |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
vagrant@vagrant-ubuntu-trusty-64:~$ docker run -h client2 -i -t foostan/consul | |
root@client2:/# |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
root@server1:/# ip a | |
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default | |
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 | |
inet 127.0.0.1/8 scope host lo | |
valid_lft forever preferred_lft forever | |
inet6 ::1/128 scope host | |
valid_lft forever preferred_lft forever | |
37: eth0: <BROADCAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000 | |
link/ether 9e:0b:9f:19:7e:e3 brd ff:ff:ff:ff:ff:ff | |
inet 172.17.0.2/16 scope global eth0 | |
valid_lft forever preferred_lft forever | |
inet6 fe80::9c0b:9fff:fe19:7ee3/64 scope link | |
valid_lft forever preferred_lft forever |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
root@server1:/# consul agent -data-dir=/tmp/consul -server -bootstrap-expect 2 & | |
==> WARNING: It is highly recommended to set GOMAXPROCS higher than 1 | |
==> Starting Consul agent... | |
==> Starting Consul agent RPC... | |
==> Consul agent running! | |
Node name: 'server1' | |
Datacenter: 'dc1' | |
Server: true (bootstrap: false) | |
Client Addr: 127.0.0.1 (HTTP: 8500, DNS: 8600, RPC: 8400) | |
Cluster Addr: 172.17.0.2 (LAN: 8301, WAN: 8302) | |
Gossip encrypt: false, RPC-TLS: false, TLS-Incoming: false | |
-以下省略- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
root@server2:/# consul agent -data-dir=/tmp/consul -server -join 172.17.0.2 & | |
==> WARNING: It is highly recommended to set GOMAXPROCS higher than 1 | |
==> Starting Consul agent... | |
==> Starting Consul agent RPC... | |
==> Joining cluster... | |
Join completed. Synced with 1 initial agents | |
==> Consul agent running! | |
Node name: 'server2' | |
Datacenter: 'dc1' | |
Server: true (bootstrap: false) | |
Client Addr: 127.0.0.1 (HTTP: 8500, DNS: 8600, RPC: 8400) | |
Cluster Addr: 172.17.0.3 (LAN: 8301, WAN: 8302) | |
Gossip encrypt: false, RPC-TLS: false, TLS-Incoming: false | |
-以下省略- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-以上省略- | |
2014/09/14 04:48:29 [INFO] serf: EventMemberJoin: server2 172.17.0.3 | |
2014/09/14 04:48:29 [INFO] consul: adding server server2 (Addr: 172.17.0.3:8300) (DC: dc1) | |
2014/09/14 04:48:29 [INFO] consul: Attempting bootstrap with nodes: [172.17.0.2:8300 172.17.0.3:8300] | |
2014/09/14 04:48:30 [WARN] raft: Heartbeat timeout reached, starting election | |
2014/09/14 04:48:30 [INFO] raft: Node at 172.17.0.2:8300 [Candidate] entering Candidate state | |
2014/09/14 04:48:30 [WARN] raft: Remote peer 172.17.0.3:8300 does not have local node 172.17.0.2:8300 as a peer | |
2014/09/14 04:48:30 [INFO] raft: Election won. Tally: 2 | |
2014/09/14 04:48:30 [INFO] raft: Node at 172.17.0.2:8300 [Leader] entering Leader state | |
2014/09/14 04:48:30 [INFO] consul: cluster leadership acquired | |
2014/09/14 04:48:30 [INFO] raft: pipelining replication to peer 172.17.0.3:8300 | |
2014/09/14 04:48:30 [INFO] consul: New leader elected: server1 | |
-以下省略- |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment