伪分布式的方式安装kafka
启动3台kafka Brokers
安装过程
1. 上传解压
2. 配置
以下配置都在此目录下 config/server.properties
配置唯一标识符
broker.id=9092
配置Broker端口
port=9092
配置Broker运行主机名称
host.name=bigdata-hpsk01.huadian.com
配置日志文件存储目录
需要自己创建
log.dirs=/opt/modules/kafka_2.11-0.8.2.1/kafkaDatas/data9092
配置ZK地址以及存储ZNode根目录
zookeeper.connect:2181=bigdata-hpsk01.huadian.com/kafka
复制server.properties
,
分别为:
server9092.properties
server9093.properties,
server9094.properties
记得修改对应的 broker.id, port, log.dirs
3. 启动服务
需要先启动Zookeeper
启动kafka进程:
bin/kafka-server-start.sh -daemon config/server9092.properties
bin/kafka-server-start.sh -daemon config/server9093.properties
bin/kafka-server-start.sh -daemon config/server9094.properties
创建topic
bin/kafka-topics.sh --create --zookeeper 192.168.59.200/kafka --replication-factor 2 --partitions 3 --topic testTopic
--replication-factor:副本数 ,需要<Brokers 数量
--partitions:分区数
查看Kafka Cluster中有多少topic
bin/kafka-topics.sh --list --zookeeper 192.168.59.200/kafka
模拟生产者发送数据到Topic中
bin/kafka-console-producer.sh --broker-list 192.168.59.200:9092,192.168.59.200:9093,192.168.59.200:9094 --topic testTopic
模拟消费者消费Topic中数据
bin/kafka-console-consumer.sh --zookeeper 192.168.59.200/kafka --topic testTopic --from-beginning