consul-atlas-alerts

28e154e6e0351c70091997d2f574295a?s=47 rrreeeyyy
August 05, 2015

 consul-atlas-alerts

#hashi_wantedly

28e154e6e0351c70091997d2f574295a?s=128

rrreeeyyy

August 05, 2015
Tweet

Transcript

  1. Consul'in'Atlas !Hashicorp!meetup!2015/08/05!5!Yoshikawa!Ryota!(!@rrreeeyyy!)! 1

  2.          !Hashicorp!meetup!2015/08/05!5!Yoshikawa!Ryota!(!@rrreeeyyy!)!

    2
  3. Hashicorp*ͱΘͨ͠(ͱձࣾ) • h#ps:/ /speakerdeck.com/rrreeeyyy/hashicorp3tools3overview • Vagrant;→;(΄΅ΈΜͳ࢖ͬͯΔ) • Packer;→;(࢖ͬͯͳ͍) • Serf;→;(࢖ͬͯͳ͍)

    • Consul;→;(࢖ͬͯΔҊ͕݅;1;ͭ͋Δ/ࣗ෼͕৮ͬͯΔ/ଞʹ΋৮ͬͯΔਓ͕͍Δ) • Terraform;→;(࢖͍͍ͨ/ݕূͯ͠Δਓ΋ࣗ෼Ҏ֎ʹډΔ) • Vault;→;(Θ͕ͨ͠৮ͬͯΔ) !Hashicorp!meetup!2015/08/05!5!Yoshikawa!Ryota!(!@rrreeeyyy!)! 3
  4. લճ·Ͱͷ͋Β͢͡!(1)!1 • consul(ͱ(consul)alerts(2(ͰΞϥʔτൃใ͢ΔγεςϜ 2"h$ps:/ /github.com/AcalephStorage/consul9alerts 1"h$p:/ /www.slideshare.net/rrreeeyyy117/consul8andalertsmonitoring !Hashicorp!meetup!2015/08/05!5!Yoshikawa!Ryota!(!@rrreeeyyy!)! 4

  5. લճ·Ͱͷ͋Β͢͡!1 • consul(ͷ(health-check(3(͕ࣦഊͨ͠Β(Pagerduty/Slack/Hipchat/ email...(ʹΞϥʔτൃใ • consul-alert(Λ࢖࣮ͬͯݱ • Nagios/Sensu(ͷεΫϦϓτΛྲྀ༻ͯ͠ઃఆՄೳ • HTTP(API(͔Β؂ࢹ/αʔϏεొ࿥͕ग़དྷͯศར

    3"h$p:/ /www.consul.io/docs/agent/checks.html 1"h$p:/ /www.slideshare.net/rrreeeyyy117/consul8andalertsmonitoring !Hashicorp!meetup!2015/08/05!5!Yoshikawa!Ryota!(!@rrreeeyyy!)! 5
  6. Atlas • ࠷ۙ(7$݄಄ࠒ)Ұൠ޲͚ϦϦʔε͞Εͨ$4 • Hashicorp$֤πʔϧͱͷ࿈ܞ͢ΔϓϥοτϑΥʔϜ • ΋ͪΖΜ$Consul$࿈ܞ΋͋Δ • લड़ͷΞϥʔτγεςϜ΋$Atlas$Λ࢖͑͹ग़དྷΔ •

    Consul$+$Atlas$͚ͩͰՄೳ 4"h$ps:/ /hashicorp.com/blog/atlas4general4availability.html !Hashicorp!meetup!2015/08/05!5!Yoshikawa!Ryota!(!@rrreeeyyy!)! 6
  7. Atlas&+&Consul • /etc/consul.conf { "server": true, "node_name": "NODE-NAME", "datacenter": "DC-NAME",

    "data_dir": "/usr/local/consul/data", "bind_addr": "192.168.2.1", "bootstrap_expect": 3, "addresses": { "http": "192.168.2.1" }, "log_level": "INFO", "atlas_token": "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", "atlas_join": true, "atlas_infrastructure": "topotal/groupname" } !Hashicorp!meetup!2015/08/05!5!Yoshikawa!Ryota!(!@rrreeeyyy!)! 7
  8. Atlas&+&Consul • consul.service : [Service] User=consul Group=consul ExecStart=/usr/local/bin/consul agent -config-file

    /etc/consul.conf ExecReload=/bin/kill -HUP $MAINPID KillMode=process Restart=on-failure RestartSec=10s : !Hashicorp!meetup!2015/08/05!5!Yoshikawa!Ryota!(!@rrreeeyyy!)! 8
  9. Atlas&+&Consul • ͜Μͳײ͡ʹͳΔ !Hashicorp!meetup!2015/08/05!5!Yoshikawa!Ryota!(!@rrreeeyyy!)! 9

  10. Service/Check+ొ࿥ํ๏ • ىಈ࣌ʹ"json"Λ౉ͯ͠ొ࿥ • HTTP"API"ܦ༝Ͱొ࿥ • (Terraform"ӽ͠ʹొ࿥) !Hashicorp!meetup!2015/08/05!5!Yoshikawa!Ryota!(!@rrreeeyyy!)! 10

  11. ىಈ࣌ʹ!json!Λ౉ͯ͠ొ࿥ • ࣍ͷΑ͏ͳ"json"Λىಈ࣌ʹ౉ͯ͋͛͠Δ • -config-file"΋͘͠͸"-config-dir { "service": { "id": "linux-server",

    "name": "linux-server", "tags": ["linux-server"] } } { "check": { "id": "check_load", "name": "Load Average", "script": "/usr/lib64/nagios/plugins/check_load -w 15,12,12 -c 30,25,20", "interval": "30s", "service_id": "linux-server" } } !Hashicorp!meetup!2015/08/05!5!Yoshikawa!Ryota!(!@rrreeeyyy!)! 11
  12. ىಈ࣌ʹ!json!Λ౉ͯ͠ొ࿥ • config-dir"͸σΟϨΫτϦΛ࠶ؼతʹಡ·ͳ͍ • -config-dir /etc/consul.d/"Λࢦఆͨ͠৔߹ • -config-dir /etc/consul.d/*.json"ΛΞϧϑΝϕοτॱͰಡΉ •

    /etc/consul.d/role/*.json"͸ಡ·ͳ͍ • ಉ͡σΟϨΫτϦʹ"Service/Check"༻ͷ"json"Λஔ͔ͳ͍ํ͕ྑ͍ • ઌʹ"Service"༻ͷ"json"͕ಡ·Εͳ͍ͱىಈ࣌ʹࢮ͵ !Hashicorp!meetup!2015/08/05!5!Yoshikawa!Ryota!(!@rrreeeyyy!)! 12
  13. HTTP$API$ӽ͠Ͱొ࿥ • ࣍ͷΑ͏ʹͯ͠౤͛Δ • json"ͷॻ͕ࣜىಈ࣌ʹ౉͢΋ͷͱ͸ҧ͏ͷͰ஫ҙ͢Δ [root@localhost ~]# cat load.json {

    "id": "check_load", "name": "Load Average", "script": "/usr/lib64/nagios/plugins/check_load -w 15,12,12 -c 30,25,20", "interval": "30s", "service_id": "linux-server" } [root@localhost ~]# curl -vvv -X PUT -d \ > @disk_root.json http://192.168.2.1:8500/v1/agent/check/register !Hashicorp!meetup!2015/08/05!5!Yoshikawa!Ryota!(!@rrreeeyyy!)! 13
  14. HTTP$API$ӽ͠Ͱొ࿥ • ಉ͡"id"Λ࣋ͬͨ"json"Λ"v1/agent/check/register"ʹ౤͛ΔͱҰॠΞ ϥʔτʹͳΔ • ᮢ஋ม͑ͨΓ͢Δͱ͖ʹ͸গ͠໘౗ष͍ • ࣍ͷ"HTTP"API"Λۦ࢖͢Δ͜ͱͰճආՄೳ • /v1/agent/service/maintenance/

    • /v1/agent/check/pass • /v1/agent/check/deregister/<checkId> !Hashicorp!meetup!2015/08/05!5!Yoshikawa!Ryota!(!@rrreeeyyy!)! 14
  15. Terraform(ӽ͠ʹొ࿥ • consul(integra/on(͋Δ͠ͳΜͱ͔ͳΒͳ͍Ͱ͔͢Ͷʁ • ৄ͍͠ํ͋ͱͰڭ͍͑ͯͩ͘͞... • ΋͘͠͸(PR(ΛૹΔ • 0.8(͙Β͍͔Β(5state(͕ཁΒͳ͘ͳΔͱ͍͏༧૝(5 5"h$p:/

    /www.infoq.com/news/2015/06/hashimoto9consul9terraform !Hashicorp!meetup!2015/08/05!5!Yoshikawa!Ryota!(!@rrreeeyyy!)! 15
  16. Ξϥʔτͷ༷ࢠ !Hashicorp!meetup!2015/08/05!5!Yoshikawa!Ryota!(!@rrreeeyyy!)! 16

  17. Status&output&ͷ༷ࢠ !Hashicorp!meetup!2015/08/05!5!Yoshikawa!Ryota!(!@rrreeeyyy!)! 17

  18. Alert&history&ͷ༷ࢠ !Hashicorp!meetup!2015/08/05!5!Yoshikawa!Ryota!(!@rrreeeyyy!)! 18

  19. ·ͱΊ • ࠓճ͸"Consul"+"Atlas"ͰΞϥʔτγεςϜΛ࡞ͬͨ • consul-alerts"ͷ͜ͱΛߟ͑ͳͯ͘ྑ͘ͳΔͷͰָ • Ϋϥελͷॳظߏஙָ͕ʹͳΔ • Atlas"͸"10"୆͙Β͍·Ͱ͸ແྉʂ •

    ݸਓن໛Ͱ"Nagios/Zabbix"ཱͯͨ͘ͳ͍ͬͯਓʹ͸Φεεϝ • ֎ܗ؂ࢹΈ͍ͨͳͷ͸ผ్ߟ͑Δඞཁ͕͋Γͦ͏ • Pingdom"ͱ͔ʁ • ຊ౰͸"Mackerel"΍"Datadog"ͱ૊Έ߹Θ͍ͤͨͳʙ !Hashicorp!meetup!2015/08/05!5!Yoshikawa!Ryota!(!@rrreeeyyy!)! 19