閱讀英文版本

分享方式:


如何將 Kafka 叢集連線至不同 VNet 中的 VM

本文件將介紹要為位於兩個不同 VNet 中的 VM 與 HDI Kafka 之間設定連線時,您必須遵循的步驟。

  1. 建立兩個不同的 VNet,分別裝載 HDInsight Kafka 叢集和 VM。 如需詳細資訊,請參閱使用 Azure 入口網站建立虛擬網路

    備註

    這兩個 VNet 必須對等互連,使其子網路 IP 位址無法彼此重疊。 如需詳細資訊,請參閱使用 Azure 入口網站透過虛擬網路對等互連來連線虛擬網路

  2. 請確定對等互連狀態顯示為已連線。

    顯示 Kafka 事件對等互連的螢幕快照。

  3. 完成上述步驟之後,我們可以在一個 VNet 中建立 HDInsight Kafka 叢集。 如需詳細資訊,請參閱建立 Apache Kafka 叢集

  4. 在第二個 VNet 中建立虛擬機器。 建立 VM 時,請指定必須部署此虛擬機器的第二個 VNet 名稱。 如需詳細資訊,請參閱在 Azure 入口網站中建立 Linux 虛擬機器

  5. 在此步驟之後,我們可以將檔案 /etc/host 的項目從 Kafka 前端節點複製到 VM。

    顯示主機檔案輸出的螢幕快照。

  6. 從檔案中移除 headnodehost 字串項目。 例如,上述影像具有 ip 10.0.0.16 的 headnodehost 項目。

  7. 建立這些項目之後,請嘗試依照下列方式使用 hn0 或 hn1 FQDN 的 curl 命令連線到 Kafka Ambari 儀表板:

    從 Linux VM

    curl hn0-vnetka.glarbkztnoqubmzjylls33qnse.bx.internal.cloudapp.net:8080 
    

    輸出:

    “<!-- 
    * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements.  See the NOTICE file  distributed with this work for   additional information regarding copyright ownership.  The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License.  You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. 
    
    --> 
    
    <!DOCTYPE html> 
    <html lang="en"> 
    
    <head> 
    
      <meta charset="utf-8"> 
      <meta http-equiv="X-UA-Compatible" content="IE=edge"> 
      <meta name="viewport" content="width=device-width, initial-scale=1.0"> 
      <link rel="stylesheet" href="stylesheets/vendor.css"> 
      <link rel="stylesheet" href="stylesheets/app.css"> 
      <script src="javascripts/vendor.js"></script> 
      <script src="javascripts/app.js"></script> 
    
      <script> 
       $(document).ready(function() { 
           require('initialize'); 
           // make favicon work in firefox 
           $('link[type*=icon]').detach().appendTo('head'); 
           $('#loading').remove(); 
       }); 
    
     </script> 
    
     <title>Ambari</title> 
     <link rel="shortcut icon" href="/img/logo.png" type="image/x-icon"> 
     </head> 
     <body> 
      <div id="loading">...Loading...</div> 
      <div id="wrapper"> 
      <!-- ApplicationView --> 
      </div> 
      <footer> 
    
         <div class="container footer-links"> 
    
             <a data-qa="license-link" href="http://www.apache.org/licenses/LICENSE-2.0" target="_blank">Licensed under the Apache License, Version 2.0</a>.        <br> 
    
             <a data-qa="third-party-link" href="/licenses/NOTICE.txt" target="_blank">See third-party tools/resources that Ambari uses and their respective authors</a> 
    
          </div> 
    
      </footer> 
    
    </body> 
    
    </html>”
    

    從 Windows VM

    顯示 Windows VM 輸出的螢幕快照。

    備註

    1. 在 Windows VM 中,靜態主機名會新增到路徑 C:\Windows\System32\drivers\etc\ 中存在的檔案主機中
    2. 本文件假設 Ambari 伺服器在 hn0 上為使用中。 如果 Ambari 伺服器在 hn1 上為使用中,則使用 hn1 的 FQDN 來存取 Ambari UI。
  8. 您也可以將訊息傳送至 kafka 主題,並從 VM 讀取主題。 為此,您可以嘗試使用此範例 Java 應用程式:https://github.com/Azure-Samples/hdinsight-kafka-java-get-started

    請務必使用該命令在 Kafka 叢集內建立主題

    java -jar kafka-producer-consumer.jar create <topic_name> $KAFKABROKERS
    
  9. 建立主題之後,我們可以使用下列命令來產生和使用。 $KAFKABROKERS 必須取代為對應的訊息代理程式背景工作節點 FQDN 和連接埠,如文件中所述。

    java -jar kafka-producer-consumer.jar producer test $KAFKABROKERS `
    java -jar kafka-producer-consumer.jar consumer test $KAFKABROKERS 
    
  10. 在此步驟之後,您會取得下列輸出:

    產生者輸出:

    顯示 Kafka 產生者輸出 VM 的螢幕快照。

    取用者輸出:

    顯示 Kafka 取用者輸出的螢幕快照。