AWS CLIツールのインストール
$ pip install awsebcli
Rails環境の用意
$ rails g controller hello index
Rails環境上で、EBS初期化
$ eb init
リージョンどこにするか聞かれる
Select a default region 1) us-east-1 : US East (N. Virginia) 2) us-west-1 : US West (N. California) 3) us-west-2 : US West (Oregon) 4) eu-west-1 : EU (Ireland) 5) eu-central-1 : EU (Frankfurt) 6) ap-southeast-1 : Asia Pacific (Singapore) 7) ap-southeast-2 : Asia Pacific (Sydney) 8) ap-northeast-1 : Asia Pacific (Tokyo) 9) sa-east-1 : South America (Sao Paulo) (default is 3):
AWSのアクセスキーとシークレットトークンを聞かれる
You have not yet set up your credentials or your credentials are incorrect You must provide your credentials. (aws-access-id): ******** (aws-secret-key): ********
どのアプリケーションを使うか聞かれる
既存のアプリが残っているので、それを使うか、別のを作るか聞かれた
- 新しく作ることにした
Select an application to use 1) elastic_beanstalk_demo 2) [ Create new Application ] (default is 1): 2
Enter Application Name (default is "elastic_beanstalk_demo2"):
Rubyアプリで良いよな? と聞かれた
It appears you are using Ruby. Is this correct? (y/n): y
Rubyのバージョン聞かれた
Select a platform version. 1) Ruby 2.2 (Puma) 2) Ruby 2.1 (Puma) 3) Ruby 2.0 (Puma) 4) Ruby 2.2 (Passenger Standalone) 5) Ruby 2.1 (Passenger Standalone) 6) Ruby 2.0 (Passenger Standalone) 7) Ruby 1.9.3 (default is 1): 1
SSH使う? と聞かれる
Do you want to set up SSH for your instances? (y/n): y
キーペアを聞かれる
Select a keypair. 1) test1234 2) [ Create new KeyPair ] (default is 2): 1
/.elasticbeanstalk が作られ、.gitignore
に追加されるので commit する
$ git diff diff --git a/.gitignore b/.gitignore index 050c9d9..964c20f 100644 --- a/.gitignore +++ b/.gitignore @@ -15,3 +15,8 @@ /log/* !/log/.keep /tmp + +# Elastic Beanstalk Files +.elasticbeanstalk/* +!.elasticbeanstalk/*.cfg.yml +!.elasticbeanstalk/*.global.yml
デプロイ
$ eb create elastic-beanstalk-demo2
サイトを開く
$ eb open
なんかエラー
A really lowlevel plumbing error occured. Please contact your local Maytag(tm) repair person.
エラーログをチェック
$ eb logs
------------------------------------- /var/log/puma/puma.log ------------------------------------- === puma startup: 2015-09-22 07:37:26 +0000 === === puma startup: 2015-09-22 07:37:26 +0000 === [20209] + Gemfile in context: /var/app/current/Gemfile [20205] - Worker 0 (pid: 20209) booted, phase: 0 2015-09-22 07:42:23 +0000: Rack app error: #<RuntimeError: Missing `secret_token` and `secret_key_base` for 'production' environment, set these values in `config/secrets.yml`>
puma?
EBS環境で使われているデフォルトのwebサーバ → A Modern, Concurrent Web Server for Ruby - Puma
- 最近はHerokuも採用しているらしい
- 非I/Oブロッキングな作りの為、スロークエリクライアントアタックに強いとの評判
- 遅いクライアントが大量に接続されて、全てのワーカープロセスが待ち状態のままにさせられる攻撃
- なんでまたこんなぐぐりにくい名前を...
この辺が詳しい。 → 最近の Rack サーバ事情について - おもしろwebサービス開発日記
シークレットキーを設定する必要があるらしいので作る
$ rake secret $ eb setenv SECRET_KEY_BASE=*******
見れた!!!
まずはここまで
TODO
- puma と、Passenger どちらがよいのじゃろ?
- リポジトリを更新してから再度デプロイ
- githubのmasterブランチ更新で自動的にデプロイ
- デプロイ完了したらslackで通知
- RDSとの連携
- stage, product環境をそれぞれ作る
- CloudWatch使う
- 独自ドメイン使う
参考
- A really lowlevel plumbing error occured. Please contact your local Maytag(tm) repair man. - keiwt’s diary
- AWS Elastic Beanstalk と Rails で Hello World してみる【11日目】 | Developers.IO
- Rails アプリケーションの Elastic Beanstalk へのデプロイ - Elastic Beanstalk
- A really lowlevel plumbing error occured. Please contact your local Maytag(tm) repair man. - keiwt’s diary