LoginSignup
8
10

More than 5 years have passed since last update.

Yamahaルータ(RTX810)のログをsyslogで飛ばしてdocker + EFKで見る

Last updated at Posted at 2017-11-02

概要

RTX810本体だとログを3000行しか貯められないので、syslogで転送する。

  • RTX810のログをsyslogで飛ばす
  • fluentdのin_syslogで受ける
  • Elasticsearchに転送してKibanaで可視化

fluentdとElasticsearch、Kibanaはdockerで1つのホスト上に構築。

ファイル構成

ファイルとディレクトリ構成は以下の通り。
syslogのログはElasticsearchに飛ばすとともに、logディレクトリにも保存する。

├── docker-compose.yaml
├── fluentd
│   ├── Dockerfile
│   └── fluent.conf
└── log

docker-composeはこんな感じ。

docker-compose.yaml
version: '2'

services:
  fluentd:
    build: ./fluentd
    environment:
      FLUENTD_CONF: fluent.conf
    restart: always
    volumes:
      - ./fluentd/fluent.conf:/fluentd/etc/fluent.conf
      - ./log:/home/fluent/syslog
    ports:
      - "514:5140/udp"
    depends_on:
      - elasticsearch

  elasticsearch:
    image: docker.elastic.co/elasticsearch/elasticsearch:5.6.3
    volumes:
      - esdata:/usr/share/elasticsearch/data
      - esconfig:/usr/share/elasticsearch/config
    expose:
      - "9200"
    restart: always
    environment:
      - bootstrap.memory_lock=true
      - xpack.security.enabled=false
      - xpack.monitoring.enabled=false
      - xpack.watcher.enabled=false
      - xpack.graph.enabled=false
      - xpack.ml.enabled=false
      - http.max_content_length=1g
      - thread_pool.index.queue_size=-1
      - thread_pool.bulk.queue_size=-1
      - "ES_JAVA_OPTS=-Xms1024m -Xmx1024m"
    ulimits:
      memlock:
        soft: -1
        hard: -1
    mem_limit: 2g

  kibana:
    image: docker.elastic.co/kibana/kibana:5.6.3
    ports:
      - "5601:5601"
    restart: always
    environment:
      - "ELASTICSEARCH_URL=http://elasticsearch:9200"
      - xpack.graph.enabled=false
      - xpack.security.enabled=false
      - xpack.ml.enabled=false
    depends_on:
      - elasticsearch

volumes:
  esdata:
    driver: local
  esconfig:
    driver: local
fluentd/Dockerfile
FROM fluent/fluentd

RUN gem install fluent-plugin-elasticsearch

fluentdのコンテナで514/udpポートを開けようとしてもエラーが出たので、
docker-composeで514⇒5140にマッピングする設定にして、コンテナではin_syslogプラグインで5140ポートで受けるようにした。

RTX810から送られるsyslogはmessage_formatrfc3164rfc5424を指定しても
うまくマッチしなかったので、全体を取るようにした。

受け取ったログはcopyプラグインでElasticsearchとfileに出力。
fileの出力先はパーミッションから見て/home/fluent/以下にするのが良さげ(例えば/var/log/以下だと書き込めないとエラーが出た)。

format single_valuemessageのみをファイルに書き出すようにして、
compress gzipで書き出したファイルを圧縮。

fluentd/fluent.conf
<source>
  @type syslog
  port 5140
  bind 0.0.0.0
  format /^? *(?<message>.*)$/ 
  time_format %Y/%m/%d %h:%M:%s 
  tag syslog
</source>

<match syslog.**>
  @type copy
  <store>
    @type elasticsearch
    include_tag_key true
    tag_key _tag
    host elasticsearch
    port 9200
    logstash_format true
    logstash_prefix logstash

    buffer_type file
    buffer_path /tmp/fluentd*.buffer
#    buffer_chunk_limit 1g
#    buffer_queue_limit 256
#    flush_interval 60s
#    retry_wait 5s
  </store>
  <store>
    @type file
    path /home/fluent/syslog/log
    compress gzip
    format single_value
  </store>
</match>

以上のファイルを用意したらコンテナ起動。

docker-compose build
docker-compose up -d

RTX810設定

  • syslog hostでdockerホストのIP(この例では192.168.100.221)を指定
  • syslog facilityはお好みで(下記はlocal7)
  • 転送対象とするログをnotice, info, debugから選ぶ
syslog host 192.168.100.221
syslog facility local7
syslog notice on
syslog info on
syslog debug on

Kibana

ブラウザからhttp://192.168.100.221:5601/にアクセス。
最初にインデックスパターンを作成すれば、めでたくログが表示される。

image.png

8
10
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
8
10