一、环境:html
centos7bootstrap
kafka_2.10-0.10.2.1centos
zookeeper-3.5.2bash
jdk1.8服务器
二、前提:ide
安装JDK直播带货测试
安装zookeeperurl
三、在master上将kafka安装包上传到Linu的/opt/softWare/kafka目录下并解压centos7
四、将/opt/softWare/kafka分发到其余服务器.net
scp -r kafka slaves1:/opt/softWare/ scp -r kafka slaves2:/opt/softWare/
五、分别配置master、slaves一、slaves2中kafka中config下的server.properties
broker.id=0 port=6667 host.name=master zookeeper.connect=master:2181,slaves1:2181,slaves2:2181
broker.id=1 port=6667 host.name=slaves1 zookeeper.connect=master:2181,slaves1:2181,slaves2:2181
broker.id=2 port=6667 host.name=slaves2 zookeeper.connect=master:2181,slaves1:2181,slaves2:2181
六、启动zookeeper
八、启动kafka
[root@master bin]# nohup ./kafka-server-start.sh ../config/server.properties & [root@slaves1 bin]# nohup ./kafka-server-start.sh ../config/server.properties & [root@slaves2 bin]# nohup ./kafka-server-start.sh ../config/server.properties &
九、建立主题
[root@master bin]# ./kafka-topics.sh --create --zookeeper master:2181,slaves1:2181,slaves2:2181 --replication-factor 3 --partitions 1 --topic mytest Created topic "mytest". [root@master bin]# ./kafka-topics.sh --list --zookeeper master:2181,slaves1:2181,slaves2:2181 mytest
十、测试:master生产数据、slaves一、slaves2消费数据
[root@master bin]# ./kafka-console-producer.sh --broker-list master:6667 --topic mytest test01 test02 test02 test03
[root@slaves1 bin]# ./kafka-console-consumer.sh --zookeeper master:2181,slaves1:2181,slaves2:2181 --topic mytest --from-beginning Using the ConsoleConsumer with old consumer is deprecated and will be removed in a future major release. Consider using the new consumer by passing [bootstrap-server] instead of [zookeeper]. test01 test02 test02 test03
[root@slaves2 bin]# ./kafka-console-consumer.sh --zookeeper master:2181,slaves1:2181,slaves2:2181 --topic mytest --from-beginning Using the ConsoleConsumer with old consumer is deprecated and will be removed in a future major release. Consider using the new consumer by passing [bootstrap-server] instead of [zookeeper]. test01 test02 test02 test03