windows安裝zookeeper和kafka,flume


一、安裝JDK

過程比較簡單,這里不做說明。

最后打開cmd輸入如下內容,表示安裝成功

二、安裝zooeleeper

下載安裝包:http://zookeeper.apache.org/releases.html#download

下載后解壓到一個目錄:

1.進入Zookeeper設置目錄,筆者D:\Java\Tool\zookeeper-3.4.6\conf
2. 將“zoo_sample.cfg”重命名為“zoo.cfg”
3. 在任意文本編輯器(如notepad)中打開zoo.cfg
4. 找到並編輯dataDir=D:\\Java\\Tool\\zookeeper-3.4.6\\tmp
5. 與Java中的做法類似,我們在系統環境變量中添加:
  a. 在系統變量中添加ZOOKEEPER_HOME = D:\Java\Tool\zookeeper-3.4.6
  b. 編輯path系統變量,添加為路徑%ZOOKEEPER_HOME%\bin;
6. 在zoo.cfg文件中修改默認的Zookeeper端口(默認端口2181)

這是筆者最終的文件內容:

    # The number of milliseconds of each tick

     tickTime=2000

# The number of ticks that the initial 
# synchronization phase can take
initLimit=10
# The number of ticks that can pass between 
# sending a request and getting an acknowledgement
syncLimit=5
# the directory where the snapshot is stored.
# do not use /tmp for storage, /tmp here is just 
# example sakes.
dataDir=D:\\Java\\Tool\\zookeeper-3.4.6\\tmp
# the port at which the clients will connect
clientPort=2181
# the maximum number of client connections.
# increase this if you need to handle more clients
#maxClientCnxns=60
#
# Be sure to read the maintenance section of the 
# administrator guide before turning on autopurge.
#
# http://zookeeper.apache.org/doc/current/zookeeperAdmin.html#sc_maintenance
#
# The number of snapshots to retain in dataDir
#autopurge.snapRetainCount=3
# Purge task interval in hours
# Set to "0" to disable auto purge feature
#autopurge.purgeInterval=1


7. 打開新的cmd,輸入zkServer,運行Zookeeper。
8. 命令行提示如下:說明本地Zookeeper啟動成功

 

三、安裝與運行Kafka

下載

http://kafka.apache.org/downloads.html。注意要下載二進制版本的

下載后解壓到任意一個目錄,筆者的是D:\Java\Tool\kafka_2.11-0.10.0.1

1. 進入Kafka配置目錄,D:\Java\Tool\kafka_2.11-0.10.0.1
2. 編輯文件“server.properties”
3. 找到並編輯log.dirs=D:\Java\Tool\kafka_2.11-0.10.0.1\kafka-log,這里的目錄自己修改成自己喜歡的
4. 找到並編輯zookeeper.connect=localhost:2181。表示本地運行
5. Kafka會按照默認,在9092端口上運行,並連接zookeeper的默認端口:2181。

運行:

重要:請確保在啟動Kafka服務器前,Zookeeper實例已經准備好並開始運行。

1.進入Kafka安裝目錄D:\Java\Tool\kafka_2.11-0.10.0.1
2.按下Shift+右鍵,選擇“打開命令窗口”選項,打開命令行。
3.現在輸入

 
.\bin\windows\kafka-server-start.bat .\config\server.properties 

 

並回車。

2.kafka第一次啟動報錯:找不到或無法加載主類

(1)在配置好kafka的server.properties文件后,cmd進入命令窗口輸入命令:.\bin\windows\kafka-server-start.bat config\server.properties提示錯誤:錯誤: 找不到或無法加載主類 Files\Java\jdk1.7.0_80\lib;C:\Program 解決方式如下:在kafka安裝目錄中找到bin\windows目錄中的kafka-run-class.bat找到142行為%CLASSPATH%加上雙引號

修改前

set COMMAND=%JAVA% %KAFKA_HEAP_OPTS% %KAFKA_JVM_PERFORMANCE_OPTS% %KAFKA_JMX_OPTS% %KAFKA_LOG4J_OPTS% -cp %CLASSPATH% %KAFKA_OPTS% %*

修改后

set COMMAND=%JAVA% %KAFKA_HEAP_OPTS% %KAFKA_JVM_PERFORMANCE_OPTS% %KAFKA_JMX_OPTS% %KAFKA_LOG4J_OPTS% -cp "%CLASSPATH%" %KAFKA_OPTS% %*

四、測試

上面的Zookeeper和kafka一直打開

(1)、創建主題

1.進入Kafka安裝目錄D:\Java\Tool\kafka_2.11-0.10.0.1
2.按下Shift+右鍵,選擇“打開命令窗口”選項,打開命令行。
3.現在輸入

 
.\bin\windows\kafka-topics.bat --create --zookeeper localhost:2181 --replication-factor 1 --partitions 1 --topic linlin

 

注意不要關了這個窗口!

(2)創建生產者

1.進入Kafka安裝目錄D:\Java\Tool\kafka_2.11-0.10.0.1
2.按下Shift+右鍵,選擇“打開命令窗口”選項,打開命令行。
3.現在輸入

注意不要關了這個窗口!

(3)創建消費者

1.進入Kafka安裝目錄D:\Java\Tool\kafka_2.11-0.10.0.1
2.按下Shift+右鍵,選擇“打開命令窗口”選項,打開命令行。
3.現在輸入

注意不要關了這個窗口!

然后在第2個窗口中輸入內容,最后記得回車


 五,安裝flume

1、運行

  1. 創建配置文件:在解壓后的文件apache-flume-1.6.0-bin/conf下創建一個flume.conf,內容如下。

     # example.conf: A single-node Flume configuration
    
     # Name the components on this agent
     a1.sources = r1
     a1.sinks = k1
     a1.channels = c1
    
     # Describe/configure the source
     a1.sources.r1.type = netcat
     a1.sources.r1.bind = localhost
     a1.sources.r1.port = 44444
    
     # Describe the sink
     a1.sinks.k1.type = logger
    
     # Use a channel which buffers events in memory
     a1.channels.c1.type = memory
     a1.channels.c1.capacity = 1000
     a1.channels.c1.transactionCapacity = 100
    
     # Bind the source and sink to the channel
     a1.sources.r1.channels = c1
     a1.sinks.k1.channel = c1

2.打開cmd進入到apache-flume-1.6.0-bin\bin目錄下,運行如下命令

flume-ng.cmd agent -conf ../conf -conf-file ../conf/flume.conf -name al -property flume.root.logger=INFO,console


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM