Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Consul 入門

Consul 入門

チーム内LT大会

AGAWA Koji

March 29, 2016
Tweet

More Decks by AGAWA Koji

Other Decks in Programming

Transcript

  1. What's Consul ? ػೳ • αʔϏεͷݕग़ͱ؅ཧ • Key-Value Storage ඇػೳ

    • ߴ͍Մ༻ੑΛඋ͑ͨ෼ࢄγεςϜ • ෳ਺ Datacenter Λαϙʔτ
  2. Service • api, mysql, ka-a ͳͲͳΜΒ͔ͷػೳΛఏڙ͢Δ΋ͷ • αʔϏεͷϝϯόʔ͸ IP ͱϙʔτͷϦετ

    • ϔϧενΣοΫʹΑΔϝϯόʔͷࢮ׆؂ࢹ • HTTP API ͱ DNS Ͱ໰͍߹Θ͕ͤͰ͖Δ
  3. DNS Ͱ A Ϩίʔυ໰͍߹Θͤ $ dig @127.0.0.1 -p 8600 web.service.consul

    ;; QUESTION SECTION: ;web.service.consul. IN A ;; ANSWER SECTION: web.service.consul. 0 IN A 128.199.137.114 web.service.consul. 0 IN A 128.199.130.243 • Consul agent Λ DNS αʔόʹࢦఆͯ͠໰͍߹Θͤ • *.service.consul Λղܾ͢ΔͱαʔϏεͷϝϯόʔ͕ฦͬͯ͘Δ • Ϧετͷฒͼ͸ϥϯμϜ (DNS ϥ΢ϯυϩϏϯ) • ϔϧενΣοΫΛ௨ͬͨੜ͖͍ͯΔϝϯόʔؚ͚͕ͩ·ΕΔ
  4. DNS Ͱ SRV Ϩίʔυ໰͍߹Θͤ $ dig @127.0.0.1 -p 8600 web.service.consul

    SRV ;; QUESTION SECTION: ;web.service.consul. IN SRV ;; ANSWER SECTION: web.service.consul. 0 IN SRV 1 1 80 node2.zem.jp.node.dc1.consul. web.service.consul. 0 IN SRV 1 1 80 node1.zem.jp.node.dc1.consul. ;; ADDITIONAL SECTION: node2.zem.jp.node.dc1.consul. 0 IN A 128.199.137.114 node1.zem.jp.node.dc1.consul. 0 IN A 128.199.130.243 • SRV ϨίʔυͰ͋Ε͹ϙʔτ൪߸·Ͱ෼͔Δ • Ψν Docker ͰαʔϏεߏ੒͢Δͱϙʔτ͕ϥϯμϜͳͷͰ༗༻ • ͨͩ͠ར༻ଆͰ SRV ͷϨκϧό͕ඞཁ • طʹ SRV ΛಡΉ࣮૷͕ͳ͚Ε͹ HTTP API ΛಡΉ࣮૷Λॻ͍ͨ΄͏ָ͕
  5. DNS Ͱ໰͍߹Θͤ ϩʔΧϧʹ dnsmasq ΛೖΕͯ .consul υϝΠϯͷ໊લղܾΛ Consul ʹ೚ ͤΔΑ͏ʹ͢ΔͱɺConsul

    ͷଘࡏΛҙࣝͤͣʹαʔϏεͷऔಘ͕Ͱ͖Δ ! [/etc/dnsmasq.conf] strict-order [/etc/dnsmasq.conf.d/consul.conf] server=/consul/127.0.0.1#8600 [/etc/resolv.conf] nameserver 127.0.0.1 nameserver 8.8.8.8
  6. DNS ໰͍߹Θͤͷར༻γʔϯ • طଘͷϓϩάϥϜʹखΛՃ͑Δ͜ͱͳ͘αʔϏεࢀর͕Ͱ͖Δ • Ϋϥελܥϛυϧ΢ΣΞ΁ͷ઀ଓઌࢦఆ val c = new

    AerospikeClient("aerospike.service.consul", 3000) • Ka$a, Aerospike, Cassandra, ZooKeeper ͳͲ͸ੜ͖͍ͯΔϊʔ υʹ઀৮Ͱ͖Ε͹Ϋϥελϝϯόʔ͕ల։͞ΕΔͷͰɺConsul service Ͱ͋Ε͹ෳ਺ͷॳظϗετΛࢦఆ͢Δඞཁ͸ͳ͍
  7. HTTP Blocking Query • HTTP API Ͱఏڙ͞Ε͍ͯΔσʔλͷมߋΛ؂ࢹͰ͖Δ • DNS ΍

    HTTP ΛϙʔϦϯάͤͣʹޮ཰తʹϝϯόʔมߋ΁௥ਵͰ͖Δ • ͍ΘΏΔ COMET ௨৴ (Server Push) • Non-Blocking ͳ HTTP Client Ͱ࢖͏͜ͱ • finagle ͕ΫϥΠΞϯταΠυͷϩʔυόϥϯαʔΛ͍࣋ͬͯΔͨΊɺͦͷϝϯόʔΛ Consul ͷαʔϏεͱಉظ͢ΔίʔυΛॻ͍ͨ 1 1 h$ps:/ /github.com/CyberAgent/acd-axion/blob/c35087433a652e66f2ef8716c6acc244c8b815aa/client/src/main/ scala/axion/finagle/consul/ConsulResolver.scala
  8. αʔϏεͷొ࿥ • ઃఆϑΝΠϧͰ੩తʹొ࿥ • ϗετʹΠϯετʔϧ͞Ε͍ͯΔϛυϧ΢ΣΞͳͲ • HTTP API Ͱಈతʹొ࿥ •

    ಈతʹσϓϩΠ͢ΔΞϓϦέʔγϣϯͳͲ • Nomad ͸σϓϩΠͨ͠ΞϓϦΛαʔϏεొ࿥͢Δػೳ͕͋ Δ
  9. ྫ͑͹ Ka$a Λొ࿥͢Δ { "service": { "name": "kafka-broker", "port": 9200,

    "checks": [ { "id": "kakfa-broker", "tcp": "localhost:9200", "interval": "5s", "timeout": "1s" } ] } } • Ka$a ͕ಈ͍͍ͯΔϗετͰ Consul ͷઃఆϑΝΠϧʹهड़ • tcp/9200 ΛϔϧενΣοΫ
  10. Key-Value Storage $ curl -X PUT -d 'test' http://localhost:8500/v1/kv/web/key1 true

    $ curl http://localhost:8500/v1/kv/web/key1 [{"CreateIndex":97,"ModifyIndex":97,"Key":"web/key1","Flags":0,"Value":"dGVzdA=="}] • ֊૚Խ͞ΕͨΩʔͷ GET/PUT/DELETE (γϯϓϧ!) • Blocking Query Ͱ watch Ͱ͖Δ͠ɺ CAS ΋͋Δ • εέʔϥϏϦςΟ͸ແ͍ͷͰ஫ҙ • ϗετ΍ΞϓϦͷઃఆͳͲࢀরස౓ͷ௿͍σʔλͷΈ֨ೲ͢Δ • ଞ͸ઐ༻ͷ KVS (Aerospike, Cassandra ͳͲ)΁!