一、环境准备
1、安装kafka
Step 1: 下载代码
你可以登录Apache kafka 官方下载。
http://kafka.apache.org/downloads.html
备注:2.11-1.1.0
版本才与JDK1.7
兼容,否则更高版本需要JDK1.8
Step 2: 启动服务
运行kafka需要使用Zookeeper,所以你需要先启动Zookeeper,如果你没有Zookeeper,你可以使用kafka自带打包和配置好的Zookeeper(PS:在kafka包里)。
//这是前台启动,启动以后,当前就无法进行其他操作(不推荐)
./zookeeper-server-start.sh ../config/zookeeper.properties
//后台启动(推荐)
./zookeeper-server-start.sh ../config/zookeeper.properties 1>/dev/null 2>&1 &
启动kafka
config/server1.properties:
broker.id=0
listeners=PLAINTEXT://192.168.10.100:9092
log.dirs=kafka-logs
zookeeper.connect=localhost:2181
//后台启动kafka
./kafka-server-start.sh ../config/server.properties 1>/dev/null 2>&1 &
写成服务启动方式,启动脚本:
#!/bin/sh
#
# kafka-manager This shell script takes care of starting and stopping
# the kafka
#
# chkconfig: - 64 36
# description: kafka
# processname: kafka-manager
# config: /opt/kafka_2.10-0.8.2.1/conf/application.conf
### BEGIN INIT INFO
# Provides: kafka
# Required-Start: $local_fs $remote_fs $network $named $syslog $time
# Required-Stop: $local_fs $remote_fs $network $named $syslog $time
# Short-Description: start and stop kafka-manager
# Description: kafka
### END INIT INFO
# Source function library.
. /etc/rc.d/init.d/functions
# Source networking configuration.
. /etc/sysconfig/network
dirkafka="/usr/local/kafka/"
pidckeck(){
pid=`ps ax | grep kafkaServer | grep -v grep | grep java| awk '{print $1}'`
}
start(){
pidckeck
if [ -z "$pid" ]; then
echo "Starting kafka"
sh $dirkafka/bin/kafka-server-start.sh $dirkafka/config/server.properties > /dev/null 2>&1 &
sleep 3
pidckeck
if [ -z "$pid" ]; then
echo "Fail Start kafka"
echo "Read logs for detail"
else
echo "kafka has started"
fi
else
echo "kafka is already running"
echo "PID $pid"
fi
}
stop(){
pidckeck
if [ -z "$pid" ]; then
echo "kafka isn't running"
else
sh $dirkafka/bin/kafka-server-stop.sh
sleep 3
pidckeck
if [ -z "$pid" ]; then
echo "kafka-manager has stopped"
else
echo "[WARNING] kafka-manager hasn't stoped"
fi
fi
}
restart(){
stop
start
}
status(){
pidckeck
if [ -z "$pid" ]; then
echo "kafka isn't running"
else
echo "kafka is already running"
echo "PID $pid"
fi
}
case "$1" in
start)
start
;;
stop)
stop
;;
status)
status
;;
restart)
restart
;;
*)
echo $"Usage: $0 {start|stop|status|restart}"
exit 2
esac
exit $?
2、安装zabbix-java-gataway
step1 安装yum源
rpm -ivh http://repo.zabbix.com/zabbix/3.0/rhel/6/x86_64/zabbix-release-3.0-1.el6.noarch.rpm
rpm -ivh http://repo.zabbix.com/zabbix/3.0/rhel/7/x86_64/zabbix-release-3.0-1.el7.noarch.rpm
step2 安装zabbix-java-gataway
yum install -y zabbix-java-gataway
step3 配置zabbix-java-gataway
cat /etc/zabbix/zabbix_java_gateway.conf |grep -v "#"|grep -v ^$
LISTEN_PORT=10052
PID_FILE="/var/run/zabbix/zabbix_java.pid"
START_POLLERS=10
TIMEOUT=30
step4 启动zabbix-java-gateway
/etc/init.d/zabbix-java-gateway start
三、配置kafka远程管理口
From
# JMX settings
if [ -z "$KAFKA_JMX_OPTS" ]; then
KAFKA_JMX_OPTS="-Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.authenticate=false - Dcom.sun.management.jmxremote.ssl=false "
fi
TO
# JMX settings
if [ -z "$KAFKA_JMX_OPTS" ]; then
KAFKA_JMX_OPTS="-Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=21060- Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false "
fi
重启kafka服务
配置kafka脚本文件
cp jmx_discovery /etc/zabbix/externalscripts
cp JMXDiscovery-0.0.1.jar /etc/zabbix/externalscripts
四、导入模板
https://github.com/loveqx/zabbix-doc/tree/master/zabbix-scripts/zabbix-template-kafka
五、配置主机
稍等片刻,查看监控结果
六、查看最新数据
七、脚本URL
https://github.com/loveqx/zabbix-doc/tree/master/zabbix-scripts/zabbix-template-kafka
来源:oschina
链接:https://my.oschina.net/u/4371309/blog/3362674