目录
一、监控mysql数据库及httpd服务
1、为server.Zabbix.com添加服务模板
2、server.zabbix.com服务端 操作
3、编辑chk_mysql.sh脚本
4、server.zabbix.com测试
二、监控apache
1、获取键值
2、服务器操作
3、zabbix监控web端导入监控模板
4、server.zabbix.com添加apache模板
三、监控ftp
1、这里用agent.zabbix.com的主机
2、为ftp添加模板
[root@server ~] cd /usr/local/zabbix/etc/
[root@server etc] vim zabbix_agentd.conf
PidFile=/tmp/zabbix_agentd.pid
Server=127.0.0.1,192.168.147.135
ServerActive=192.168.147.135
Hostname=server.zabbix.com
LogFile=/usr/local/zabbix/logs/zabbix_agentd.log
Include=/usr/local/zabbix/etc/zabbix_agentd.conf.d/*.conf
UnsafeUserParameters=1
UserParameter=mysql.version,mysql -V
UserParameter=mysql.status[*],/usr/local/zabbix/etc/chk_mysql.sh $1
UserParameter=mysql.ping,mysqladmin -uroot -p123123 -P3306 -h192.168.147.135 ping | grep -c alive
#解释
#UnsafeUserParameters=1 //允许所有字符的参数传递给用户定义的参数。
#UserParameter=mysql.version,mysql -V //定义键值mysql.version,以及键值的值mysql -V
#UserParameter=mysql.status[*],/usr/local/zabbix/etc/chk_mysql.sh $1 //定义键值#mysql.status[*]
#UserParameter=mysql.ping,mysqladmin -uroot -p123123 -P3306 -h192.168.200.111 ping | grep #-c alive ///定义键值mysql.ping,指定chk_mysql.sh脚本,使用此脚本检查mysql的运行状态,#使用mysqladmin命令指定agent端的数据库连接用户密码ip地址,注意保证mysqladmin命令的链接;
[root@server etc] pwd
/usr/local/zabbix/etc
[root@server etc] vim chk_mysql.sh
#!/bin/bash
#FileName: check_mysql.sh
# Revision: 1.0
# Date: 2015/06/09
# Author: DengYun
# Email: [email protected]
# Website: www.ttlsa.com
# Description:
# Notes: ~
# -------------------------------------------------------------------------------
# Copyright: 2015 (c) DengYun
# License: GPL
# 用户名
MYSQL_USER='root'
# 密码
MYSQL_PWD='123123'
# 主机地址/IP
MYSQL_HOST='192.168.147.135'
# 端口
MYSQL_PORT='3306'
# 数据连接
MYSQL_CONN="/usr/bin/mysqladmin -u${MYSQL_USER} -p${MYSQL_PWD} -h${MYSQL_HOST} -P${MYSQL_PORT}"
# 参数是否正确
if [ $# -ne "1" ];then
echo "arg error!"
fi
# 获取数据
case $1 in
Uptime)
result=`${MYSQL_CONN} status|cut -f2 -d":"|cut -f1 -d"T"`
echo $result
;;
Com_update)
result=`${MYSQL_CONN} extended-status |grep -w "Com_update"|cut -d"|" -f3`
echo $result
;;
Slow_queries)
result=`${MYSQL_CONN} status |cut -f5 -d":"|cut -f1 -d"O"`
echo $result
;;
Com_select)
result=`${MYSQL_CONN} extended-status |grep -w "Com_select"|cut -d"|" -f3`
echo $result
;;
Com_rollback)
result=`${MYSQL_CONN} extended-status |grep -w "Com_rollback"|cut -d"|" -f3`
echo $result
;;
Questions)
result=`${MYSQL_CONN} status|cut -f4 -d":"|cut -f1 -d"S"`
echo $result
;;
Com_insert)
result=`${MYSQL_CONN} extended-status |grep -w "Com_insert"|cut -d"|" -f3`
echo $result
;;
Com_delete)
result=`${MYSQL_CONN} extended-status |grep -w "Com_delete"|cut -d"|" -f3`
echo $result
;;
Com_commit)
result=`${MYSQL_CONN} extended-status |grep -w "Com_commit"|cut -d"|" -f3`
echo $result
;;
Bytes_sent)
result=`${MYSQL_CONN} extended-status |grep -w "Bytes_sent" |cut -d"|" -f3`
echo $result
;;
Bytes_received)
result=`${MYSQL_CONN} extended-status |grep -w "Bytes_received" |cut -d"|" -f3`
echo $result
;;
Com_begin)
result=`${MYSQL_CONN} extended-status |grep -w "Com_begin"|cut -d"|" -f3`
echo $result
;;
*)
echo "Usage:$0(Uptime|Com_update|Slow_queries|Com_select|Com_rollback|Questions|Com_insert|Com_delete|Com_commit|Bytes_sent|Bytes_received|Com_begin)"
;;
esac
[root@server etc] chmod 777 chk_mysql.sh //为脚本加权
[root@server etc] mysql -u root -p123123 //mysql授权
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 4111
Server version: 5.5.56-MariaDB MariaDB Server
Copyright (c) 2000, 2017, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]> grant all on *.* to 'root'@'server.zabbix.com' identified by '123123';
Query OK, 0 rows affected (0.10 sec)
MariaDB [(none)]> flush privileges;
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> \q
Bye
[root@server etc] killall -9 zabbix_agentd
[root@server etc] killall -9 zabbix_server
[root@server etc] /usr/local/zabbix/sbin/zabbix_agentd
[root@server etc] /usr/local/zabbix/sbin/zabbix_server
[root@server etc] netstat -anpt | egrep ':10050|10051'
tcp 0 0 0.0.0.0:10050 0.0.0.0:* LISTEN 34683/zabbix_agentd
tcp 0 0 0.0.0.0:10051 0.0.0.0:* LISTEN 34691/zabbix_server
tcp6 0 0 :::10050 :::* LISTEN 34683/zabbix_agentd
[root@server etc] zabbix_get -s 192.168.147.135 -k mysql.ping
1
[root@server etc] zabbix_get -s 192.168.147.135 -k mysql.status[Com_update]
452
[root@server ~] vim /opt/check_httpd.sh
#!/bin/bash
#
netstat -lnpt |grep -q :80
if [ $? -eq 0 ]
then
echo "1"
else
echo "0"
fi
[root@server ~]chmod +x /opt/check_httpd.sh
[root@server ~] vim /usr/local/zabbix/etc/zabbix_agentd.conf
UnsafeUserParameters=1
UserParameter=httpd.status,/opt/check_httpd.sh
[root@server ~]killall -9 zabbix_agentd
[root@server ~]zabbix_agentd
[root@server ~] ln -s /usr/local/zabbix/bin/zabbix_get /usr/local/bin/zabbix_get
[root@server ~] zabbix_get -s 192.168.200.111 -p 10050 -k httpd.status
[root@serve ~] which netstat
/usr/bin/netstat
[root@serve~] chmod u+s /usr/bin/netstat
[root@server ~] zabbix_get -s 192.168.200.111 -p 10050 -k httpd.status
[root@server ~]systemctl stop httpd
首先在本机下载模板:https://github.com/rdvn/zabbix-templates/archive/master.zip
该zip包有apache、memcache、redis、varnish模板,我们解压后使用其中的apache模板。
[root@server ~] wget https://github.com/rdvn/zabbix-templates/archive/master.zip
[root@server ~] ls
anaconda-ks.cfg jdk-8u91-linux-x64.tar.gz 图片
apache-tomcat-8.5.16.tar.gz master.zip 文档
catalina-jmx-remote.jar zabbix-3.4.11.tar.gz 下载
dead.letter 公共 音乐
grafana-4.2.0-1.x86_64.rpm 模板 桌面
initial-setup-ks.cfg 视频
[root@server ~] mv master.zip /usr/local/src/ //该文件夹没有文件方便查看
[root@server ~] cd /usr/local/src/
[root@server src] unzip master.zip //解压下载的zip压缩包
[root@server src] ls
master.zip zabbix-templates-master
[root@server src] cd zabbix-templates-master/
[root@server zabbix-templates-master] ls
apache memcached README redis varnish //apache中有我们需要的文件
[root@server zabbix-templates-master] cd apache/
[root@server apache] ls
apache_status.sh apache.xml README
//apache_status.sh 该文件时apache的agent监控需要的脚本文件
//apache.xml文件是zabbix需要的模板
[root@server apache] cp apache_status.sh /usr/local/zabbix/sbin/
[root@server apache] vim /usr/local/zabbix/etc/zabbix_agentd.conf
UserParameter=apache[*],/usr/local/zabbix/sbin/apache_status.sh $1
//末行追加引用apache_status.sh的监控脚本
[root@server apache] cd
[root@server ~] chmod +x /usr/local/zabbix/sbin/apache_status.sh //为脚本加执行权限
[root@server ~] ll /usr/local/zabbix/sbin/
总用量 7264
-rwxr-xr-x 1 zabbix zabbix 248 8月 9 14:03 apache_status.sh
-rwxr-xr-x 1 zabbix zabbix 1477216 8月 7 15:00 zabbix_agentd
drwxr-xr-x 4 zabbix zabbix 84 8月 8 05:57 zabbix_java
-rwxr-xr-x 1 zabbix zabbix 5954120 8月 7 15:00 zabbix_server
导入
自此模板就导入成功了 现在为server.zabbix.com添加我们导入的模板
[root@agent ~] yum install -y vsftpd
[root@agent ~] systemctl start vsftpd //启动ftp服务
[root@agent ~] systemctl enable vsftpd //设置ftp服务开机自启
Created symlink from /etc/systemd/system/multi-user.target.wants/vsftpd.service to /usr/lib/systemd/system/vsftpd.service.