NetflowをElastiflowで取り込む

Elasticsearchで取り込んだデータをKibanaでインデックス化まではいけたのだけれど, ダッシュボードにNetflowがないのでフォーラムに問い合わせしてみたら, 「ElastiFlowをおすすめする」と言われたのでそちらでやってみた。

手順はここにある。
https://github.com/robcowart/elastiflow

しかし必要リソースが多い・・・。

flows/sec (v)CPUs Memory Disk (30-days) ES JVM Heap LS JVM Heap
250 4 24 GB 305 GB 8 GB 4 GB
1000 8 32 GB 1.22 TB 12 GB 4 GB
2500 12 64 GB 3.05 TB 24 GB 6 GB

手順

  1. 確認
  2. Javaのヒープサイズ確認
  3. Logstash Pluginインストール
  4. Git Hubから関連ファイル取得・配置
  5. 設定ファイル編集
  6. プロセス再起動
  7. Kibanaでインデックス作成・ダッシュボードjsonを読み込む

アップデート

もろもろアップデートしておく。なお, Elasticsearchのバージョンは6.2.4。

yum update -y

Javaのヒープサイズ変更

It is recommended that Logstash be given at least 2GB of JVM heap. If all options, incl. DNS lookups (requires version 3.0.10 or later of the DNS filter), are enabled increase this to 4GB. 

とあったので初期値1G, MAX値を4Gへ変更。

vi /etc/logstash/jvm.options
# Xms represents the initial size of total heap space
# Xmx represents the maximum size of total heap space

#-Xms256m
#-Xmx1g
-Xms1g
-Xmx4g

Logstash Pluginインストール

# ./logstash-plugin install logstash-codec-sflow
Validating logstash-codec-sflow
Installing logstash-codec-sflow
Installation successful
# ./logstash-plugin update logstash-codec-netflow
Updating logstash-codec-netflow
Updated logstash-codec-netflow 3.13.2 to 3.14.0
# ./logstash-plugin update logstash-input-udp
Updating logstash-input-udp
Updated logstash-input-udp 3.3.2 to 3.3.3
# ./logstash-plugin update logstash-filter-dns
Updating logstash-filter-dns
Updated logstash-filter-dns 3.0.9 to 3.0.10

Git Hubから関連ファイル取得・配置・編集

% git clone https://github.com/robcowart/elastiflow.git
% ls -l elastiflow
total 32
drwxrwxr-x. 2 centos centos 75 May 24 20:02 kibana
-rw-rw-r--. 1 centos centos 1026 May 24 20:02 LICENSE.md
drwxrwxr-x. 3 centos centos 23 May 24 20:02 logstash
drwxrwxr-x. 2 centos centos 54 May 24 22:49 logstash.service.d
drwxrwxr-x. 2 centos centos 26 May 24 20:02 profile.d
-rw-rw-r--. 1 centos centos 28091 May 24 20:02 README.md

設定ファイル配置

# cp -r ./elastiflow/logstash/elastiflow/ /etc/logstash/

設定ファイル編集。
netflow以外使わないので, それ以外のファイルはdisableにした。

10_input_ipfix_ipv4.logstash.conf.disabled
10_input_ipfix_ipv6.logstash.conf.disabled
10_input_netflow_ipv4.logstash.conf
10_input_netflow_ipv6.logstash.conf.disabled
10_input_sflow_ipv4.logstash.conf.disabled
10_input_sflow_ipv6.logstash.conf.disabled
20_filter_10_begin.logstash.conf
20_filter_20_netflow.logstash.conf
20_filter_30_ipfix.logstash.conf.disabled
20_filter_40_sflow.logstash.conf.disabled
20_filter_90_post_process.logstash.conf
30_output.logstash.conf

インプットファイル編集

# vi 10_input_netflow_ipv4.logstash.conf

変更点。

host => "${ELASTIFLOW_NETFLOW_IPV4_HOST:172.16.10.50}"
port => "${ELASTIFLOW_NETFLOW_IPV4_PORT:9995}"

アウトプットファイル編集

# vi 30_output.logstash.conf

変更点。

hosts => [ "${ELASTIFLOW_ES_HOST:172.16.10.50:9200}" ]
user => "${ELASTIFLOW_ES_USER:elastic}"
password => "${ELASTIFLOW_ES_PASSWD:elastic}"

起動スクリプト配置

# cp -r ./elastiflow/logstash.service.d/ /etc/systemd/system/

起動スクリプト編集

# vi /etc/systemd/system/logstash.service.d/elastiflow.conf

変えたところは以下。

Environment="ELASTIFLOW_NAMESERVER=1.1.1.1"
Environment="ELASTIFLOW_ES_HOST=172.16.10.50"
Environment="ELASTIFLOW_ES_PASSWD=changeme"
Environment="ELASTIFLOW_NETFLOW_IPV4_HOST=172.16.10.50"
Environment="ELASTIFLOW_NETFLOW_IPV4_PORT=9995"

アプリケーションID登録。

# vi /etc/logstash/elastiflow/dictionaries/app_id.srctype.yml

Cisco841を登録。

"192.168.1.2": "c841m"

pipeline.ymlに以下追加。合わせてnetflowの行はコメントアウト。

# For ElastiFlow
- pipeline.id: elastiflow
path.config: "/etc/logstash/elastiflow/conf.d/*.conf"

プロセス再起動

#systemctl restart logstash
#systemctl daemon-reload

Kibanaにjson取り込み

「Management -> Save Objects -> Import」でGitから取得したelastiflow.dashboards.jsonをインポート。

できた!

ただ, うちの仮想マシンのスペック不足で結構な頻度でエラーが出る。
この辺は今の状況ではどうしようもないなー。