博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
docker-compose部署zk集群、kafka集群以及kafka-manager,及其遇到的问题和解决
阅读量:6827 次
发布时间:2019-06-26

本文共 6068 字,大约阅读时间需要 20 分钟。

zk集群docker-compose.yml

1、新建网络

docker network create --driver bridge --subnet 172.23.0.0/25 --gateway 172.23.0.1  zookeeper_network

2、zk集群

version: '3.4'services:  zoo1:    image: zookeeper    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=0.0.0.0:2888:3888 server.2=zoo2:2888:3888 server.3=zoo3:2888:3888    networks:      default:        ipv4_address: 172.23.0.11  zoo2:    image: zookeeper    restart: always    hostname: zoo2    container_name: zoo2    ports:    - 2180:2181    volumes:    - "./zoo2/data:/data"    - "./zoo2/datalog:/datalog"    environment:      ZOO_MY_ID: 2      ZOO_SERVERS: server.1=zoo1:2888:3888 server.2=0.0.0.0:2888:3888 server.3=zoo3:2888:3888    networks:      default:        ipv4_address: 172.23.0.12  zoo3:    image: zookeeper    restart: always    hostname: zoo3    container_name: zoo3    ports:    - 2179: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=0.0.0.0:2888:3888    networks:      default:        ipv4_address: 172.23.0.13networks:  default:    external:      name: zookeeper_network

3、kafka集群以及kafka-manager

version: '2'services:  kafka1:    image: wurstmeister/kafka    restart: always    hostname: kafka1    container_name: kafka1    ports:    - "9092:9092"    environment:      KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://192.168.0.6:9092      KAFKA_ADVERTISED_HOST_NAME: 192.168.0.6      KAFKA_ADVERTISED_PORT: 9092      KAFKA_ZOOKEEPER_CONNECT: zoo1:2181,zoo2:2181,zoo3:2181      JMX_PORT: 9999     volumes:    - ./kafka1/logs:/kafka    external_links:    - zoo1    - zoo2    - zoo3    networks:      default:        ipv4_address: 172.23.0.14  kafka2:    image: wurstmeister/kafka    restart: always    hostname: kafka2    container_name: kafka2    ports:    - "9093:9092"    environment:      KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://192.168.0.6:9093       KAFKA_ADVERTISED_HOST_NAME: 192.168.0.6      KAFKA_ADVERTISED_PORT: 9093      KAFKA_ZOOKEEPER_CONNECT: zoo1:2181,zoo2:2181,zoo3:2181      JMX_PORT: 9988    volumes:    - ./kafka2/logs:/kafka    external_links:  # 连接本compose文件以外的container    - zoo1    - zoo2    - zoo3    networks:      default:        ipv4_address: 172.23.0.15  kafka3:    image: wurstmeister/kafka    restart: always    hostname: kafka3    container_name: kafka3    ports:    - "9094:9092"    environment:      KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://192.168.0.6:9094      KAFKA_ADVERTISED_HOST_NAME: 192.168.0.6      KAFKA_ADVERTISED_PORT: 9094      KAFKA_ZOOKEEPER_CONNECT: zoo1:2181,zoo2:2181,zoo3:2181      JMX_PORT: 9977    volumes:    - ./kafka3/logs:/kafka    external_links:  # 连接本compose文件以外的container    - zoo1    - zoo2    - zoo3    networks:      default:        ipv4_address: 172.23.0.16  kafka-manager:    image: sheepkiller/kafka-manager:latest    restart: always    container_name: kafa-manager    hostname: kafka-manager    ports:      - "9002:9000"    links:            # 连接本compose文件创建的container      - kafka1      - kafka2      - kafka3    external_links:   # 连接本compose文件以外的container      - zoo1      - zoo2      - zoo3    environment:      ZK_HOSTS: zoo1:2181,zoo2:2181,zoo3:2181      KAFKA_BROKERS: kafka1:9092,kafka2:9093,kafka3:9094      APPLICATION_SECRET: letmein      KM_ARGS: -Djava.net.preferIPv4Stack=true    networks:      default:        ipv4_address: 172.23.0.10networks:  default:    external:   # 使用已创建的网络      name: zookeeper_network

 

错误:

 

1、kafka使用external_links仍连不上zookeeper

