当前位置:   article > 正文

1、docker部署kafka_kafka在docker上需要持久化的目录

kafka在docker上需要持久化的目录

1、部署注册中心ZooKeeper

创建ZooKeeper 挂载目录(数据挂载目录、配置挂载目录和日志挂载目录)

mkdir -p /export/server/docker/zookeeper/data # 数据挂载目录
mkdir -p /export/server/docker/zookeeper/conf # 配置挂载目录
mkdir -p /export/server/docker/zookeeper/logs # 日志挂载目录
  • 1
  • 2
  • 3

添加配置文件,挂载在/export/server/docker/zookeeper/conf 文件夹下

cd /export/server/docker/zookeeper/conf 
vim zoo.cfg
  • 1
  • 2
# 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
# 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
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35

启动ZooKeeper 容器

docker run -d \
--name zookeeper \
--privileged=true \
-p 2181:2181 \
--restart=always \
-v /export/server/docker/zookeeper/data:/data \
-v /export/server/docker/zookeeper/conf:/conf \
-v /export/server/docker/zookeeper/logs:/datalog \
zookeeper
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9

验证

查看容器状态

docker ps
  • 1

查看容器日志

docker logs zookeeper 
  • 1

查看运行状态

docker exec -it zookeeper /bin/bash 
./bin/zkServer.sh status
  • 1
  • 2

2、部署kafka

安装kafka容器

docker run -d --name kafka \
-p 9092:9092 \
-e KAFKA_BROKER_ID=0 \
-e KAFKA_ZOOKEEPER_CONNECT=192.168.43.10:2181 \
-e KAFKA_ADVERTISED_LISTENERS=PLAINTEXT://192.168.43.10:9092 \
-e KAFKA_LISTENERS=PLAINTEXT://0.0.0.0:9092 wurstmeister/kafka 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

验证kafka容器

进入kafka容器内部

docker exec -it kafka /bin/sh
  • 1

Kafka 创建Topic 流程步骤

#进入容器
docker exec -it ${CONTAINER ID} /bin/bash
cd /opt/kafka_2.13-2.8.1/bin
#单机方式:创建一个主题
bin/kafka-topics.sh --create --zookeeper 192.168.10.100:2181 --replication-factor 1 --partitions 1 --topic mykafka
#运行一个生产者
bin/kafka-console-producer.sh --broker-list 192.168.10.100:9092 --topic mykafka
#运行一个消费者
bin/kafka-console-consumer.sh --zookeeper 192.168.10.100:2181 --topic mykafka --from-beginning
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9

3、kafka客户端工具推荐 传送门

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/盐析白兔/article/detail/485462
推荐阅读
相关标签
  

闽ICP备14008679号