Kafka安装部署
集群规划
主机 | Hadoop141 | Hadoop142 | Hadoop143 |
---|---|---|---|
集群 | ZK | ZK | ZK |
集群 | Kafka | Kafka | Kafka |
jar包下载
http://kafka.apache.org/downloads.html
集群部署
- 1、解压安装包
[root@hadoop141 software]# tar -zxvf kafka_2.11-0.11.0.0.tgz /opt/module/
- 2、修改解压文件
[root@hadoop141 module]# mv kafka_2.11-0.11.0.0/ kafka
- 3、在/opt/module/kafka 目录下创建 logs 文件夹
[root@hadoop141 kafka]# mkdir logs
[root@hadoop141 kafka]# ll
总用量 56
drwxr-xr-x 3 root root 4096 6月 23 2017 bin
drwxr-xr-x 2 root root 4096 6月 23 2017 config
drwxr-xr-x 2 root root 4096 5月 2 15:13 libs
-rw-r--r-- 1 root root 28824 6月 23 2017 LICENSE
drwxr-xr-x 2 root root 4096 5月 2 15:41 logs
-rw-r--r-- 1 root root 336 6月 23 2017 NOTICE
drwxr-xr-x 2 root root 4096 6月 23 2017 site-docs
- 4、修改配置文件
[root@hadoop141 kafka]# vim config/server.properties
- 5、修改一下内容
#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=hadoop141:2181,hadoop142:2181,hadoop143:2181
- 6、配置环境变量
[root@hadoop141 kafka]# vim /etc/profile
添加以下内容:
#KAFKA_HOME
export KAFKA_HOME=/opt/module/kafka
export PATH=$PATH:$KAFKA_HOME/bin
- 7、分发安装包
[root@hadoop141 module]# xrsync.sh kafka/
注意:分发之后记得配置其他机器的环境变量
-
8 、分别在hadoop142和hadoop143上修改配置文件/opt/module/kafka/config/server.properties中的broker.id=1、broker.id=2
注:broker.id不得重复 -
9、 启动集群
依次在hadoop141、hadoop142、hadoop143节点上启动kafka
启动之前 先启动3台节点得 zookeeper:
[root@hadoop141 kafka]# cd /opt/module/zookeeper-3.4.10/
[root@hadoop141 zookeeper-3.4.10]# bin/zkServer.sh start
ZooKeeper JMX enabled by default
Using config: /opt/module/zookeeper-3.4.10/bin/../conf/zoo.cfg
Starting zookeeper ... STARTE
然后启动Kafka:
[root@hadoop141 kafka]# bin/kafka-server-start.sh -daemon config/server.properties
[root@hadoop142 kafka]# bin/kafka-server-start.sh -daemon config/server.properties
[root@hadoop143 kafka]# bin/kafka-server-start.sh -daemon config/server.properties
启动成功:
[root@hadoop141 kafka]# xcall.sh jps
============= hadoop141 jps =============
3657 Kafka
3338 QuorumPeerMain
3759 Jps
============= hadoop142 jps =============
3573 Jps
3526 Kafka
3215 QuorumPeerMain
============= hadoop143 jps =============
3602 Jps
3214 QuorumPeerMain
3518 Kafka
- 10、 关闭集群
[atguigu@hadoop141 kafka]$ bin/kafka-server-stop.sh stop
[atguigu@hadoop142 kafka]$ bin/kafka-server-stop.sh stop
[atguigu@hadoop143 kafka]$ bin/kafka-server-stop.sh stop
- 11、kafka集群启动脚本
[root@hadoop141 bin]# vim /bin/kk.sh
#!/bin/bash
arg=$#
if((arg==0));then
echo no args;
exit;
fi
case $1 in
"start"){
for i in 'cat /opt/module/hadoop-2.7.2/etc/hadoop/slaves'
do
echo "========== $i =========="
ssh $i 'source /etc/profile&&/opt/module/kafka/bin/kafka-server-start.sh -daemon /opt/module/kafka/config/server.properties'
echo $?
done
};;
"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/bin/kafka-server-stop.sh -daemon /opt/module/kafka/config/server.properties'
echo $?
done
};;
esac
#!/bin/bash
arg=$#
if((arg==0));then
echo no args;
exit;
fi
case $1 in
"start"){
for i in hadoop141 hadoop142 hadoop143
do
echo "========== $i =========="
ssh $i "/opt/module/kafka/bin/kafka-server-start.sh -daemon /opt/module/kafka/config/server.properties"
done
};;
"stop"){
for i in hadoop141 hadoop142 hadoop143
do
echo "========== $i =========="
ssh $i "/opt/module/kafka/bin/kafka-server-stop.sh"
done
};;
esac
修改权限:
[root@hadoop141 bin]# chmod 777 kk.sh