十年网站开发经验 + 多家企业客户 + 靠谱的建站团队
量身定制 + 运营维护+专业推广+无忧售后,网站问题一站解决
这篇文章将为大家详细讲解有关如何使用zabbix监控MySQL,小编觉得挺实用的,因此分享给大家做个参考,希望大家阅读完这篇文章后可以有所收获。
创新互联是专业的连山网站建设公司,连山接单;提供成都网站制作、网站建设,网页设计,网站设计,建网站,PHP网站建设等专业做网站服务;采用PHP框架,可快速的进行连山网站开发网页制作和功能扩展;专业做搜索引擎喜爱的网站,专业的做网站团队,希望更多企业前来合作!
概要:
如果你想搭建一套mysql监控
如果你想学习zabbix
那么此篇文章适合你
MySQL监控--zabbix
--刘春雷修改 vi /etc/services,添加下面几行
zabbix-agent 10050/tcp #zabbix agent
zabbix-agent 10050/udp #zabbix agent
zabbix-trapper 10051/tcp #zabbix trapper
zabbix-trapper 10051/udp #zabbix trapper
[root@192.168.94.78 zabbix-2.4.4]# vi /usr/local/zabbix/etc/zabbix_server.conf
[root@192.168.94.78 zabbix-2.4.4]# cat /usr/local/zabbix/etc/zabbix_server.conf|grep -v ^# | grep -v ^$
LogFile=/data/zabbix/zabbix_server.log
PidFile=/data/zabbix/zabbix_server.pid
DBHost=192.168.94.78
DBName=zabbix
DBUser=zabbix
DBPassword=zabbix
DBSocket=/tmp/mysql.sock
DBPort=6001
StartPollers=20
StartTrappers=15
StartPingers=10
User=zabbix
[root@localhost ~]# vi /etc/init.d/zabbix_server
BASEDIR=/usr/local/zabbix ##########修改这行
[root@localhost ~]# vi /etc/init.d/zabbix_agentd
BASEDIR=/usr/local/zabbix ##########修改这行
[root@192.168.94.78 zabbix-2.4.4]# vi /etc/httpd/conf/httpd.conf
ServerName 127.0.0.1
DocumentRoot "/var/www/html"
ServerName 192.168.94.78
[root@192.168.94.78 core]# service httpd restart
Stopping httpd: [ OK ]
Starting httpd: httpd: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1 for ServerName
[ OK ]
[root@192.168.94.78 core]# lsof -i:80
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
httpd 23923 root 4u IPv4 2582967064 0t0 TCP *:80(LISTEN)
httpd 23925 apache 4u IPv4 2582967064 0t0 TCP *:80 (LISTEN)
httpd 23926 apache 4u IPv4 2582967064 0t0 TCP *:80 (LISTEN)
httpd 23927 apache 4u IPv4 2582967064 0t0 TCP *:80 (LISTEN)
httpd 23928 apache 4u IPv4 2582967064 0t0 TCP *:80 (LISTEN)
httpd 23929 apache 4u IPv4 2582967064 0t0 TCP *:80 (LISTEN)
httpd 23930 apache 4u IPv4 2582967064 0t0 TCP *:80 (LISTEN)
httpd 23931 apache 4u IPv4 2582967064 0t0 TCP *:80 (LISTEN)
httpd 23932 apache 4u IPv4 2582967064 0t0 TCP *:80 (LISTEN)
[root@localhost ~]# ln -s /usr/local/zabbix/bin/* /usr/bin/
[root@localhost ~]# ln -s /usr/local/zabbix/sbin/* /usr/sbin/
[root@localhost ~]# cd /data/zabbix/zabbix-2.4.4/misc/init.d/fedora/core
[root@localhost ~]# cp * /etc/init.d/
[root@192.168.94.78 subsys]# chown zabbix.zabbix /var/lock/subsys/ -R
[root@192.168.94.78 subsys]# chown zabbix.zabbix /usr/local/zabbix -R
[root@192.168.94.78 subsys]# chown zabbix.zabbix /data/zabbix/ -R
[root@192.168.94.78 core]#[root@192.168.94.78 zabbix]# scp zabbix-2.4.4.tar.gz 192.168.94.144:/data/zabbix_agent/
[root@192.168.94.144 zabbix_agent]# groupadd -g 201 zabbix
[root@192.168.94.144 zabbix_agent]# useradd -g zabbix -u 201 -m zabbix
[root@192.168.94.144 zabbix_agent]# passwd zabbix
Changing password for user zabbix.
New password:
BAD PASSWORD: it is based on a dictionary word
BAD PASSWORD: is too simple
Retype new password:
passwd: all authentication tokens updated successfully.
[root@192.168.94.144 zabbix-2.4.4]# cd /data/zabbix_agent/zabbix-2.4.4
[root@192.168.94.144 zabbix-2.4.4]# ./configure --prefix=/usr/local/zabbix --enable-agent --enable-proxy --with-mysql=/usr/local/mysql5.5/bin/mysql_config
[root@192.168.94.144 zabbix-2.4.4]# make && make install
[root@192.168.94.144 zabbix-2.4.4]# pwd
/data/zabbix_agent/zabbix-2.4.4
[root@192.168.94.144 zabbix-2.4.4]# cp misc/init.d/tru64/zabbix_agentd /etc/init.d/
[root@192.168.94.144 zabbix-2.4.4]# chmod +x /etc/init.d/zabbix_agentd
[root@192.168.94.144 zabbix-2.4.4]# vi /usr/local/zabbix/etc/zabbix_agentd.conf
[root@192.168.94.144 zabbix-2.4.4]# cat /usr/local/zabbix/etc/zabbix_agentd.conf | grep -v ^# | grep -v ^$
LogFile=/data/zabbix_agent/zabbix_agentd.log
UnsafeUserParameters=1
Include= /usr/local/zabbix/etc/zabbix_agentd.conf.d/
Server=192.168.94.78 #server端IP
ServerActive=192.168.94.78 #server端IP
Hostname=192.168.94.144 #客户端IP
[root@192.168.94.133 zabbix-2.4.4]# chown zabbix.zabbix /data/zabbix_agent/ -R
[root@192.168.94.133 zabbix-2.4.4]# chown zabbix.zabbix /usr/local/zabbix/ -R
[root@192.168.94.133 zabbix-2.4.4]# chown zabbix.zabbix /soft/mysqlmonitor/port_6190 -R
[root@192.168.94.144 tmp]#5、界面添加host
此时可以在界面上面添加host进行监控测试了,因后面添加自定义监控,此处忽略
准备检查mysql状态的脚本
[root@192.168.94.144 ~]# cd /soft/port_6190/
[root@192.168.94.144 port_6190]# ./mysql_status.pl|grep com_writes
com_writes=0
[root@192.168.94.144 port_6190]# /soft/port_6190/mysql_status.pl |grep com_writes|awk -F '=' '{print $2}'
0
注:此处可以自定义脚本,返回key=value 即可,或者使用percona的模板,此处以自定义监控脚本为例来进行配置监控
[root@192.168.94.144 port_6190]# vi /usr/local/zabbix/etc/zabbix_agentd.conf
[root@192.168.94.144 port_6190]# cat /usr/local/zabbix/etc/zabbix_agentd.conf|grep -v '^#'|grep -v '^$'
LogFile=/data/zabbix_agent/zabbix_agentd.log
UnsafeUserParameters=1
Include= /usr/local/zabbix/etc/zabbix_agentd.conf.d/
Server=192.168.94.78
ServerActive=192.168.94.78
Hostname=test
UserParameter=com_writes,/soft/port_6190/mysql_status.pl |grep com_writes|awk -F '=' '{print $2}'
UserParameter=com_reads,/soft/port_6190/mysql_status.pl |grep com_reads |awk -F '=' '{print $2}'
UserParameter=com_update,/soft/port_6190/mysql_status.pl |grep com_update|awk -F '=' '{print $2}'
UserParameter=com_insert,/soft/port_6190/mysql_status.pl |grep com_insert|awk -F '=' '{print $2}'
UserParameter=com_delete,/soft/port_6190/mysql_status.pl |grep com_delete|awk -F '=' '{print $2}'
注:com_delet 为键值名,后面为键值的值
重启agent
/etc/init.d/zabbix_agentd stop
/usr/local/zabbix/sbin/zabbix_agentd -c /usr/local/zabbix/etc/zabbix_agentd.conf
检查
[root@192.168.94.78 bin]# pwd
/usr/local/zabbix/bin
[root@192.168.94.784.1添加host
关于“如何使用zabbix监控MySQL”这篇文章就分享到这里了,希望以上内容可以对大家有一定的帮助,使各位可以学到更多知识,如果觉得文章不错,请把它分享出去让更多的人看到。