一、安装zookeeper
# 1.拉取依赖
[root@iZ2ze55utcxcqfjjo9y750Z kiki-kafka]# docker pull wurstmeister/zookeeper
Using default tag: latest
latest: Pulling from wurstmeister/zookeeper
a3ed95caeb02: Pull complete
ef38b711a50f: Pull complete
e057c74597c7: Pull complete
666c214f6385: Pull complete
c3d6a96f1ffc: Pull complete
3fe26a83e0ca: Pull complete
3d3a7dd3a3b1: Pull complete
f8cc938abe5f: Pull complete
9978b75f7a58: Pull complete
4d4dbcc8f8cc: Pull complete
8b130a9baa49: Pull complete
6b9611650a73: Pull complete
5df5aac51927: Pull complete
76eea4448d9b: Pull complete
8b66990876c6: Pull complete
f0dd38204b6f: Pull complete
Digest: sha256:7a7fd44a72104bfbd24a77844bad5fabc86485b036f988ea927d1780782a6680
Status: Downloaded newer image for wurstmeister/zookeeper:latest
docker.io/wurstmeister/zookeeper:latest
# 后台运行zookeeper
docker run -d --restart=always --name kiki-zookeeper -p 2181:2181 wurstmeister/zookeeper
[root@iZ2ze55utcxcqfjjo9y750Z localtime]# docker pull wurstmeister/kafka
Using default tag: latest
latest: Pulling from wurstmeister/kafka
540db60ca938: Pull complete
f0698009749d: Pull complete
d67ee08425e3: Pull complete
1a56bfced4ac: Pull complete
dccb9e5a402a: Pull complete
Digest: sha256:4916aa312512d255a6d82bed2dc5fbee29df717fd9efbdfd673fc81c6ce03a5f
Status: Downloaded newer image for wurstmeister/kafka:latest
docker.io/wurstmeister/kafka:latest
# 后台运行kafka
docker run --name kiki-kafka -d -p 9092:9092 --restart=always -e KAFKA_BROKER_ID=0 -e KAFKA_ZOOKEEPER_ConNECT=8.131.80.230:2181/kafka -e KAFKA_ADVERTISED_LISTENERS=PLAINTEXT://8.131.80.230:9092 -e KAFKA_LISTENERS=PLAINTEXT://0.0.0.0:9092 wurstmeister/kafka
#以交互模式进入
docker exec -it kikic-kafka bash
# 进入bin
cd /opt/kafka_2.13-2.8.1/bin/
#然后启动生产者
./kafka-console-producer.sh --broker-list localhost:9092 --topic mmr
#发送消息
bash-5.1# ./kafka-console-producer.sh --broker-list localhost:9092 --topic mmr
>hi,kiki
[2022-03-14 13:25:02,827] WARN [Producer clientId=console-producer] Error while fetching metadata with correlation id 3 : {mmr=LEADER_NOT_AVAILABLE} (org.apache.kafka.clients.NetworkClient)
[2022-03-14 13:25:02,930] WARN [Producer clientId=console-producer] Error while fetching metadata with correlation id 4 : {mmr=LEADER_NOT_AVAILABLE} (org.apache.kafka.clients.NetworkClient)
[2022-03-14 13:25:03,039] WARN [Producer clientId=console-producer] Error while fetching metadata with correlation id 5 : {mmr=LEADER_NOT_AVAILABLE} (org.apache.kafka.clients.NetworkClient)
[2022-03-14 13:25:03,147] WARN [Producer clientId=console-producer] Error while fetching metadata with correlation id 6 : {mmr=LEADER_NOT_AVAILABLE} (org.apache.kafka.clients.NetworkClient)
[2022-03-14 13:25:03,254] WARN [Producer clientId=console-producer] Error while fetching metadata with correlation id 7 : {mmr=LEADER_NOT_AVAILABLE} (org.apache.kafka.clients.NetworkClient)
>
#消费者消费消息
[root@iZ2ze55utcxcqfjjo9y750Z ~]# docker exec -it kiki-kafka bash
bash-5.1# cd /opt/kafka_2.13-2.8.1/bin
bash-5.1# ./kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic mmr --from-beginning
hi,kiki