Kafka 一:安装(单机),测试)
安装 Zookeeper
解压,重命名,进conf目录
[root@test200 conf]# mv zoo_sample.cfg zoo.cfg
配置 zoo.cfg
此处与 Hbase 的安装 Zoopkeeper 的目录不一致,可去Hbase安装博客看看
dataDir=/opt/bigdata/zookeeper345
dataLogDir=/opt/bigdata/zookeeper345
zookeeper环境变量
export ZOOKEEPER_HOME=/opt/greeinstall/zookeeper345
export PATH=$PATH:$ZOOKEEPER_HOME/bin
启动zookeeper
[root@caicai bin]# ./zkServer.sh start
安装 Kafka
解压
[root@cai install]# tar -zxvf kafka_2.11-2.0.0.tgz -C ../bigdata/
配置 server.properties
[root@cai config]# vi server.properties
delete.topic.enable=true
auto.create.topics.enable = false
log.dirs=/opt/bigdata/kafka211/kafka-logs
advertised.listeners=PLAINTEXT://192.168.101.130:9092
zookeeper.connect=192.168.101.130:9092
配置环境变量
export KAFKA_HOME=/opt/bigdata/kafka
export PATH=$PATH:$KAFKA_HOME/bin
刷新环境变量
[root@cai kafka211]# source /etc/profile
启动
[root@cai bin]# ./kafka-server-start.sh ../config/server.properties
后台启动
[root@cai bin]# ./kafka-server-start.sh -daemon ../config/server.properties
创建 topic
# partitions 1 分区 replication-factor 1 备份因子
[root@cai bin]# ./kafka-topics.sh --create --topic mydemo --zookeeper 192.168.101.130:2181 --partitions 1 --replication-factor 1
Created topic "mydemo".
查看
[root@cai bin]# ./kafka-topics.sh --zookeeper 192.168.101.130:2181 --list
mydemo
删除 topic(mydemo)
[root@cai bin]# ./kafka-topics.sh --delete --zookeeper 192.168.101.130:2181 --topic mydemo
查看 topic 详细情况
[root@cai bin]# ./kafka-topics.sh --describe --zookeeper 192.168.101.130:2181 --topic mydemo
Topic:mydemo PartitionCount:1 ReplicationFactor:1 Configs:
Topic: mydemo Partition: 0 Leader: 0 Replicas: 0 Isr: 0
启动kafaka消费者
[root@lijia1 /]# kafka-console-consumer.sh --bootstrap-server 192.168.101.130:9092 --topic mydemo --from-beginning
启动kafaka生产者
[root@lijia1 /]# kafka-console-producer.sh --broker-list 192.168.101.130:9092 --topic mydemo
查看topic消息数量
[root@lijia1 /]# kafka-run-class.sh kafka.tools.GetOffsetShell --broker-list 192.168.101.130:9092 --topic mydemo --offsets 1