在三台服务器上搭建kafka集群

Kafka集群

参考-->kafka

主机ip 服务
192.168.86.58 Kafka1,zoo1
192.168.86.19 Kafka2,zoo2
192.168.86.43 Kafka,zoo3

在主机为192.168.86.58部署kafka,zookeeper

mkdir -p /data/deploy/kafkaCluster
cd /data/deploy/kafkaCluster/
vim docker-compose.yaml

version: '3.1'
services:
  zoo1:
    image: wurstmeister/zookeeper
    restart: always
    hostname: zoo1
    container_name: zoo1
    ports:
      - 2181:2181
      - 2888:2888
      - 3888:3888
    volumes:
      - /data/wangzunbin/volume/zkcluster/zoo1/data:/data:Z
      - /data/wangzunbin/volume/zkcluster/zoo1/datalog:/datalog:Z
    environment:
      ZOO_MY_ID: 1
      ZOO_SERVERS: server.1=192.168.86.58:2888:3888:2181 server.2=192.168.86.19:2888:3888:2181 server.3=192.168.86.43:2888:3888:2181
    network_mode: host

  kafka1:
    image: wurstmeister/kafka
    restart: always
    hostname: kafka1
    container_name: kafka1
    ports:
      - 9092:9092
    environment:
      KAFKA_ADVERTISED_HOST_NAME: 192.168.86.58
      KAFKA_HOST_NAME: 192.168.86.58
      KAFKA_ADVERTISED_PORT: 9092
      KAFKA_BROKER_ID: 1
      KAFKA_ZOOKEEPER_CONNECT: 192.168.86.58:2181,192.168.86.19:2181,192.168.86.43:2181
      KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://192.168.86.58:9092
      KAFKA_LISTENERS: PLAINTEXT://192.168.86.58:9092
    volumes:
      - /data/wangzunbin/volume/kfkluster/kafka1/logs:/kafka:Z
    network_mode: host

启动: docker-compose up -d

在主机IP为192.168.86.19服务器上部署zoo2、kafka2应用服务

mkdir -p /data/deploy/kafkaCluster
cd /data/deploy/kafkaCluster/
vim docker-compose.yml

version: '3.1'
services:
  zoo2:
    image: wurstmeister/zookeeper
    restart: always
    hostname: zoo2
    container_name: zoo2
    ports:
      - 2181:2181
      - 2888:2888
      - 3888:3888
    volumes:
      - /data/wangzunbin/volume/zkcluster/zoo2/data:/data:Z
      - /data/wangzunbin/volume/zkcluster/zoo2/datalog:/datalog:Z
    environment:
      ZOO_MY_ID: 2
      ZOO_SERVERS: server.1=192.168.86.58:2888:3888;2181 server.2=192.168.86.19:2888:3888;2181 server.3=192.168.86.43:2888:3888;2181
    network_mode: host

  kafka2:
    image: wurstmeister/kafka
    restart: always
    hostname: kafka2
    container_name: kafka2
    ports:
      - 9092:9092
    environment:
      KAFKA_ADVERTISED_HOST_NAME: 192.168.86.19
      KAFKA_HOST_NAME: 192.168.86.19
      KAFKA_ADVERTISED_PORT: 9092
      KAFKA_BROKER_ID: 2
      KAFKA_ZOOKEEPER_CONNECT: 192.168.86.58:2181,192.168.86.19:2181,192.168.86.43:2181
      KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://192.168.86.19:9092
      KAFKA_LISTENERS: PLAINTEXT://192.168.86.19:9092
    volumes:
      - /data/wangzunbin/volume/kfkluster/kafka2/logs:/kafka:Z
    network_mode: host

启动: docker-compose up -d

在主机IP为192.168.86.43服务器上部署zoo3、kafka3应用服务

mkdir -p /data/deploy/kafkaCluster
cd /data/deploy/kafkaCluster/
vim docker-compose.yml

version: '3.1'
services:
  zoo3:
    image: wurstmeister/zookeeper
    restart: always
    hostname: zoo3
    container_name: zoo3
    ports:
      - 2181:2181
      - 2888:2888
      - 3888:3888
    volumes:
      - /data/wangzunbin/volume/zkcluster/zoo3/data:/data:Z
      - /data/wangzunbin/volume/zkcluster/zoo3/datalog:/datalog:Z
    environment:
      ZOO_MY_ID: 3
      ZOO_SERVERS: server.1=192.168.86.58:2888:3888;2181 server.2=192.168.86.19:2888:3888;2181 server.3=192.168.86.43:2888:3888;2181
    network_mode: host

  kafka3:
    image: wurstmeister/kafka
    restart: always
    hostname: kafka3
    container_name: kafka3
    ports:
      - 9092:9092
    environment:
      KAFKA_ADVERTISED_HOST_NAME: 192.168.86.43
      KAFKA_HOST_NAME: 192.168.86.43
      KAFKA_ADVERTISED_PORT: 9092
      KAFKA_BROKER_ID: 3
      KAFKA_ZOOKEEPER_CONNECT: 192.168.86.58:2181,192.168.86.19:2181,192.168.86.43:2181
      KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://192.168.86.43:9092
      KAFKA_LISTENERS: PLAINTEXT://192.168.86.43:9092
    volumes:
      - /data/wangzunbin/volume/kfkluster/kafka3/logs:/kafka:Z
    network_mode: host

启动: docker-compose up -d

posted @ 2022-09-01 15:20  freedomAndWind  阅读(264)  评论(0编辑  收藏  举报