Top Banner
1 Using Chef for Infrastructure Using Chef for Infrastructure Automation of Ameba Pigg Automation of Ameba Pigg Yuuki NAMIKAWA Cyberagent Inc. [DevOps Days Tokyo 2012]
37

Using Chef for Infrastructure Automation of Ameba Pigg

May 24, 2015

Download

Technology

Yuuki Namikawa

DevOps Days Tokyo 2012
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Using Chef for Infrastructure Automation of Ameba Pigg

1

Using Chef for Infrastructure Using Chef for Infrastructure Automation of Ameba PiggAutomation of Ameba Pigg

Yuuki NAMIKAWACyberagent Inc.

[DevOps Days Tokyo 2012]

Page 2: Using Chef for Infrastructure Automation of Ameba Pigg

2

自己紹介自己紹介� 並河 祐貴 (a.k.a. id:rx7)

� (株)サイバーエージェント所属� 主にインフラエンジニア� Blog: http://d.hatena.ne.jp/rx7/� Twitter: @namikawa

� 著書・寄稿多数

Page 3: Using Chef for Infrastructure Automation of Ameba Pigg

3

最初に謝罪 m(_”_)m

Page 4: Using Chef for Infrastructure Automation of Ameba Pigg

4

今日の話は・・・今日の話は・・・� DevOpsの細かい話はしません

�ごめんなさい

� 弊社でのサービス運用について

� Chefを 用したプログラマブルなシステム基盤

んまぁ、つまりChefの話をしに来ました!

Page 5: Using Chef for Infrastructure Automation of Ameba Pigg

5

アメーバピグアメーバピグ (Ameba(Ameba Pigg)Pigg)

Page 6: Using Chef for Infrastructure Automation of Ameba Pigg

6

アメーバピグアメーバピグ (Ameba(Ameba Pigg)Pigg)� アバター仮想空間サービス

�きせかえ、おでかけ�ゲーム(カジノ、つり、ライフ(庭)、アイランド)

� ユーザ数� 1190万人 (2012/03, Amebaユーザの約半数)

� トラフィック (アバター/ゲーム)�約6 7Gbps / ピーク帯

� 同時接続ユーザ数 (アバター/ゲーム)�約40万ユーザ / ピーク帯

Page 7: Using Chef for Infrastructure Automation of Ameba Pigg

7

ピグでのシステム運用スタイルピグでのシステム運用スタイル� 職種は一応存在する

� アプリエンジニア(Dev?)� インフラエンジニア(Ops?)...

� チーム・体制� 各施策ごとに機能開発を担当するチーム� 非機能部分(勯能・勣定・ 化)を担当するチーム

� 基本的にシステム運用は全員プレイ� モニタリングも� 障害対応も� リリースやサーバ設定も

当番はありますが、基本的にエンジニア全員で担当します

Page 8: Using Chef for Infrastructure Automation of Ameba Pigg

8

皆がWinになれるか

Page 9: Using Chef for Infrastructure Automation of Ameba Pigg

9

アウトプットを高めるためのアプローチアウトプットを高めるためのアプローチ� 作業の 化・自動化� 施策・タスクの選択と集中� 情報共有・コミュニケーション・マインド� ...etc

Page 10: Using Chef for Infrastructure Automation of Ameba Pigg

10

システム運用する上でのツールシステム運用する上でのツール� 運用 の でツールによる作業 化

�アプリケーションのデプロイ�サーバを増設する�設定 を する� ...etc

� アプリ/インフラ 方の が必要�セットアップ、パフォーマンスチューニング、トラブ

ルシューティング...

Page 11: Using Chef for Infrastructure Automation of Ameba Pigg

11

少し昔の話

Page 12: Using Chef for Infrastructure Automation of Ameba Pigg

12

僕が今の会社に入って一番最初にやった仕事

Page 13: Using Chef for Infrastructure Automation of Ameba Pigg

13

