《Kafka实战》之kafka环境配置

cd kafka.xx.xx.x.x/config
vim server.properties
broker.id=0  为每台机器设置一个id
zookeeper.connect=192.168.29.167:2181,192.168.29.168:2181,192.168.29.169:2181

启动zookeeper集群
bin/zkServer.sh start  开启zookeeper
bin/zkServer.sh status 查看zookeeper状态

启动kafka集群
./kafka-server-start.sh  [-daemon] ../config/server.properties
kafka-topics.sh 创建topic
./kafka-topics.sh --create --zookeeper 192.168.29.167:2181,192.168.29.168:2181,192.168.29.169:2181 --topic kafka_new  --partitions 3 --replication-factor 2
查看已经创建的topics
./kafka-topics.sh --list --zookeeper 192.168.29.167:2181,192.168.29.168:2181,192.168.29.169:2181

生产数据
./kafka-console-producer.sh --broker-list 192.168.29.160:9092,192.168.29.161:9092,192.168.29.162:9092,192.168.29.163:9092 --topic kafka_new
其中--broker-list后面的是kafka集群的IP地址

消费数据
./kafka-console-consumer.sh --zookeeper 192.168.29.167:2181,192.168.29.168:2181,192.168.29.169:2181 --topic kafka_new

查看详细的说明
./kafka-topics.sh   --describe  --zookeeper 192.168.29.167:2181,192.168.29.168:2181,192.168.29.169:2181 --topic kafka_new
结果如下:
Topic: kafka_new Partition: 0 Leader: 2 Replicas: 2,3 Isr: 2,3
Topic: kafka_new Partition: 1 Leader: 3 Replicas: 3,0 Isr: 3,0
Topic: kafka_new Partition: 2 Leader: 0 Replicas: 0,1 Isr: 0
对于第一行:kafka_new 这个topic的Partition0 由broker2负责读写    其中Replicas的副本即在broker2和broker3上有副本  Isr是说broker2和broker3上面已经有副本了

你可能感兴趣的:(Kafka)