kafka环境搭建

kafka需要zookeeper

安装zookeeper地址:

https://www.cnblogs.com/nanxiang/p/14051057.html

 

三台服务器:

172.16.252.128

172.16.252.129

172.16.252.130

 

 

官网地址:

https://kafka.apache.org/downloads

下载地址:

https://downloads.apache.org/kafka/2.8.0/kafka_2.12-2.8.0.tgz

 

wget https://downloads.apache.org/kafka/2.8.0/kafka_2.12-2.8.0.tgz
tar xvf kafka_2.12-2.8.0.tgz -C /usr/local/
mv /usr/local/kafka_2.12-2.8.0/ /usr/local/kafka
mkdir -p /usr/local/kafka/data

 

修改配置文件:

 vi /usr/local/kafka/config/server.properties 
broker.id=128  #写成IP地址尾数,每个服务器不一样
listeners=PLAINTEXT://172.16.252.130:9092. #写成本机ip地址,每个服务器不一样 log.dirs
=/usr/local/kafka/data
zookeeper.connect=172.16.252.128:2181,172.16.252.129:2181,172.16.252.130:2181

 

发送到其它服务器

scp -r kafka/ root@172.16.252.129:/usr/local/
scp -r kafka/ root@172.16.252.130:/usr/local/

并修改这两个服务器的server.properties配置文件中的broker.id

 

启动

 

[root@localhost kafka]# bin/kafka-server-start.sh config/server.properties 
[root@localhost kafka]# bin/kafka-server-start.sh -daemon config/server.properties ---以守护进程方式启动

关闭

[root@localhost kafka]# bin/kafka-server-stop.sh 

kafka命令操作:
查看服务器中所有topic
[root@localhost kafka]# bin/kafka-topics.sh --zookeeper 172.16.252.128:2181 --list

创建topic
[root@localhost kafka]# bin/kafka-topics.sh --zookeeper 172.16.252.128:2181 --create --replication-factor 3 --partitions 1 --topic first
选项说明:
--topic 定义topic名称
--replication-factor 定义副本数
--partitons 定义分区数

删除topic
[root@localhost kafka]# bin/kafka-topics.sh --zookeeper 172.16.252.128:2181 --delete --topic first

查看topic描述
[root@localhost kafka]# bin/kafka-topics.sh --zookeeper 172.16.252.128:2181 --describe --topic first

 


生产者和消费者
生产者:
[root@localhost kafka]# bin/kafka-console-producer.sh --topic first --broker-list 172.16.252.128:9092
--broker-list 参数已经弃用,改用--bootstrap-server
[root@localhost kafka]# kafka-console-producer.sh --topic first --bootstrap-server 172.16.252.128:9092
>czg
>

消费者:
[root@localhost ~]# kafka-console-consumer.sh --topic first --bootstrap-server 172.16.252.128:9092 --from-beginning
OpenJDK 64-Bit Server VM warning: If the number of processors is expected to increase from one, then you should configure the number of parallel GC threads appropriately using -XX:ParallelGCThreads=N
czg

 

posted on 2021-05-08 13:04  柴米油盐酱醋  阅读(171)  评论(0编辑  收藏  举报

导航