pip install kafka-python
#新建个文件
from kafka import KafkaProducer
# 设置 Kafka 地址
producer = KafkaProducer(bootstrap_servers='localhost:9092')
# 设置需要发送的 topic 及内容
producer.send('test', b'I am the most handsome man in the world! I think! ').get(timeout=30)
如果要使用内网访问,新版配置直接修改server.properties
默认zookeeper.properties是不用修改的
Kafka接入Elasticsearch
output {
输出到命令行,一般用于调试
stdout { codec => rubydebug }
输出到 Kafka,topic 名称为 logs,地址为默认的端口号
kafka { topic_id => "logs" bootstrap_servers => "10.200.136.20:9092" } }
kafka-to-es.conf
input { kafka { bootstrap_servers => "10.200.136.20:9092" topics => ["logs"] } } output {
for debugging
stdout { codec => rubydebug }
elasticsearch { hosts => "localhost:9200" index => "system-log" } }