环境说明:
Logstash部署在本地Windows环境:10.168.92.3,版本2.4.1
Kafka集群部署在虚拟服务器:
10.168.92.111,
10.168.92.112,
10.168.92.113,
ZK集群同上三台虚拟服务器
各个集群节点之间,时间要同步NTP时间服务器,
简单点:sudo date -s "2018-05-01 17:47:00"
发往全部节点
启动所有ZK
$ZK_HOME/bin/zkServer.sh start
查看所有ZK的状态
可以看出谁是Follower,谁是Leader
$ZK_HOME/bin/zkServer.sh status
启动所有Kafa
$KAFKA_HOME/bin/kafka-server-start.sh $KAFKA_HOME/config/server.properties > /dev/null 2>&1 &
安装配置Logstash
Logstash解压即可,在根目录下新建conf文件夹,在此文件夹下新建配置文件
file-to-kafka.txt
input {
file {
codec => plain {
charset => "GB2312"
}
path => "D:/BaiduNetdiskDownload/server-log/BaseDir/*/*.txt"
discover_interval => 5
start_position => "beginning"
}
}
output {
kafka {
topic_id => "gamelog"
codec => plain {
format => "%{message}"
charset => "GB2312"
}
//kafka集群的broker-list
bootstrap_servers => "kafka-01:9092,kafka-02:9092,kafka-03:9092"
}
}
启动Logstash
$LOGSTASH_HOME\bin\logstash -f ..\conf\file-to-kafka.txt
C:\Users\dummy\Downloads\logstash-2.4.1\bin>.\logstash -f ..\conf\file-to-kafka.txt
Settings: Default pipeline workers: 8
Pipeline main started
jps下,64504 org/jruby/Main
就是Logstash的进程
。
C:\Program Files\Java\jdk1.7.0_80\bin>jps -l
74916 sun.tools.jps.Jps
62732 org.jetbrains.jps.cmdline.Launcher
31256
59612
64504 org/jruby/Main
在Kafaka集群上任意一个节点启动消费者
即可经过Logstash
拉取文件到Kafka
。
kafka-console-consumer.sh --zookeeper zk-01:2181,zk-02:2181,zk-03:2181 --topic gamelog --from-beginning