Slide 1

Slide 1 text

Mesos Mesosを使った を使ったImmutable Infra Immutable Infra 管理システムを作ってみた 管理システムを作ってみた Tatsuru WATANABE 2014/03/25 Immutable Infrastracture Conference

Slide 2

Slide 2 text

自己紹介 ● Tatsuru WATANABE ● id:wtatsuru @tatsuru ● サーバ運用@はてな ● 最近 AWS 6割くらい

Slide 3

Slide 3 text

Outline ● Immutable Infrastracture ● 作ってみた ● 中身のこと – Cluster Management – Log Aggregation – Metrics/Monitoring

Slide 4

Slide 4 text

Immutable Infrastracture

Slide 5

Slide 5 text

実際、今どこまでできるんだろう

Slide 6

Slide 6 text

● Git push ● Docker Build ● Test ● Deploy-ready ● Deploy 作ってみた

Slide 7

Slide 7 text

詳しくはブログで サービス開発合宿を開催しました http://developer.hatenastaff.com/entry/2013/12/24/182329

Slide 8

Slide 8 text

中身 ● Docker ● Mesos ● Jenkins ● Fluentd ● Graphite ● Sensu ● Dashboard

Slide 9

Slide 9 text

中身 ● Docker ● Mesos ● Jenkins ● Fluentd ● Graphite ● Sensu ● Dashboard VM VM Cluster Cluster Test Test Log Log Visualize Visualize Monitoring Monitoring Orchestration Orchestration

Slide 10

Slide 10 text

中身 ● Docker ● Mesos ● Jenkins ● Fluentd ● Graphite ● Sensu ● Dashboard VM VM Cluster Cluster Test Test Log Log Visualize Visualize Monitoring Monitoring Orchestration Orchestration

Slide 11

Slide 11 text

詳細略 ● 仮想化 – Docker – AWS – KVM ● Test & Deploy – Jenkins – 差分ビルド – serverspec

Slide 12

Slide 12 text

Cluster Management Server app1 tcp/8000

Slide 13

Slide 13 text

Cluster Management Server app1 tcp/8000 Server app2 tcp/8001 app2 tcp/8001

Slide 14

Slide 14 text

Server Cluster Management Server Server Server Server Server Server Server Server

Slide 15

Slide 15 text

Cluster Management ● 自前 – 1 Active VM/Host – Serf ● 全部入り – OpenStack – Coud Foundry ● リソース管理システム – Apache Mesos – Omega (Google)

Slide 16

Slide 16 text

Cluster Management ● Apache Mesos – Master/Slave – Framework – Executor ● リソースの提供だけ Hindman, Benjamin, et al. "Mesos: A platform for fine-grained resource sharing in the data center." Proceedings of the 8th USENIX conference on Networked systems design and implementation. 2011. http://mesos.apache.org/documentation/latest/mesos-architecture/

Slide 17

Slide 17 text

Cluster Management ● Apache Mesos – Master/Slave – Framework: Marathon – Executor: Mesos-Docker Marathon POST /v1/apps/start { “executor”: “/opt/mesos-docker”, “instances”: 2, “cpus”: 1, “mem”: 128,... } Server1: 4CPU 4GB Server2: 2CPU 8GB Server3: 8CPU 7GB Task1: Server1 1CPU 128MB Server2 1CPU 128MB 1 2 3

Slide 18

Slide 18 text

Cluster Management ● 最近の Mesos/Marathon – API v2: Docker 対応 – Deimos: Docker の仕組みを組み込む ● 実際どうなの – 仕組みは悪くはない。中身見える

Slide 19

Slide 19 text

Log Aggregation ● Log Aggregation – Fluentd – rsyslog, Flume, Kafka, ● コンテナ内で Fluentd – Supervisor 経由 docker-+-lxc-start---supervisord-+-fluentd | |-ruby (sensu_server) |-run---/opt/App/start_server `-sshd Server Container Application Fluentd sshd Sensu

Slide 20

Slide 20 text

Log Aggregation Docker Log Management Using Fluentd http://jasonwilder.com/blog/2014/03/17/docker-log-management-using-fluentd/

Slide 21

Slide 21 text

Log Aggregation ● Collection Inside Container ● Collection Outside Container ● Collection In Separate Container Server Container Fluentd Container Fluentd Server Container Container Log Volume Fluentd App App App App Server Container Container App App Container Log Volume Fluentd Inside Outside In Separate

Slide 22

Slide 22 text

Metrics ● サーバメトリクス – サーバが頻繁に入れ替わる:サーバ単位ではダメ ● サービスメトリクス ● いい感じに集めたい – アプリケーションごと – デプロイごと

Slide 23

Slide 23 text

Metrics ● サーバメトリクス – ホストから: cgroup, netstat – 他はヘルプにあります http://docs.docker.io/en/latest/articles/runmetrics/ ● いい感じに集めたい – Sensu/Fluentd で送る – Graphite: glob + 名前空間 $ cat /sys/fs/cgroup/lxc/718e*/cpuacct.stat user 28707710 system 6369370 docker.$host.$app-$rev.$seq.memory -> docker.*.$app-*.memory -> docker.*.$app-$rev.*.memory

Slide 24

Slide 24 text

Metrics ● ログベース解析 – Latency, Error Ratio ● 従来通り – フローで解析: Fluentd (fluent-plugin-datacounter etc.) – バッチ解析: MongoDBに貯める – Kibana, 外部サービスに流す, etc.

Slide 25

Slide 25 text

Metrics ● サーバメトリクス:ホスト単位だと運用が難しい – Munin, Zabbix ● Agent型もあり – 台数課金なサービスはつらい: NewRelic ● Aggregation が課題

Slide 26

Slide 26 text

Monitoring ● 監視 ● エージェント型 – Sensu – Zabbix – NewRelic ● 外部監視:いけそう – Nagios: Docker API から公開されているポートを取得して監視 https://github.com/tatsuru/nagios-plugin/blob/master/check_docker_container_exported_port.pl

Slide 27

Slide 27 text

Visualization/Monitoring ● エージェント型 ● ログと同じパターンで運用できそう Server Container Sensu Container Sensu Server Container Container App App App App Server Container Container App App Container Sensu Sensu

Slide 28

Slide 28 text

Helper Containers? ● Ambassador Container よりもう少し高機能 – http://docs.docker.io/en/latest/use/ambassador_pattern_linking/ ● 監視、ログ収集 etc. Server Container Application Container Application Container Application Container Sensu Container Fluentd

Slide 29

Slide 29 text

Orchestration ● ダッシュボード ● マスターデータ – サービスとリポジトリの対応 – リソース状況 – デプロイ状態

Slide 30

Slide 30 text

Orchestration ● アプリのリポジトリ ● クラスタにもたせる – Serf ● 中央で管理する何か – AWS Elatic Beanstalk – NewRelicでがんばる – 自作

Slide 31

Slide 31 text

まとめ ● Immutable 環境作ってみた ● 課題いろいろ – Cluster Management – Log Aggregation – Metrics/monitoring ● どんどん作っていきましょう – 教えてください

Slide 32

Slide 32 text

以上です はてなでは、こういうのを一緒に作ってくれる人を募集してます