linux下Cacti网络监控之监控Mysql服务器
一、搭建实验环境监控主机的操作系统linux enterprise 5.4,ip地址192.168.101.50,
1、配置ip地址及一些网络参数(此服务器要联网)
# setup
http://blog.运维网.com/attachment/201206/014834752.png
重启网络服务
# service network restart
做DNS指向(在本实验中不在配置DNS服务器)
# vim /etc/resolv.conf
添加一行:nameserver222.88.88.88
2、建立光盘挂载点,配置yum客户端
# mkdir /mnt/cdrom
# mount /dev/cdrom /mnt/cdrom/
# vim /etc/yum.repos.d/rhel-debuginfo.repo
name=Red Hat Enterprise Linux server
baseurl=file:///mnt/cdrom/Server
enabled=1
gpgcheck=1
gpgkey=file:///mnt/cdrom/RPM-GPG-KEY-redhat-release
3、安装一些相关的软件
# yum install httpd php php-mysql php-snmp mysql-server perl-DBD-MySQL php-pdo net-snmp net-snmp-libs net-snmp-utils net-snmp-devel ruby ruby-devel -y
4、启动先关的各项服务,并设置开机自启动
# service httpd start
# chkconfig httpd on
# service mysqld start
# chkconfig mysqld on
配置snmp
# vim /etc/snmp/snmpd.conf
修改62行为:
62 access notConfigGroup "" any noauth exact all none none
打开85行:
85 view all included .1 80
启动snmp
# service snmpd start
# chkconfig snmpd on
5、将Cacti所需的软件包传入系统(这里使用xftp工具)
# ll
total 9040
-rw-r--r-- 1 root root 2236916 Feb 7 20:54 cacti-0.8.7g.tar.gz
-rw-r--r-- 1 root root 207069 Feb 7 20:54 cacti-plugin-0.8.7g-PA-v2.8.tar.gz
-rw-r--r-- 1 root root 4960221 Feb 7 20:54 feition.tar.bz2
-rw-r--r-- 1 root root 442525 Feb 7 20:54 monitor-latest.tgz
-rw-r--r-- 1 root root 1154026 Feb 7 20:54 rrdtool-1.4.4-1.el5.wrl.i386.rpm
-rw-r--r-- 1 root root 55839 Feb 7 20:54 rrdtool-perl-1.4.4-1.el5.wrl.i386.rpm
-rw-r--r-- 1 root root 18906 Feb 7 20:54 rrdtool-ruby-1.4.4-1.el5.wrl.i386.rpm
-rw-r--r-- 1 root root 6701 Feb 7 20:54 sendMsg.zip
-rw-r--r-- 1 root root 25570 Feb 7 20:54 settings-latest.tgz
-rw-r--r-- 1 root root 90488 Feb 7 20:54 thold-latest.tgz
首先安装rrdtool(实现绘图功能)
# yum localinstall rrdtool* --nogpgcheck –y
安装Cacti
# tar zxvf cacti-0.8.7g.tar.gz -C /var/www/html/
# cd /var/www/html/
# ll
total 4
drwxr-xr-x 12 1000 users 4096 Jul 10 2010 cacti-0.8.7g
# mv cacti-0.8.7g/ cacti
6、在mysql中建相关的数据库
# mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.0.77 Source distribution
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
mysql> CREATE DATABASE cacti; #数据库cacti
Query OK, 1 row affected (0.02 sec)
#授权本地用户
mysql> grant all privileges on cacti.* to cacti@localhost identified by 'cacti';
Query OK, 0 rows affected (0.05 sec)
mysql> grant all privileges on cacti.* to cacti@127.0.0.1 identified by 'cacti';
Query OK, 0 rows affected (0.00 sec)
#授权远程用户
mysql> rant all privileges on cacti.* to cacti@192.168.101.0 identified by 'cacti';
Query OK, 0 rows affected (0.00 sec)
mysql> flush privileges; #刷新
Query OK, 0 rows affected (0.01 sec)
7、定义轮询
# crontab –e
填入的内容:
*/1 * * * * php /var/www/html/cacti/poller.php >/dev/null 2>&1 #定义每隔一分钟轮询依次
创建有效的账号cacti及密码cacti
# useradd cacti
# passwd cacti
Changing password for user cacti.
New UNIX password: #输入密码cacti
BAD PASSWORD: it is too short
Retype new UNIX password: #再次输入密码cacti
passwd: all authentication tokens updated successfully.
导入数据库
# mysql -ucacti -pcacti cacti grant process,super on *.* to 'cacti'@'192.168.101.50' identified by 'cacti';
Query OK, 0 rows affected (0.01 sec)
mysql>grant all privileges on cacti.* to cacti@"192.168.101.50" identified by "cacti";
Query OK, 0 rows affected (0.00 sec)
mysql> quit
Bye
2、在监控主机上配置cacti
(1)、下载cacti监控mysql的模板:
http://mysql-cacti-templates.googlecode.com/files/mysql-cacti-templates-1.1.2.tar.gz
# tar zxvf mysql-cacti-templates-1.1.2.tar.gz
# cd mysql-cacti-templates-1.1.2
# cp ss_get_mysql_stats.php /var/www/html/cacti/scripts/
2、修改ss_get_mysql_stats.php 文件:
# cd /var/www/html/cacti/scripts/
# vim ss_get_mysql_stats.php
修改30、31、34行:
30 $mysql_user = 'cacti';
31 $mysql_pass = 'cacti';
34 $cache_dir = '/var/www/html/cacti/cache';
3、设置准备监控的数据库的账户相关信息:
# mkdir /var/www/html/cacti/cache
# chmod 777 -R /var/www/html/cacti/cache/
# chown -R apache.apache /var/www/html/cacti/cache/
4.在web下新建设备
找到“console”下的“setting”将“snmp version”改为“Version 2“
http://blog.运维网.com/attachment/201206/015420548.png
保存。
找到“console”下的“dervices”单击“ADD”添加设备:
http://blog.运维网.com/attachment/201206/015514501.png
保存
http://blog.运维网.com/attachment/201206/015630593.png
http://blog.运维网.com/attachment/201206/015652628.png
单击“create”。
http://blog.运维网.com/attachment/201206/015733857.png
单击“create”
然后单击“Graph Trees”下的“ADD”,创建图形树。
http://blog.运维网.com/attachment/201206/015814748.png
将“linux-mysql”添加到“linux-server”树中
http://blog.运维网.com/attachment/201206/015908823.png
5、导入监控mysql的模板
通过web访问cacti并且点击 console à Import Templates à Browse
选择您要导入的模板cacti_host_template_x_db_server_ht_0.8.6i.xml
http://blog.运维网.com/attachment/201206/015948765.png
单击“import”后:
http://blog.运维网.com/attachment/201206/020023920.png
在“devices”下再次找到“linux-mysql”
http://blog.运维网.com/attachment/201206/020110157.png
http://blog.运维网.com/attachment/201206/020123787.png
单击“Save”
创建图形监控:
http://blog.运维网.com/attachment/201206/020204947.png
全部创建图形:
http://blog.运维网.com/attachment/201206/020250996.png
单击“graphs”
在树“linux-server”下单击“liunx-mysql”,可以查看mysql的相关的一些图形:
http://blog.运维网.com/attachment/201206/020337565.png
http://blog.运维网.com/attachment/201206/020350913.png
至此我们可以用cacti来监控mysql了。
下一篇续cacti监控windows server 2003(实验环境不变)
页:
[1]