监控MySQL服务及httpd服务

一:监控MySQL服务
[root@server ~]# vim /usr/local/zabbix/etc/zabbix_agentd.conf
PidFile=/tmp/zabbix_agentd.pid
Server=127.0.0.1,192.168.200.11
ServerActive=192.168.200.11
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.200.11 ping | grep -c alive
[root@server etc]# vim chk_mysql.sh                             #准备脚本
#!/bin/bash
#FileName:    check_mysql.sh
# Revision:    1.0
# Date:        2015/06/09
# Author:      DengYun
# Email:       dengyun@ttlsa.com
# Website:     www.ttlsa.com
# Description:
# Notes:       ~
# -------------------------------------------------------------------------------
# Copyright:   2015 (c) DengYun
# License:     GPL
# 用户名
MYSQL_USER='root'
# 密码
MYSQL_PWD='123123'
# 主机地址/IP
MYSQL_HOST='192.168.200.11'
# 端口
MYSQL_PORT='3306'
# 数据连接
# 参数是否正确
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
        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]# cd
[root@server ~]# mysql -uroot -p123123 
MariaDB [(none)]> grant all on *.* to 'root'@'server.zabbix.com' identified by '123123';                #授权
Query OK, 0 rows affected (0.03 sec)
MariaDB [(none)]> flush privileges;                                             #刷新授权表
Query OK, 0 rows affected (0.00 sec)
#重新启动zabbix_agentd服务
[root@server etc]# killall -9 zabbix_agentd
[root@server etc]# zabbix_agentd
#测试数据库参数是否成功
[root@server etc]# /usr/local/zabbix/bin/zabbix_get -s 192.168.200.11 -k mysql.ping
1

 

 二:监控httpd服务

[root@server etc]# vim /usr/local/zabbix/etc/zabbix_agentd.conf
PidFile=/tmp/zabbix_agentd.pid
Server=127.0.0.1,192.168.200.11
ServerActive=192.168.200.11
  stname=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.200.11 ping | grep -c a
live
UserParameter=httpd.status,/usr/local/zabbix/etc/chk_httpd.sh                 #添加一条引用httpd的脚本
[root@server etc]# vim chk_httpd.sh                                      #准备脚本                         
#!/bin/bash
#检查httpd服务是否正常运行,正常输出1不正常输出2
netstat -lnupt | grep -q :80
if [ $? -eq 0 ];then
        echo "1"
else
        echo "0"
fi
~   
[root@server etc]# chmod 777 chk_httpd.sh            #给脚本加权限
#重启zabbix_agentd服务

 [root@server etc]# killall -9 zabbix_agentd
[root@server etc]# zabbix_agentd

[root@server etc]# /usr/local/zabbix/bin/zabbix_get -s 192.168.200.11 -k httpd.status
(Not all processes could be identified, non-owned process info
 will not be shown, you would have to be root to see it all.)
1
[root@server etc]# which netstat
/usr/bin/netstat
[root@server etc]# chmod u+s /usr/bin/netstat
[root@server etc]# /usr/local/zabbix/bin/zabbix_get -s 192.168.200.11 -k httpd.status
1

 

 

添加图形

创建触发器

 

 

 

 

 

三:磁盘监控

[root@server ~]# vim /usr/local/zabbix/etc/zabbix_agentd.conf
PidFile=/tmp/zabbix_agentd.pid
Server=127.0.0.1,192.168.200.11
ServerActive=192.168.200.11
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.200.11 ping | grep -c alive
UserParameter=httpd.status,/usr/local/zabbix/etc/chk_httpd.sh
UserParameter=sdb1.used,df -hT| awk -F'[ %]' 'NR==7{ print $(NF-2)}'                                          #引入命令
#重启服务
[root@server ~]# killall -9 zabbix_agentd
[root@server ~]# zabbix_agentd 
[root@server ~]# /usr/local/zabbix/bin/zabbix_get -s 192.168.200.11 -k sda1.used
17

 

 

 

 

 

 

原文地址:https://www.cnblogs.com/ZCQ123456/p/11805956.html