flow indexer
v0.2.2
流索引器
flow-indexer indexes flows
Usage:
flow-indexer [command]
Available Commands:
compact Compact the database
daemon Start daemon
expandcidr Expand a CIDR range from those seen in the database
index Index flows
search Search flows
help Help about any command
Flags:
--dbpath="flows.db": Database path
-h, --help[=false]: help for flow-indexer
Use "flow-indexer [command] --help" for more information about a command.
$ export GOPATH=~/go
$ go get github.com/JustinAzoff/flow-indexer
$ cp ~/go/src/github.com/JustinAzoff/flow-indexer/example_config.json config.json
$ vi config.json # Adjust log paths and database paths.
索引配置如下:
如何分区数据库的决定因素是您每天看到多少个独特的IP。我建议从每月索引开始。如果到本月底的索引性能会大大打击,请切换到每日索引。
indexall命令将展开file_glob并索引任何匹配的日志文件。
$ ~/go/bin/flow-indexer indexall
初始索引完成后,开始守护程序。启动守护程序将展开最近的_file_glob,并索引任何匹配的最近创建的日志文件。
$ ~/go/bin/flow-indexer daemon
它将在60秒的循环中执行此操作,以保持自己的最新状态。
$ curl -s 'localhost:8080/search?i=conn&q=1.2.3.0/24'
$ curl -s 'localhost:8080/dump?i=conn&q=1.2.3.0/24'
$ curl -s 'localhost:8080/stats?i=conn&q=1.2.3.0/24'
运行流索引作为服务
要使用SystemD在系统上运行Flow-Indexer作为服务,您可以使用提供的Flow-indexer.service文件。
如果您打算在消耗贵族的系统上运行流索引作为服务,则可能需要考虑以下内容,以便从Flow-Indexer中正确使用Syslog STDOUT和STDERR,并作为非root用户运行。
# flow-indexer - Flow Indexer
#
# flow-indexer is a service that indexes and allows retrieval of flows using bro logs
description "Flow Indexer Daemon"
start on runlevel [345]
stop on runlevel [!345]
setuid flowindexer
setgid flowindexer
exec /path/to/bin/flow-indexer daemon --config /path/to/flow-indexer/config.json 2>&1 | logger -t flow-indexer
为了避免too many open files错误,您可能需要增加允许流量indexer运行的用户可以访问的打开文件的数量。这可以通过在/etc/security/limits.conf中更改nofile设置来完成,如下所示。
flowindexer soft nofile 65535
flowindexer hard nofile 65535
在实践中不再真正使用过,守护程序是使用流索引器的推荐方法。但是这些命令对于测试和开发可能很有用。
./flow-indexer --dbpath /tmp/f/flows.db index /tmp/f/conn*
2016/02/06 23:36:51 /tmp/f/conn.00:00:00-01:00:00.log.gz: Read 4260 lines in 24.392765ms
2016/02/06 23:36:51 /tmp/f/conn.00:00:00-01:00:00.log.gz: Wrote 281 unique ips in 2.215219ms
2016/02/06 23:36:51 /tmp/f/conn.01:00:00-02:00:00.log.gz: Read 4376 lines in 24.186168ms
2016/02/06 23:36:51 /tmp/f/conn.01:00:00-02:00:00.log.gz: Wrote 310 unique ips in 1.495277ms
[...]
2016/02/06 23:36:51 /tmp/f/conn.22:00:00-23:00:00.log.gz: Read 7799 lines in 18.350788ms
2016/02/06 23:36:51 /tmp/f/conn.22:00:00-23:00:00.log.gz: Wrote 775 unique ips in 5.155262ms
2016/02/06 23:36:51 /tmp/f/conn.23:00:00-00:00:00.log.gz: Read 5255 lines in 15.296847ms
2016/02/06 23:36:51 /tmp/f/conn.23:00:00-00:00:00.log.gz: Wrote 400 unique ips in 2.910344ms
./flow-indexer --dbpath /tmp/f/flows.db index /tmp/f/conn*
2016/02/06 23:37:36 /tmp/f/conn.00:00:00-01:00:00.log.gz Already indexed
2016/02/06 23:37:36 /tmp/f/conn.01:00:00-02:00:00.log.gz Already indexed
2016/02/06 23:37:36 /tmp/f/conn.02:00:00-03:00:00.log.gz Already indexed
2016/02/06 23:37:36 /tmp/f/conn.03:00:00-04:00:00.log.gz Already indexed
[...]
2016/02/06 23:37:36 /tmp/f/conn.20:00:00-21:00:00.log.gz Already indexed
2016/02/06 23:37:36 /tmp/f/conn.21:00:00-22:00:00.log.gz Already indexed
2016/02/06 23:37:36 /tmp/f/conn.22:00:00-23:00:00.log.gz Already indexed
2016/02/06 23:37:36 /tmp/f/conn.23:00:00-00:00:00.log.gz Already indexed
./flow-indexer --dbpath /tmp/f/flows.db expandcidr 192.30.252.0/24
192.30.252.86
192.30.252.87
192.30.252.92
192.30.252.124
192.30.252.125
192.30.252.126
192.30.252.127
192.30.252.128
192.30.252.129
192.30.252.130
192.30.252.131
192.30.252.141
./flow-indexer --dbpath /tmp/f/flows.db search 192.30.252.0/24
/tmp/f/conn.03:00:00-04:00:00.log.gz
/tmp/f/conn.04:00:00-05:00:00.log.gz
/tmp/f/conn.06:00:00-07:00:00.log.gz
/tmp/f/conn.14:00:00-15:00:00.log.gz
/tmp/f/conn.18:00:00-19:00:00.log.gz
/tmp/f/conn.20:00:00-21:00:00.log.gz
/tmp/f/conn.22:00:00-23:00:00.log.gz