0%

CentOS 7安装Kafka

环境:CentOS 7
Kafka版本:kafka_2.12-2.6.2

下载Kafka安装文件

1
$ sudo wget https://mirror.nodesdirect.com/apache/kafka/2.6.2/kafka_2.12-2.6.2.tgz

解压安装

1
$ sudo tar -xzf kafka_2.12-2.6.2.tgz -C /usr/local/kafka

启动Zookeeper

1
$ sudo bin/zookeeper-server-start.sh config/zookeeper.properties

启动Kafka

修改server.properties配置文件。

如果要使用外部程序去调用Kafka的话,需要设置advertised.listeners参数的IP地址。
advertised.listeners=PLAINTEXT://192.168.0.2:9092

1
$ sudo bin/kafka-server-start.sh config/server.properties

测试

创建Topic

1
2
3
4
5
$ bin/kafka-topics.sh --create --topic quickstart-events --bootstrap-server localhost:9092
$ bin/kafka-topics.sh --describe --topic quickstart-events --bootstrap-server localhost:9092
Topic:quickstart-events PartitionCount:1 ReplicationFactor:1 Configs:
Topic: quickstart-events Partition: 0 Leader: 0 Replicas: 0 Isr: 0
S

写消息

1
2
3
$ bin/kafka-console-producer.sh --topic quickstart-events --bootstrap-server localhost:9092
This is my first event
This is my second event

读消息

1
2
3
$ bin/kafka-console-consumer.sh --topic quickstart-events --from-beginning --bootstrap-server localhost:9092
This is my first event
This is my second event