docker-compose安装kafka集群
docker-compose 安装kafka集群
·
先行安装docker,docker-compose服务
编写docker-compose.yml
version: '3'
services:
zookeeper:
image: bitnami/zookeeper:latest
container_name: zookeeper
ports:
- 2181:2181
environment:
- ALLOW_ANONYMOUS_LOGIN=yes
volumes:
- ./zookeeper:/bitnami/zookeeper
restart: always
kafka1:
image: bitnami/kafka:2.8.0
container_name: kafka1
ports:
- 9092:9092
- 9992:9992
environment:
- KAFKA_BROKER_ID=1
- KAFKA_CFG_LISTENERS=PLAINTEXT://:9092
- KAFKA_CFG_ADVERTISED_LISTENERS=PLAINTEXT://192.168.229.128:9092
- KAFKA_CFG_ZOOKEEPER_CONNECT=zookeeper:2181
- ALLOW_PLAINTEXT_LISTENER=yes
- KAFKA_CFG_AUTO_CREATE_TOPICS_ENABLE=false
- KAFKA_CFG_LOG_RETENTION_HOURS=6
- JMX_PORT=9992
volumes:
- ./kafka1:/bitnami/kafka
depends_on:
- zookeeper
restart: always
kafka2:
image: bitnami/kafka:2.8.0
container_name: kafka2
ports:
- 9093:9093
- 9993:9993
environment:
- KAFKA_BROKER_ID=2
- KAFKA_CFG_LISTENERS=PLAINTEXT://:9093
- KAFKA_CFG_ADVERTISED_LISTENERS=PLAINTEXT://192.168.229.128:9093
- KAFKA_CFG_ZOOKEEPER_CONNECT=zookeeper:2181
- ALLOW_PLAINTEXT_LISTENER=yes
- KAFKA_CFG_AUTO_CREATE_TOPICS_ENABLE=false
- KAFKA_CFG_LOG_RETENTION_HOURS=6
- JMX_PORT=9993
volumes:
- ./kafka2:/bitnami/kafka
depends_on:
- zookeeper
restart: always
kafka3:
image: bitnami/kafka:2.8.0
container_name: kafka3
ports:
- 9094:9094
- 9994:9994
environment:
- KAFKA_BROKER_ID=3
- KAFKA_CFG_LISTENERS=PLAINTEXT://:9094
- KAFKA_CFG_ADVERTISED_LISTENERS=PLAINTEXT://192.168.229.128:9094
- KAFKA_CFG_ZOOKEEPER_CONNECT=zookeeper:2181
- ALLOW_PLAINTEXT_LISTENER=yes
- KAFKA_CFG_AUTO_CREATE_TOPICS_ENABLE=false
- KAFKA_CFG_LOG_RETENTION_HOURS=6
- JMX_PORT=9994
volumes:
- ./kafka3:/bitnami/kafka
depends_on:
- zookeeper
restart: always
kafka-manager:
image: hlebalbau/kafka-manager:latest
container_name: kafka-manager
ports:
- 9000:9000
environment:
ZK_HOSTS: zookeeper:2181
depends_on:
- zookeeper
- kafka1
- kafka2
- kafka3
当前目录下:
docker-compose up -d 启动
docker-compose ps 查询服务基本信息(启动时间,端口等)
docker-compose logs -f {name} 查询日志
ps:挂载目录权限问题
mkdir: cannot create directory ‘/bitnami/zookeeper/data’: Permission denied
需要为挂载目录./zookeeper授权,开发环境中推荐各位小伙伴为挂载目录授最高权限777;生产环境需要查看官网文档,结合实际生产环境进行授权。
以上yaml中只配置了一些基础的环境变量,更多的设置参数,请参考链接
更多推荐
已为社区贡献1条内容
所有评论(0)