人的知识就好比一个圆圈,圆圈里面是已知的,圆圈外面是未知的。你知道得越多,圆圈也就越大,你不知道的也就越多。

0%

基于 Docker 搭建 Kafka 集群

  1. 创建 network

    1
    docker network create --driver bridge --subnet 172.22.0.0/16 --gateway 172.22.0.1  op_net
  2. 创建 zookeeper.yml

    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
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    version: '3.1'

    services:
    zk-1:
    image: zookeeper
    restart: always
    hostname: zk-1
    container_name: zk-1
    ports:
    - 2181:2181
    environment:
    ZOO_MY_ID: 1
    ZOO_SERVERS: server.1=0.0.0.0:2888:3888 server.2=zk-2:2888:3888 server.3=zk-3:2888:3888
    networks:
    default:
    ipv4_address: 172.22.0.11

    zk-2:
    image: zookeeper
    restart: always
    hostname: zk-2
    container_name: zk-2
    ports:
    - 2182:2181
    environment:
    ZOO_MY_ID: 2
    ZOO_SERVERS: server.1=zk-1:2888:3888 server.2=0.0.0.0:2888:3888 server.3=zk-3:2888:3888;
    networks:
    default:
    ipv4_address: 172.22.0.12

    zk-3:
    image: zookeeper
    restart: always
    hostname: zk-3
    container_name: zk-3
    ports:
    - 2183:2181
    environment:
    ZOO_MY_ID: 3
    ZOO_SERVERS: server.1=zk-1:2888:3888 server.2=zk-2:2888:3888 server.3=0.0.0.0:2888:3888
    networks:
    default:
    ipv4_address: 172.22.0.13

    networks:
    default:
    external:
    name: op_net
  3. 创建 kafka.yml

    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
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    version: '3.1'

    services:
    kafka-1:
    image: wurstmeister/kafka
    restart: always
    hostname: kafka-1
    container_name: kafka-1
    ports:
    - 9092:9092
    environment:
    KAFKA_LISTENERS: PLAINTEXT://0.0.0.0:9092
    KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://10.11.155.23:9092
    KAFKA_ZOOKEEPER_CONNECT: zk-1:2181,zk-2:2181,zk-3:2181
    external_links:
    - zk-1
    - zk-2
    - zk-3
    networks:
    default:
    ipv4_address: 172.22.0.14

    kafka-2:
    image: wurstmeister/kafka
    restart: always
    hostname: kafka-2
    container_name: kafka-2
    ports:
    - 9093:9092
    environment:
    KAFKA_LISTENERS: PLAINTEXT://0.0.0.0:9092
    KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://10.11.155.23:9093
    KAFKA_ZOOKEEPER_CONNECT: zk-1:2181,zk-2:2181,zk-3:2181
    external_links:
    - zk-1
    - zk-2
    - zk-3
    networks:
    default:
    ipv4_address: 172.22.0.15

    kafka-3:
    image: wurstmeister/kafka
    restart: always
    hostname: kafka-3
    container_name: kafka-3
    ports:
    - 9094:9092
    environment:
    KAFKA_LISTENERS: PLAINTEXT://0.0.0.0:9092
    KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://10.11.155.23:9094
    KAFKA_ZOOKEEPER_CONNECT: zk-1:2181,zk-2:2181,zk-3:2181
    external_links:
    - zk-1
    - zk-2
    - zk-3
    networks:
    default:
    ipv4_address: 172.22.0.16

    networks:
    default:
    external:
    name: op_net
  4. 启动 ZooKeeper 集群

    1
    docker-compose -f zookeeper.yml up -d
  5. 启动 Kafka 集群

    1
    docker-compose -f kafka.yml up -d

参考资料:

  1. docker安装zookeeper集群
  2. docker安装kafka集群
小礼物走一走,来 Github 关注我