赞
踩
hadoop102 | hadoop103 | hadoop104 |
---|---|---|
zk | zk | zk |
kafka | kafka | kafka |
http://kafka.apache.org/downloads.html
[liujh@hadoop102 software]$ tar -zxvf kafka_2.11-0.11.0.0.tgz -C /opt/module/
[liujh@hadoop102 module]$ mv kafka_2.11-0.11.0.0/ kafka
[liujh@hadoop102 kafka]$ mkdir logs
[liujh@hadoop102 kafka]$ cd config/
[liujh@hadoop102 config]$ vi server.properties
输入以下内容:
#broker的全局唯一编号,不能重复 broker.id=0 #删除topic功能使能 delete.topic.enable=true #处理网络请求的线程数量 num.network.threads=3 #用来处理磁盘IO的现成数量 num.io.threads=8 #发送套接字的缓冲区大小 socket.send.buffer.bytes=102400 #接收套接字的缓冲区大小 socket.receive.buffer.bytes=102400 #请求套接字的缓冲区大小 socket.request.max.bytes=104857600 #kafka运行日志存放的路径 log.dirs=/opt/module/kafka/logs #topic在当前broker上的分区个数 num.partitions=1 #用来恢复和清理data下数据的线程数量 num.recovery.threads.per.data.dir=1 #segment文件保留的最长时间,超时将被删除 log.retention.hours=168 #配置连接Zookeeper集群地址 zookeeper.connect=hadoop102:2181,hadoop103:2181,hadoop104:2181 #当Kafka broker启动时,它会在ZK上注册自己的IP和端口号,客户端就通过这个IP和端口号来连接 advertised.listeners=PLAINTEXT://hadoop102:9092
[liujh@hadoop102 module]$ sudo vi /etc/profile
#KAFKA_HOME
export KAFKA_HOME=/opt/module/kafka
export PATH=$PATH:$KAFKA_HOME/bin
[liujh@hadoop102 module]$ source /etc/profile
[liujh@hadoop102 module]$ xsync kafka/
注意:分发之后记得配置其他机器的环境变量
broker.id=1、broker.id=2
注:broker.id不得重复
[liujh@hadoop102 kafka]$ bin/kafka-server-start.sh -daemon config/server.properties
[liujh@hadoop103 kafka]$ bin/kafka-server-start.sh -daemon config/server.properties
[liujh@hadoop104 kafka]$ bin/kafka-server-start.sh -daemon config/server.properties
[liujh@hadoop102 kafka]$ bin/kafka-server-stop.sh stop
[liujh@hadoop103 kafka]$ bin/kafka-server-stop.sh stop
[liujh@hadoop104 kafka]$ bin/kafka-server-stop.sh stop
for i in `cat /opt/module/hadoop-2.7.2/etc/hadoop/slaves`
do
echo "========== $i =========="
ssh $i 'source /etc/profile&&/opt/module/kafka_2.11-0.11.0.2/bin/kafka-server-start.sh -daemon /opt/module/kafka_2.11-0.11.0.2/config/server.properties'
echo $?
done
[liujh@hadoop102 kafka]$ bin/kafka-topics.sh --zookeeper hadoop102:2181 --list
[liujh@hadoop102 kafka]$ bin/kafka-topics.sh --zookeeper hadoop102:2181 \
--create --replication-factor 3 --partitions 1 --topic first
选项说明:
–topic 定义topic名
–replication-factor 定义副本数
–partitions 定义分区数
[liujh@hadoop102 kafka]$ bin/kafka-topics.sh --zookeeper hadoop102:2181 \
--delete --topic first
需要server.properties中设置delete.topic.enable=true否则只是标记删除。
[liujh@hadoop102 kafka]$ bin/kafka-console-producer.sh \
--broker-list hadoop102:9092 --topic first
>hello world
>liujh liujh
[liujh@hadoop103 kafka]$ bin/kafka-console-consumer.sh \
--bootstrap-server hadoop102:9092 --from-beginning --topic first
[liujh@hadoop103 kafka]$ bin/kafka-console-consumer.sh \
--bootstrap-server hadoop102:9092 --from-beginning --topic first
–from-beginning:会把主题中以往所有的数据都读取出来。
[liujh@hadoop102 kafka]$ bin/kafka-topics.sh --zookeeper hadoop102:2181 \
--describe --topic first
[liujh@hadoop102 kafka]$bin/kafka-topics.sh --zookeeper hadoop102:2181 --alter --topic first --partitions 6
简书:https://www.jianshu.com/u/0278602aea1d
CSDN:https://blog.csdn.net/u012387141
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。