Centos8.2环境下docker安装配置Kafka和zookeeper

Centos8.2环境下docker安装配置Kafka和zookeeper

1.下载kafka和Zookeeper镜像

docker pull wurstmeister/kafka
docker pull wurstmeister/zookeeper

2.查看镜像

[root@localhost ~]# docker images
REPOSITORY               TAG                 IMAGE ID            CREATED             SIZE
wurstmeister/kafka       latest              40094a582680        3 months ago        435MB
wurstmeister/zookeeper   latest              3f43f72cb283        22 months ago       510MB

3.运行zookeeper

docker run -d --name zookeeper -p 2181:2181 -t wurstmeister/zookeeper

## 4.运行kafka

``docker run --name kafka \
-p 9092:9092 \
-e KAFKA_BROKER_ID=0 \
-e KAFKA_ZOOKEEPER_CONNECT=192.168.200.129:2181 \
-e KAFKA_ADVERTISED_LISTENERS=PLAINTEXT://192.168.200.129:9092 \
-e KAFKA_LISTENERS=PLAINTEXT://0.0.0.0:9092 \
-d  wurstmeister/kafka  
## 5.查看容器状态

```java
[root@localhost ~]# docker ps -a
CONTAINER ID        IMAGE                    COMMAND                  CREATED             STATUS              PORTS                                                NAMES
7b18d4e2c2f7        wurstmeister/kafka       "start-kafka.sh"         10 hours ago        Up 46 minutes       0.0.0.0:9092->9092/tcp                               kafka
8d5c19706fe8        wurstmeister/zookeeper   "/bin/sh -c '/usr/sb…"   10 hours ago        Up About an hour    22/tcp, 2888/tcp, 3888/tcp, 0.0.0.0:2181->2181/tcp   zookeeper

6.测试

6.1进入kafka容器里面

[root@localhost ~]# docker exec -it kafka /bin/bash
bash-4.4# 

6.2 切换到如下目录下

bash-4.4# cd /opt/kafka_2.13-2.6.0/bin
bash-4.4# ls
connect-distributed.sh               kafka-consumer-perf-test.sh          kafka-reassign-partitions.sh         trogdor.sh
connect-mirror-maker.sh              kafka-delegation-tokens.sh           kafka-replica-verification.sh        windows
connect-standalone.sh                kafka-delete-records.sh              kafka-run-class.sh                   zookeeper-security-migration.sh
kafka-acls.sh                        kafka-dump-log.sh                    kafka-server-start.sh                zookeeper-server-start.sh
kafka-broker-api-versions.sh         kafka-leader-election.sh             kafka-server-stop.sh                 zookeeper-server-stop.sh
kafka-configs.sh                     kafka-log-dirs.sh                    kafka-streams-application-reset.sh   zookeeper-shell.sh
kafka-console-consumer.sh            kafka-mirror-maker.sh                kafka-topics.sh
kafka-console-producer.sh            kafka-preferred-replica-election.sh  kafka-verifiable-consumer.sh
kafka-consumer-groups.sh             kafka-producer-perf-test.sh          kafka-verifiable-producer.sh

6.3 启动消息发送方

bash-4.4# ./kafka-console-producer.sh --broker-list 192.168.200.129:9092 --topic mykafka
>

# 6.4 重新打开一个终端,进入kafka容器,切换到/opt/kafka_2.13-2.6.0/bin目录下,然后启动消息消费方

```java
bash-4.4# ./kafka-console-consumer.sh --bootstrap-server 192.168.200.129:9092 --topic mykafka --from-beginning

## 6.5 在消息发送方终端输入

```java
bash-4.4# ./kafka-console-producer.sh --broker-list 192.168.200.129:9092 --topic mykafka
>hello world

6.6 在消息消费方看到如下内容,即表示kafka和zookeeper环境搭建成功

bash-4.4# ./kafka-console-consumer.sh --bootstrap-server 192.168.200.129:9092 --topic mykafka --from-beginning
./bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 --topic mykafka --from-beginning
hello world

6.7 redis容器设置密码和开机自启动

docker run -d --name fuyou-redis-01 -p 6379:6379 redis --requirepass “该redis容器密码”

docker update --restart=always 容器ID

7.docker安装rabbitmq并设置开机自启动

docker run -d --name rabbitmq -p 5671:5671 -p 5672:5672 -p 4369:4369 -p 25672:25672 -p 15671:15671 -p 15672:15672 rabbitmq:management

7.1开机自启动

docker update rabbitmq --restart=always

8.1 docker安装zipkin

docker run -d -p 9411:9411 openzipkin/zipkin

8.2 zip设置开机自启动

docker update intelligent_mirzakhani  --restart=always