1 解壓kafka
建立一個kafka的文件夾,用戶存放kafka文件java
mkdir /usr/local/kafka
經過ftp工具把下載好的kafka安裝包上傳到kafka文件夾下。redis
解壓:vim
cd /usr/local/kafka</pre> tar -vxzf redis-3.2.10.tar.gz
解壓完成bash
2 修改配置
zookeeper相關工具
進入到kafka配置文件夾並編輯zookeeper配置測試
cd kafka_2.11-2.0.0/config vim zookeeper.properties
設置zookeeper的數據存放位置以及端口:ui
# 數據的存放目錄 dataDir=/tmp/zookeeper # 端口,默認就是2181 clientPort=2181
kafka相關rest
編輯kafka配置日誌
vim server.properties
修改kafka配置code
# broker的全局惟一編號,不能重複 broker.id=0 # 監聽 listeners=PLAINTEXT://10.168.1.213:9092 # 日誌目錄 log.dirs=/tmp/kafka-logs # 配置zookeeper的鏈接(若是不是本機,須要該爲ip或主機名) zookeeper.connect=localhost:2181
1.3 啓動
進入kafka根目錄
cd /usr/local/kafka/kafka_2.11-2.0.0
啓動zookeeper
./bin/zookeeper-server-start.sh -daemon ./config/zookeeper.properties &
啓動kafka
./bin/kafka-server-start.sh -daemon ./config/server.properties &
查看是否啓動成功
jps
1.4 設置開機啓動
進入/etc/init.d/
目錄下
cd /etc/init.d/
建立文件kafka
vim kafka
寫入開機啓動相關的腳本內容
#!/bin/bash #chkconfig:2345 20 90 #description:kafka #processname:kafka ### BEGIN INIT INFO # Required-Start: # Required-Stop: # Default-Start: 2 3 4 5 # Default-Stop: 0 1 6 # Short-Description: kafka server # Description: kafka server. ### END INIT INFO export JAVA_HOME=/usr/local/java/jdk1.8.0_181 export PATH=$JAVA_HOME/bin:$PATH zookeeperStart(){ /usr/local/kafka/kafka_2.11-2.0.0/bin/zookeeper-server-start.sh -daemon /usr/local/kafka/kafka_2.11-2.0.0/config/zookeeper.properties & } kafkaStart(){ /usr/local/kafka/kafka_2.11-2.0.0/bin/kafka-server-start.sh -daemon /usr/local/kafka/kafka_2.11-2.0.0/config/server.properties & } zookeeperStop(){ /usr/local/kafka/kafka_2.11-2.0.0/bin/zookeeper-server-stop.sh } kafkaStop(){ /usr/local/kafka/kafka_2.11-2.0.0/bin/kafka-server-stop.sh } case $1 in start) echo -n "Starting Kafka:" zookeeperStart sleep 5 kafkaStart exit $? ;; stop) echo -n "stop Kafka:" kafkaStop sleep 5 zookeeperStop exit $? ;; status) jps exit $? ;; restart) echo "restart" stop sleep 5 start exit $? ;; *) echo "require start|stop|status|restart" exit 1 ;; esac
設置文件權限
chmod +x kafka
添加到服務中
update-rc.d -f kafka defaults
測試
service kafka start
查看服務是否啓動成功
jps
重啓測試
reboot