Kafka安裝配置及簡單通道傳輸操作(kafka2.9.2)

一、kafka安裝(kafka_2.9.2-0.8.1.1.zip)

1、下載並解壓安裝包

tar -xvf kafka_2.9.2-0.8.1.1.tgz 或者 unzip kafka_2.9.2-0.8.1.1.zip

2、修改配置文件conf/server.properties:

broker.id=0;
host.name=xxx.xxx.xxx.xxx
zookeeper.connect= xxx.xxx.xxx.xxx可逗號分隔配置多個

3、修改配置文件vim log4j.properties(最新版則不需要修改)

① log4j.appender.D.File = /data1/home/shaka/kafka/kafka_2.9.2-0.8.1.1/logs/debug.log
② log4j.appender.E.File = /data1/home/shaka/kafka/kafka_2.9.2-0.8.1.1/logs/error.log

4、啓動kafka服務

bin/kafka-server-start.sh -daemon ./config/server.properties

5、查看是否啓動: jsp -l

這裏寫圖片描述

6、創建topic主題:

bin/kafka-topics.sh --create --zookeeper 主機名:2181 --replication-factor 1 --partitions 2 --topic mytopic

7、啓動consumer
bin/kafka-console-consumer.sh --zookeeper 主機名:2181 --topic mytopic
(進入等待狀態)

8、開啓另外一個終端連接主機,啓動productor

bin/kafka-console-producer.sh --broker-list <主機名>:9092 --topic mytopic
(進入等待狀態)

9、開啓第三個終端連接主機,發送腳本shelllogger.sh
編輯腳本,註釋#log=”….”在下面添加
log=”INSERT INTO test(user,content) VALUES(‘xxxx’,’xxxxx’);”保存

10、運行腳本
./shelllogger.sh &

11、查看腳本是否運行:
tail -f access.log
(動態顯示日誌內容)

12、將日誌實時傳送到kafka指定主題中

nohup tail -f /home/storm/app/kafka_2.10-0.9.0.1/access.log | bin/kafka-console-producer.sh --broker-list mystorm:9092 --topic topic-003-name >logs/producer.log 2>&1 &
(此時ConsoleConsumer端會接收到日誌信息說明成功!)

這裏寫圖片描述

附:停止持續輸出日誌信息操作

jps
kill -USR2 [ConsoleProducer的進程號PID]
ps -l
kill -USR2 [shelllogger.sh進程的PID]
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章