同Syslog-ng一样,Nxlog也有对应的Kafka模块,我们可以通过源码来编译安装,也能通过下面的方式快速安装。
具体步骤如下:
1、RPM包安装Nxlog普通版

yum install apr libdbi -y
rpm -ivh http://nxlog.org/system/files/products/files/1/nxlog-ce-2.9.1347-1_rhel6.x86_64.rpm

2、下载对应的Kafka文件

wget -O /usr/libexec/nxlog/modules/output/om_kafka.so http://update.biglog.cn/cep/nxlog/om_kafka.so
wget -O /lib64/librdkafka.so.1 http://update.biglog.cn/cep/nxlog/librdkafka.so.1

3、编辑Nxlog的默认配置文件:/etc/nxlog.conf

########################################
# Global directives #
########################################
User nxlog
Group nxlog
LogFile /var/log/nxlog/nxlog.log
LogLevel INFO
#LogLevel DEBUG
########################################
# Modules #
########################################
<input inFile>
Module im_file
File "/home/biglog/*.log"
SavePos TRUE
Recursive TRUE
</Input>

<output outKafka>
Module om_kafka
BrokerList 127.0.0.1:9092
Topic cdnlog
#-- Partition - defaults to RD_KAFKA_PARTITION_UA
#-- Compression, one of none, gzip, snappy
Compression snappy
#Partition 6
</output>
########################################
# Routes #
########################################
<Route 1>
  Path inFile => outKafka
</Route>

4、启动Nxlog

/etc/init.d/nxlog start

可以通过日志文件:/var/log/nxlog/nxlog.log 检查是否启动成功。