docker部署kafka&zookeeper服务

前言

… …

部署

]# mkdir -p /data/deploy/kafka
]# cd /data/deploy/kafka
]# cat > docker-compose.yml <<-EOF
version: '3.1'
services:
  zookeeper:
    image: wurstmeister/zookeeper
    restart: always
    hostname: zookeeper
    container_name: zookeeper
#    ports:
#      - 2181:2181
#      - 2888:2888
#      - 3888:3888
    volumes:
      - /etc/localtime:/etc/localtime:ro
      - /etc/timezone:/etc/timezone:ro    
      - /data/volume/zkcluster/zookeeper/data:/data:Z
      - /data/volume/zkcluster/zookeeper/datalog:/datalog:Z
    environment:
      ZOO_MY_ID: 1
      ZOO_SERVERS: server.1=192.168.1.40:2888:3888;2181
    network_mode: host

  kafka:
    image: wurstmeister/kafka
    restart: always
    hostname: kafka
    container_name: kafka
#    ports:
#      - 9092:9092
    environment:
      KAFKA_ADVERTISED_HOST_NAME: 192.168.1.40
      KAFKA_HOST_NAME: 192.168.1.40
      KAFKA_ADVERTISED_PORT: 9092
      KAFKA_BROKER_ID: 0
      KAFKA_ZOOKEEPER_CONNECT: 192.168.1.40:2181
      KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://192.168.1.40:9092
      KAFKA_LISTENERS: PLAINTEXT://192.168.1.40:9092
    volumes:
      - /etc/localtime:/etc/localtime:ro
      - /etc/timezone:/etc/timezone:ro    
      - /data/volume/kfkcluster/kafka/logs:/kafka/kafka-logs-kafka:Z
    network_mode: host
EOF    
]# docker-compose up -d

云上服务器的配置修改

注:如果是部署到公网服务器,从内网访问,则需要调整下面的参数

KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://117.2.31.47:9092	# 公网IP,把kafka的地址端口注册给zookeeper
KAFKA_LISTENERS: PLAINTEXT://0.0.0.0:9092	# 0.0.0.0,配置kafka的监听端口

结语

kafka专题:kafka的消息丢失、重复消费、消息积压等线上问题汇总及优化

上一篇:大数据开发之zookeeper的数据与存储


下一篇:kafka和zookeeper的安装