INFO Opening socket connection to server zk2.zookeeper_default/172.22.0.3:2180. Will not attempt to authenticate using SASL (unknown error) (org.apache.zookeeper.ClientCnxn)docker-kafka     | [2019-01-19 05:22:45,206] WARN Session 0x0 for server null, unexpected error, closing socket connection and attempting reconnect (org.apache.zookeeper.ClientCnxn)docker-kafka     | java.net.ConnectException: Connection refuseddocker-kafka     |     at sun.nio.ch.SocketChannelImpl.checkConnect(Native Method)docker-kafka     |     at sun.nio.ch.SocketChannelImpl.finishConnect(SocketChannelImpl.java:717)docker-kafka     |     at org.apache.zookeeper.ClientCnxnSocketNIO.doTransport(ClientCnxnSocketNIO.java:361)docker-kafka     |     at org.apache.zookeeper.ClientCnxn$SendThread.run(ClientCnxn.java:1141)docker-kafka     | [2019-01-19 05:22:45,311] INFO Opening socket connection to server zk3.zookeeper_default/172.22.0.2:2179. Will not attempt to authenticate using SASL (unknown error) (org.apache.zookeeper.ClientCnxn)

解决办法:

两个docker-compose使用相同的网络

 

2、kafka节点相互连不上

kafka3    | [2019-01-19 05:49:11,086] WARN [Controller id=1001, targetBrokerId=1003] Connection to node 1003 could not be established. Broker may not be available. (org.apache.kafka.clients.NetworkClient)kafka3    | [2019-01-19 05:49:11,146] WARN [Controller id=1001, targetBrokerId=1001] Connection to node 1001 could not be established. Broker may not be available. (org.apache.kafka.clients.NetworkClient)kafka3    | [2019-01-19 05:49:11,187] WARN [Controller id=1001, targetBrokerId=1003] Connection to node 1003 could not be established. Broker may not be available. (org.apache.kafka.clients.NetworkClient)

找了挺多靠谱和不靠谱的解决方案,都没能解决问题,但也给我提示。

这个问题无非就是kafka集群,这里是通过宿主机连接节点的,

KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://kafka3:9094  KAFKA_ADVERTISED_HOST_NAME: kafka3 这两个配置可以配置宿主机的IP或者容器的hostname都可,但是有两点:1、端口需要暴露出来 2、并且可以通过宿主机访问进去 我是第二点被坑了,fire-wall开发端口,就没有上面这个错误了。

3、kafka-manager报jmx相关错误

 

然后点击链接开启jmx

于是就出现下面的错误

[error] k.m.j.KafkaJMX$ - Failed to connect to service:jmx:rmi:///jndi/rmi://9.11.8.48:-1/jmxrmi java.lang.IllegalArgumentException: requirement failed: No jmx port but jmx polling enabled!

 解决办法是:

在每一个kafka节点加上环境变量  JMX_PORT=端口

加上之后发现连不上,又是网络连接的问题,于是又把每个jmx端口暴露出来,然后fire-wall放行, 解决问题。

KAFKA_ADVERTISED_HOST_NAME: 这个最好设置宿主机的ip,宿主机以外的代码或者工具来连接,后面的端口也需要设置暴露的端口。

 

转载于:https://www.cnblogs.com/jay763190097/p/10292227.html

你可能感兴趣的文章
UIView 进行各种动画展示及其用法解释
查看>>
公布2012年5月赛CSDN算法达人赛试题及参考答案
查看>>
Mysql ON子句和USING子句
查看>>
linux杂谈
查看>>
类型、值和变量
查看>>
UIImage+Scale
查看>>
Linux sed 替换第一次出现的字符串
查看>>
windows 下VLC播放器应用之二------LIBVLC API解析
查看>>
用户权限管理,LINQ去除它的重复菜单项
查看>>
php mysql 导出excel
查看>>
android 日期选择器(DatePicker)学习与应用 (转)
查看>>
web页面常用功能js实现
查看>>
30天学会 MooTools 教学(1): 认识MooTools
查看>>
【转载】iphone IOS plist文件
查看>>
linux下多进程、多线程编程
查看>>
jmeter最简单使用
查看>>
Android开发中SharedPreferences的应用
查看>>
Forward框架的逆袭:解析Forward+渲染
查看>>
转 互斥锁和条件变量
查看>>
java打包jar的入口问题解决
查看>>