kafka参考:、

​http://www.yunweipai.com/36806.html​

​https://www.bbsmax.com/A/QV5ZgGKVdy/​

​https://copyfuture.com/blogs-details/20210706183258030Y​

​http://www.yunweipai.com/36806.html​

​https://www.jianshu.com/p/d77149efa59f​

version: '2'
 
services:
  kafka1:
    image: wurstmeister/kafka:0.10.2.1
    restart: always
    hostname: kafka1
    container_name: kafka1
    ports:
    - "9092:9092"
    environment:
      KAFKA_BROKER_ID: 1
      KAFKA_ZOOKEEPER_CONNECT: 11.88.171.16:2181,11.88.171.20:2181,11.88.171.24:2181
      KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://11.88.171.19:9092
      KAFKA_LISTENERS: PLAINTEXT://0.0.0.0:9092
      KAFKA_NUM_PARTITIONS: 3
      KAFKA_DEFAULT_REPLICATION_FACTOR: 2
    volumes:
    - ./kafka1/logs:/kafka
     
 
  kafka2:
    image: wurstmeister/kafka:0.10.2.1
    restart: always
    hostname: kafka2
    container_name: kafka2
    ports:
    - "9093:9093"
    environment:
      KAFKA_BROKER_ID: 2
      KAFKA_ZOOKEEPER_CONNECT: 11.88.171.16:2181,11.88.171.20:2181,11.88.171.24:2181
      KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://11.88.171.19:9093
      KAFKA_LISTENERS: PLAINTEXT://0.0.0.0:9093
      KAFKA_NUM_PARTITIONS: 3
      KAFKA_DEFAULT_REPLICATION_FACTOR: 2
    volumes:
    - ./kafka2/logs:/kafka
     
 
  kafka3:
    image: wurstmeister/kafka:0.10.2.1
    restart: always
    hostname: kafka3
    container_name: kafka3
    ports:
    - "9094:9094"
    environment:
      KAFKA_BROKER_ID: 3
      KAFKA_ZOOKEEPER_CONNECT: 11.88.171.16:2181,11.88.171.20:2181,11.88.171.24:2181
      KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://11.88.171.19:9094
      KAFKA_LISTENERS: PLAINTEXT://0.0.0.0:9094
      KAFKA_NUM_PARTITIONS: 3
      KAFKA_DEFAULT_REPLICATION_FACTOR: 2
    volumes:
    - ./kafka3/logs:/kafka

 

kafka-topics.sh --create --zookeeper 11.88.171.16:2181,11.88.171.20:2181,11.88.171.24:2181 --replication-factor 3 --partitions 5 --topic www

 kafka-topics.sh --describe --zookeeper 11.88.171.16:2181,11.88.171.20:2181,11.88.171.24:2181  --topic www

kafka-console-producer.sh --broker-list 11.88.171.21:9092,11.88.171.17:9092,11.88.171.23:9092 --topic www

kafka-console-consumer.sh --bootstrap-server 11.88.171.21:9092,11.88.171.17:9092,11.88.171.23:9092 --topic www --from-beginning

  

zk参考:

​https://www.bbsmax.com/A/QV5ZgGKVdy/​

 

docker network create --driver bridge --subnet 172.168.0.0/16 --gateway 172.168.0.1  zk_network

version: '3.1'
 
services:
  zoo1:
    image: zookeeper:3.4.11
    restart: always
    hostname: zoo1
    container_name: zoo1
    ports:
      - 2181:2181
    volumes:
    - "./zoo1/data:/data"
    - "./zoo1/datalog:/datalog"
    environment:
      ZOO_MY_ID: 1
      ZOO_SERVERS: server.1=zoo1:2888:3888 server.2=zoo2:2888:3888 server.3=zoo3:2888:3888
    networks:
      zk_default:
        ipv4_address: 172.168.0.2
 
  zoo2:
    image: zookeeper:3.4.11
    restart: always
    hostname: zoo2
    container_name: zoo2
    ports:
      - 2182:2181
    volumes:
    - "./zoo2/data:/data"
    - "./zoo2/datalog:/datalog"
    environment:
      ZOO_MY_ID: 2
      ZOO_SERVERS: server.1=zoo1:2888:3888 server.2=zoo2:2888:3888 server.3=zoo3:2888:3888
    networks:
      zk_default:
        ipv4_address: 172.168.0.3
 
  zoo3:
    image: zookeeper:3.4.11
    restart: always
    hostname: zoo3
    container_name: zoo3
    ports:
      - 2183:2181
    volumes:
    - "./zoo3/data:/data"
    - "./zoo3/datalog:/datalog"
    environment:
      ZOO_MY_ID: 3
      ZOO_SERVERS: server.1=zoo1:2888:3888 server.2=zoo2:2888:3888 server.3=zoo3:2888:3888
    networks:
      zk_default:
        ipv4_address: 172.168.0.4
 
networks:
  zk_default:
    external:
      name: zk_network