docker安装kafka快速入门
1.安装zookeeper
docker search zookeeper
docker pull zookeeper
docker run -d -v /home/soft/zookeeperhost/zookeeperDataDir:/data -v /home/soft/zookeeperhost/zookeeperDataLogDir:/datalog --name zookeeper -p 2181:2181 zookeeper
2.安装kafka
docker search kafka
docker pull wurstmeister/kafka
docker run -d --name kafka -p 9092:9092 --env KAFKA_ADVERTISED_HOST_NAME=localhost -e KAFKA_ZOOKEEPER_CONNECT=localhost:2181 -e KAFKA_ADVERTISED_LISTENERS=PLAINTEXT://localhost:9092 -e KAFKA_LISTENERS=PLAINTEXT://0.0.0.0:9092 -e KAFKA_HEAP_OPTS="-Xmx256M -Xms128M" wurstmeister/kafka
3.登录kafka,创建主题,发送消息,接受消息
a.进入kafka
docker exec -it kafka bash
cd /opt/kafka_2.11-2.0.0/bin/
b.创建名为test的主题
./kafka-topics.sh --create --zookeeper localhost:2181 --replication-factor 1 --partitions 8 --topic test
c.创建提供者
./kafka-console-producer.sh --broker-list localhost:9092 --topic test
d.另起一个标签,执行如下命令 创建kafka消费者消费消息:
docker exec -it kafka bash
cd /opt/kafka_2.11-2.0.0/bin/
./kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic test --from-beginning