logstash与kafka消息传输<一>
1、版本:
logstash6.1.2、kafka-0.11、kafka-0.8.2、java1.8
Note:
Logstash requires Java 8. Java 9 is not supported. Use the official Oracle distribution or an open-source distribution such as OpenJDK.
2、下载:
https://www.elastic.co/downloads/logstash(推荐下载tar包,yum源安装总提示Unable to find JRuby.)
https://kafka.apache.org/downloads
3、安装
1)kafka
#tar xf kafka_2.11-0.11.0.2.tgz
#配置使用kafka参考我的其他文章http://www.cnblogs.com/cuishuai/p/7475356.html。
2)logstash
#tar xf logstash-6.1.2.tar.gz
#cp ./logstash-6.1.2/bin/* /usr/bin
创建配置文件:
#cat etl.conf
input{
kafka{
bootstrap_servers => ["10.10.11.2:9092"]
client_id => "shence"
#auto_offset_reset => "latest"
consumer_threads => 5
#decorate_events => true
topics => ["event_topic"]
# type => "bhy"
}
}
output {
kafka {
bootstrap_servers => "10.10.8.2:9092"
codec => json
compression_type => "gzip"
topic_id => "shence"
}
}
详细配置参考:
https://www.elastic.co/guide/en/logstash/6.1/plugins-inputs-kafka.html
https://www.elastic.co/guide/en/logstash/6.1/filter-plugins.html
https://www.elastic.co/guide/en/logstash/6.1/codec-plugins.html
https://www.elastic.co/guide/en/logstash/6.1/plugins-outputs-kafka.html
https://github.com/joekiller/logstash-kafka/blob/master/README.md
4、启动logstash
#./bin/logstash -f etl.conf
这种启动方式是前端启动关掉终端程序就退出了。可以使用nohup启动:
# nohup ./bin/logstash -f etl.conf 2>&1 &
5、检查
1)output端的kafka查看消息:
#./kafka-console-consumer.sh --zookeeper localhost:2181 --topic shence
2)output端kafka查看topic
#./kafka-topics.sh --list --zookeeper localhost:2181
3) output端kafka查看topic shence的详细信息:
#./kafka-topics.sh --describe --zookeeper localhost:2181 --topic shence
6、报错解决
1)启动logstash的时候报错:
Unable to find JRuby.
If you are a user, this is a bug.
If you are a developer, please run 'rake bootstrap'. Running 'rake' requires the 'ruby' program be available.
解决方式:
去官网下载tar解压,使用bin下的logstash启动,就好了。
2)启动logstash后,发现没有数据进来,并有如下报错:
Error while fetching metadata with correlation id 39 : {shence=
LEADER_NOT_AVAILABLE
}
(org.apache.kafka.clients.NetworkClient)
解决方式:
检查kafka的listen的地址:listeners = PLAINTEXT://your.host.name:9092
将your.host.name 换成服务器的ip或0.0.0.0
重启服务就好了。
我是直接重启logstash就好了