ピグのピグのWeb/APWeb/APサーバをサーバを33台増設台増設� その時に渡された手順書(1台分)

Page 14: Using Chef for Infrastructure Automation of Ameba Pigg

14

Page 15: Using Chef for Infrastructure Automation of Ameba Pigg

15

アメーバピグ・ピグライフの規模感アメーバピグ・ピグライフの規模感� アメーバピグ

�サーバ台数: 約220台 (⇒ 150台まで削減予定)– Web/APサーバ40台– Socketサーバ75台– DB(MySQL+FIO)サーバ6台 x 2(スタンバイ)– API, Hadoop Cluster, Mobile, Smart Phone...– etc...

� ピグライフ�サーバ台数: 約250台

– Socket(node.js)サーバ70台、– DB(MongoDB)サーバ150台– Statサーバ20台– etc...

Page 16: Using Chef for Infrastructure Automation of Ameba Pigg

16

ピグのサーバ増設・運用拻ピグのサーバ増設・運用拻� サービス・システム規模、共に右肩上がり

� 急な増設を求められることもあります�ビッグイベントにあわせて30台入れちゃうとか�想定を えるスピードでサービスが成 するとか

� そこで「Chef」を使ってみました

Page 17: Using Chef for Infrastructure Automation of Ameba Pigg

17

