51
ブログ製本サービス MyBooks.jpのアーキテクチャ Part.3 AWS Elastic Beanstalkについて 欧文印刷株式会社・ソフトウェアエンジニア・田名辺健人 2014/04/11 第13回勉強会

ブログ製本サービス MyBooks.jpのアーキテクチャ Part.3 AWS Elastic Beanstalkについて

Embed Size (px)

DESCRIPTION

第13回JAWS-UG札幌勉強会で発表した資料です。Immutable InfrastructureとElastic Beanstalkのお話です。

Citation preview

Page 1: ブログ製本サービス MyBooks.jpのアーキテクチャ Part.3 AWS Elastic Beanstalkについて

ブログ製本サービス MyBooks.jpのアーキテクチャ Part.3

AWS Elastic Beanstalkについて 欧文印刷株式会社・ソフトウェアエンジニア・田名辺健人

2014/04/11 第13回勉強会

Page 2: ブログ製本サービス MyBooks.jpのアーキテクチャ Part.3 AWS Elastic Beanstalkについて

Who am I ?!(この顔にピンときたら)

Page 3: ブログ製本サービス MyBooks.jpのアーキテクチャ Part.3 AWS Elastic Beanstalkについて

田名辺 健人(たなべたけひと) ソフトウェアエンジニア !

!

欧文印刷株式会社(東京都) 2011年11月クラウド移住 札幌でリモート勤務中 初代AWSサムライ 好きなサービス: SWF

@dateofrock

http://blog.dateofrock.com/

Page 4: ブログ製本サービス MyBooks.jpのアーキテクチャ Part.3 AWS Elastic Beanstalkについて
Page 5: ブログ製本サービス MyBooks.jpのアーキテクチャ Part.3 AWS Elastic Beanstalkについて
Page 6: ブログ製本サービス MyBooks.jpのアーキテクチャ Part.3 AWS Elastic Beanstalkについて
Page 7: ブログ製本サービス MyBooks.jpのアーキテクチャ Part.3 AWS Elastic Beanstalkについて
Page 8: ブログ製本サービス MyBooks.jpのアーキテクチャ Part.3 AWS Elastic Beanstalkについて

www.mybooks.jp

EC2Instance

WordPress(AMI元)

Elastic IP Address

ELB

EC2InstanceEBS

EBS snapshot

S3

Simple Workflow Service

Tomcat Session Store

Book Data

Tomcat7 (Grails/back-end)

EC2 InstancesELB

Decider

Worker

EC2 Instances(Auto Scaling)

Tomcat7 (Grails/front-end)

CloudWatch

Simple Email Service

S3 (App Resources)

editor.mybooks.jpA. 静的サイト B. 動的サイト

Route53

Page 9: ブログ製本サービス MyBooks.jpのアーキテクチャ Part.3 AWS Elastic Beanstalkについて

www.mybooks.jp

EC2Instance

WordPress(AMI元)

Elastic IP Address

ELB

EC2InstanceEBS

EBS snapshot

S3

Simple Workflow Service

Tomcat Session Store

Book Data

Tomcat7 (Grails/back-end)

EC2 InstancesELB

Decider

Worker

EC2 Instances(Auto Scaling)

Tomcat7 (Grails/front-end)

CloudWatch

Simple Email Service

S3 (App Resources)

editor.mybooks.jpA. 静的サイト B. 動的サイト

Route53

www.mybooks.jp

EC2Instance

WordPress(AMI元)

Elastic IP Address

ELB

EC2InstanceEBS

EBS snapshot

S3

Simple Workflow Service

Tomcat Session Store

Book Data

Tomcat7 (Grails/back-end)

EC2 InstancesELB

Decider

Worker

EC2 Instances(Auto Scaling)

Tomcat7 (Grails/front-end)

CloudWatch

Simple Email Service

S3 (App Resources)

editor.mybooks.jpA. 静的サイト B. 動的サイト

Route53

www.mybooks.jp

EC2Instance

WordPress(AMI元)

Elastic IP Address

ELB

EC2InstanceEBS

EBS snapshot

S3

Simple Workflow Service

Tomcat Session Store

Book Data

Tomcat7 (Grails/back-end)

EC2 InstancesELB

Decider

Worker

EC2 Instances(Auto Scaling)

Tomcat7 (Grails/front-end)

CloudWatch

Simple Email Service

S3 (App Resources)

editor.mybooks.jpA. 静的サイト B. 動的サイト

Route53

Page 10: ブログ製本サービス MyBooks.jpのアーキテクチャ Part.3 AWS Elastic Beanstalkについて

AWS Elastic Beanstalk

Page 11: ブログ製本サービス MyBooks.jpのアーキテクチャ Part.3 AWS Elastic Beanstalkについて

Immutable Infrastructure

今一番ナウい!

そして日本人には発音がつらいww

Page 12: ブログ製本サービス MyBooks.jpのアーキテクチャ Part.3 AWS Elastic Beanstalkについて

Blue Green Deployment

Page 13: ブログ製本サービス MyBooks.jpのアーキテクチャ Part.3 AWS Elastic Beanstalkについて

