Bootstrap

Docker安装kafka

1、拉取zookeeper镜像

kafka需要zookeeper管理,所以需要先安装zookeeper。

docker pull zookeeper:3.6

2、启动zookeeper容器

docker run -d --name zookeeper -p 2181:2181 -v /etc/localtime:/etc/localtime zookeeper:3.6

3、拉取kafka镜像

docker pull wurstmeister/kafka:2.12-2.5.0

[root@~]$docker pull wurstmeister/kafka:2.12-2.5.0
Trying to pull repository docker.io/wurstmeister/kafka ...
2.12-2.5.0: Pulling from docker.io/wurstmeister/kafka
e7c96db7181b: Already exists
f910a506b6cb: Pull complete
b6abafe80f63: Pull complete
9daa71a3a025: Pull complete
a4cad7b8f41a: Pull complete
d77df92e7131: Pull complete
Digest: sha256:ec8dfb24c643b73903905fdd2b7bbffe818891fdba968bd97c8a8057bd01f3c7
Status: Downloaded newer image for docker.io/wurstmeister/kafka:2.12-2.5.0
复制代码

4、启动kafka镜像

启动kafka镜像生成容器
## docker run -d --name kafka -p 9002:9002 -e KAFKA_BROKER_ID=0 -e KAFKA_ZOOKEEPER_CONNECT=192.168.124.28:2181/kafka -e KAFKA_ADVERTISED_LISTENERS=PLAINTEXT://192.168.124.28:9002 -e KAFKA_LISTENERS=PLAINTEXT://0.0.0.0:9002 -v /etc/localtime:/etc/localtime wurstmeister/kafka:2.12-2.5.0
$ docker run -d --restart=always --log-driver json-file --log-opt max-size=100m --log-opt max-file=2 --name kafka -p 9002:9002 -e KAFKA_BROKER_ID=0 -e KAFKA_ZOOKEEPER_CONNECT=172.16.152.136:2181/kafka -e KAFKA_ADVERTISED_LISTENERS=PLAINTEXT://172.16.152.136:9002 -e KAFKA_LISTENERS=PLAINTEXT://0.0.0.0:9002 -v /etc/localtime:/etc/localtime wurstmeister/kafka:2.12-2.5.0
参数说明:
-e KAFKA_BROKER_ID=0  在kafka集群中,每个kafka都有一个BROKER_ID来区分自己

-e KAFKA_ZOOKEEPER_CONNECT=192.168.124.28:2181/kafka 配置zookeeper管理kafka的路径192.168.124.28:2181/kafka

-e KAFKA_ADVERTISED_LISTENERS=PLAINTEXT://192.168.124.28:9002  把kafka的地址端口注册给zookeeper,如果是远程访问要改成外网IP,类如Java程序访问出现无法
;