默认三台机器已经安装java,设置好ssh免密连接。
集群hosts文件:
image.png
1.下载kafka
http://kafka.apache.org/downl...
image.png
2.发送到集群解压到指定目录/usr/local下

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,3

cd kafka_2.11-0.10.0.1
mkdir zk_kfk_data
vi myid

image.png
4.创建目录

mkdir logs
mkdir kafka-logs-1

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

cd config
vi zookeeper.properties

image.png
6.修改server.properties

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的myid

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.properties

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:

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

11.启动kafka集群

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


ch123
60 声望7 粉丝

积土而为山,积水而为海。