LoginSignup
12
11

More than 5 years have passed since last update.

SentryをEC2 (Amazon Linux)に導入しRavenでロギング確認するまで

Last updated at Posted at 2015-06-07

Install sentry on ec2 (Amazon Linux)

まずはec2 (Amazon LINUX)インスタンスをビルド

モジュールインストール

以下ec2-userにて実行しています。

$ sudo yum install -y gcc python-devel gcc-c++ kernel-devel python-devel mysql-devel libxslt-devel libffi-devel openssl-devel wget epel-release vim

redisインストール・起動

$ cd /usr/local/src
$ sudo wget -r --no-parent -A 'epel-release-*.rpm' http://dl.fedoraproject.org/pub/epel/7/x86_64/e/
$ sudo rpm -Uvh dl.fedoraproject.org/pub/epel/7/x86_64/e/epel-release-*.rpm
$ sudo yum -y install redis
$ sudo service redis start
$ sudo chkconfig redis on
  • redis状態確認
$ sudo service redis status
  • 起動確認
$ redis-cli ping

PONG ← このように出力されれば成功

Sentry

sentryインストール
$ sudo easy_install -U sentry
初期化設定

sentry init実行するとsentry設定ファイルが作成されたことが確認できます。

$ sentry init

Configuration file created at ‘/home/ec2-user/.sentry/sentry.conf.py’
sentry 実行
$ sentry upgrade

しばらくすると、以下のように尋ねられる。

Would you like to create a user account now? (yes/no): yes (yesでユーザ作成)
Email: xxx@xxx (メールアドレス登録)
Password: xxxxx (パスワード入力)
Should this user be a superuser? [yN] y
  • 以上でsentry初期設定は完了です。
sentry 起動
$ sentry --config=~/.sentry/sentry.config.py start

Performing upgrade before service startup...
Loading help page membership.md
Loading help page organizations.md
Loading help page quotas.md
Loading help page teams_and_projects.md
Loading help page sampling.md
Loading help page tagging.md
Loading help page single_sign_on.md
Running service: 'http'
[2015-06-05 16:51:55 +0000] [2269] [INFO] Starting gunicorn 19.3.0
[2015-06-05 16:51:55 +0000] [2269] [INFO] Listening at: http://0.0.0.0:9000 (2269)
[2015-06-05 16:51:55 +0000] [2269] [INFO] Using worker: sync
[2015-06-05 16:51:55 +0000] [2276] [INFO] Booting worker with pid: 2276
[2015-06-05 16:51:55 +0000] [2277] [INFO] Booting worker with pid: 2277
[2015-06-05 16:51:55 +0000] [2278] [INFO] Booting worker with pid: 2278

AWS ElasticIP設定

ElasticIPをビルドしたインスタンスと関連付け

http://ElasticIP:9000アクセス

Sentryのログイン・新規ユーザ登録ページが表示される。

チームやプロジェクトを作成できるようになります。


上記まででまず簡単にアクセスできるようになりますが、
以下設定することでsentryの管理がしやすくなります。

  • nginxインストール

→ リバースプロキシ設定 :9000とつける必要がなくなる。

メンバーへ招待メールを送った際にhttp://ElasticIP/accept/xxxxxxxxxxxのように、:9000ポートがないため、アクセスしても「アクセスできない」というエラーになります。

  • supervisordインストール

→ sentryをdaemon起動できます。
通常コマンドラインでsentry start等実行しますが
何気にsentry stopのようなコマンドがなく
一旦起動したらそのまま。
なので、sentryの起動・ストップを管理できます。

これらはSentry 公式ドキュメントでも推奨されています。
むしろ使えという感じです。


nginx インストール

nginx インストール
$ yum install -y nginx
/etc/nginx/nginx.conf 設定
  • locationにてリバースプロキシ設定

sentryのweb表示には、http://ElasticIP:9000のようにポートまで指定してアクセスする必要がありましたが、
http://ElasticIPにアクセスすると9000番ポートにアクセスするようにする設定をします。

以下が設定箇所です。

location / {
...
}

  • /etc/nginx/nginx.conf
user  nginx;
worker_processes  1;

error_log  /var/log/nginx/error.log;
pid        /var/run/nginx.pid;

events {
    worker_connections  1024;
}

http {
    include       /etc/nginx/mime.types;
    default_type  application/octet-stream;

    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  /var/log/nginx/access.log  main;

    sendfile        on;

    keepalive_timeout  65;

    include /etc/nginx/conf.d/*.conf;

    index   index.html index.htm;

    server {
        listen       80;
        server_name  localhost;
        root         /usr/share/nginx/html;

        #charset koi8-r;

        #access_log  /var/log/nginx/host.access.log  main;

        location / {
            proxy_pass         http://ElasticIP:9000;
            proxy_redirect     off;

            proxy_set_header   Host              $host;
            proxy_set_header   X-Real-IP         $remote_addr;
            proxy_set_header   X-Forwarded-For   $proxy_add_x_forwarded_for;
            proxy_set_header   X-Forwarded-Proto $scheme;
        }
    }
}

nginx 起動
$ sudo service nginx start
nginx 起動スクリプト登録
$ sudo chkconfig nginx on

supervisord

supervisordインストール
$ sudo easy_install supervisor
supervisord設定ファイル編集
$ sudo vim /etc/supervisord.conf
  • /etc/supervisord.conf
[supervisord]

[program:sentry-web]
command=sentry --config=/home/ec2-user/.sentry/sentry.conf.py start http
autostart=true
autorestart=true

[program:sentry-worker]
command=sentry --config=/home/ec2-use/.sentry/sentry.conf.py celery worker -B
autostart=true
autorestart=true
redirect_stderr=true

supervisordをconfigファイル指定し起動

$ supervisord -c /etc/supervisord.conf

http://ElasticIPにアクセス

sentryのログインページが表示されることを確認できるでしょう♪

loggingの確認

ローカルのMacOSX や 別サーバからロギングできるか確認する。

http://ElasticIP/docs/platforms/php/参照

$ git clone https://github.com/getsentry/raven-php
$ cd raven-php
$ vim t.php
  • t.php
<?php

require_once './lib/Raven/Autoloader.php';

Raven_Autoloader::register();

$client = new Raven_Client('http://da58299b45544669b89e930ba50a83ba:415c3258b3444fc39bea22ac597105f6@ElasticIP/2');

// 簡単なメッセージを記録
$client->captureMessage('hoge'.date(YmdHis));

// 例外を捕捉
try {
    throw new Exception('Uh oh!');
}
catch (Exception $e) {
    $client->captureException($e);
}
  • ravenで非同期ロギングテスト
$ php t.php

指定プロジェクトでロギングされていることを確認できます♪

12
11
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
12
11