Based docker build kafka cluster environment

1.kafka dependent on zookeeper (portal https://www.cnblogs.com/answerThe/p/11267179.html), and it is necessary to pull kafka zookeeper mirror.

  docker pull wurstmeister/kafka

  docker pull wurstmeister/zookeeper

 

2. Start zookeeper container (wurstmeister / zookeeper has mirrored the default command "/ usr / sbin / sshd && bash /usr/bin/start-zk.sh", so just start a guardian of the container can be)

  docker run --name zookeeper -p 12181:2181 -d wurstmeister/zookeeper:latest

 

3. Start two kafka container

docker run -p 19092:9092 --name kafka1 -d -e KAFKA_BROKER_ID=0 -e KAFKA_ZOOKEEPER_CONNECT=宿主机IP:12181 -e KAFKA_ADVERTISED_LISTENERS=PLAINTEXT://宿主机IP:19092 -e KAFKA_LISTENERS=PLAINTEXT://0.0.0.0:9092 wurstmeister/kafka:latest

docker run -p 19093:9093 --name kafka2 -d -e KAFKA_BROKER_ID=1 -e KAFKA_ZOOKEEPER_CONNECT=宿主机IP:12181 -e KAFKA_ADVERTISED_LISTENERS=PLAINTEXT://宿主机IP:19093 -e KAFKA_LISTENERS=PLAINTEXT://0.0.0.0:9092 wurstmeister/kafka:latest
docker run -p 19094:9094 --name kafka3 -d -e KAFKA_BROKER_ID=2 -e KAFKA_ZOOKEEPER_CONNECT=宿主机IP:12181 -e KAFKA_ADVERTISED_LISTENERS=PLAINTEXT://宿主机IP:19094 -e KAFKA_LISTENERS=PLAINTEXT://0.0.0.0:9092 wurstmeister/kafka:latest

4. respectively into the container kafka1, kafka2, kafka3 create topic test1, test2, test3. Below kafka3 example.

# Start an interactive process in guard vessel in 
Docker Exec -i -t kafka3 / bin / bash
 # Create a theme Test3 
./kafka-topics.sh --zookeeper 192.168.181.163:12181 --creat --topic Test3 - 3 --partitions factor-1 Replication the Created topic " Test3 " 
# View topic Test3 
./kafka-topics.sh --zookeeper 192.168.181.163:12181 --describe --topic Test3

You can see, is already a cluster environment, you can see the leader machine, save a copy of the situation on the partition, and ISR list members

5. Test cluster, sending a message to test1 on kafka3, test1 consumption on kafka2

./kafka-console-producer.sh --broker-list 192.168.181.163:19092,192.168.181.163:19093,192.168.181.163:19094 --topic test1

 

 

./kafka-console-consumer.sh --bootstrap-server 192.168.181.163:19092,192.168.181.163:19093,192.168.181.163:19094 --topic test1 --from-beginning

6. Click Close kafka2, after test1 View cluster status

 

Guess you like

Origin www.cnblogs.com/answerThe/p/11267129.html