您好,登錄后才能下訂單哦!
小編給大家分享一下Centos6.5下kafka如何部署安裝,希望大家閱讀完這篇文章之后都有所收獲,下面讓我們一起去探討吧!
一)安裝JDK
步驟1:新建路徑/usr/Java, 并在其下解壓 jdk-7u71-linux-x64.tar.gz
# mkdir -p /usr/java
# tar -zxvf jdk-7u71-linux-x64.tar.gz
步驟2:添加JDK到系統環境變量
# vi /etc/profile
新增以下內容:
export JAVA_HOME=/usr/java/jdk1.7.0_71
export PATH=$JAVA_HOME/bin:$PATH
export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
步驟3:使配置生效
source /etc/profile #使配置文件立即生效
# java -version //JDK版本java version "1.7.0_79" 也可以,目前JDK1.8版本不支持;
Java version "1.7.0_71"
Java(TM) SE Runtime Environment (build 1.7.0_71-b14)
Java HotSpot(TM) 64-Bit Server VM (build 24.71-b01, mixed mode)
二)安裝zookeeper
步驟1:解壓zookeeper安裝包(路徑無關,安裝路徑可以自定義)
# tar -zxvf zookeeper-3.3.6.tar.gz
步驟2:配置環境變量
# vim /etc/profile
export zookeeper_home=/home/laoyang/zookeeper
#source /etc/profile
# sh $zookeeper_home/bin/zkServer.sh start
JMX enabled by default
Using config: /home/laoyang/zookeeper/bin/../conf/zoo.cfg
grep: /home/laoyang/zookeeper/bin/../conf/zoo.cfg: No such file or directory
Starting zookeeper ... STARTED
三)安裝kafka
步驟1:解壓&移動到/usr/local
# tar -xzvf kafka_2.11-0.9.0.1.tgz
# mv kafka_2.11-0.9.0.1 /usr/local/kafka
步驟2:配置kafka,修改server.properties
# mkdir /usr/local/kafka/log/kafka #創建kafka日志目錄
# cd /usr/local/kafka/config #進入配置目錄
# vim server.properties #編輯修改相應的參數
broker.id=0
port=9092 #端口號
host.name=10.8.5.101 #服務器IP地址,修改為自己的服務器IP
log.dirs=/usr/local/kafka/log/kafka #日志存放路徑,上面創建的目錄
zookeeper.connect=localhost:2181 #zookeeper地址和端口,單機配置部署,localhost:2181
步驟3、配置kafka下的zookeeper
# mkdir /usr/local/kafka/zookeeper #創建zookeeper目錄
# mkdir /usr/local/kafka/log/zookeeper #創建zookeeper日志目錄
# cd /usr/local/kafka/config #進入配置目錄
# vim zookeeper.properties #編輯修改相應的參數
dataDir=/usr/local/kafka/zookeeper #zookeeper數據目錄
dataLogDir=/usr/local/kafka/log/zookeeper #zookeeper日志目錄
clientPort=2181
maxClientCnxns=100
tickTime=2000
initLimit=10
syncLimit=5
步驟4:創建啟動、關閉kafka腳本
1)創建啟動kafka腳本
#cd /usr/local/kafka/bin/
# vim kafkastart.sh
#!/bin/bash
#啟動zookeeper
/usr/local/kafka/bin/zookeeper-server-start.sh /usr/local/kafka/config/zookeeper.properties &
sleep 3
#Start kafka
/usr/local/kafka/bin/kafka-server-start.sh /usr/local/kafka/config/server.properties &
2)創建關閉kafka腳本
# vim kafkastop.sh
#!/bin/bash
#stop zookeeper
/usr/local/kafka/bin/zookeeper-server-stop.sh /usr/local/kafka/config/zookeeper.properties &
sleep 3
#Stop kafka
/usr/local/kafka/bin/kafka-server-stop.sh /usr/local/kafka/config/server.properties &
3)#添加腳本執行權限
chmod +x kafkastart.sh
chmod +x kafkastop.sh
4)設置腳本開機自動執行
# vim /etc/rc.d/rc.local #編輯,在最后添加一行
sh /usr/local/kafka/kafkastart.sh & #設置開機自動在后臺運行腳本
sh /usr/local/kafka/kafkastart.sh #啟動kafka
sh /usr/local/kafka/kafkastop.sh #關閉kafka
到此為止CentOs6.5下Kafka安裝配置完成。
成功標志:
四)測試kafka
步驟1:啟動zookeeper
# sh $zookeeper_home/bin/zkServer.sh start
JMX enabled by default
Using config: /home/laoyang/zookeeper/bin/../conf/zoo.cfg
grep: /home/laoyang/zookeeper/bin/../conf/zoo.cfg: No such file or directory
Starting zookeeper ... STARTED
步驟2:啟動kafka
# ./kafkastart.sh
步驟3:測試創建topic
# cd /usr/local/kafka/bin
# ./kafka-topics.sh --create --zookeeper localhost:2181 --replication-factor 1 --partitions 1 --topic test
步驟4:通過list命令查看創建的topic
# cd /usr/local/kafka/bin
# ./kafka-topics.sh –list –zookeeper localhost:2181
步驟5:生產消息測試
# ./kafka-console-producer.sh --broker-list localhost:9092 --topic test
Kafka test! //這里的“Kafka test!”為手動輸入的,輸入后“ctrl +c”退出;
步驟6:消費消息測試
# ./kafka-console-consumer.sh --zookeeper localhost:2181 --topic test --from-beginning
I'm laoyang #之前測試輸入的內容
kafka test!
經過上面幾步,代表kafka安裝成功。
五)停止kafka
步驟1:停止Kafka
cd /usr/local/kafka
# ./kafkastop.sh //這里的kafka進程并沒有關掉,需要手動kill
步驟2:停止Zookeeper server
# sh $zookeeper_home/bin/zkServer.sh stop
至此,啟動,測試,停止全過程ok。
kafka啟動過程中的報錯:
WARN caught end of stream exception (org.apache.zookeeper.server.NIOServerCnxn)
EndOfStreamException: Unable to read additional data from client sessionid 0x157ac94cd940002, likely client has closed socket
at org.apache.zookeeper.server.NIOServerCnxn.doIO(NIOServerCnxn.java:228)
at org.apache.zookeeper.server.NIOServerCnxnFactory.run(NIOServerCnxnFactory.java:208)
at java.lang.Thread.run(Thread.java:745)
報錯原因:
zookeeper服務端和客戶端的jar版本不一致導致的 ;
解決辦法:
從zookeeper服務端安裝目錄的根目錄復制zookeeper-xxx.jar到kafka安裝目錄下的libs目錄下即可,將kafka下libs目錄下的jar包刪除;
報錯:
java.lang.RuntimeException: A broker is already registered on the path /brokers/ids/1. This probably indicates that you either have configured a brokerid that is already in use, or else you have shutdown this broker and restarted it faster than the zookeeper timeout so it appears to be re-registering.
at kafka.utils.ZkUtils$.registerBrokerInZk(ZkUtils.scala:205)
at kafka.server.KafkaHealthcheck.register(KafkaHealthcheck.scala:57)
at kafka.server.KafkaHealthcheck.startup(KafkaHealthcheck.scala:44)
at kafka.server.KafkaServer.startup(KafkaServer.scala:103)
at kafka.server.KafkaServerStartable.startup(KafkaServerStartable.scala:34)
at kafka.Kafka$.main(Kafka.scala:46)
at kafka.Kafka.main(Kafka.scala)
報錯原因:
該錯誤是由于server.properties 中的broker.id 重復
解決辦法:
# vim server.properties
# The id of the broker. This must be set to a unique integer for each broker.
broker.id=0
看完了這篇文章,相信你對“Centos6.5下kafka如何部署安裝”有了一定的了解,如果想了解更多相關知識,歡迎關注億速云行業資訊頻道,感謝各位的閱讀!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。