http://martinfowler.com/bliki/BlueGreenDeployment.html

Page 14: ブログ製本サービス MyBooks.jpのアーキテクチャ Part.3 AWS Elastic Beanstalkについて

それ Elastic Beanstalk そのものですから

Page 15: ブログ製本サービス MyBooks.jpのアーキテクチャ Part.3 AWS Elastic Beanstalkについて

AWS Elastic Beanstalk

Page 16: ブログ製本サービス MyBooks.jpのアーキテクチャ Part.3 AWS Elastic Beanstalkについて

Elastic Beanstalk で

Blue Green Deployment してみる

Page 17: ブログ製本サービス MyBooks.jpのアーキテクチャ Part.3 AWS Elastic Beanstalkについて
Page 18: ブログ製本サービス MyBooks.jpのアーキテクチャ Part.3 AWS Elastic Beanstalkについて
Page 19: ブログ製本サービス MyBooks.jpのアーキテクチャ Part.3 AWS Elastic Beanstalkについて

DNS

Storage

DB

LB LB

Servers Servers

Server Image Server Image

Blue Green

Live Pendingversion1

Page 20: ブログ製本サービス MyBooks.jpのアーキテクチャ Part.3 AWS Elastic Beanstalkについて

DNS

Storage

DB

LB LB

Servers Servers

Server Image Server Image

Blue Green

Live Pendingversion1 version2

Page 21: ブログ製本サービス MyBooks.jpのアーキテクチャ Part.3 AWS Elastic Beanstalkについて
Page 22: ブログ製本サービス MyBooks.jpのアーキテクチャ Part.3 AWS Elastic Beanstalkについて
Page 23: ブログ製本サービス MyBooks.jpのアーキテクチャ Part.3 AWS Elastic Beanstalkについて
Page 24: ブログ製本サービス MyBooks.jpのアーキテクチャ Part.3 AWS Elastic Beanstalkについて
Page 25: ブログ製本サービス MyBooks.jpのアーキテクチャ Part.3 AWS Elastic Beanstalkについて
Page 26: ブログ製本サービス MyBooks.jpのアーキテクチャ Part.3 AWS Elastic Beanstalkについて

DNS

Storage

DB

LB LB

Servers Servers

Server Image Server Image

Blue Green

Live Pendingversion1 version2

Page 27: ブログ製本サービス MyBooks.jpのアーキテクチャ Part.3 AWS Elastic Beanstalkについて

DNS

Storage

DB

LB LB

Servers Servers

Server Image Server Image

Blue Green

Pending Liveversion1 version2

Page 28: ブログ製本サービス MyBooks.jpのアーキテクチャ Part.3 AWS Elastic Beanstalkについて

1.サーバーを直接触らない ✓上書きデプロイしてリスタートとか事故の元w ✓(基本的に)サーバーにログインしての作業はやらない。

Immutable InfrastructureとしてのElastic Beanstalk

Page 29: ブログ製本サービス MyBooks.jpのアーキテクチャ Part.3 AWS Elastic Beanstalkについて

そもそもkey pair指定が必須ではない

(注)私は臆病者なので指定してますw

Page 30: ブログ製本サービス MyBooks.jpのアーキテクチャ Part.3 AWS Elastic Beanstalkについて

EC2のセットアップ1.あらかじめセットアップ済みAMIを作る 2.cloud-initやChefなどで頑張るw 3.configを利用する • Elastic Beanstalk的には王道

Page 31: ブログ製本サービス MyBooks.jpのアーキテクチャ Part.3 AWS Elastic Beanstalkについて

EC2のセットアップ1.あらかじめセットアップ済みAMIを作る 2.cloud-initやChefなどで頑張るw 3.configを利用する • Elastic Beanstalk的には王道

Page 32: ブログ製本サービス MyBooks.jpのアーキテクチャ Part.3 AWS Elastic Beanstalkについて

YAML

Page 33: ブログ製本サービス MyBooks.jpのアーキテクチャ Part.3 AWS Elastic Beanstalkについて

YAML

