ブログ製本サービス mybooks.jpのアーキテクチャ part.3 aws elastic...
DESCRIPTION
第13回JAWS-UG札幌勉強会で発表した資料です。Immutable InfrastructureとElastic Beanstalkのお話です。TRANSCRIPT
ブログ製本サービス MyBooks.jpのアーキテクチャ Part.3
AWS Elastic Beanstalkについて 欧文印刷株式会社・ソフトウェアエンジニア・田名辺健人
2014/04/11 第13回勉強会
Who am I ?!(この顔にピンときたら)
田名辺 健人(たなべたけひと) ソフトウェアエンジニア !
!
欧文印刷株式会社(東京都) 2011年11月クラウド移住 札幌でリモート勤務中 初代AWSサムライ 好きなサービス: SWF
@dateofrock
http://blog.dateofrock.com/
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
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
AWS Elastic Beanstalk
Immutable Infrastructure
今一番ナウい!
そして日本人には発音がつらいww
Blue Green Deployment
http://martinfowler.com/bliki/BlueGreenDeployment.html
それ Elastic Beanstalk そのものですから
AWS Elastic Beanstalk
Elastic Beanstalk で
Blue Green Deployment してみる
DNS
Storage
DB
LB LB
Servers Servers
Server Image Server Image
Blue Green
Live Pendingversion1
DNS
Storage
DB
LB LB
Servers Servers
Server Image Server Image
Blue Green
Live Pendingversion1 version2
DNS
Storage
DB
LB LB
Servers Servers
Server Image Server Image
Blue Green
Live Pendingversion1 version2
DNS
Storage
DB
LB LB
Servers Servers
Server Image Server Image
Blue Green
Pending Liveversion1 version2
1.サーバーを直接触らない ✓上書きデプロイしてリスタートとか事故の元w ✓(基本的に)サーバーにログインしての作業はやらない。
Immutable InfrastructureとしてのElastic Beanstalk
そもそもkey pair指定が必須ではない
(注)私は臆病者なので指定してますw
EC2のセットアップ1.あらかじめセットアップ済みAMIを作る 2.cloud-initやChefなどで頑張るw 3.configを利用する • Elastic Beanstalk的には王道
EC2のセットアップ1.あらかじめセットアップ済みAMIを作る 2.cloud-initやChefなどで頑張るw 3.configを利用する • Elastic Beanstalk的には王道
YAML
YAML
$APP_ROOT/.ebextensions/*.config
✓パッケージインストール ✓アーカイブダウンロード + 展開 ✓ファイル生成 or コピー ✓OSユーザー・グループ作成 ✓コマンド実行(OS用) ✓コマンド実行(コンテナ用) ✓サービス設定(/etc/init.d) ✓Beanstalk固有の設定
packages: yum: libmemcached: [] ruby-devel: [] nfs-utils: [1.0.9]
rpm, yum, apt, rubygems (chef)
sources: /usr/local/bin:↵ http://hoge.com/hoge.tar.gz
tar, tar+gzip, tar+bz2, zip
files: "/home/ec2-user": mode: "000777" owner: ec2-user group: ec2-user source: http://hoge.com/a.txt
files: "/home/ec2-user": mode: "000777" owner: ec2-user group: ec2-user content: | # this is my file # with content
content直書きOK
users: myuser: groups: group1 group2 uid: "50" homeDir: “/tmp” groups: - groupOne - groupTwo gid: "45"
commands: test: command: myscript.py cwd: /home/ec2-user env: myvarname: myvarvalue
container_commands: replace-server_xml: command: ↵ cp .ebextensions/server.xml ↵ /etc/tomcat7/server.xml
server.xmlの置換
container_commands: 01syncdb: command: "django-admin.py syncdb --noinput" leader_only: true 02migrate: command: "django-admin.py migrate" leader_only: true
マイグレーションの実行
services: sysvinit: myservice: enabled: true ensureRunning: true
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
2.App側も気を使う必要あり ✓Immutableである→ステートレス ✓ステートレスなアーキテクチャ ✓メンテが楽!! ✓スケーラブル!!
Immutable InfrastructureとしてのElastic Beanstalk
DNS
Storage
DB
LB
Servers
Server Image
Blue
Live
DNS
Storage
DB
LB
Servers
Server Image
Blue
Live
データ(状態)はサーバーの外へ!
DNS
Storage
DB
LB
Servers
Server Image
Blue
Live
サーバーはいつでも捨てられる!
Immutable Infrastructure
今一番ナウい!
そして日本人には発音がつらいww
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
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