通过Docker单机部署Zookeeper/Kafka

生产环境的Kafka一般都是集群部署,但是有时候为了测试方便,快速部署一套单机版的Kafka还是狠提高效率的!

1、编写docker-compose.yml:

version: '2'
services:
  zookeeper:
    container_name: zookeeper
    image: wurstmeister/zookeeper
    restart: always 
    volumes:
      - ./zookeeper/data:/data
    ports:
      - "2181:2181"
        
  kafka:
    container_name: kafka
    image: wurstmeister/kafka
    restart: always 
    ports:
      - "9092:9092"
    environment:
      KAFKA_ADVERTISED_HOST_NAME: 10.206.73.139
      KAFKA_MESSAGE_MAX_BYTES: 2000000
      KAFKA_CREATE_TOPICS: "test:1:1"
      KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181
    volumes:
      - ./kafka:/kafka
      - /var/run/docker.sock:/var/run/docker.sock
  
  kafka-manager:
    container_name: kafka-manager
    image: sheepkiller/kafka-manager
    restart: always 
    ports:
      - 9020:9000
    environment:
      ZK_HOSTS: zookeeper:2181

2、常用命令:

# 启动:
$ docker-compose up -d
 
# 删除容器:
$ docker-compose down
 
# 增加更多Broker:
$ docker-compose scale kafka=3
 
# 合并:
$ docker-compose up --scale kafka=3

3、使用客户端连接:

image.png

4、使用kafka-manager连接:

image.png

jiguiquan@163.com

文章作者信息...

留下你的评论

*评论支持代码高亮<pre class="prettyprint linenums">代码</pre>

相关推荐