kafka 安裝步驟
kafka安裝文檔
1、解壓縮(官網下載:http://kafka.apache.org/downloads.html)
tar -xzf kafka_2.10-0.8.2.0.tgz
cd kafka_2.10-0.8.2.0
2、啟動server服務(包含zookeeper服務、kafka服務)
bin/zookeeper-server-start.sh config/zookeeper.properties & (&表示在後臺運行)
bin/kafka-server-start.sh config/server.properties &
3、創建topic
bin/kafka-topics.sh --create --zookeeper localhost:2181 --replication-factor 1 --partitions 1 --topic test
查看topic命令:
bin/kafka-topics.sh --list --zookeeper localhost:2181
4、發消息(producer發消息給kafka實例(broker)、consumer從kafka實例中接受數據)
Producer: bin/kafka-console-producer.sh --broker-list localhost:9092 --topic test
This is a message
This is another message
5、啟動consumer
bin/kafka-console-consumer.sh --zookeeper localhost:2181 --topic test --from-beginning
接受到的數據為:
This is a message
This is another message 註意:到這裏單機kafka測試完畢 以下介紹kafka集群安裝與測試
6、首先準備3個虛擬機 安裝
這裏就不介紹了!!!。!!
!
7、安裝好zookeeper後 在3個節點分別運行 zkServer.sh start
查看狀態命令為:zkServer.sh status
8、Hadoop0(192.168.80.100) 、Hadoop1(192.168.80.101) 、hadoop2(192.168.80.102) 相應主機 kafka以下的$KAFKA_HOME/conf/server.properties 分別改動文件為:
Hadoop0:
broker.id=0
port=9092
host.name=hadoop0
advertised.host.name=hadoop0
.....
num.partitions=2
zookeeper.contact=hadoop0:2181,hadoop1:2181,hadoop2:2181
Hadoop1:
broker.id=1
port=9093
host.name=hadoop1
advertised.host.name=hadoop1
.....
num.partitions=2
zookeeper.contact=hadoop0:2181,hadoop1:2181,hadoop2:2181
Hadoop2:
broker.id=2
port=9094
host.name=hadoop2
advertised.host.name=hadoop2
.....
num.partitions=2
zookeeper.contact=hadoop0:2181,hadoop1:2181,hadoop2:2181
9、模擬測試:
(1)分別在hadoop0、Hadoop1、hadoop2節點分別運行:
$KAFKA_HOME/bin/kafka-server-start.sh $KAFKA_HOME/config/server.properties &
(2)在hadoop0新建topic 命令為:
kafka-topics.sh --create --topic test --replication-factor 3 --partitions 2 --zookeeper hadoop0:2181
查看多少個topic命令:
&
kafka 安裝步驟