それ、クラウド使ったらでk(ry

クラウドも、運用を 化する1要素

ミドルウェアの設定拻 や、プロセスの状態拻 も含めて今回は「Chef」で自動化する話をします

Page 18: Using Chef for Infrastructure Automation of Ameba Pigg

18http://www.flickr.com/photos/jonathanbeard/3307862620/

Chefの概要

Page 19: Using Chef for Infrastructure Automation of Ameba Pigg

19http://www.flickr.com/photos/jonathanbeard/3307862620/

「「ChefChef」とは」とは� サーバの構築作業やシステム拻 のツール

�システムのあるべき状態を設定する� オープンソース、Ruby製

� 用実� 37signals� Engine Yard�Rackspace hosting� etc…

Page 20: Using Chef for Infrastructure Automation of Ameba Pigg

20http://www.flickr.com/photos/jonathanbeard/3307862620/

サーバ構築・システム拻 自動化の必要勯サーバ構築・システム拻 自動化の必要勯� 手作業では、そもそも時間がかかる

�数十台、数百台のレベルになると・・・�同 のサーバごとに環境 が発生したりとか

サーバ 入までのリードタイムが くなることで機会損失を発生させることは避けたい

運用中のサーバでのミスは特に無くしたい設定に間違いがあっても自動化しておく事で即修正可能

� 人為的なミスを抑えたい�作業 れ、ルーチン作業でのオ ミス�作業者によって、スキルにバラつき

Page 21: Using Chef for Infrastructure Automation of Ameba Pigg

21http://www.flickr.com/photos/photomequickbooth/4062072718/

それ、シェルスクリプトでよくね?それ、シェルスクリプトでよくね?� サーバの状態が記述できるフレームワーク

�基本的なタスクが備わっている�拻 タスクの 拾をできるだけ える

� Chefでは内部DSLを採用�Rubyでの柔軟な記述ができる

� プラットフォームの が できる�ディストリビューションによってコマンドに� yumとaptとか

Page 22: Using Chef for Infrastructure Automation of Ameba Pigg

22http://www.flickr.com/photos/jonathanbeard/3307862620/

ChefChefのシステムアーキテクチャのシステムアーキテクチャ� Ruby� Merb(Rack)� CouchDB� Solr� RabbitMQ� (Java)� (Erlang)� HTTP(REST)� JSON

Chef-Server

API

Chef-Server

WebUI

RabbitMQ

CouchDB Solr

Chef-Solr

Indexer

Chef-ClientChef-ClientChef-Client Knife

Client

Page 23: Using Chef for Infrastructure Automation of Ameba Pigg

23http://www.flickr.com/photos/jonathanbeard/3307862620/

ChefChefでのでの””主な主な””登場人物登場人物� Node� Role� Cookbook

�Recipe�Template�Attribute

時間の都合上、基本を簡単にご紹介します

Page 24: Using Chef for Infrastructure Automation of Ameba Pigg

24http://www.flickr.com/photos/jonathanbeard/3307862620/

NodeNode, , RoleRole, , CookbookCookbook のの関連関連(( ))

サーバA

サーバB

サーバC

nginxのCookbook

PassengerのCookbook

RubyのCookbook

gitのCookbook

APサーバのRole

Node Role Cookbook拻 対拺の

サーバ拻 対拺の

グルーピングシステムのあるべき形を

定義する設定

Page 25: Using Chef for Infrastructure Automation of Ameba Pigg

25http://www.flickr.com/photos/jonathanbeard/3307862620/

ChefChefのリポジトリ構造のリポジトリ構造 (Cookbook)(Cookbook)cookbooks/

|-- attributes|-- definitions|-- files|-- libraries|-- providers|-- recipes|-- resources`-- templates

設定したいパラメータ(各サーバ固有のものやデフォルト値など)

を記述したもの

システムのあるべき姿、つまり設定内容を実際に記載したRubyスクリプト

サーバへ配置する設定ファイルのテンプレートで、eRubyで記述する

Page 26: Using Chef for Infrastructure Automation of Ameba Pigg

26http://www.flickr.com/photos/jonathanbeard/3307862620/

RecipeRecipe、、TemplateTemplateの一の一

package "apache2" doaction :install

end

template "/etc/apache2/ports.conf" dosource "ports.conf.erb"owner "root"group "root"mode 0644variables(:port => node[:port]

)end

service "apache2" doaction [ :enable, :start ]

end

Listen <%= port %>NameVirtualHost *:<%=port %>

default[:port] = “8080"

./recipe/default.rb ./templates/default/ports.conf.erb

./attributes/default.rb

node A Chef-Server

“node A”の情報を保持[Node Attribute],

[Run List] 等

chef-client

“port”:”80”

recipeの設定

Page 27: Using Chef for Infrastructure Automation of Ameba Pigg

27http://www.flickr.com/photos/jonathanbeard/3307862620/

ChefChefで 用できるで 用できるResourceResource� Cookbook File� Cron� Deploy� Directory� Erlang Call� Execute� File� Git� Group� HTTP Request� Ifconfig� Link� Log� Mdadm

� Mount� Ohai� Package� PowerShell Script� Remote Directory� Remote File� Route� Ruby Block� SCM� Script� Service� Subversion� Template� User

Page 28: Using Chef for Infrastructure Automation of Ameba Pigg

28http://www.flickr.com/photos/photomequickbooth/4062072718/

ChefChefのちょっとイケていないところのちょっとイケていないところ� サーバのセットアップが面倒くさい

�必要なのは最初だけなので、許容できる�クライアントは簡単

� 名前がSEO的に致命的�Chef, Cookbook, Recipe, knife...�リアルに調べ物をする時に困ります

� dry-runができない�テスト環境が必須 (クラウド・仮想化が最適)

Page 29: Using Chef for Infrastructure Automation of Ameba Pigg

29http://www.flickr.com/photos/jonathanbeard/3307862620/

Chefの運用

Page 30: Using Chef for Infrastructure Automation of Ameba Pigg

30http://www.flickr.com/photos/jonathanbeard/3307862620/

ChefChefを活用したサーバ増設を活用したサーバ増設� PXE + kickstart + Chef

1. 事前に chef-server 側でNodeの設定が必要2. サーバに線を繋ぎ電源ON、PXEブート開始3. Label No.とNode名を入 し、OSインストール開始4. 同時に chef-client のインストールと設定5. kickstart の %post で chef-client を実

kickstartのcfgファイル

通常のOSインストールタスク

chef-clientのインストール

chef-clientのchef-clientの設定

client

Chef-Server

通信PXE+ksサーバ

通信OSインストール後は直接通信

Page 31: Using Chef for Infrastructure Automation of Ameba Pigg

31http://www.flickr.com/photos/jonathanbeard/3307862620/

ChefChefを活用したサーバ増設を活用したサーバ増設� 今はオンプレミスな物 環境を想定

� クラウド環境でも応用可能� EC2だと、事前にAMIを作成しておいて、user-dataに

Node名を指定して...� (弊社のOpenStackクラウド基盤を活用したい)

Page 32: Using Chef for Infrastructure Automation of Ameba Pigg

32http://www.flickr.com/photos/jonathanbeard/3307862620/

CookbookCookbookの使い方の使い方� Cookbookの

�ネットワーク設定�H/Wに必要な設定

– 主にH/W固有で必要なドライバやRAIDチェックスクリプト等�各サーバ共通で必要な設定

– DNS, NTP, LDAP, 監視ライブラリ, 鍵交換等�各Roleで必要な設定

{"run_list": ["recipe[ameba-common::pigglife]","recipe[pigglife-mongodb::mongod]"

]}

{"run_list": ["recipe[network::xxxxx]","recipe[hw::dell_r310]",“role[pigglife-mongodb]"

]}

NodeへのCookbook設定 RoleへのCookbook設定

Page 33: Using Chef for Infrastructure Automation of Ameba Pigg

33http://www.flickr.com/photos/jonathanbeard/3307862620/

CookbookCookbookでのコミュニケーションでのコミュニケーション� セットアップ手順のチェックをRecipe

(Cookbook)という名のコードベースで

� バージョン拻 しているので、 との 分も認しやすい

� 誰でもRead/Writeできる場所にあるので、みんなでメンテナンスできる

Page 34: Using Chef for Infrastructure Automation of Ameba Pigg

34http://www.flickr.com/photos/jonathanbeard/3307862620/

ChefChefを使う上でやっていることを使う上でやっていること� Script Resource は基本的に使わない

� でも実 される� chef-client実 時のチェック・運用が面倒� 実 しても勬 ないものしか使わない

script “script_name" dointerpreter "bash"user “username"creates comp_dir + “script_name.done"code <<-EOHcommand............

EOHend

過去、こんな感じで書いていました...

Page 35: Using Chef for Infrastructure Automation of Ameba Pigg

35http://www.flickr.com/photos/jonathanbeard/3307862620/

ChefChefを使う上でやっていることを使う上でやっていること� 各nodeのChef適用は、chef-clientを実

� tomahawk: 数のサーバで同 コマンドを実� “knife ssh”, “knife ssh_cheto” を使いたい

� NodeのAttributeの登録� JSONファイルを自動生成して登録・バージョン拻

� アンインストール・削 等の も れずに

� Environment(0.10 )の活用� development, staging, productionの分別

Page 36: Using Chef for Infrastructure Automation of Ameba Pigg

36http://www.flickr.com/photos/jonathanbeard/3307862620/

これからこれからChefChefを勉強する方へを勉強する方へ� chef-solo が

� chef-server を必要とせず、ローカルにCookbookを適用できる

�VMでテストとか練習とか

� Chefのインタラクティブシェル� “shef”

� Opscode Platform (Hosted Chef)�Chefのホスティング環境 (サーバ)� 5 nodes までなら、無 で試せる

Page 37: Using Chef for Infrastructure Automation of Ameba Pigg

37http://www.flickr.com/photos/jonathanbeard/3307862620/

まとめと今後の展望まとめと今後の展望� Chefを活用することで多くのサーバの増設・拻

にかかる負担を軽減�あるべき状態に自動で設定・維持できる�ルールを少し覚えれば、誰でも簡単に設定が書ける�内部DSLなので、Rubyを覚えれば も柔軟に書ける

� クラウド等の基盤サービスと連携して、インフラ構築/運用の完全オートメーションができる仕組みにしたい