下载镜像
- zookeeper
docker pull zookeeper
- kafka
docker pull wurstmeister/kafka:latest
启动zookeeper
- 创建需要的挂在的问文件目录
mkdir -p /AppService/zookeeper/data # 数据挂载目录
mkdir -p /AppService/zookeeper/conf # 配置挂载目录
mkdir -p /AppService/zookeeper/logs # 日志挂载目录
- 在 /AppService/zookeeper/conf 下创建zoo.cfg 配置文件
# The number of milliseconds of each tick
tickTime=2000
# The number of ticks that the initial
# synchronization phase can take
initLimit=10
# The number of ticks that can pass between
# sending a request and getting an acknowledgement
syncLimit=5
# the directory where the snapshot is stored.
# do not use /tmp for storage, /tmp here is just
# example sakes.
dataDir=/data/zookeeper/data
# the port at which the clients will connect
clientPort=2181
# the maximum number of client connections.
# increase this if you need to handle more clients
#maxClientCnxns=60
#
# Be sure to read the maintenance section of the
# administrator guide before turning on autopurge.
#
# http://zookeeper.apache.org/doc/current/zookeeperAdmin.html#sc_maintenance
#
# The number of snapshots to retain in dataDir
#autopurge.snapRetainCount=3
# Purge task interval in hours
# Set to "0" to disable auto purge feature
#autopurge.purgeInterval=1
## Metrics Providers
#
# https://prometheus.io Metrics Exporter
#metricsProvider.className=org.apache.zookeeper.metrics.prometheus.PrometheusMetricsProvider
#metricsProvider.httpPort=7000
#metricsProvider.exportJvmInfo=true
- 启动zookeeper
docker run -d \
--name zookeeper \
--privileged=true \
-p 2181:2181 \
--restart=always \
-v /AppService/zookeeper/data:/data \
-v /AppService/zookeeper/conf:/conf \
-v /AppService/zookeeper/logs:/datalog \
zookeeper
启动kafka
注意下面的命令是有问题的,其中127.0.0.1需要替换为宿主机的ip
docker run -d --name kafka \
-p 9092:9092 \
-e KAFKA_BROKER_ID=0 \
-e KAFKA_ZOOKEEPER_CONNECT=127.0.0.1:2181 \
-e KAFKA_ADVERTISED_LISTENERS=PLAINTEXT://127.0.0.1:9092 \
-e KAFKA_LISTENERS=PLAINTEXT://0.0.0.0:9092 wurstmeister/kafka
比如我的ip为 192.168.0.222
docker run -d --name kafka \
-p 9092:9092 \
-e KAFKA_BROKER_ID=0 \
-e KAFKA_ZOOKEEPER_CONNECT=192.168.0.222:2181 \
-e KAFKA_ADVERTISED_LISTENERS=PLAINTEXT://192.168.0.222:9092 \
-e KAFKA_LISTENERS=PLAINTEXT://0.0.0.0:9092 wurstmeister/kafka
评论区