LoginSignup
1
1

More than 5 years have passed since last update.

NetFlow v5 を fluentd-docker で受け取る方法

Posted at

OpenvSwitch240 on RaspberryPi2 して、OVS上に定義した Bridge 上を通るトラフィックを Netflow v5で fluentd に飛ばしてみました。fluentd は Docker 上で動かします。
OVS on RasPi と、ElasticSearch + KIBANA は別エントリで。

1. fluentd-docker を構築
・ディレクトリを作成
$ mkdir custom-fluentd
$ cd custom-fluentd
$ curl https://raw.githubusercontent.com/fluent/fluentd-docker-image/master/VERSION/OS-onbuild/fluent.conf > fluent.conf
$ mkdir plugins
$ curl https://raw.githubusercontent.com/fluent/fluentd-docker-image/master/Dockerfile.sample > Dockerfile

curl は見ての通りサンプルのダウンロードなので要らない場合は省略。

・Dockerfileとfluentd.confを用意
Dockerfile
FROM fluent/fluentd
RUN fluent-gem install fluent-plugcin-netflow
RUN fluent-gem install fluent-plugin-elasticsearch
fluentd.conf
<source>
  type netflow
  tag netflow.event
  port 24224
</source>
#<match **>
#  @type stdout
#</match>
<match docker.**>
  @type file
  @id   output1
   path         /fluentd/log/dockerdata.*.log
   symlink_path /fluentd/log/dockerdata.log
   append       true
   time_slice_format %Y%m%d
   time_slice_wait   1m
   time_format       %Y%m%dT%H%M%S%z
</match>
<match netflow.event>
  @type file
   path         /fluentd/log/data.*.log
   symlink?path /fluentd/log/data.log
   append       true
</match>
#<match **>
#  type file
#  path /home/fluentd
#</match>
・Dockerコンテナ構築と実行
$ sudo docker build -t custom-fluentd:latest ./
$ sudo docker run -d -p 24224:24224 -p 24224:24224/udp -v /home/fluentd/log:/fluentd/log -v /home/fluentd:/fluentd/etc -e FLUENTD_CONF=fluentd.conf custom-fluentd
・確認
ps_a
CONTAINER ID IMAGE          COMMAND                 CREATED        STATUS                    PORTS  NAMES
324ffa9df98f custom-fluent  "/bin/entrypoint.s..."  23 seconds ago Exited (1) 18 seconds ago        ecstatic_khorana

ありゃ、瞬殺されてる。。。
log確認

$ sudo docker logs $NAMES

fluentd.confのpathが違ってました。 ついでにlogも直しておく。

$ sudo docker run -d -p 24224:24224 -p 24224:24224/udp -v /home/hayashi/custom-fluentd/log:/fluentd/log -v /home/hayashi/custom-flunentd:/fluentd/etc -e FLUENTD_CONF=fluentd.conf custom-fluentd
ps_a
CONTAINER ID IMAGE          COMMAND                 CREATED         STATUS        PORTS                                                          NAMES
f29abe9bd870 custom-fluentd "/bin/entrypoint.s..."  10 seconds ago  Up 8 seconds  5140/tcp, 0.0.0.0:24224->24224/tcp, 0.0.0.0:24224->24224/udp   silly_cori

OK !

別途用意していたOVS240のNetflow定義を今回のfluentdの環境に合わせる。

$ sudo ovs-vsctl -- set Bridge netflowbr netflow=@nf -- --id=@nf create NetFlow targets=\"192.168.0.31:24224\"

docker run で、ログディレクトリとして設定していたディレクトリにちゃんとファイルが出来てました。終了。

参考リンク
fluent-docker-image公式
https://github.com/fluent/fluentd-docker-image

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