LoginSignup
33

More than 5 years have passed since last update.

CoreOS 上の全てのログをリモートサーバへ送る

Last updated at Posted at 2014-09-11

概要

CoreOS 上で出る全てのログをリモートのログサーバへ送るという話。
CoreOS には systemd が入っており、全てのサービスを systemd 経由で管理すると systemd 付属の jounalctl によってログが一元管理できる。 CoreOS マシンを disposable にしておくために一元管理したログをリモートサーバへ送る

ログのルーティング

収集したログは ncat のコネクトモードを使ってログ保存先の listen ポートへ UDP データとして送る。

$ journalctl -o short -f | ncat remote-destination.com 12345

ログのルーティング先は色々ある。

Logentries へルーティングする例

Logentries は固有ポートへの Plain TCP, UDP 経由で送ると、送信元 IP で判別するので、CoreOS マシンを捨てられなくなる。Logentries へは Token ベースで送信する

core@core-01 ~ $ journalctl -o short -f | sed \"s/^/<YOUR_TOKEN> \\0/g\" | ncat data.logentries.com 10000"

json 形式で送る

core@core-01 ~ $ journalctl -o json -f | sed \"s/^/<YOUR_TOKEN> \\0/g\" | ncat data.logentries.com 10000"

Cloud-Config で起動する

#cloud-config

coreos:
  update:
    group: stable
  etcd:
    discovery: https://discovery.etcd.io/xxxxxxxxxxxxxxxxxxx
    addr: $public_ipv4:4001
    peer-addr: $public_ipv4:7001
  fleet:
    public-ip: $public_ipv4
  units:
    - name: journal-router-short.service
      command: start
      content: |
        [Unit]
        Description=Journal Router (short)

        [Service]
        TimeoutStartSec=0
        ExecStart=/bin/sh -c '/usr/bin/journalctl -o short -f | sed \"s/^/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx \\0/g\" | ncat data.logentries.com 10000'

        [Install]
        WantedBy=multi-user.target
    - name: journal-router-json.service
      command: start
      content: |
        [Unit]
        Description=Journal Router (json)

        [Service]
        TimeoutStartSec=0
        ExecStart=/bin/sh -c '/usr/bin/journalctl -o json -f | sed \"s/^/xxxxxxxxxxxxxxxxxxxxxxxxxxxx \\0/g\" | ncat data.logentries.com 10000'

        [Install]
        WantedBy=multi-user.target
  • human readable なログとして short 、後で詳細を調べる、ログを使って何かするときのために json ログともに送信しておく

補足: Logentries の設定例

host___Logentries.png

host___Logentries.png

host___Logentries.png

host___Logentries_と_CoreOS_上の全てのログをリモートサーバへ送る.png

メモと感想

各コンテナの起動失敗等のログも欲しいので一番最初に起動するよう書く

units の一番上に書けばいいんだと思う

REF

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
33