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

來源:互聯網
上載者:User

一、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端會接收到日誌資訊說明成功。)

附:停止持續輸出日誌資訊操作

jpskill -USR2 [ConsoleProducer的進程號PID]ps -lkill -USR2 [shelllogger.sh進程的PID]

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.