如何使用zabbix监控MySQL
这篇文章将为大家详细讲解有关如何使用zabbix监控MySQL,小编觉得挺实用的,因此分享给大家做个参考,希望大家阅读完这篇文章后可以有所收获。
网站建设哪家好,找创新互联!专注于网页设计、网站建设、微信开发、小程序定制开发、集团企业网站建设等服务项目。为回馈新老客户创新互联还提供了交城免费建站欢迎大家使用!
概要:
如果你想搭建一套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
8、修改zabbix的配置:
[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 ##########修改这行
9、修改httpd配置
[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
10、开启httpd
[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)
10、做几个软连接
[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/
11.开启zabbix server端:
[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
2、拷贝/创建快捷
[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
3、修改配置文件
[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
4、开启zabbix 的agent
[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进行监控测试了,因后面添加自定义监控,此处忽略
三、自定义监控配置
1、准备检查脚本
准备检查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的模板,此处以自定义监控脚本为例来进行配置监控
2、修改agent的配置文件
[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
3、server端检查
检查
[root@192.168.94.78 bin]# pwd
/usr/local/zabbix/bin
[root@192.168.94.784.1添加host
4.2 添加模版
4.3 创建应用集
4.4创建项目
4.5 创建图形
5、查看监控图
6、其他过程
关于“如何使用zabbix监控MySQL”这篇文章就分享到这里了,希望以上内容可以对大家有一定的帮助,使各位可以学到更多知识,如果觉得文章不错,请把它分享出去让更多的人看到。
本文名称:如何使用zabbix监控MySQL
文章出自:http://scjbc.cn/article/jsodoi.html