快速搭建kafka集羣3臺

默認三臺機器已經安裝java,設置好ssh免密鏈接。
集羣hosts文件:
image.png
1.下載kafka
http://kafka.apache.org/downl...
image.png
2.發送到集羣解壓到指定目錄/usr/local下java

tar -zxvf kafka_2.11-0.10.0.1.tar.gz -C /usr/local

3.進入kafka_2.11-0.10.0.1目錄,建立文件夾zk_kfk_data(自取)
,並在該目錄下建立myid文件,內容在三個集羣中不一樣,分別是1,2,3apache

cd kafka_2.11-0.10.0.1
mkdir zk_kfk_data
vi myid

image.png
4.建立目錄centos

mkdir logs
mkdir kafka-logs-1

image.png
5.修改/config/zookeeper.properties文件ssh

cd config
vi zookeeper.properties

image.png
6.修改server.propertiesoop

vi server.properties

image.png
image.png
image.png
7.把kafka整個文件夾分發給兩個子節點測試

scp -r /usr/local/kafka_2.11-0.10.1.1 hadoop@centos2:/usr/local
scp -r /usr/local/kafka_2.11-0.10.1.1 hadoop@centos3:/usr/local

8.修改centos2和centos3的myidspa

ssh centos2
cd /usr/local/kafka_2.11-0.10.1.1/zk_kfk_data
vi myid

image.png

ssh centos3
cd /usr/local/kafka_2.11-0.10.1.1/zk_kfk_data
vi myid

9.修改centos2和centos3的server.properties3d

ssh centos2
cd /usr/local/kafka_2.11-0.10.1.1/config
vi server.properties

image.png

ssh centos3
cd /usr/local/kafka_2.11-0.10.1.1/config
vi server.properties

image.png
安裝完成!
運行測試:(默認在/usr/local/kafka_2.11-0.10.1.1目錄下執行)
10.三臺集羣分別啓動zk:code

./bin/zookeeper-server-start.sh config/zookeeper.properties & 
或
nohup ./bin/zookeeper-server-start.sh config/zookeeper.properties &>> zookeeper.log &

11.啓動kafka集羣server

nohup ./bin/kafka-server-start.sh config/server.properties &>> kafka.log &

12.建立topic:

./bin/kafka-topics.sh --create --zookeeper centos1:2181,centos2:2181,centos3:2181  --replication-factor 1 --partitions 1 --topic test

13.查看topic:

./bin/kafka-topics.sh --list --zookeeper localhost:2181

image.png
14.發送數據:

./bin/kafka-console-producer.sh --broker-list centos1:9092,centos2:9092,centos3:9092 --topic test

image.png
15.消費:

./bin/kafka-console-consumer.sh --zookeeper centos1:2181,centos2:2181,centos3:2181 --from-beginning --topic test

image.png

相關文章
相關標籤/搜索