完成zookeeper集群部署后,继续kafka集群部署:
1.安装配置:
a.同样3台 Linux Server Redhat 7.2
[root@kafka-pr opt]# more /etc/hosts
10.170.195.12 kafka-con2
10.170.194.98 kafka-con1
10.170.197.16 kaka-pro
b. kafka 0.10 (http://mirrors.tuna.tsinghua.edu.cn/apache/kafka/0.10.0.0/kafka_2.11-0.10.0.0.tgz)
2.安装与配置
a.首先在kafka-pr解压kafka包:
[root@kafka-pr opt]# pwd
/opt
[root@kafka-pr opt]# tar -zvxf kafka_2.11-0.10.0.0.tgz
b.创建kafka消息目录:
[root@kafka-pr kafka_2.11-0.10.0.0]# mkdir kafkalog/
c.配置server.properties 文件:
将如下参数添加到 server.properties
broker.id=0
*#broker 在集群中的标示*
log.dirs=/opt/kafka_2.11-0.10.0.0/kafkalog
*#消息日志目录*
listeners=PLAINTEXT://10.170.197.16:9092
*#broker 监听IP与端口*
replica.fetch.max.bytes=5048576
*#broker可复制的消息的最大字节数*
max.message.bytes=5048576
*#server可以接收的消息最大字节数*
default.replication.factor=2
*#消息副本数*
zookeeper.connect=10.170.197.16:2181,10.170.194.98:2181,10.170.195.12:2181
*#各zookeeper节点ip与端口*
在kafka-con1,kafka-con2中执行a-c步骤。
特别提示:server.properties 中broker.id 值各不相同,其他相同:
kafka-con1:broker.id=2
kafka-con2:broker.id=3
3.启动集群
a.分别在kafka-pr,kafka-con1,kafka-con2上运行kafka-server-start.sh
[root@kafka-pr bin]# pwd
/opt/kafka_2.11-0.10.0.0/bin
[root@kafka-pr bin]# ./kafka-server-start.sh -daemon ../config/server.properties
[root@kafka-con1 bin]# pwd
/opt/kafka_2.11-0.10.0.0/bin
[root@kafka-con1 bin]# ./kafka-server-start.sh -daemon ../config/server.properties
[root@kafka-con2 bin]# pwd
/opt/kafka_2.11-0.10.0.0/bin
[root@kafka-con2 bin]# ./kafka-server-start.sh -daemon ../config/server.properties
4.订阅topic
a.在kafka-pr中订阅名为leontest 的topic:
[root@kafka-pr bin]# ./kafka-topics.sh --create --zookeeper localhost:2181 --replication-factor 2 --partitions 1 --topic looniest
b.确认topic订阅成功:
[root@kafka-pr bin]# ./kafka-topics.sh --list --zookeeper localhost:2181
looniest
5.集群消息收发:
a.启动消费者
启动kafka-con1:
[root@kafka-con1 bin]# ./kafka-console-consumer.sh --zookeeper localhost:2181 --topic leontest --from-beginning
启动kafka-con2:
[root@kafka-con2 bin]# ./kafka-console-consumer.sh --zookeeper localhost:2181 --topic leontest --from-beginning
启动kafka-pr生产者:
[root@kafka-pr bin]# ./kafka-console-producer.sh --broker-list localhost:9092 --topic leontest