Centos 安装 Kafka 后台启动 教程

安装

官网

http://kafka.apache.org/downloads

1.下载

Python
➜ wget http://mirrors.tuna.tsinghua.edu.cn/apache/kafka/0.11.0.0/kafka_2.12-0.11.0.0.tgz 1
1
2
➜ wget http : / / mirrors . tuna . tsinghua . edu . cn / apache / kafka / 0.11.0.0 / kafka_2 . 12 - 0.11.0.0.tgz 1
 

2.解压

Python
➜ tar zxvf kafka_2.12-0.11.0.0.tgz ➜ mv kafka_2.12-0.11.0.0 kafka ➜ cd kafka12345
1
2
3
4
5
6
➜ tar zxvf kafka_2 . 12 - 0.11.0.0.tgz
 
➜ mv kafka_2 . 12 - 0.11.0.0 kafka
 
➜ cd kafka12345
 

功能验证

1.启动 Zookeeper

使用安装包中的脚本启动单节点Zookeeper 实例:

Python
➜ bin/zookeeper-server-start.sh -daemon config/zookeeper.properties
1
2
➜ bin / zookeeper - server - start . sh - daemon config / zookeeper . properties
 

2. 前台启动 Kafka 服务

使用kafka-server-start.sh 启动kafka 服务:

Python
➜ bin/kafka-server-start.sh config/server.properties
1
2
➜ bin / kafka - server - start . sh config / server . properties
 

2.1 Kafka 后台启动

 目的是想让服务后台启动,隐约记得&符号代表后台启动,运行命令后服务确实后台启动了,但日志会打印在控制台,而且关掉命令行窗口,服务就会随之停止,这个让我挺困惑的。后来,参考了其他的启动脚本,通过测试和调试最终找到了完全满足要求的命令。

满意的命令:

Python
sh kafka-server-start.sh ../config/server.properties 1>/dev/null  2>&1  &
1
2
sh kafka - server - start . sh . . / config / server . properties 1 > / dev / null  2 > & 1  &
 

其中1>/dev/null  2>&1 是将命令产生的输入和错误都输入到空设备,也就是不输出的意思。
/dev/null代表空设备。

3.创建topic

使用kafka-topics.sh 创建单分区单副本的topic test:

Python
➜ bin/kafka-topics.sh --create --zookeeper localhost:2181 --replication-factor 1 --partitions 1 --topic test1
1
2
➜ bin / kafka - topics . sh -- create -- zookeeper localhost : 2181 -- replication - factor 1 -- partitions 1 -- topic test1
 

查看topic:

Python
➜ bin/kafka-topics.sh --list --zookeeper localhost:2181 test123
1
2
3
4
➜ bin / kafka - topics . sh -- list -- zookeeper localhost : 2181
 
test123
 

4.产生消息

使用kafka-console-producer.sh 发送消息:

Python
➜ bin/kafka-console-producer.sh --broker-list localhost:9092 --topic test Hello world!123
1
2
3
➜ bin / kafka - console - producer . sh -- broker - list localhost : 9092 -- topic test
Hello world! 123
 

5.消费消息

使用kafka-console-consumer.sh 接收消息并在终端打印:

Python
➜ bin/kafka-console-consumer.sh --zookeeper localhost:2181 --topic test --from-beginning Hello world!123
1
2
3
4
➜ bin / kafka - console - consumer . sh -- zookeeper localhost : 2181 -- topic test -- from - beginning
 
Hello world ! 123
 



  • zeropython 微信公众号 5868037 QQ号 5868037@qq.com QQ邮箱
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值