监控MySQL服务与httpd服务

mac2026-08-11  8

一、MySQL服务监听,服务端配置 修改配置文件

[root@zabbix ~]# vim /usr/local/zabbix/etc/zabbix_agentd.conf Server=127.0.0.1,192.168.200.111 ServerActive=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.111 ping | grep -c alive
#准备脚本 cat 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.111' # 端口 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 #加执行权限 chmod 777 chk_mysql.sh
#为MySQL用户进行授权 mysql -uroot -p123123 grant all on *.* to 'root'@'zabbix.server.com' identified by '123123'; flush privileges; exit #重启zabbix_agentd服务 killall -9 zabbix_agentd zabbix_agentd #测试数据库参数是否成功 /usr/local/zabbix/bin/zabbix_get -s 192.168.200.111 -k mysql.ping 1

二、MySQL服务web端配置 为MySQL创建图形 查看一下

三、httpd服务的监听,服务端配置 添加httpd信息

[root@zabbix ~]# vim /usr/local/zabbix/etc/zabbix_agentd.conf Server=127.0.0.1,192.168.200.111 ServerActive=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.111 ping | grep -c alive UserParameter=httpd.status,/usr/local/zabbix/etc/chk_httpd.sh #这条

配置脚本

[root@zabbix ~]# vim /usr/local/zabbix/etc/chk_httpd.sh #!/bin/bash #检查httpd服务是否正常运行,正常输出1不正常输出2 netstat -lnupt | grep -q :80 if [ $? -eq 0 ];then echo "1" else echo "0" fi #为脚本添加权限 chmod 777 /usr/local/zabbix/etc/chk_httpd.sh
#重启服务 killall -9 zabbix_agentd zabbix_agentd

测试httpd参数

/usr/local/zabbix/bin/zabbix_get -s 192.168.200.111 -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 #发现有其他内容 which netstat /usr/bin/netstat chmod u+s /usr/bin/netstat /usr/local/zabbix/bin/zabbix_get -s 192.168.200.111 -k httpd.status 1

四、web端添加httpd监控

添加图形 添加触发器用作报警 查看一下 五、自定义监控磁盘 监测sdb1磁盘空间

[root@zabbix ~]# df -hT 文件系统 类型 容量 已用 可用 已用% 挂载点 /dev/mapper/centos-root xfs 38G 2.3G 36G 6% / devtmpfs devtmpfs 481M 0 481M 0% /dev tmpfs tmpfs 490M 0 490M 0% /dev/shm tmpfs tmpfs 490M 6.6M 484M 2% /run tmpfs tmpfs 490M 0 490M 0% /sys/fs/cgroup /dev/sda1 xfs 497M 102M 395M 21% /boot
vim /usr/local/zabbix/etc/zabbix_agentd.conf Server=127.0.0.1,192.168.200.111 ServerActive=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.111 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)}' #添加这一条 #重启服务 killall -9 zabbix_agentd zabbix_agentd #查看参数是否成功 /usr/local/zabbix/bin/zabbix_get -s 192.168.200.111 -k s db1.used 21

六、web添加磁盘监控

最新回复(0)