ブログ製本サービス mybooks.jpのアーキテクチャ part.3 aws elastic...
DESCRIPTION
第13回JAWS-UG札幌勉強会で発表した資料です。Immutable InfrastructureとElastic Beanstalkのお話です。TRANSCRIPT
![Page 1: ブログ製本サービス MyBooks.jpのアーキテクチャ Part.3 AWS Elastic Beanstalkについて](https://reader033.vdocuments.net/reader033/viewer/2022060115/5577b154d8b42af34a8b53b7/html5/thumbnails/1.jpg)
ブログ製本サービス MyBooks.jpのアーキテクチャ Part.3
AWS Elastic Beanstalkについて 欧文印刷株式会社・ソフトウェアエンジニア・田名辺健人
2014/04/11 第13回勉強会
![Page 2: ブログ製本サービス MyBooks.jpのアーキテクチャ Part.3 AWS Elastic Beanstalkについて](https://reader033.vdocuments.net/reader033/viewer/2022060115/5577b154d8b42af34a8b53b7/html5/thumbnails/2.jpg)
Who am I ?!(この顔にピンときたら)
![Page 3: ブログ製本サービス MyBooks.jpのアーキテクチャ Part.3 AWS Elastic Beanstalkについて](https://reader033.vdocuments.net/reader033/viewer/2022060115/5577b154d8b42af34a8b53b7/html5/thumbnails/3.jpg)
田名辺 健人(たなべたけひと) ソフトウェアエンジニア !
!
欧文印刷株式会社(東京都) 2011年11月クラウド移住 札幌でリモート勤務中 初代AWSサムライ 好きなサービス: SWF
@dateofrock
http://blog.dateofrock.com/
![Page 4: ブログ製本サービス MyBooks.jpのアーキテクチャ Part.3 AWS Elastic Beanstalkについて](https://reader033.vdocuments.net/reader033/viewer/2022060115/5577b154d8b42af34a8b53b7/html5/thumbnails/4.jpg)
![Page 5: ブログ製本サービス MyBooks.jpのアーキテクチャ Part.3 AWS Elastic Beanstalkについて](https://reader033.vdocuments.net/reader033/viewer/2022060115/5577b154d8b42af34a8b53b7/html5/thumbnails/5.jpg)
![Page 6: ブログ製本サービス MyBooks.jpのアーキテクチャ Part.3 AWS Elastic Beanstalkについて](https://reader033.vdocuments.net/reader033/viewer/2022060115/5577b154d8b42af34a8b53b7/html5/thumbnails/6.jpg)
![Page 7: ブログ製本サービス MyBooks.jpのアーキテクチャ Part.3 AWS Elastic Beanstalkについて](https://reader033.vdocuments.net/reader033/viewer/2022060115/5577b154d8b42af34a8b53b7/html5/thumbnails/7.jpg)
![Page 8: ブログ製本サービス MyBooks.jpのアーキテクチャ Part.3 AWS Elastic Beanstalkについて](https://reader033.vdocuments.net/reader033/viewer/2022060115/5577b154d8b42af34a8b53b7/html5/thumbnails/8.jpg)
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について](https://reader033.vdocuments.net/reader033/viewer/2022060115/5577b154d8b42af34a8b53b7/html5/thumbnails/9.jpg)
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について](https://reader033.vdocuments.net/reader033/viewer/2022060115/5577b154d8b42af34a8b53b7/html5/thumbnails/10.jpg)
AWS Elastic Beanstalk
![Page 11: ブログ製本サービス MyBooks.jpのアーキテクチャ Part.3 AWS Elastic Beanstalkについて](https://reader033.vdocuments.net/reader033/viewer/2022060115/5577b154d8b42af34a8b53b7/html5/thumbnails/11.jpg)
Immutable Infrastructure
今一番ナウい!
そして日本人には発音がつらいww
![Page 12: ブログ製本サービス MyBooks.jpのアーキテクチャ Part.3 AWS Elastic Beanstalkについて](https://reader033.vdocuments.net/reader033/viewer/2022060115/5577b154d8b42af34a8b53b7/html5/thumbnails/12.jpg)
Blue Green Deployment
![Page 13: ブログ製本サービス MyBooks.jpのアーキテクチャ Part.3 AWS Elastic Beanstalkについて](https://reader033.vdocuments.net/reader033/viewer/2022060115/5577b154d8b42af34a8b53b7/html5/thumbnails/13.jpg)
http://martinfowler.com/bliki/BlueGreenDeployment.html
![Page 14: ブログ製本サービス MyBooks.jpのアーキテクチャ Part.3 AWS Elastic Beanstalkについて](https://reader033.vdocuments.net/reader033/viewer/2022060115/5577b154d8b42af34a8b53b7/html5/thumbnails/14.jpg)
それ Elastic Beanstalk そのものですから
![Page 15: ブログ製本サービス MyBooks.jpのアーキテクチャ Part.3 AWS Elastic Beanstalkについて](https://reader033.vdocuments.net/reader033/viewer/2022060115/5577b154d8b42af34a8b53b7/html5/thumbnails/15.jpg)
AWS Elastic Beanstalk
![Page 16: ブログ製本サービス MyBooks.jpのアーキテクチャ Part.3 AWS Elastic Beanstalkについて](https://reader033.vdocuments.net/reader033/viewer/2022060115/5577b154d8b42af34a8b53b7/html5/thumbnails/16.jpg)
Elastic Beanstalk で
Blue Green Deployment してみる
![Page 17: ブログ製本サービス MyBooks.jpのアーキテクチャ Part.3 AWS Elastic Beanstalkについて](https://reader033.vdocuments.net/reader033/viewer/2022060115/5577b154d8b42af34a8b53b7/html5/thumbnails/17.jpg)
![Page 18: ブログ製本サービス MyBooks.jpのアーキテクチャ Part.3 AWS Elastic Beanstalkについて](https://reader033.vdocuments.net/reader033/viewer/2022060115/5577b154d8b42af34a8b53b7/html5/thumbnails/18.jpg)
![Page 19: ブログ製本サービス MyBooks.jpのアーキテクチャ Part.3 AWS Elastic Beanstalkについて](https://reader033.vdocuments.net/reader033/viewer/2022060115/5577b154d8b42af34a8b53b7/html5/thumbnails/19.jpg)
DNS
Storage
DB
LB LB
Servers Servers
Server Image Server Image
Blue Green
Live Pendingversion1
![Page 20: ブログ製本サービス MyBooks.jpのアーキテクチャ Part.3 AWS Elastic Beanstalkについて](https://reader033.vdocuments.net/reader033/viewer/2022060115/5577b154d8b42af34a8b53b7/html5/thumbnails/20.jpg)
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について](https://reader033.vdocuments.net/reader033/viewer/2022060115/5577b154d8b42af34a8b53b7/html5/thumbnails/21.jpg)
![Page 22: ブログ製本サービス MyBooks.jpのアーキテクチャ Part.3 AWS Elastic Beanstalkについて](https://reader033.vdocuments.net/reader033/viewer/2022060115/5577b154d8b42af34a8b53b7/html5/thumbnails/22.jpg)
![Page 23: ブログ製本サービス MyBooks.jpのアーキテクチャ Part.3 AWS Elastic Beanstalkについて](https://reader033.vdocuments.net/reader033/viewer/2022060115/5577b154d8b42af34a8b53b7/html5/thumbnails/23.jpg)
![Page 24: ブログ製本サービス MyBooks.jpのアーキテクチャ Part.3 AWS Elastic Beanstalkについて](https://reader033.vdocuments.net/reader033/viewer/2022060115/5577b154d8b42af34a8b53b7/html5/thumbnails/24.jpg)
![Page 25: ブログ製本サービス MyBooks.jpのアーキテクチャ Part.3 AWS Elastic Beanstalkについて](https://reader033.vdocuments.net/reader033/viewer/2022060115/5577b154d8b42af34a8b53b7/html5/thumbnails/25.jpg)
![Page 26: ブログ製本サービス MyBooks.jpのアーキテクチャ Part.3 AWS Elastic Beanstalkについて](https://reader033.vdocuments.net/reader033/viewer/2022060115/5577b154d8b42af34a8b53b7/html5/thumbnails/26.jpg)
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について](https://reader033.vdocuments.net/reader033/viewer/2022060115/5577b154d8b42af34a8b53b7/html5/thumbnails/27.jpg)
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について](https://reader033.vdocuments.net/reader033/viewer/2022060115/5577b154d8b42af34a8b53b7/html5/thumbnails/28.jpg)
1.サーバーを直接触らない ✓上書きデプロイしてリスタートとか事故の元w ✓(基本的に)サーバーにログインしての作業はやらない。
Immutable InfrastructureとしてのElastic Beanstalk
![Page 29: ブログ製本サービス MyBooks.jpのアーキテクチャ Part.3 AWS Elastic Beanstalkについて](https://reader033.vdocuments.net/reader033/viewer/2022060115/5577b154d8b42af34a8b53b7/html5/thumbnails/29.jpg)
そもそもkey pair指定が必須ではない
(注)私は臆病者なので指定してますw
![Page 30: ブログ製本サービス MyBooks.jpのアーキテクチャ Part.3 AWS Elastic Beanstalkについて](https://reader033.vdocuments.net/reader033/viewer/2022060115/5577b154d8b42af34a8b53b7/html5/thumbnails/30.jpg)
EC2のセットアップ1.あらかじめセットアップ済みAMIを作る 2.cloud-initやChefなどで頑張るw 3.configを利用する • Elastic Beanstalk的には王道
![Page 31: ブログ製本サービス MyBooks.jpのアーキテクチャ Part.3 AWS Elastic Beanstalkについて](https://reader033.vdocuments.net/reader033/viewer/2022060115/5577b154d8b42af34a8b53b7/html5/thumbnails/31.jpg)
EC2のセットアップ1.あらかじめセットアップ済みAMIを作る 2.cloud-initやChefなどで頑張るw 3.configを利用する • Elastic Beanstalk的には王道
![Page 32: ブログ製本サービス MyBooks.jpのアーキテクチャ Part.3 AWS Elastic Beanstalkについて](https://reader033.vdocuments.net/reader033/viewer/2022060115/5577b154d8b42af34a8b53b7/html5/thumbnails/32.jpg)
YAML
![Page 33: ブログ製本サービス MyBooks.jpのアーキテクチャ Part.3 AWS Elastic Beanstalkについて](https://reader033.vdocuments.net/reader033/viewer/2022060115/5577b154d8b42af34a8b53b7/html5/thumbnails/33.jpg)
YAML
$APP_ROOT/.ebextensions/*.config
✓パッケージインストール ✓アーカイブダウンロード + 展開 ✓ファイル生成 or コピー ✓OSユーザー・グループ作成 ✓コマンド実行(OS用) ✓コマンド実行(コンテナ用) ✓サービス設定(/etc/init.d) ✓Beanstalk固有の設定
![Page 34: ブログ製本サービス MyBooks.jpのアーキテクチャ Part.3 AWS Elastic Beanstalkについて](https://reader033.vdocuments.net/reader033/viewer/2022060115/5577b154d8b42af34a8b53b7/html5/thumbnails/34.jpg)
packages: yum: libmemcached: [] ruby-devel: [] nfs-utils: [1.0.9]
rpm, yum, apt, rubygems (chef)
![Page 35: ブログ製本サービス MyBooks.jpのアーキテクチャ Part.3 AWS Elastic Beanstalkについて](https://reader033.vdocuments.net/reader033/viewer/2022060115/5577b154d8b42af34a8b53b7/html5/thumbnails/35.jpg)
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について](https://reader033.vdocuments.net/reader033/viewer/2022060115/5577b154d8b42af34a8b53b7/html5/thumbnails/36.jpg)
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について](https://reader033.vdocuments.net/reader033/viewer/2022060115/5577b154d8b42af34a8b53b7/html5/thumbnails/37.jpg)
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について](https://reader033.vdocuments.net/reader033/viewer/2022060115/5577b154d8b42af34a8b53b7/html5/thumbnails/38.jpg)
users: myuser: groups: group1 group2 uid: "50" homeDir: “/tmp” groups: - groupOne - groupTwo gid: "45"
![Page 39: ブログ製本サービス MyBooks.jpのアーキテクチャ Part.3 AWS Elastic Beanstalkについて](https://reader033.vdocuments.net/reader033/viewer/2022060115/5577b154d8b42af34a8b53b7/html5/thumbnails/39.jpg)
commands: test: command: myscript.py cwd: /home/ec2-user env: myvarname: myvarvalue
![Page 40: ブログ製本サービス MyBooks.jpのアーキテクチャ Part.3 AWS Elastic Beanstalkについて](https://reader033.vdocuments.net/reader033/viewer/2022060115/5577b154d8b42af34a8b53b7/html5/thumbnails/40.jpg)
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について](https://reader033.vdocuments.net/reader033/viewer/2022060115/5577b154d8b42af34a8b53b7/html5/thumbnails/41.jpg)
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について](https://reader033.vdocuments.net/reader033/viewer/2022060115/5577b154d8b42af34a8b53b7/html5/thumbnails/42.jpg)
services: sysvinit: myservice: enabled: true ensureRunning: true
![Page 43: ブログ製本サービス MyBooks.jpのアーキテクチャ Part.3 AWS Elastic Beanstalkについて](https://reader033.vdocuments.net/reader033/viewer/2022060115/5577b154d8b42af34a8b53b7/html5/thumbnails/43.jpg)
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について](https://reader033.vdocuments.net/reader033/viewer/2022060115/5577b154d8b42af34a8b53b7/html5/thumbnails/44.jpg)
2.App側も気を使う必要あり ✓Immutableである→ステートレス ✓ステートレスなアーキテクチャ ✓メンテが楽!! ✓スケーラブル!!
Immutable InfrastructureとしてのElastic Beanstalk
![Page 45: ブログ製本サービス MyBooks.jpのアーキテクチャ Part.3 AWS Elastic Beanstalkについて](https://reader033.vdocuments.net/reader033/viewer/2022060115/5577b154d8b42af34a8b53b7/html5/thumbnails/45.jpg)
DNS
Storage
DB
LB
Servers
Server Image
Blue
Live
![Page 46: ブログ製本サービス MyBooks.jpのアーキテクチャ Part.3 AWS Elastic Beanstalkについて](https://reader033.vdocuments.net/reader033/viewer/2022060115/5577b154d8b42af34a8b53b7/html5/thumbnails/46.jpg)
DNS
Storage
DB
LB
Servers
Server Image
Blue
Live
データ(状態)はサーバーの外へ!
![Page 47: ブログ製本サービス MyBooks.jpのアーキテクチャ Part.3 AWS Elastic Beanstalkについて](https://reader033.vdocuments.net/reader033/viewer/2022060115/5577b154d8b42af34a8b53b7/html5/thumbnails/47.jpg)
DNS
Storage
DB
LB
Servers
Server Image
Blue
Live
サーバーはいつでも捨てられる!
![Page 48: ブログ製本サービス MyBooks.jpのアーキテクチャ Part.3 AWS Elastic Beanstalkについて](https://reader033.vdocuments.net/reader033/viewer/2022060115/5577b154d8b42af34a8b53b7/html5/thumbnails/48.jpg)
Immutable Infrastructure
今一番ナウい!
そして日本人には発音がつらいww
![Page 49: ブログ製本サービス MyBooks.jpのアーキテクチャ Part.3 AWS Elastic Beanstalkについて](https://reader033.vdocuments.net/reader033/viewer/2022060115/5577b154d8b42af34a8b53b7/html5/thumbnails/49.jpg)
AWS Elastic Beanstalk
![Page 50: ブログ製本サービス MyBooks.jpのアーキテクチャ Part.3 AWS Elastic Beanstalkについて](https://reader033.vdocuments.net/reader033/viewer/2022060115/5577b154d8b42af34a8b53b7/html5/thumbnails/50.jpg)
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について](https://reader033.vdocuments.net/reader033/viewer/2022060115/5577b154d8b42af34a8b53b7/html5/thumbnails/51.jpg)
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