侧边栏壁纸
博主头像
实习两年半

基础不牢,地动山摇。

  • 累计撰写 43 篇文章
  • 累计创建 40 个标签
  • 累计收到 4 条评论

目 录CONTENT

文章目录

Docker安装Zookeeper和Kafka

实习两年半
2023-07-15 / 0 评论 / 0 点赞 / 715 阅读 / 403 字
温馨提示:
本文最后更新于 2023-07-15,若内容或图片失效,请留言反馈。部分素材来自网络,若不小心影响到您的利益,请联系我们删除。

下载镜像

  1. zookeeper
docker pull zookeeper 
  1. kafka
docker pull wurstmeister/kafka:latest

启动zookeeper

  1. 创建需要的挂在的问文件目录
mkdir -p /AppService/zookeeper/data  # 数据挂载目录
mkdir -p /AppService/zookeeper/conf  # 配置挂载目录
mkdir -p /AppService/zookeeper/logs  # 日志挂载目录
  1. /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
  1. 启动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

启动状态

image-1689430007387

image-1689430023856

0

评论区