Docker Compose 安装 Kafka 集群

1、配置Kafka集群

1.1、新建docker-compose.yml

version: '3.1'

services:
  kafka_1:
    container_name: kafka_1
    image: wurstmeister/kafka
    restart: always
    hostname: kafka_1
    ports:
      - 9091:9092
    volumes:
      - "/var/run/docker.sock:/var/run/docker.sock"
    environment:
      TZ: Asia/Shanghai
      KAFKA_VERSION: 1.1.0
      KAFKA_ADVERTISED_HOST_NAME: 输入您的宿主机IP
      KAFKA_CREATE_TOPICS: "test:1:1"
      KAFKA_ZOOKEEPER_CONNECT: 输入您的ZK地址:ZK端口,输入您的ZK地址:ZK端口,输入您的ZK地址:ZK端口
  kafka_2:
    container_name: kafka_2
    image: wurstmeister/kafka
    restart: always
    hostname: kafka_2
    ports:
      - 9092:9092
    volumes:
      - "/var/run/docker.sock:/var/run/docker.sock"
    environment:
      TZ: Asia/Shanghai
      KAFKA_VERSION: 1.1.0
      KAFKA_ADVERTISED_HOST_NAME: 输入您的宿主机IP
      KAFKA_CREATE_TOPICS: "test:1:1"
      KAFKA_ZOOKEEPER_CONNECT: 输入您的ZK地址:ZK端口,输入您的ZK地址:ZK端口,输入您的ZK地址:ZK端口
  kafka_3:
    container_name: kafka_3
    image: wurstmeister/kafka
    restart: always
    hostname: kafka_3
    ports:
      - 9093:9092
    volumes:
      - "/var/run/docker.sock:/var/run/docker.sock"
    environment:
      TZ: Asia/Shanghai
      KAFKA_VERSION: 1.1.0
      KAFKA_ADVERTISED_HOST_NAME: 输入您的宿主机IP
      KAFKA_CREATE_TOPICS: "test:1:1"
      KAFKA_ZOOKEEPER_CONNECT: 输入您的ZK地址:ZK端口,输入您的ZK地址:ZK端口,输入您的ZK地址:ZK端口

1.2、 创建并启动容器

docker-compose up -d

2、添加UI监控(kafka-manager)

2.1、新建docker-compose.yml

version: '3.1'

services:
  kafka-manager:
    container_name: kafka-manager
    image: sheepkiller/kafka-manager
    restart: always
    ports:
      - 9892:9000
    environment:
      KM_VERSION: 1.3.3.18
      ZK_HOSTS: 输入您的ZK地址:ZK端口,输入您的ZK地址:ZK端口,输入您的ZK地址:ZK端口

2.2、 创建并启动容器

docker-compose up -d

浏览器访问http://宿主机ip:9892即可。

3、配置Nginx代理

server {
    listen       80;
    server_name  输入您域名;

    #charset koi8-r;
    access_log  /var/log/nginx/kafka.access.log  main;

    location / {
        proxy_pass http://输入您的宿主机IP:9892;
        proxy_redirect off;
        proxy_set_header HOST $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    }

}

未经允许不得转载:君子如兰 » Docker Compose 安装 Kafka 集群

赞 (0)