這篇文章主要介紹“kafka-2.11集群的搭建步驟”,在日常操作中,相信很多人在kafka-2.11集群的搭建步驟問(wèn)題上存在疑惑,小編查閱了各式資料,整理出簡(jiǎn)單好用的操作方法,希望對(duì)大家解答”kafka-2.11集群的搭建步驟”的疑惑有所幫助!接下來(lái),請(qǐng)跟著小編一起來(lái)學(xué)習(xí)吧!
目前成都創(chuàng)新互聯(lián)已為上千家的企業(yè)提供了網(wǎng)站建設(shè)、域名、虛擬主機(jī)、網(wǎng)站托管維護(hù)、企業(yè)網(wǎng)站設(shè)計(jì)、尼開(kāi)遠(yuǎn)網(wǎng)站維護(hù)等服務(wù),公司將堅(jiān)持客戶導(dǎo)向、應(yīng)用為本的策略,正道將秉承"和諧、參與、激情"的文化,與客戶和合作伙伴齊心協(xié)力一起成長(zhǎng),共同發(fā)展。producer:消息生產(chǎn)者,向kafka broker發(fā)消息的客戶端
consumer:消息消費(fèi)者,向kafka broker取消息的客戶端
Topic:發(fā)布到Kafka集群消息的一個(gè)類別
broker:一臺(tái)kafka服務(wù)器就是一個(gè)broker,一個(gè)集群由多個(gè)broker組成,一個(gè)broker可以容納多個(gè)topic
1.下載安裝zookeeper(必須先安裝zookeeper和jdk)
[root@node1 ~]# wget http://mirror.bit.edu.cn/apache/zookeeper/stable/zookeeper-3.4.13.tar.gz
[root@node1 ~]# tar xvf zookeeper-3.4.13.tar.gz -C /opt/
[root@node1 ~]# cd /opt/zookeeper-3.4.13/conf/
[root@node1 conf]# vim zoo.cfg
tickTime=2000
dataDir=/opt/zookeeper-3.4.13/data
clientPort=2181
initLimit=5
syncLimit=2
server.1=node1:2888:3888
server.2=node2:2888:3888
server.3=node3:2888:3888
[root@node1 conf]# mkdir /opt/zookeeper-3.4.13/data
[root@node1 conf]# cd /opt/zookeeper-3.4.13/data --myid必須要在data目錄下面,否則會(huì)報(bào)錯(cuò)
[root@node1 data]# cat myid
1
[root@node1 zookeeper-3.4.13]# cd ..
[root@node1 opt]# scp -r zookeeper-3.4.13 node2:/opt/
[root@node1 opt]# scp -r zookeeper-3.4.13 node3:/opt/
2.在node2修改myid文件
[root@node2 opt]# cat /opt/zookeeper-3.4.13/data/myid
2
[root@node2 opt]#
3.在node3修改myid文件
[root@node3 ~]# cat /opt/zookeeper-3.4.13/data/myid
3
[root@node3 ~]# zkServer.sh start --每個(gè)節(jié)點(diǎn)都要啟動(dòng)zookeeper服務(wù)
ZooKeeper JMX enabled by default
Using config: /opt/zookeeper-3.4.13/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED
[root@node3 opt]# zkCli.sh --使用客戶端登陸
3.下載安裝kafka(三個(gè)節(jié)點(diǎn)一樣)
[root@node1 ~]# wget http://mirror.bit.edu.cn/apache/kafka/2.2.0/kafka_2.11-2.2.0.tgz
[root@node1 ~]# tar xvf kafka_2.11-2.2.0.tgz -C /opt/
[root@node1 ~]# cd /opt/kafka_2.11-2.2.0/
[root@node1 kafka_2.11-2.2.0]# cd config/
[root@node1 config]# vim server.properties
broker.id=0 --每個(gè)id不一樣
zookeeper.connect=172.16.8.23:2181,172.16.8.24:2181,172.16.8.178:2181 --zookeeper集群IP地址
[root@node1 config]# cd /opt/
[root@node1 opt]# scp -r kafka_2.11-2.2.0/ node2:/opt/
[root@node1 opt]# scp -r kafka_2.11-2.2.0/ node3:/opt/
[root@node1 opt]# cd kafka_2.11-2.2.0/bin/
[root@node1 bin]# ./kafka-server-start.sh ../config/server.properties & --三臺(tái)kafka都要后臺(tái)啟動(dòng)服務(wù)
4.查看kafka服務(wù)是否啟動(dòng)正常
[root@node1 bin]# jps
30851 Kafka
3605 HMaster
12728 QuorumPeerMain
12712 DFSZKFailoverController
31656 Jps
3929 DataNode
15707 JournalNode
32188 NameNode
14335 ResourceManager
[root@node1 bin]# netstat -antulp | grep 30851
tcp6 0 0 :::9092 :::* LISTEN 30851/java
tcp6 0 0 :::37161 :::* LISTEN 30851/java
tcp6 0 0 172.16.8.23:40754 172.16.8.178:9092 ESTABLISHED 30851/java
tcp6 0 0 172.16.8.23:9092 172.16.8.23:39704 ESTABLISHED 30851/java
tcp6 0 0 172.16.8.23:45480 172.16.8.24:9092 ESTABLISHED 30851/java
tcp6 0 0 172.16.8.23:45294 172.16.8.178:2181 ESTABLISHED 30851/java
tcp6 0 0 172.16.8.23:39704 172.16.8.23:9092 ESTABLISHED 30851/java
[root@node1 bin]#
5.使用命令接口
[root@node1 bin]# ./kafka-topics.sh --create --zookeeper node1:2181 --topic tongcheng --replication-factor 3 --partitions 3 --創(chuàng)建topic
Created topic tongcheng.
[root@node1 bin]# ./kafka-topics.sh --list --zookeeper node1:2181 --查看topic
tongcheng
[root@node1 bin]# ./kafka-topics.sh --delete --zookeeper node1:2181 --topic tongcheng --刪除topic
Topic tongcheng is marked for deletion.
Note: This will have no impact if delete.topic.enable is not set to true.
[root@node1 bin]# ./kafka-topics.sh --list --zookeeper node1:2181
[root@node1 bin]#
6.發(fā)送消息/接收消息
[root@node1 bin]# ./kafka-console-producer.sh --broker-list node2:9092 --topic ttt
>tongcheng is goods;
>tong is goods;
>cheng is goods!
>
--------接收端-------------
[root@node2 bin]# ./kafka-console-consumer.sh --topic ttt --bootstrap-server node1:9092,node2:9092,node3:9092 --from-beginning
tongcheng is goods;
tong is goods;
cheng is goods!
[root@node2 bin]# ./kafka-topics.sh --describe --zookeeper node1:2181 --topic ttt --查看分區(qū)數(shù)和副本數(shù)
Topic:tttPartitionCount:1ReplicationFactor:1Configs:
Topic: tttPartition: 0Leader: 0Replicas: 0Isr: 0
[root@node2 bin]#
7.查看zookeeper數(shù)據(jù)
[root@node1 bin]# ./zkCli.sh
Connecting to localhost:2181
[zk: localhost:2181(CONNECTED) 0] ls /
[cluster, controller, brokers, zookeeper, hadoop-ha, admin, isr_change_notification, log_dir_event_notification, controller_epoch, consumers, latest_producer_id_block, config, hbase]
[zk: localhost:2181(CONNECTED) 1]
8.接收組消息(當(dāng)消費(fèi)者發(fā)送消息時(shí),只能是組中一個(gè)接收都者接收消息)
[root@node1 bin]# ./kafka-console-producer.sh --broker-list node1:9092 --topic tong --在node1節(jié)點(diǎn)發(fā)送消息
>
------啟動(dòng)兩臺(tái)消費(fèi)者-----------
[root@node2 bin]# vim ../config/consumer.properties --兩臺(tái)消費(fèi)都都要修改
group.id=wuhan
[root@node2 bin]# ./kafka-console-consumer.sh --topic tong --bootstrap-server node1:9092 --consumer.config ../config/consumer.properties
[2019-04-05 20:52:09,152] WARN [Consumer clientId=consumer-1, groupId=wuhan] Error while fetching metadata with correlation id 2 :
9.在發(fā)送端發(fā)送消息,接收端組接收消息
[root@node1 bin]# ./kafka-console-producer.sh --broker-list node1:9092 --topic tong
>[2019-04-05 20:51:31,094] INFO [GroupMetadataManager brokerId=0] Removed 0 expired offsets in 0 milliseconds. (kafka.coordinator.group.GroupMetadataManager)
[2019-04-05 20:52:09,114] INFO Creating topic tong with configuration {} and initial partition assignment Map(0 -> ArrayBuffer(2)) (kafka.zk.AdminZkClient)
[2019-04-05 20:52:09,124] INFO [KafkaApi-0] Auto creation of topic tong with 1 partitions and replication factor 1 is successful (kafka.server.KafkaApis)
>hello ttt;
>
-----------接收端--------------
[root@node2 bin]# ./kafka-console-consumer.sh --topic tong --bootstrap-server node1:9092 --consumer.config ../config/consumer.properties --在node2節(jié)點(diǎn)接收到消息
[2019-04-05 20:52:09,152] WARN [Consumer clientId=consumer-1, groupId=wuhan] Error while fetching metadata with correlation id 2 : {tong=LEADER_NOT_AVAILABLE}
(org.apache.kafka.clients.NetworkClient)
hello ttt;
到此,關(guān)于“kafka-2.11集群的搭建步驟”的學(xué)習(xí)就結(jié)束了,希望能夠解決大家的疑惑。理論與實(shí)踐的搭配能更好的幫助大家學(xué)習(xí),快去試試吧!若想繼續(xù)學(xué)習(xí)更多相關(guān)知識(shí),請(qǐng)繼續(xù)關(guān)注創(chuàng)新互聯(lián)-成都網(wǎng)站建設(shè)公司網(wǎng)站,小編會(huì)繼續(xù)努力為大家?guī)?lái)更多實(shí)用的文章!
標(biāo)題名稱:kafka-2.11集群的搭建步驟-創(chuàng)新互聯(lián)
分享地址:http://aaarwkj.com/article34/dddose.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站策劃、品牌網(wǎng)站設(shè)計(jì)、靜態(tài)網(wǎng)站、Google、網(wǎng)站排名、自適應(yīng)網(wǎng)站
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容