前回はこちら→セキュリティテストプラットフォームMinion最速ガイド3
こんにちは。こんばんは。CTOの馬場です。
OSSのセキュリティテストプラットフォームのガイドの第4回です。
マニアックなのは自覚しています。
今回はProduction環境の設定をしてみましょう。
環境は `nginx(https) + supervisord`
minion標準の環境は `nginx(https) + supervisord` です。
`supervisord + virtualenv + gunicorn/celery` で動かします。
なお、あらかじめnginx, supervisord用の設定ファイルが用意されているので、それをもとに構築してみます。
段取りとしては
- nginxをインストールして自己証明書を発行
- supervisordをインストール
- minion用設定ファイルを用意
その他検証環境はこんな感じ。
- Ubuntu 12.04 Server LTS 64bit
- minion起動ユーザ: minion
- minionインストールディレクトリ: /home/minion/minion/{minion-frontend,minion-backend}
- minion設定ディレクトリ: /etc/minion
nginxをインストールして自己証明書を発行
↓でできます。
sudo apt-get -y install nginx
sudo mkdir /etc/nginx/ssl
cd /etc/nginx/ssl
sudo openssl genrsa -des3 -out server.key 1024
sudo openssl req -new -key server.key -out server.csr
sudo cp server.key server.key.org
sudo openssl rsa -in server.key.org -out server.key
sudo openssl x509 -req -days 365 -in server.csr -signkey server.key -out server.crt
sudo mv server.key /etc/ssl/private/${MINION_FRONTEND_HOST:?}.key
sudo mv server.crt /etc/ssl/private/${MINION_FRONTEND_HOST:?}.crt
これができたら
service nginx restart
してHTTPSアクセスできるようになればok!
簡単ですね!
※nginxよくわからん、という方はこちらもどうぞ
→nginx連載1回目: nginxの紹介 – インフラエンジニアway – Powered by HEARTBEATS
supervisordをインストール
↓これだけ
sudo apt-get -y install supervisor
簡単ですね!
設定ファイルの用意
nginxは設定ファイルのサンプルが `${MINION_HOME:?}/minion-frontend/etc/minion-dev-server.nginx.conf` にあるので、これを参考に自分用のものを作ります。
supervisordは設定ファイルのサンプルが
`${MINION_HOME}/{minion-frontend,minion-backend}/etc/*.supervisor.conf` にあります。
これをもとに下記の変更を実施してます。
- 実行ユーザをminionに変更
- 作業ディレクトリを `
${MINION_HOME}/minion-{frontend,backend}` に変更 - minion-frontendの設定ファイル( `
frontend.json` )を用意 - gunicornとceleryをvirtualenv環境下で実行できるようにラッパーを用意
- 参考: Supervisord + Virtualenv な環境で gunicorn を起動する – Memo
- supervisordから直接gunicorn、celeryを起動するようにする
- `
${MINION_HOME}/env/bin/minion-*-worker` 経由だとsupervisordとの親子関係が切れてしまうので
具体的な手順はこちら
→mozilla minion production config files
あと、この手順で生成したファイルをgistに貼っておきました。
- `
envwrapper.sh` はこちら →wapper for supervisord + gunicorn/celery with virtualenv - 生成した設定ファイルの例はこちら →mozilla minion production config files
簡単ですね!ぜひ使ってください!!誰か!!!