kafka學(xué)習(xí) 安裝與使用

請(qǐng)確保在啟動(dòng)Kafka服務(wù)器前烁设,Zookeeper實(shí)例已經(jīng)準(zhǔn)備好并開始運(yùn)行

1.Zookeeper搭建

1.1 Zookeeper

Zookeeper簡(jiǎn)單介紹: Zookeeper wiki
Zookeeper主頁(yè): Apache Zookeeper主頁(yè)
IBM developerWorks: 分布式服務(wù)框架 Zookeeper -- 管理分布式環(huán)境中的數(shù)據(jù)

1.2 Zookeeper搭建方式

Zookeeper安裝方式有三種灾部,單機(jī)模式和集群模式以及偽集群模式桐玻。
單機(jī)模式:Zookeeper只運(yùn)行在一臺(tái)服務(wù)器上号杏,適合測(cè)試環(huán)境瓤摧;
偽集群模式:就是在一臺(tái)物理機(jī)上運(yùn)行多個(gè)Zookeeper實(shí)例薪者;
集群模式:Zookeeper運(yùn)行于一個(gè)集群上纵苛,適合生產(chǎn)環(huán)境,這個(gè)計(jì)算機(jī)集群被稱為一個(gè)“集合體”(ensemble)

1.3 搭建步驟

采用偽集群的模式搭建.
1.下載Zookeeper: Zookeeper
2.解壓Zookeeper文件
3.創(chuàng)建文件目錄

image.png

4.在data文件下創(chuàng)建文本文件myid,里面只含數(shù)字攻人,表明自己是哪臺(tái)服務(wù)器取试,server0目錄里的myid為0,server1目錄里的myid為1怀吻,server2目錄里的myid為2
5.分別修改三個(gè)zookeeper-3.4.6/conf/zoo_sample.cfg為zoo.cfg
6.修改zoo.cfg里的文件內(nèi)容
server0/zookeeper-3.4.6/conf/zoo.cfg

# 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=/xxx/xxx/zk/server0/data
dataLogDir=/xxx/xxx/zk/server0/dataLog
# 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

server.0=127.0.0.1:2880:3880
server.1=127.0.0.1:2881:3881
server.2=127.0.0.1:2882:3882

server1/zookeeper-3.4.6/conf/zoo.cfg

# 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=/xxx/xxxx/zk/server1/data
dataLogDir=/xxx/xxxx/zk/server1/dataLog
# the port at which the clients will connect
clientPort=2182
# 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

server.0=127.0.0.1:2880:3880
server.1=127.0.0.1:2881:3881
server.2=127.0.0.1:2882:3882

server2/zookeeper-3.4.6/conf/zoo.cfg

# 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=/xxx/xxx/zk/server2/data
dataLogDir=/xxx/xxxx/zk/server2/dataLog
# the port at which the clients will connect
clientPort=2183
# 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
server.0=127.0.0.1:2880:3880
server.1=127.0.0.1:2881:3881
server.2=127.0.0.1:2882:3882

每個(gè)配置相當(dāng)于一臺(tái)服務(wù)器瞬浓,所以每個(gè)配置文件里的dataDir,dataLgDir, clientPort都不一樣蓬坡,每個(gè)配置文件的最后三行是一樣的猿棉。
server.A=B:C:D:其中 A 是一個(gè)數(shù)字,就是myid里的那個(gè)數(shù)字屑咳,表示這個(gè)是第幾號(hào)服務(wù)器铺根;B 是這個(gè)服務(wù)器的 ip 地址,C和D是兩個(gè)端口乔宿,C和D兩個(gè)端口是用來(lái)交換信息與leader選舉的。

Finally, note the two port numbers after each server name: “ 2888” and “3888”. Peers use the former port to connect to other peers. Such a connection is necessary so that peers can communicate, for example, to agree upon the order of updates. More specifically, a ZooKeeper server uses this port to connect followers to the leader. When a new leader arises, a follower opens a TCP connection to the leader using this port. Because the default leader election also uses TCP, we currently require another port for leader election. This is the second port in the server entry.

