1.下载kafka
2.安装kafka
2.1解压kafka
[doda@host166 kafka]$ tar zxvf kafka_2.11-2.4.1.tgz
2.2配置kafka
主要修改kafka的监听端口,日志数据地址,zk连接地址
[doda@host166 config]$ vim server.properties
listeners=PLAINTEXT://172.21.72.166:9092
log.dirs=/home/doda/shangeshishi/bigdata/kafka/logs
zookeeper.connect=172.21.72.166:2181
3.守护线程方式启动kafka
[doda@host166 kafka_2.11-2.4.1]$ ./bin/kafka-server-start.sh -daemon ./config/server.properties
4.验证kafka是否启动成功
4.1查找kafka进程
[doda@host166 kafka_2.11-2.4.1]$ ps -ef|grep kafka
4.2测试连接kafka
4.2.1创建topic
[doda@host166 kafka_2.11-2.4.1]$ ./bin/kafka-topics.sh --create --zookeeper localhost:2181 --replication-factor 1 --partitions 1 --topic testTopic
Created topic testTopic.
若报错:Exception in thread "main" joptsimple.UnrecognizedOptionException: zookeeper is not a recognized option
原因如果使用的是 3.0.0 及以上版本,必须使用 --bootstrap-server
。如果需要继续使用 ZooKeeper 方式,需降级到 2.8.1 及以下版本
doda@host166[/home/wdp/kafka/kafka_2.12-3.1.0]$ ./bin/kafka-topics.sh --create \
--bootstrap-server localhost:9092 \
--replication-factor 1 \
--partitions 1 \
--topic testTopic
Created topic testTopic.
4.2.2查看当前topic
[doda@host166 kafka_2.11-2.4.1]$ ./bin/kafka-topics.sh --zookeeper localhost:2181 --describe --topic testTopic
Topic: testTopic PartitionCount: 1 ReplicationFactor: 1 Configs:
Topic: testTopic Partition: 0 Leader: 0 Replicas: 0 Isr: 0
./bin/kafka-topics.sh --describe \ --bootstrap-server 172.21.72.152:9092 \topic testTopic