赞
踩
docker pull wurstmeister/zookeeper
docker pull wurstmeister/kafka
docker run -d --name zookeeper -p 2181:2181 -t wurstmeister/zookeeper
docker run -d --name kafka --publish 9092:9092
--link zookeeper
--env KAFKA_ZOOKEEPER_CONNECT=zookeeper:2181
--env KAFKA_ADVERTISED_HOST_NAME=192.168.59.101
--env KAFKA_ADVERTISED_PORT=9092
--volume /etc/localtime:/etc/localtime
wurstmeister/kafka:latest
运行 docker ps,找到kafka的 CONTAINER ID,运行 docker exec -it ${CONTAINER ID} /bin/bash,进入kafka容器。进入kafka默认目录 /opt/kafka_2.11-0.10.1.0
配置文件位置:${KAFKA_HOME}/config/server.properties
修改内容如下
# 默认配置 advertised.listeners=PLAINTEXT://your.host.name:9092
advertised.listeners=PLAINTEXT://${本机服务器IP}:9092
# broker.id标识本机
broker.id=0
# log.dirs
log.dirs=/data/logs/kafka-logs
# zookeeper.connect指定连接的zookeeper集群地址
三台机器:192.168.244.128 192.168.244.130 192.168.244.131
# 192.168.244.128
broker.id=1
log.dirs=/data/logs/kafka-logs
zookeeper.connect=192.168.244.128:2181,192.168.244.130:2181,192.168.244.131:2181
# 192.168.244.130
broker.id=2
log.dirs=/data/logs/kafka-logs
zookeeper.connect=192.168.244.128:2181,192.168.244.130:2181,192.168.244.131:2181
# 192.168.244.131
broker.id=3
log.dirs=/data/logs/kafka-logs
zookeeper.connect=192.168.244.128:2181,192.168.244.130:2181,192.168.244.131:2181
在三个节点上分别执行nohup ./kafka-server-start.sh -daemon ../config/server.properties &
# 创建TOPIC
./kafka-topics.sh --create --zookeeper 192.168.244.128:2181,192.168.244.130:2181,192.168.244.131:2181 --replication-factor 3 --partitions 6 --topic kfk_test
#列出创建的topic
./kafka-topics.sh --list --zookeeper 192.168.244.128:2181,192.168.244.130:2181,192.168.244.131:2181
# 生成数据,注意这里的端口号是kafka的端口 9092
./kafka-console-producer.sh -broker-list 192.168.244.128:9092,192.168.244.130:9092,192.168.244.131:9092 --topic kfk_test
# 消费生产数据,kafka 0.9版本之前用zookeeper
./kafka-console-consumer.sh --zookeeper 192.168.244.128:2181,192.168.244.130:2181,192.168.244.131:2181 --from-beginning --topic kfk_test
# kafka 0.9版本之后不推荐zookeeper方式,仍然支持,但逐渐会被取消,推荐bootstrap-server方式,注意这里的端口号是kafka的端口 9092
./kafka-console-consumer.sh --bootstrap-server 192.168.244.128:9092,192.168.244.130:9092,192.168.244.131:9092 --from-beginning --topic kfk_test
#查看指定topic信息
./kafka-topics.sh --describe --zookeeper 192.168.244.128:2181,192.168.244.130:2181,192.168.244.131:2181 --topic kfk_test
#删除kafka中的topic
./kafka-topics.sh --delete --zookeeper 192.168.244.128:2181,192.168.244.130:2181,192.168.244.131:2181 --topic kfk_test
# 删除zookeeper中的topic信息
rmr /brokers/topics/kfk_test
rmr /config/topics/kfk_test
rmr /admin/delete_topics/kfk_test
rmr /consumers/kfk_test-group
# 删除topic数据相关的目录
rm -rf /var/local/kafka/data/kfk_test*
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。