Kafka學習之(二)Centos下安裝Kafka

OldBoy~發表於2018-01-16

環境:Centos6.4,官方下載地址:http://kafka.apache.org/downloads  ,前提是還需要安裝了Java環境,本部落格http://www.cnblogs.com/wt645631686/p/8267239.html有安裝方法

# wget https://archive.apache.org/dist/kafka/0.10.1.0/kafka_2.10-0.10.1.0.tgz
# tar zxvf kafka_2.10-0.10.1.0.tgz
# mv ./kafka_2.10-0.10.1.0 /usr/local/kafka
# cd /usr/local/kafka/config/
# vim zookeeper.properties   #編輯zookeeper配置檔案
#---------------------------------------------------------#
dataDir=/tmp/zookeeper
# the port at which the clients will connect
#客戶端埠2181,也就是通過zookeeper啟動kafka的時候,指定埠號
clientPort=2181
# disable the per-ip limit on the number of connections since this is a non-production config
maxClientCnxns=0
# vim server.properties   #編輯kafka配置檔案
#------------------------------------------------------#
listeners=PLAINTEXT://127.0.0.1:9092

記住先啟動zookeeper,再啟動kafka

# ./bin/zookeeper-server-start.sh ./config/zookeeper.properties   #啟動zookeeper
# ./bin/kafka-server-start.sh config/server.properties            #開啟新終端啟動kafka
[root@localhost ~]# netstat -tunlp | grep 9092
tcp        0      0 ::ffff:127.0.0.1:9092       :::*                        LISTEN      3092/java 

啟動成功,測試一下

建立消費者

# bin/kafka-console-consumer.sh --zookeeper localhost:2181 --topic mytest --from-beginning  //消費的叢集--zookeeper  localhost:2181 zookeeper埠地址  --topic mytest   監聽的主題
#--from-beginning   從開頭監聽 
Using the ConsoleConsumer with old consumer is deprecated and will be removed in a future major release. Consider using the new consumer by passing [bootstrap-server] instead of [zookeeper].

開啟新終端建立生產者

# bin/kafka-console-producer.sh --broker-list localhost:9092 --topic mytest

繼續操作,輸入想要輸入的字串敲擊回車,觀察消費者終端會發現有新訊息。

OK~

相關文章