kafka Windows安裝

1:安裝JDK、html

2:安裝Zookeeperjava

 下載地址:https://zookeeper.apache.org/releases.html
apache

    下載後,解壓放在目錄D:\bigdata(本文所用的目錄)下,關於zookeeper以及kafka的目錄,路徑中最好不要出現空格,好比D:\Program Files,儘可能別用,運行腳本時會有問題。windows

①進入zookeeper的相關設置所在的文件目錄,例如本文的:D:\bigdata\zookeeper-3.4.10\conf服務器

②將"zoo_sample.cfg"重命名爲"zoo.cfg"編輯器

③打開zoo.cfg(至於使用什麼編輯器,根據本身喜愛選便可),找到並編輯:ide

dataDir=/tmp/zookeeper  to  D:/bigdata/zookeeper-3.4.10/data D:\\bigdata\\zookeeper-3.4.10\\data(路徑僅爲示例,具體可根據須要配置)
ui

這裏注意,路徑要麼是"/"分割,要麼是轉義字符"\\",這樣會生成正確的路徑(層級,子目錄)。this

④與配置jre相似,在系統環境變量中添加:spa

    a.系統變量中添加ZOOKEEPER_HOME=D:\bigdata\zookeeper-3.4.10

    b.編輯系統變量中的path變量,增長%ZOOKEEPER_HOME%\bin

⑤在zoo.cfg文件中修改默認的Zookeeper端口(默認端口2181)

這是本文最終的zoo.cfg文件的內容:

 

    1. # The number of milliseconds of each tick  
    2. tickTime=2000  
    3. # The number of ticks that the initial   
    4. # synchronization phase can take  
    5. initLimit=10  
    6. # The number of ticks that can pass between   
    7. # sending a request and getting an acknowledgement  
    8. syncLimit=5  
    9. # the directory where the snapshot is stored.  
    10. # do not use /tmp for storage, /tmp here is just   
    11. # example sakes.  
    12. dataDir=D:/bigdata/zookeeper-3.4.10/data  
    13. #dataDir=D:\\bigdata\\zookeeper-3.4.10\\data  
    14. # the port at which the clients will connect  
    15. clientPort=2181  
    16. # the maximum number of client connections.  
    17. # increase this if you need to handle more clients  
    18. #maxClientCnxns=60  
    19. #  
    20. # Be sure to read the maintenance section of the   
    21. # administrator guide before turning on autopurge.  
    22. #  
    23. # http://zookeeper.apache.org/doc/current/zookeeperAdmin.html#sc_maintenance  
    24. #  
    25. # The number of snapshots to retain in dataDir  
    26. #autopurge.snapRetainCount=3  
    27. # Purge task interval in hours  
    28. # Set to "0" to disable auto purge feature  
    29. #autopurge.purgeInterval=1 

 

⑥打開cmd窗口,輸入zkserver,運行Zookeeper,運行結果以下:

Zookeeper已經安裝完成,已在2181端口運行。

 

3 安裝kafka

下載地址:http://kafka.apache.org/downloads

    要下載Binary downloads這個類型,不要下載源文件,這種方便使用。下載後,解壓放在D:\bigdata目錄下。

 

①進入kafka配置文件所在目錄,D:\bigdata\kafka_2.11-0.9.0.1\config

 

②編輯文件"server.properties",找到並編輯:

 

 log.dirs=/tmp/kafka-logs  to  log.dirs=D:/bigdata/kafka_2.11-0.9.0.1/kafka-logs 或者 D:\\bigdata\\kafka_2.11-0.9.0.1\\kafka-logs

 

一樣注意:路徑要麼是"/"分割,要麼是轉義字符"\\",這樣會生成正確的路徑(層級,子目錄)。錯誤路徑狀況可自行嘗試,文件夾名爲這種形式:bigdatakafka_2.11-0.9.0.1kafka-logs

 

③在server.properties文件中,zookeeper.connect=localhost:2181表明kafka所鏈接的zookeeper所在的服務器IP以及端口,可根據須要更改。本文在同一臺機器上使用,故不用修改。

 

④啓動kafka:

在命令行中輸入:.\bin\windows\kafka-server-start.bat .\config\server.properties   回車。

kafka會按照默認配置,在9092端口上運行,並鏈接zookeeper的默認端口2181。

 

3 增長kafka用戶

(1)
# 添加下面的配置  ip和端口改爲本身須要
listeners=SASL_PLAINTEXT://xx.xx.xx.xx:8123
security.inter.broker.protocol=SASL_PLAINTEXT
sasl.enabled.mechanisms=PLAIN
sasl.mechanism.inter.broker.protocol=PLAIN

(2)

在config目錄添加kafka_server_jaas.conf 文件 此文件是服務端 設置用戶名  和密碼

KafkaServer {
    org.apache.kafka.common.security.plain.PlainLoginModule required
    username="kafka"
    password="kafkapswd"
    user_kafka="kafkapswd"
    user_mooc="moocpswd";
};

其中 Kafka 定義了關鍵字KafkaServer字段用於指定服務端登陸配置。該配置經過org.apache.
org.apache.kafka.common.security.plain.PlainLoginModule由指定採用PLAIN 機制, 定義了兩個用戶, 用戶通
過usemame 和password 指定該代理與集羣其餘代理初始化鏈接的用戶名和密碼, 經過「 user_ "
爲前綴後接用戶名方式建立鏈接代理的用戶名和密碼,例如, user_mooc = "moocpswd」 是指
用戶名爲mooc, 密碼爲moocpswd
 

(3)

在config目錄添加kafka_client_jaas.conf

KafkaClient {
        org.apache.kafka.common.security.plain.PlainLoginModule required
        username="mooc"
        password="moocpswd";
};
 (4)

修改目錄/usr/local/kafka_2.12-1.1.1/bin 下的 kafka-server-start.sh文件 。 個人作法也是複製出來一份 ,而後進行修改

kafka-server-start-saal.sh  添加如下文件

if [ "x$KAFKA_OPTS"  ]; then
    export KAFKA_OPTS="-Djava.security.auth.login.config=/usr/local/kafka_2.12-1.1.1/config/kafka_server_jaas.conf"
fi

(5)

 

修改目錄/usr/local/kafka_2.12-1.1.1/bin 下的  kafka-console-producer.sh 和 kafka-console-consumer.sh 文件

 

也是 都各自複製一份 在複製上面進行修改

if [ "x$KAFKA_OPTS"  ]; then    export KAFKA_OPTS="-Djava.security.auth.login.config=/usr/local/kafka_2.12-1.1.1/config/kafka_client_jaas.conf"fi

相關文章
相關標籤/搜索