黑猴子的家:Kafka集群部署
1、 集群规划
node1 | node2 | node3 |
---|---|---|
zookeeper | zookeeper | zookeeper |
kafka | kafka | kafka |
2、 jar包下载
http://kafka.apache.org/downloads.html
3、虚拟机准备
1)准备3台虚拟机
2)配置ip地址
3)配置主机名称
4)配置主机名映射hosts
5)禁用selinux
6)关闭防火墙
7)安装jdk
https://www.jianshu.com/p/76a415f9fb0f
8)安装 zookeeper
https://www.jianshu.com/p/e04167aef33a
4、Kafka集群部署
1)解压安装包
[[email protected] software]$ tar -xzvf kafka_2.11-0.11.0.0.tgz -C /opt/module/
2)添加软连接
[[email protected] software]$ cd /opt/module
[[email protected] module]$ ln -s kafka_2.11-0.11.0.0 kafka
3)在/opt/module/kafka目录下创建logs文件夹
[[email protected] module]$ cd kafka/
[[email protected] kafka]$ mkdir logs
4)修改配置文件
[[email protected] kafka]$ cd config/
[[email protected] config]$ vim 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=node1:2181,node2:2181,node3:2181
5)配置环境变量
[[email protected] module]# vim /etc/profile
#KAFKA_HOME
export KAFKA_HOME=/opt/module/kafka
export PATH=$PATH:$KAFKA_HOME/bin
:wq
[[email protected] module]# source /etc/profile
6)分发安装包
[[email protected] ~]# cd /etc
[[email protected] etc]# rsync -rvl profile [email protected]:/etc/profile
[[email protected] etc]# rsync -rvl profile [email protected]:/etc/profile
[[email protected] etc]# su - victor
[[email protected] ~]$ cd /opt/module/
[[email protected] module]$ rsync -rvl kafka_2.11-0.11.0.0 [email protected]: /opt/module/
[[email protected] module]$ rsync -rvl kafka_2.11-0.11.0.0 [email protected]:/opt/module/
[[email protected] module]$ rsync -rvl kafka [email protected]: /opt/module/kafka
[[email protected] module]$ rsync -rvl kafka [email protected]:/opt/module/kafka
7)修改server.properties
分别在node2和node3上修改配置文件/opt/module/kafka/config/server.properties中的broker.id=1、broker.id=2
node2
[[email protected] ~]$ cd /opt/module/kafka/config/
[[email protected] config]$ vim server.properties
broker.id=1
node3
[[email protected] ~]$ cd /opt/module/kafka/config/
[[email protected] config]$ vim server.properties
broker.id=2
尖叫提示:broker.id不得重复
8)启动集群
首先启动zookeeper,然后依次在node1、node2、node3节点上启动kafka
启动zookeeper
[[email protected] zookeeper-3.4.10]# bin/zkServer.sh start
[[email protected] zookeeper-3.4.10]# bin/zkServer.sh start
[[email protected] zookeeper-3.4.10]# bin/zkServer.sh start
启动kafka
[[email protected] kafka]$ bin/kafka-server-start.sh config/server.properties &
[[email protected] kafka]$ bin/kafka-server-start.sh config/server.properties &
[[email protected] kafka]$ bin/kafka-server-start.sh -daemon config/server.properties
尖叫提示:“-daemon”和“&”都表示后台运行, 如果忘记切到后台运行 → Ctrl + z → bg
9)关闭集群
[[email protected] kafka]$ bin/kafka-server-stop.sh config/server.properties
[[email protected] kafka]$ bin/kafka-server-stop.sh config/server.properties
[[email protected] kafka]$ bin/kafka-server-stop.sh config/server.properties
[[email protected] kafka]$ kill -9 8953