7.啟動(dòng)服務(wù)
進(jìn)入每個(gè)目錄/zookeeper-3.4.6访雪,執(zhí)行bin/zkServer.sh start详瑞,開啟服務(wù)


image.png

8.接入客戶端
可以進(jìn)入server2/zookeeper-3.4.6,去連接server0臣缀,
執(zhí)行bin/zkCli.sh -server 127.0.0.1:2181


image.png

2.kafka搭建

2.1 kafka 簡(jiǎn)介

kafka 主頁(yè)
IBM Apache kafka 工作原理介紹
kafka入門介紹

2.2 搭建步驟

1.下載 kafka
2.解壓 kafka
3.啟動(dòng)zk坝橡,可以用kafka自帶的zookeeper(bin/zookeeper-server-start.sh config/zookeeper.properties &)
4.啟動(dòng)kafka server
bin/kafka-server-start.sh config/server.properties &
5.創(chuàng)建主題
bin/kafka-topics.sh --create --zookeeper localhost:2181 --replication-factor 1 --partitions 1 --topic 20170517
6.查看已經(jīng)創(chuàng)建的主題
bin/kafka-topics.sh --list --zookeeper localhost:2181.
7.啟動(dòng)生產(chǎn)者
bin/kafka-console-producer.sh --broker-list localhost:9092 --topic 20170517
8.啟動(dòng)消費(fèi)者
另開一個(gè)終端,bin/kafka-console-consumer.sh --zookeeper localhost:2181 --topic 20170517 --from-beginning
在生產(chǎn)者下輸入消息后回車精置,消費(fèi)者就可以看到消息了
9.用監(jiān)控工具查看kafka
下載 KafkaOffsetMonitor-assembly-0.2.0.jar
啟動(dòng)監(jiān)控服務(wù)
java -cp KafkaOffsetMonitor-assembly-0.2.0.jar \
com.quantifind.kafka.offsetapp.OffsetGetterWeb \
--zk 127.0.0.1:2181 \
--port 8089 \
--refresh 10.seconds \
--retain 1.days

