标签:
上文已经讲过如何安装Zookeeper集群,因为Kafka集群需要依赖Zookeeper服务,虽然Kafka有内置Zookeeper,但是还是建议独立安装Zookeeper集群服务,此处不再赘述
kafka集群还是安装在192.168.20.178 、 192.168.20.179 、192.168.20.174三台机器上面
zookeeper集群
192.168.20.178 kafka1
192.168.20.179 kafka2
192.168.20.174 kafka3
192.168.20.37 zookeeper1
192.168.20.38 zookeeper2
192.168.20.39 zookeeper3
1、kafka官网下载kafka_2.10-0.10.0.0.tgz压缩包,解压缩
2、修改/appcom/kafka_2.10-0.10.0.0/config/server.properties文件:
192.168.20.178机器:
broker.id=1
host.name=kafka1
listeners=PLAINTEXT://kafka1:9092
advertised.listeners=PLAINTEXT://kafka1:9092
log.dirs=/data/kafka/logs
num.partitions=4
zookeeper.connect=zookeeper1:2181,zookeeper2:2181,zookeeper3:2181
其他配置暂时采取默认
192.168.20.179机器:
broker.id=2
host.name=kafka2
listeners=PLAINTEXT://kafka2:9092
advertised.listeners=PLAINTEXT://kafka2:9092
log.dirs=/data/kafka/logs
num.partitions=4
zookeeper.connect=zookeeper1:2181,zookeeper2:2181,zookeeper3:2181
其他配置暂时采取默认
192.168.20.39机器:
broker.id=3
host.name=kafka3
listeners=PLAINTEXT://kafka3:9092
advertised.listeners=PLAINTEXT://kafka3:9092
log.dirs=/data/kafka/logs
num.partitions=4
zookeeper.connect=zookeeper1:2181,zookeeper2:2181,zookeeper3:2181
其他配置暂时采取默认
3、在每台服务器分别启动kafka服务:
./kafka-server-start.sh /appcom/kafka/config/server.properties & (以这种方式启动kafka应用后,kafka总会莫名其妙的退出。后来改为这种命令启动:
./kafka-server-start.sh -daemon /appcom/kafka/config/server.properties 解决了问题)
4、任意一台机器上面,测试: 在kafka中创建名为“cmy_nbd_topic1”的topic,该topic切分为4份,每一份备份数为3
./kafka-topics.sh --create --zookeeper zookeeper1:2181 --replication-factor 3 --partitions 4 --topic cinyi_topic1
5、列出所有topic :
./kafka-topics.sh --list --zookeeper zookeeper1:2181,zookeeper2:2181,zookeeper3:2181
标签:
原文地址:http://www.cnblogs.com/fengjian2016/p/5654217.html