LoginSignup
0
0

More than 5 years have passed since last update.

ElasticBeansTalkにdeployしたRailsアプリのlogをPapertrailで試しに取得する

Posted at

概要

Image from Gyazo

注意

あくまで 試しに取得 です。DeployもしくはElasticBeansTalkの環境を作り直すと、ログがとれなくなります。

永続的にPapertrailでログを取得したい場合は、こちらの Papertrail Solution for Rails Applications on ElasticBeanstalkを参考に行ってください。

手順

  • remote_syslog2をインストール
  • /etc/log_files.yml を編集

remote_syslog2をインストール

  • ec2にssh接続します。下記の赤矢印箇所参考にしてください。

Image from Gyazo

  • こちらの中からインストールします。

今回はrpmパッケージremote_syslog2-0.20-1.x86_64.rpmを使います。

wgetでダウンロードして、rpmをインストールします。

wget https://github.com/papertrail/remote_syslog2/releases/download/v0.20/remote_syslog2-0.20-1.x86_64.rpm
sudo rpm -ivh remote_syslog2-0.20-1.x86_64.rpm

設定ファイル /etc/log_files.yml を編集

ベースとなる設定ファイルを取得します。 Add systems をクリックしして、

Image from Gyazo

  • app log file を選択して、 download a custom config file をクリックしてベースとなる設定ファイルを取得します。

Image from Gyazo

上記で取得したベースとなるファイルとこちらの例を参考に /etc/log_files.yml 作成します。

sudoで行う必要あります。編集は vimとかnanoなどで行ってください。

railsとpumaとnginx_errorのログを取得する設定例です。

ElasticBeansTalkの場合、railsのアプリは /var/app/current/ にインストールされていますので、railsのログは /var/app/current/log/production.log に保存されています。

/etc/log_files.yml
files:
  - path: /var/app/current/log/production.log # railsのログ
    tag: rails # 名前はなんでもよし
  - path: /var/log/puma/puma.log # pumaのログ
    tag: puma # 名前はなんでもよし
  - path: /var/log/nginx/error.log # nginxのエラーログ
    tag: nginx_error # 名前はなんでもよし
destination:
  host: logs7.papertrailapp.com # download a custom config fileに書かれた値を使ってください。
  port: 12345 # download a custom config fileに書かれた値を使ってください。
  protocol: tls
pid_file: /var/run/remote_syslog.pid
host: server01 # ログ内で区別できるサーバー名を入力する

再起動

下記のコマンドで再起動する

sudo reboot

Papertrailのeventsページにアクセスしてログが表示された成功です。

Image from Gyazo

参考

0
0
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
0
0