分类:
2012-09-07 15:21:37
1 安装需要的perl包
yum install perl-libwww-perl
yum install perl-File-Which # Dries repository
yum install perl-DBD-MySQL(失败)
yum install perl-Digest-SHA1
yum install perl-Time-HiRes(没有)
yum install perl-Crypt-SSLeay # to use https
2. 安装perl-Time-HiRes
cdrom没带此包,去网上下载一个
wget ftp://ftp.pbone.net/mirror/dag.wieers.com/redhat/el5/en/x86_64/dag/RPMS/perl-Time-HiRes-1.9724-1.el5.rf.x86_64.rpm
rpm -ivh perl-Time-HiRes-1.9724-1.el5.rf.x86_64.rpm --excludedocs
3. 安装perl-DBD-MySQL
都是mysql5.1的,而我的mysql是5.5的
wget ftp://ftp.pbone.net/mirror/apt.sw.be/redhat/el5/en/x86_64/extras/RPMS/perl-DBD-MySQL-4.014-1.el5.rfx.x86_64.rpm
libmysqlclient.so.15 is needed by perl-DBD-MySQL-4.014-1.el5.rfx.i386
rpm -ivh perl-DBD-MySQL-4.014-1.el5.rfx.x86_64.rpm --nodeps
rpm -ql perl-DBD-MySQL-4.014-1.el5.rfx
/usr/lib64/perl5/vendor_perl/5.8.8/x86_64-linux-thread-multi/auto/DBD/mysql
/usr/lib64/perl5/vendor_perl/5.8.8/x86_64-linux-thread-multi/auto/DBD/mysql/mysql.bs
/usr/lib64/perl5/vendor_perl/5.8.8/x86_64-linux-thread-multi/auto/DBD/mysql/mysql.so
ldd /usr/lib64/perl5/vendor_perl/5.8.8/x86_64-linux-thread-multi/auto/DBD/mysql/mysql.so|grep not
libmysqlclient.so.15 => not found
wget DBD-mysql-4.014.tar.gz
cd DBD-mysql-4.014
perl Makefile.PL
make
make test
make install(不跑)
#find . -name mysql.so
./blib/arch/auto/DBD/mysql/mysql.so
# cp ./blib/arch/auto/DBD/mysql/mysql.so /usr/lib64/perl5/vendor_perl/5.8.8/x86_64-linux-thread-multi/auto/DBD/mysql
测试程序:
#!/usr/bin/perl -w
use DBI;
my $database = "mysql";
my $hostname = "localhost";
my $data_source = "DBI:mysql:$database:$hostname";
my $username = "root";
my $password = "";
my $dbh = DBI->connect( $data_source,$username,$password)
or die "Cant connect to $data_source\n";
perl test
4 下载mysql_performance_monitor
wget
tar zxvf mysql_performance_monitor-latest.tar.gz
mysql_performance_monitor_agent-0.9.tar.gz
mysql_performance_monitor_templates-0.9.tar.gz
有两部分agent的perl脚本和模板文件xml
5 加载模板
Configuration → Templates → Import → Select the module → Import
可以添加的模块:
mpm(必选)
mysql
process
myisam
innodb
master
slave
ndb
导出模块的时候有2个错误,发现原始y轴的最大值必须大于最小值,简单把0,0改为0,100
6 安装agent
tar mysql_performance_monitor_agent-0.9.tar.gz
mv mysql_performance_monitor_agent-0.9 /usr/local/mpm/
cp /usr/local/mpm/etc/FromDualMySQLagent.conf.template /etc/zabbix_mpm.conf
chown zabbix /etc/zabbix_mpm.conf
mkdir /var/log/zabbix
touch /var/log/zabbix/FromDualMySQLagent.log
chown -R zabbix:zabbix /var/log/zabbix
在zabbix agent中注入mpm
vi /etc/zabbix_agentd.conf
在末尾添加这行
UserParameter=FromDual.MySQL.check,/usr/local/mpm/FromDualMySQLagent.pl /etc/zabbix_mpm.conf
7 配置
mpm支持监控多个实例
设置三个级别defaut-->host-->instanc
# cat /etc/zabbix_mpm.conf
[default]
Type = mysqld
Debug = 2
LogFile = /var/log/zabbix/FromDualMySQLagent.log
# Information for MySQL connections:
Username = root
Password =
MysqlHost = 127.0.0.1
MysqlPort = 3306
Modules = process mysql myisam innodb
# Zabbix Server IP address
ZabbixServer = 192.168.110.129
[slave2]
Type = mysqld
Modules = mpm server
[mysql01-5.5.21] # This MUST match Hostname in Zabbix!
Type = mysqld
MysqlPort = 3306
Modules = process mysql myisam innodb master slave
PidFile = /data/mysql/log/mysql.pid
8 重新启动zabbix agent
/etc/init.d/zabbix_agentd restart
简单测试
zabbix_agentd -c /etc/zabbix_agentd.conf -t FromDual.MySQL.check
9 添加数据库
每次以host方式添加数据库实例,就是同一个server有多个实例,就添加多次
Host name必须填zabbix_mpm.conf[mysql-5.1.43]中一样的名字
10 权限问题
出现下面的错误
14855:2012-09-05 15:38:56.010 - ERR : Cannot read PID file /data/mysql/log/mysql.pid.
解决方法:
usermod -G mysql zabbix
总结:
关于mpm的刷新频率:
应该是模板Template_FromDual.MySQL.mpm中的MPM Agent is alive,它的interval缺省10秒
就只该插件每10秒被激活,然后收集所有item数据,上传而不是每个item调用一次。从log中可以看到如果前一个运行还没有结束,直接退出,不重入
RogerZhuo:
嗯,现在就是使用zabbix_sender的方式来做的,
原理是,zabbix_sender不依赖于zabbix agent, 只要运行就会把数据发送到指定的zabbix server.
目前收集的数据量少,策略为, 用脚本收集数据,保存到文本中,然后用zabbix_sender -i 数据文件 的形式发送。
效果还是很不错的,再加上MPM的这种策略,外层包装一个agent 形式的item,就可以了定期执行脚本,调用 sender发送数据。
示例:
./zabbix_sender -vv -z $ZABBIX_SERVER -i $DATA_FILE 2>>$LOG_FILE 1>>$LOG_FILE
-z指定zabbix_server
-i 收集的数据文件
数据文件格式:
主机IP(也是agent配置文件里的hostname) key(server上模式中定义的trapper item), value