$APP_ROOT/.ebextensions/*.config

✓パッケージインストール ✓アーカイブダウンロード + 展開 ✓ファイル生成 or コピー ✓OSユーザー・グループ作成 ✓コマンド実行(OS用) ✓コマンド実行(コンテナ用) ✓サービス設定(/etc/init.d) ✓Beanstalk固有の設定

Page 34: ブログ製本サービス MyBooks.jpのアーキテクチャ Part.3 AWS Elastic Beanstalkについて

packages: yum: libmemcached: [] ruby-devel: [] nfs-utils: [1.0.9]

rpm, yum, apt, rubygems (chef)

Page 35: ブログ製本サービス MyBooks.jpのアーキテクチャ Part.3 AWS Elastic Beanstalkについて

sources: /usr/local/bin:↵ http://hoge.com/hoge.tar.gz

tar, tar+gzip, tar+bz2, zip

Page 36: ブログ製本サービス MyBooks.jpのアーキテクチャ Part.3 AWS Elastic Beanstalkについて

files: "/home/ec2-user": mode: "000777" owner: ec2-user group: ec2-user source: http://hoge.com/a.txt

Page 37: ブログ製本サービス MyBooks.jpのアーキテクチャ Part.3 AWS Elastic Beanstalkについて

files: "/home/ec2-user": mode: "000777" owner: ec2-user group: ec2-user content: | # this is my file # with content

content直書きOK

Page 38: ブログ製本サービス MyBooks.jpのアーキテクチャ Part.3 AWS Elastic Beanstalkについて

users: myuser: groups: group1 group2 uid: "50" homeDir: “/tmp” groups: - groupOne - groupTwo gid: "45"

Page 39: ブログ製本サービス MyBooks.jpのアーキテクチャ Part.3 AWS Elastic Beanstalkについて

commands: test: command: myscript.py cwd: /home/ec2-user env: myvarname: myvarvalue

Page 40: ブログ製本サービス MyBooks.jpのアーキテクチャ Part.3 AWS Elastic Beanstalkについて

container_commands: replace-server_xml: command: ↵ cp .ebextensions/server.xml ↵ /etc/tomcat7/server.xml

server.xmlの置換

Page 41: ブログ製本サービス MyBooks.jpのアーキテクチャ Part.3 AWS Elastic Beanstalkについて

container_commands: 01syncdb: command: "django-admin.py syncdb --noinput" leader_only: true 02migrate: command: "django-admin.py migrate" leader_only: true

マイグレーションの実行

Page 42: ブログ製本サービス MyBooks.jpのアーキテクチャ Part.3 AWS Elastic Beanstalkについて

services: sysvinit: myservice: enabled: true ensureRunning: true

Page 43: ブログ製本サービス MyBooks.jpのアーキテクチャ Part.3 AWS Elastic Beanstalkについて

option_settings: - namespace: ↵ aws:elasticbeanstalk:container:tomcat:jvmoptions option_name: Xmx value: 512m - option_name: AWS_SECRET_KEY value: SECRET_KEY - option_name: AWS_ACCESS_KEY_ID value: ACCESS_KEY

Page 44: ブログ製本サービス MyBooks.jpのアーキテクチャ Part.3 AWS Elastic Beanstalkについて

2.App側も気を使う必要あり ✓Immutableである→ステートレス ✓ステートレスなアーキテクチャ ✓メンテが楽!! ✓スケーラブル!!

Immutable InfrastructureとしてのElastic Beanstalk

Page 45: ブログ製本サービス MyBooks.jpのアーキテクチャ Part.3 AWS Elastic Beanstalkについて

DNS

Storage

DB

LB

Servers

Server Image

Blue

Live

Page 46: ブログ製本サービス MyBooks.jpのアーキテクチャ Part.3 AWS Elastic Beanstalkについて

DNS

Storage

DB

LB

Servers

Server Image

Blue

Live

データ(状態)はサーバーの外へ!

Page 47: ブログ製本サービス MyBooks.jpのアーキテクチャ Part.3 AWS Elastic Beanstalkについて

DNS

Storage

DB

LB

Servers

Server Image

Blue

Live

サーバーはいつでも捨てられる!

Page 48: ブログ製本サービス MyBooks.jpのアーキテクチャ Part.3 AWS Elastic Beanstalkについて

Immutable Infrastructure

今一番ナウい!

そして日本人には発音がつらいww

Page 49: ブログ製本サービス MyBooks.jpのアーキテクチャ Part.3 AWS Elastic Beanstalkについて

AWS Elastic Beanstalk

Page 50: ブログ製本サービス MyBooks.jpのアーキテクチャ Part.3 AWS Elastic Beanstalkについて

www.mybooks.jp

EC2Instance

WordPress(AMI元)

Elastic IP Address

ELB

EC2InstanceEBS

EBS snapshot

S3

Simple Workflow Service

Tomcat Session Store

Book Data

Tomcat7 (Grails/back-end)

EC2 InstancesELB

Decider

Worker

EC2 Instances(Auto Scaling)

Tomcat7 (Grails/front-end)

CloudWatch

Simple Email Service

S3 (App Resources)

editor.mybooks.jpA. 静的サイト B. 動的サイト

Route53

Page 51: ブログ製本サービス MyBooks.jpのアーキテクチャ Part.3 AWS Elastic Beanstalkについて

www.mybooks.jp

EC2Instance

WordPress(AMI元)

Elastic IP Address

ELB

EC2InstanceEBS

EBS snapshot

S3

Simple Workflow Service

Tomcat Session Store

Book Data

Tomcat7 (Grails/back-end)

EC2 InstancesELB

Decider

Worker

EC2 Instances(Auto Scaling)

Tomcat7 (Grails/front-end)

CloudWatch

Simple Email Service

S3 (App Resources)

editor.mybooks.jpA. 静的サイト B. 動的サイト

Route53

Private Distribution

State Sharing

Snapshot Scale Up

Floating IP

NFS Sharing

DB Replication

Queuing Chain

Multi Datacenter Bootstrap Cloud DI

Web Strage Archive Functional Firewall Operational Firewall

Multi Datacenter Bootstrap Cloud DI

Web Strage Archive Functional Firewall Operational Firewall

Snapshot