目录
一、Zabbix监控mysql数据库
1、为server.Zabbix.com添加服务模板
2、创建mysql服务图形
二、server.zabbix.com服务器操作
编辑chk_mysql.sh脚本
三、server.Zabbix.com测试
四、查看web效果
五、Zabbix监控apache(httpd服务)
安装master
六、Zabbix监控web端导入监控模板
七、Server.zabbix.com添加apache模板
八、查看zabbix出图效果
一、Zabbix监控mysql数据库
1、为server.Zabbix.com添加服务模板

 
 
 
2、创建mysql服务图形

 
 
添加图形的操作

二、server.zabbix.com服务器操作
[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.2.20
ServerActive=192.168.2.20
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		    #定义键值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.2.20  ping | grep -c alive		            #定义键值mysql.ping,指定chk_mysql.sh脚本,使用此脚本检查mysql的运行状态,使用mysqladmin命令指定agent端的数据库连接用户密码ip地址,注意保证mysqladmin命令的链接;编辑chk_mysql.sh脚本
[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:       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.2.20'
 
# 端口
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)]> UPDATE mysql.user SET Password=PASSWORD('123123') WHERE User='root';
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 
tcp6       0      0 :::10051                :::*                    LISTEN      34691/zabbix_server三、server.Zabbix.com测试
[root@server etc]# ln -s /usr/local/zabbix/bin/* /usr/local/bin/
[root@server etc]# zabbix_get -s 192.168.2.20 -k mysql.ping
1
[root@server etc]# zabbix_get -s 192.168.2.20 -k mysql.status[Com_update]
3164四、查看web效果

 
 
五、Zabbix监控apache(httpd服务)
[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 anaconda-ks.cfg  
[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.2.20 -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.2.20 -p 10050 -k httpd.status
[root@server ~]#systemctl stop httpd安装master
master源码包提取链接:https://pan.baidu.com/s/1OxG63zP6niAOAoavUDX6Sw?pwd=vwds 
提取码:vwds
[root@server ~]# ls
master.zip
[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
[root@server ~]# sz /usr/local/src/zabbix-templates-master/apache/apache.xml      #将apache.xml文件传到windows端六、Zabbix监控web端导入监控模板

 
 
 
 
自此模板就导入成功了 现在为server.zabbix.com添加我们导入的模板
七、Server.zabbix.com添加apache模板

 
 
 
 
 
八、查看zabbix出图效果

 
 
apche监控成功



















![[MySQL]MySQL用户管理](https://img-blog.csdnimg.cn/img_convert/bc2ec15e195617e2974468e0afd19359.png)