Kafka集群搭建
下面是以三台机器搭建为例,(扩展到4台以上一样,修改下配置文件即可)
1、下载kafka
http://apache.fayea.com/kafka/0.9.0.1/ ,拷贝到三台服务器,并解压文件
2、 修改配置文件 server.properties:
183服务器:
broker.id=
host.name=132.228.28.183
advertised.host.name=132.228.28.183
zookeeper.connect=132.228.28.183:,132.228.28.184:,132.228.28.185:
184服务器:
broker.id=
host.name=132.228.28.183
advertised.host.name=132.228.28.183
zookeeper.connect=132.228.28.183:,132.228.28.184:,132.228.28.185:
185服务器:
broker.id=
host.name=132.228.28.183
advertised.host.name=132.228.28.183
zookeeper.connect=132.228.28.183:,132.228.28.184:,132.228.28.185:
3、 添加主机域名,启动zookeeper可能会找不到host.name导致出错
183服务器:
在文件/etc/hosts末尾添加:
132.228.28.183 dsjtest01 184服务器:
在文件/etc/hosts末尾添加:
132.228.28.184 dsjtest02 185服务器:
在文件/etc/hosts末尾添加:
132.228.28.185 dsjtest03
4、 启动kafka
进入到kafka的bin目录,三台服务器都要启动
启动zookeeper: ./zookeeper-server-start.sh ../config/zookeeper.properties & 启动kafka: ./kafka-server-start.sh ../config/server.properties &
5、测试
在183创建topic:
./kafka-topics.sh --create --zookeeper localhost: --replication-factor --partitions --topic test
在184生产消息,发送到kafka
./kafka-console-producer.sh --broker-list 132.228.28.183: --topic test
终端输入:hello kafka
在185消费消息
./kafka-console-consumer.sh --zookeeper 132.228.28.183: --topic test --from-beginning
接收到消息:hello kafka