上篇:用户行为数据采集 第5节 日志采集分析、ETL拦截器、分类型拦截器及脚本编写
详见:参照自己上次写的博客:
Kafka集群部署
集群规划:
服务器hadoop1.x | 服务器hadoop2.x | 服务器hadoop2.x | |
---|---|---|---|
Kafka | Kafka | Kafka | Kafka |
[root@hadoop1 bin]# vim kf.sh
//在脚本中填写如下内容
#! /bin/bash
case $1 in
"start"){
for i in hadoop1.x hadoop2.x hadoop3.x
do
echo " --------启动 $i Kafka-------"
# 用于KafkaManager监控
ssh $i "export JMX_PORT=9988 && /usr/local/etc/hadoop/module/kafka/bin/kafka-server-start.sh -daemon /usr/local/etc/hadoop/module/kafka/config/server.properties "
done
};;
"stop"){
for i in hadoop1.x hadoop2.x hadoop3.x
do
echo " --------停止 $i Kafka-------"
ssh $i "/usr/local/etc/hadoop/module/kafka/bin/kafka-server-stop.sh "
done
};;
esac
说明:启动Kafka时要先开启JMX端口,是用于后续KafkaManager监控。
[root@hadoop1 bin]# chmod 777 kf.sh
//先启动zookeeper
```java
[root@hadoop1 bin]# ./zk.sh
[root@hadoop1 bin]# ./zk.sh start
JMX enabled by default
Using config: /usr/local/etc/hadoop/module/zookeeper-3.4.5/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED
JMX enabled by default
Using config: /usr/local/etc/hadoop/module/zookeeper-3.4.5/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED
JMX enabled by default
Using config: /usr/local/etc/hadoop/module/zookeeper-3.4.5/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED
//查看集群进程
[root@hadoop1 bin]# ./xcall.sh jps
--------- hadoop1.x ----------
11152 Application
11508 Jps
11321 Application
11484 QuorumPeerMain
--------- hadoop2.x ----------
8611 QuorumPeerMain
8631 Jps
--------- hadoop3.x ----------
8035 Jps
8015 QuorumPeerMain
[root@hadoop1 bin]#
//kf集群启动脚本
[root@hadoop1 bin]# ./kf.sh start
--------启动 hadoop1.x Kafka-------
--------启动 hadoop2.x Kafka-------
--------启动 hadoop3.x Kafka-------
//再次查看集群所有进程
[root@hadoop1 bin]# ./xcall.sh jps
--------- hadoop1.x ----------
11152 Application
11778 Kafka
11848 Jps
11321 Application
11484 QuorumPeerMain
--------- hadoop2.x ----------
8896 Kafka
8962 Jps
8611 QuorumPeerMain
--------- hadoop3.x ----------
8301 Kafka
8015 QuorumPeerMain
8367 Jps
[root@hadoop1 kafka]# bin/kafka-topics.sh --zookeeper hadoop1.x:2181 --list
//没有创建过这两个topic,默认却出现了
topic_event
topic_start
原因:
在启动fluem服务的情况下就开始生成这两个topic,除非把flume删除掉,不然就默认存在了
[root@hadoop1 kafka]# bin/kafka-console-consumer.sh \
--zookeeper hadoop1.x:2181 --from-beginning --topic topic_start
–from-beginning:会把主题中以往所有的数据都读取出来。根据业务场景选择是否增加该配置。
数据就会在生产了,如图所示:
Kafka Manager是yahoo的一个Kafka监控管理项目
https://github.com/yahoo/kafka-manager/releases
下载工具包: kafka-manager-1.3.3.18.zip,点击即可下载
kafka-manager.zip
//查看
[root@hadoop1 hadoop]# ll
total 132104
-rw-r--r--. 1 root root 55711670 Apr 3 06:25 apache-flume-1.7.0-bin.tar.gz
-rw-r--r--. 1 root root 79552840 Apr 8 08:56 kafka-manager-1.3.3.18.zip
drwxr-xr-x. 8 root root 4096 Apr 8 16:54 module
//解压编译包到指定文件目录
[root@hadoop1 hadoop]# unzip kafka-manager-1.3.3.18.zip -d module/
//发现无法解压,查看一下,发现自己的环境没有安装unzip,需要安装,执行命令:yum install -y unzip zip
-bash: unzip: command not found
[root@hadoop1 hadoop]# yum install -y unzip zip
[root@hadoop1 module]# cd kafka-manager-1.3.3.18/conf/
[root@hadoop1 conf]#
[root@hadoop1 conf]# vim application.conf
//配置参数
kafka-manager.zkhosts="hadoop1.x:2181,hadoop2.x:2181,hadoop3.x:2181"
[root@hadoop1 kafka-manager-1.3.3.18]# nohup bin/kafka-manager -Dhttp.port=7456 > /usr/local/etc/hadoop/module/kafka-manager-1.3.3.18/start.log 2>&1 &
[1] 12537
起初,由于权限不够,导致kafka-manager无法启动起来,所以在启动的时候需要赋予权限chmod -R 744
[root@hadoop1 module]# chmod -R 744 kafka-manager-1.3.3.18/
再次启动KafkaManager
[root@hadoop1 kafka-manager-1.3.3.18]# nohup bin/kafka-manager -Dhttp.port=7456 > /usr/local/etc/hadoop/module/kafka-manager-1.3.3.18/start.log 2>&1 &
[1] 10653
//进程查看
[root@hadoop1 kafka-manager-1.3.3.18]# jps
10150 QuorumPeerMain
10746 Jps
10443 Kafka
10653 ProdServerStart //kafka-manager已经成功启动了
接下来,就是访问Web页面
http://hadoop1.x:7456
至此,就可以查看整个Kafka集群的状态,包括:Topic的状态、Brokers的状态、Cosumer的状态。
在Kafka的module/kafka-manager-1.3.3.22/application.home_IS_UNDEFINED
目录下面,可以看到Kafka-Manager的日志。
[root@hadoop1 bin]# vim km.sh
//在脚本中填写如下内容
#! /bin/bash
case $1 in
"start"){
echo " -------- 启动 KafkaManager -------"
nohup /usr/local/etc/hadoop/module/kafka-manager-1.3.3.18/bin/kafka-manager -Dhttp.port=7456 >start.log 2>&1 &
};;
"stop"){
echo " -------- 停止 KafkaManager -------"
ps -ef | grep ProdServerStart | grep -v grep |awk '{print $2}' | xargs kill
};;
esac
[root@hadoop1 bin]# chmod 777 km.sh
[root@hadoop1 bin]# ./km.sh start
-------- 启动 KafkaManager -------
[root@hadoop1 bin]# ./xcall.sh jps
--------- hadoop1.x ----------
11093 Jps
10150 QuorumPeerMain
10443 Kafka
10653 ProdServerStart
--------- hadoop2.x ----------
7728 QuorumPeerMain
8013 Kafka
8189 Jps
--------- hadoop3.x ----------
7987 Kafka
7702 QuorumPeerMain
8167 Jps
[root@hadoop1 bin]# ./km.sh stop
-------- 停止 KafkaManager -------
//查看集群进程,发现ProdServerStart进程成功停了
[root@hadoop1 bin]# ./xcall.sh jps
--------- hadoop1.x ----------
11156 Jps
10150 QuorumPeerMain
10443 Kafka
--------- hadoop2.x ----------
7728 QuorumPeerMain
8013 Kafka
8221 Jps
--------- hadoop3.x ----------
7987 Kafka
7702 QuorumPeerMain
8200 Jps