1.新建网络

docker network ls #查看当前网络
docker network create --subnet=172.18.0.0/16 mynetwork #创建子网段为172.18.0.0/16 的IP网络

2.zk集群docker-compose.yml

version: '3.4'
services:
 zoo1:
  image: zookeeper:3.4 # 镜像名称
  restart: always # 当发生错误时自动重启
  hostname: zoo1
  container_name: zoo1
  privileged: true
  ports: # 端口
   - 2184:2181
  volumes: # 挂载数据卷
   - ./zoo1/data:/data
   - ./zoo1/datalog:/datalog
  environment:
   TZ: Asia/Shanghai
   ZOO_MY_ID: 1 # 节点ID
   ZOO_PORT: 2181 # zookeeper端口号
   ZOO_SERVERS: server.1=zoo1:2888:3888 server.2=zoo2:2888:3888 server.3=zoo3:2888:3888 # zookeeper节点列表
  networks:
   mynetwork:
    ipv4_address: 172.18.0.4
 zoo2:
  image: zookeeper:3.4
  restart: always
  hostname: zoo2
  container_name: zoo2
  privileged: true
  ports:
   - 2182:2181
  volumes:
   - ./zoo2/data:/data
   - ./zoo2/datalog:/datalog
  environment:
   TZ: Asia/Shanghai
   ZOO_MY_ID: 2
   ZOO_PORT: 2181
   ZOO_SERVERS: server.1=zoo1:2888:3888 server.2=zoo2:2888:3888 server.3=zoo3:2888:3888
  networks:
   mynetwork:
    ipv4_address: 172.18.0.5
 zoo3:
  image: zookeeper:3.4
  restart: always
  hostname: zoo3
  container_name: zoo3
  privileged: true
  ports:
   - 2183:2181
  volumes:
   - ./zoo3/data:/data
   - ./zoo3/datalog:/datalog
  environment:
   TZ: Asia/Shanghai
   ZOO_MY_ID: 3
   ZOO_PORT: 2181
   ZOO_SERVERS: server.1=zoo1:2888:3888 server.2=zoo2:2888:3888 server.3=zoo3:2888:3888
  networks:
   mynetwork:
    ipv4_address: 172.18.0.6
networks:
 mynetwork:
  external:
   name: mynetwork

3.kafka集群docker-compose.yml

version: '2'
services:
 broker1:
  image: wurstmeister/kafka
  restart: always
  hostname: broker1
  container_name: broker1
  privileged: true
  ports:
   - "9091:9092"
  environment:
   KAFKA_BROKER_ID: 1
   KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://服务器ip:9091
   KAFKA_ADVERTISED_HOST_NAME: 服务器ip
   KAFKA_ADVERTISED_PORT: 9091
   KAFKA_ZOOKEEPER_CONNECT: zoo1:2181,zoo2:2181,zoo3:2181
   JMX_PORT: 9988
  volumes:
   - /var/run/docker.sock:/var/run/docker.sock
   - ./broker1:/kafka/kafka\-logs\-broker1
  external_links:
  - zoo1
  - zoo2
  - zoo3
  networks:
   mynetwork:
    ipv4_address: 172.18.0.14
 broker2:
  image: wurstmeister/kafka
  restart: always
  hostname: broker2
  container_name: broker2
  privileged: true
  ports:
   - "9092:9092"
  environment:
   KAFKA_BROKER_ID: 2
   KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://服务器ip:9092
   KAFKA_ADVERTISED_HOST_NAME: 服务器ip
   KAFKA_ADVERTISED_PORT: 9092
   KAFKA_ZOOKEEPER_CONNECT: zoo1:2181,zoo2:2181,zoo3:2181
   JMX_PORT: 9977
  volumes:
   - /var/run/docker.sock:/var/run/docker.sock
   - ./broker2:/kafka/kafka\-logs\-broker2
  external_links: # 连接本compose文件以外的container
  - zoo1
  - zoo2
  - zoo3
  networks:
   mynetwork:
    ipv4_address: 172.18.0.15
 broker3:
  image: wurstmeister/kafka
  restart: always
  hostname: broker3
  container_name: broker3
  privileged: true
  ports:
   - "9093:9092"
  environment:
   KAFKA_BROKER_ID: 3
   KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://服务器ip:9093
   KAFKA_ADVERTISED_HOST_NAME: 服务器ip
   KAFKA_ADVERTISED_PORT: 9093
   KAFKA_ZOOKEEPER_CONNECT: zoo1:2181,zoo2:2181,zoo3:2181
   JMX_PORT: 9999
  volumes:
   - /var/run/docker.sock:/var/run/docker.sock
   - ./broker3:/kafka/kafka\-logs\-broker3
  external_links: # 连接本compose文件以外的container
  - zoo1
  - zoo2
  - zoo3
  networks:
   mynetwork:
    ipv4_address: 172.18.0.16
 kafka-manager:
  image: sheepkiller/kafka-manager:latest
  restart: always
  container_name: kafka-manager
  hostname: kafka-manager
  ports:
   - "9000:9000"
  links:      # 连接本compose文件创建的container
   - broker1
   - broker2
   - broker3
  external_links:  # 连接本compose文件以外的container
   - zoo1
   - zoo2
   - zoo3
  environment:
   ZK_HOSTS: zoo1:2181,zoo2:2181,zoo3:2181
   KAFKA_BROKERS: broker1:9091,broker2:9092,broker3:9093
   APPLICATION_SECRET: letmein
   KM_ARGS: -Djava.net.preferIPv4Stack=true
  networks:
   mynetwork:
    ipv4_address: 172.18.0.10
networks:
 mynetwork:
  external:  # 使用已创建的网络
   name: mynetwork

4. kafka-manager配置

Cluster Zookeeper Hosts: zoo1:2181,zoo2:2181,zoo3:2181

引用

1、https://www.cnblogs.com/jay763190097/p/10292227.html
2、https://www.bbsmax.com/A/gGdXvxjYJ4/

Last modification:February 14th, 2020 at 01:51 am
如果觉得我的文章对你有用,请随意赞赏