文章目录
- 一:拉取 kafka镜像: docker pull bitnami/kafka
- 二:运行 kafka容器: docker run containerId
- 三:开放防火墙
一:拉取 kafka镜像: docker pull bitnami/kafka
docker search kafka
docker pull bitnami/kafka
[root@vboxnode3ccccccttttttchenyang data]# docker pull bitnami/kafka
Using default tag: latest
latest: Pulling from bitnami/kafka
0796bf144e3f: Pull complete
6d8d1650718e: Retrying in 12 seconds
295a174e4cfb: Retrying in 1 second
165586489a46: Retrying in 1 second
462b8c8ce5a5: Waiting
8a9dcdf65003: Waiting
47c266a8c4bf: Waiting
baacf938d67b: Waiting
4f65080d9aff: Waiting
7598e22d2eda: Waiting
1bed0f0253ed: Waiting
cf9a6955b62d: Waiting
6de0db3a4a7b: Waiting
latest: Pulling from bitnami/kafka
b9dd917e5b67: Pull complete
Digest: sha256:510326ce7bec53d5cdd4be948228871f4f5732af9cfde168be0f15c94ae0d7ee
Status: Downloaded newer image for bitnami/kafka:latest
docker.io/bitnami/kafka:latest
二:运行 kafka容器: docker run containerId
在Kafka集群中,每个broker都有一个唯一的id值用来区分彼此。
Kafka在启动时会在zookeeper中/brokers/ids路径下创建一个与当前broker的id为名称的虚节点,Kafka的健康状态检查就依赖于此节点。
当broker下线时,该虚节点会自动删除,其他broker或者客户端通过判断/brokers/ids路径下是否有此broker的id来确定该broker的健康状态。
docker run -d --name kafka -p 9092:9092 --restart=always \
> -e KAFKA_BROKER_ID=0 \
> -e ALLOW_PLAINTEXT_LISTENER=yes \
> -e KAFKA_CFG_ZOOKEEPER_CONNECT=192.168.56.103:2181 \
> -e KAFKA_CFG_ADVERTISED_LISTENERS=PLAINTEXT://192.168.56.103:9092 \
> -e TZ="Asia/Shanghai" bitnami/kafka:latest
[root@vboxnode3ccccccttttttchenyang data]# docker run -d --name kafka -p 9092:9092 --restart=always \
> -e KAFKA_BROKER_ID=0 \
> -e ALLOW_PLAINTEXT_LISTENER=yes \
> -e KAFKA_CFG_ZOOKEEPER_CONNECT=192.168.56.103:2181 \
> -e KAFKA_CFG_ADVERTISED_LISTENERS=PLAINTEXT://192.168.56.103:9092 \
> -e TZ="Asia/Shanghai" bitnami/kafka:latest
a3e131e6907dbfb57e330ba2e8d65fecde7f6d3f582e9f5c12fc631abecca317
[root@vboxnode3ccccccttttttchenyang data]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
a3e131e6907d bitnami/kafka:latest "/opt/bitnami/script…" 13 seconds ago Up 12 seconds 0.0.0.0:9092->9092/tcp, :::9092->9092/tcp kafka
c69d6caece82 08616d26b8e7 "start_runit" 20 minutes ago Up 20 minutes k8s_calico-node_calico-node-m84mj_kube-system_ab5d7060-5c41-4ec1-b089-3285a140c7d9_4
490e4d88400c a4ca41631cc7 "/coredns -conf /etc…" 20 minutes ago Up 20 minutes k8s_coredns_coredns-545d6fc579-bn8hg_kube-system_cd934cf8-f20a-4c51-949d-5ce889e92d39_3
三:开放防火墙
[root@vboxnode3ccccccttttttchenyang data]# firewall-cmd --permanent --zone=public --add-port=9092/tcp
success
[root@vboxnode3ccccccttttttchenyang data]# firewall-cmd --reload
success
[root@vboxnode3ccccccttttttchenyang data]# firewall-cmd --permanent --zone=public --list-port
3306/tcp 8848/tcp 8091/tcp 8879/tcp 8887/tcp 8083/tcp 8086/tcp 8090/tcp 8099/tcp 9600/tcp 4560/tcp 5601/tcp 443/tcp 8443/tcp 30001/tcp 6443/tcp 2181/tcp 9092/tcp
[root@vboxnode3ccccccttttttchenyang data]#