image.png

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
  • 序言:七十年代末计寇,一起剝皮案震驚了整個(gè)濱河市,隨后出現(xiàn)的幾起案子脂倦,更是在濱河造成了極大的恐慌番宁,老刑警劉巖,帶你破解...
    沈念sama閱讀 216,692評(píng)論 6 501
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件赖阻,死亡現(xiàn)場(chǎng)離奇詭異蝶押,居然都是意外死亡,警方通過查閱死者的電腦和手機(jī)火欧,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 92,482評(píng)論 3 392
  • 文/潘曉璐 我一進(jìn)店門棋电,熙熙樓的掌柜王于貴愁眉苦臉地迎上來(lái),“玉大人苇侵,你說我怎么就攤上這事赶盔。” “怎么了榆浓?”我有些...
    開封第一講書人閱讀 162,995評(píng)論 0 353
  • 文/不壞的土叔 我叫張陵于未,是天一觀的道長(zhǎng)。 經(jīng)常有香客問我,道長(zhǎng)沉眶,這世上最難降的妖魔是什么打却? 我笑而不...
    開封第一講書人閱讀 58,223評(píng)論 1 292
  • 正文 為了忘掉前任,我火速辦了婚禮谎倔,結(jié)果婚禮上柳击,老公的妹妹穿的比我還像新娘。我一直安慰自己片习,他們只是感情好捌肴,可當(dāng)我...
    茶點(diǎn)故事閱讀 67,245評(píng)論 6 388
  • 文/花漫 我一把揭開白布。 她就那樣靜靜地躺著藕咏,像睡著了一般状知。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發(fā)上孽查,一...
    開封第一講書人閱讀 51,208評(píng)論 1 299
  • 那天饥悴,我揣著相機(jī)與錄音,去河邊找鬼盲再。 笑死西设,一個(gè)胖子當(dāng)著我的面吹牛,可吹牛的內(nèi)容都是我干的答朋。 我是一名探鬼主播贷揽,決...
    沈念sama閱讀 40,091評(píng)論 3 418
  • 文/蒼蘭香墨 我猛地睜開眼,長(zhǎng)吁一口氣:“原來(lái)是場(chǎng)噩夢(mèng)啊……” “哼梦碗!你這毒婦竟也來(lái)了禽绪?” 一聲冷哼從身側(cè)響起,我...
    開封第一講書人閱讀 38,929評(píng)論 0 274
  • 序言:老撾萬(wàn)榮一對(duì)情侶失蹤洪规,失蹤者是張志新(化名)和其女友劉穎印屁,沒想到半個(gè)月后,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體淹冰,經(jīng)...
    沈念sama閱讀 45,346評(píng)論 1 311
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡库车,尸身上長(zhǎng)有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 37,570評(píng)論 2 333
  • 正文 我和宋清朗相戀三年,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了樱拴。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片柠衍。...
    茶點(diǎn)故事閱讀 39,739評(píng)論 1 348
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡,死狀恐怖晶乔,靈堂內(nèi)的尸體忽然破棺而出珍坊,到底是詐尸還是另有隱情,我是刑警寧澤正罢,帶...
    沈念sama閱讀 35,437評(píng)論 5 344
  • 正文 年R本政府宣布阵漏,位于F島的核電站,受9級(jí)特大地震影響,放射性物質(zhì)發(fā)生泄漏履怯。R本人自食惡果不足惜回还,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 41,037評(píng)論 3 326
  • 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望叹洲。 院中可真熱鬧柠硕,春花似錦、人聲如沸运提。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,677評(píng)論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽(yáng)民泵。三九已至癣丧,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間栈妆,已是汗流浹背胁编。 一陣腳步聲響...
    開封第一講書人閱讀 32,833評(píng)論 1 269
  • 我被黑心中介騙來(lái)泰國(guó)打工, 沒想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留鳞尔,地道東北人掏呼。 一個(gè)月前我還...
    沈念sama閱讀 47,760評(píng)論 2 369
  • 正文 我出身青樓唇牧,卻偏偏與公主長(zhǎng)得像绰播,于是被迫代替她去往敵國(guó)和親眠寿。 傳聞我的和親對(duì)象是個(gè)殘疾皇子,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 44,647評(píng)論 2 354

推薦閱讀更多精彩內(nèi)容

  • 一昧旨、入門1、簡(jiǎn)介Kafka is a distributed,partitioned,replicated com...
    HxLiang閱讀 3,348評(píng)論 0 9
  • ** 今天看了一下kafka官網(wǎng)祥得,嘗試著在自己電腦上安裝和配置兔沃,然后學(xué)一下官方document。** Introd...
    RainChang閱讀 5,002評(píng)論 1 30
  • 1 Zookeeper概述# ZooKeeper是一個(gè)為分布式應(yīng)用所設(shè)計(jì)的分布的级及、開源的協(xié)調(diào)服務(wù)乒疏,它主要是用來(lái)解決...
    七寸知架構(gòu)閱讀 7,351評(píng)論 0 101
  • 很多時(shí)候,朋友們?cè)谝黄鹆奶煲梗傆幸粋€(gè)人反應(yīng)慢怕吴,大家都會(huì)說,哥們县踢,和我們沒在同一邁上白痢! 聊天不在同一邁上硼啤,還不是最...
    張恒睿睿閱讀 98評(píng)論 0 2
  • 雨輕點(diǎn)著屋檐 在我的對(duì)面 分不清是雨還是你的容顏 模糊了視線 門外空蕩的秋千 笑聲傳去多遠(yuǎn) 而我只能眺望天邊 祭奠...
    Mohistmen閱讀 380評(píng)論 0 0