代码之家  ›  专栏  ›  技术社区  ›  grep

无法在docker容器外访问卡夫卡

  •  0
  • grep  · 技术社区  · 6 年前

    我在docker容器中安装了最新的HDP。

    docker ps
    >hortonworks/sandbox-proxy:1.0
    >hortonworks/sandbox-hdp:3.0.1
    

    卡夫卡经纪人正在 6667 港口 很好。

       >ssh hdfs@sandbox-hdp.hortonworks.com -p 2222
       > echo "send test message" | kafka-console-producer.sh --broker-list sandbox-hdp.hortonworks.com:6667 --topic hotelReservation > /dev/null
       >kafka-console-consumer.sh   --bootstrap-server sandbox-hdp.hortonworks.com:6667 --topic test --from-beginning
    

    唯一的问题是,我无法访问docker容器之外的Kafka代理。

    有关疑难解答的更多信息:

    我确认所有端口都打开了 本地机器->代理->hdp

    HDP服务器:

          hostname -I
          172.18.0.2
    
          netstat -vatn | grep 6667
          tcp        0      0 172.18.0.2:6667         0.0.0.0:*               LISTEN
    

    代理服务器

      hostname -I
      172.18.0.3
    
      nmap 172.18.0.2 -p 6667
      6667/tcp open  irc
    
      netstat -vatn | grep 6667
      tcp        0      0 0.0.0.0:6667            0.0.0.0:*               LISTEN
    

    我的本地机器:

    nmap sandbox-hdp.hortonworks.com -p 6667
        Host is up (0.000064s latency).
        rDNS record for 127.0.0.1: localhost
        PORT     STATE SERVICE
        6667/tcp open  irc
    

    注意:6668也是开放的。

    包括默认流配置(/etc/nginx/conf)/ 流动D / tcp hdp。形态 ):

    server {
      listen 6668;
      proxy_pass sandbox-hdp:6667;
    }
    

    所以我决定创建新的配置文件http:/etc/nginx/conf/ 流动D / tcp hdp。形态

    server {
      listen 6667;
      server_name sandbox-hdp.hortonworks.com;
      location / {
        proxy_pass http://sandbox-hdp:6667;
      }
    }
    

    注: 我读了( here )我应该用它。侦听器可以访问医生之外的代理:

    >listeners=PLAINTEXT://0.0.0.0:6667
    >advertised.listeners=PLAINTEXT://172.18.0.2:6667
    

    但我相信这对我的情况是不正确的。我可以访问这个网络,问题是某种类型的 仅限Nginx映射 .

    0 回复  |  直到 6 年前
        1
  •  1
  •   grep    6 年前

    解决方案:

    运行以下命令以查找 hortonworks/沙盒代理 容器id。

    docker ps
    

    登录到代理服务器

    docker exec -it CONTAINER_ID /bin/bash
    

    在nginx中添加新映射

    cd /etc/nginx/conf.stream.d
    vim tcp-hdp.conf
    

    配置:

    server {
      listen 6667;
      proxy_pass sandbox-hdp:6667;
    }
    

    重新加载nginx映射:

    /etc/init.d/nginx reload
    

    测试:

    > ./kafka-console-consumer.sh --bootstrap-server localhost:6668 --topic topicName --from-beginning
    > echo "msg" | ./kafka-console-producer.sh --broker-list sandbox-hdp.hortonworks.com:6668 --topic topicName > /dev/nul
    

    问题是6667:6667映射缺失。现在,代理可以访问6667和6668端口。