docker安装不在这里叙述,镜像不是本人制作,用的现成的,没有在集群下实验,适合单机快速启动
安装zookeeper
docker run -d --name zookeeper --net=host -t wurstmeister/zookeeper
安装kafka 需要改配置文件还有变量IP
docker run --name kafka -d -e KAFKA_ADVERTISED_HOST_NAME=“10.4.59.119” -e HOST_IP=IP -e KAFKA_ZOOKEEPER_CONNECT=“IP:2181” --net=host -v /opt/kafka/config/server.properties:/opt/kafka_2.12-1.0.0/config/server.properties -v /etc/localtime:/etc/localtime:ro -e KAFKA_ADVERTISED_PORT=9092 -e KAFKA_BROKER_ID=1 -t wurstmeister/kafka
验证
#进入容器
#docker exec -it kafka /bin/bash
#创建topic test2
bash-4.3# kafka-topics.sh --create --zookeeper IP:2181 --replication-factor 1 --partitions 1 --topic test
Created topic “test2”.
#查询topic
bash-4.3# kafka-topics.sh --list --zookeeper IP:2181
__consumer_offsets
test
test1
test2
#发送消息,发送后ctrl+c退出即可
bash-4.3# kafka-console-producer.sh --broker-list IP:9092 --topic test2
nihao test2
#读取消息
^Cbash-4.3# kafka-console-consumer.sh --zookeeper IP:2181 --topic test2 --from-beginning
Using the ConsoleConsumer with old consumer is deprecated and will be removed in a future major release. Consider using the new consumer by passing [bootstrap-server] instead of [zookeeper].
nihao test2