一、搭建实验环境
监控主机的操作系统linux enterprise 5.4,ip地址192.168.101.50,
1、配置ip地址及一些网络参数(此服务器要联网)
[root@Eleven ~]# setup
重启网络服务
[root@Eleven ~]# service network restart
做DNS指向(在本实验中不在配置DNS服务器)
[root@Eleven ~]# vim /etc/resolv.conf
添加一行:nameserver 222.88.88.88
2、建立光盘挂载点,配置yum客户端
[root@Eleven ~]# mkdir /mnt/cdrom
[root@Eleven ~]# mount /dev/cdrom /mnt/cdrom/
[root@Eleven ~]# vim /etc/yum.repos.d/rhel-debuginfo.repo
[rhel-server]
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、安装一些相关的软件
[root@Eleven ~]# 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、启动先关的各项服务,并设置开机自启动
[root@Eleven ~]# service httpd start
[root@Eleven ~]# chkconfig httpd on
[root@Eleven ~]# service mysqld start
[root@Eleven ~]# chkconfig mysqld on
配置snmp
[root@Eleven ~]# vim /etc/snmp/snmpd.conf
修改62行为:
62 access notConfigGroup "" any noauth exact all none none
打开85行:
85 view all included .1 80
启动snmp
[root@Eleven ~]# service snmpd start
[root@Eleven ~]# chkconfig snmpd on
5、将Cacti所需的软件包传入系统(这里使用xftp工具)
[root@Eleven cacti]# 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(实现绘图功能)
[root@Eleven cacti]# yum localinstall rrdtool* --nogpgcheck –y
安装Cacti
[root@Eleven cacti]# tar zxvf cacti-0.8.7g.tar.gz -C /var/www/html/
[root@Eleven cacti]# cd /var/www/html/
[root@Eleven html]# ll
total 4
drwxr-xr-x 12 1000 users 4096 Jul 10 2010 cacti-0.8.7g
[root@Eleven html]# mv cacti-0.8.7g/ cacti
6、在mysql中建相关的数据库
[root@Eleven html]# 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、定义轮询
[root@Eleven html]# crontab –e
填入的内容:
*/1 * * * * php /var/www/html/cacti/poller.php >/dev/null 2>&1 #定义每隔一分钟轮询依次
创建有效的账号cacti及密码cacti
[root@Eleven html]# useradd cacti
[root@Eleven html]# 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.
导入数据库
[root@Eleven html]# mysql -ucacti -pcacti cacti </var/www/html/cacti/cacti.sql
修改权限
[root@Eleven cacti]# cd /var/www/html/cacti/
[root@Eleven cacti]# chown –R root.root *
修改cacti配置脚本
[root@Eleven cacti]# vim include/config.php
修改29、30行
29 $database_username = "cacti"; #用户名改为cacti
30 $database_password = "cacti"; #密码也改为cacti
8、现在可以通过浏览器访问了
单击“next”
单击“next”
单击“finish”(注意在这步中,查看一些路径是否已经找到,即显示“OK”
单击“finish”后出现登陆界面,首次登陆的用户名和密码都为“admin”
首次登陆进去的界面如下:
至此我们已经完成cacti的安装。
二、配置cacti监控mysql:
1、配置mysql服务器:
mysql服务器的ip地址:192.168.101.128
[root@localhost ~]# mkdir /mnt/cdrom
[root@localhost ~]# mount /dev/cdrom /mnt/cdrom/
mount: block device /dev/cdrom is write-protected, mounting read-only
[root@localhost ~]# vim /etc/yum.repos.d/rhel-debuginfo.repo
内容为:
[rhel-server]
name=Red Hat Enterprise Linux server
baseurl=file:///mnt/cdrom/Server
enabled=1
gpgcheck=1
gpgkey=file:///mnt/cdrom/RPM-GPG-KEY-redhat-release
安装mysql服务器:
[root@localhost ~]# yum install mysql-server –y
[root@localhost ~]# service mysqld start
[root@localhost ~]# chkconfig mysqld on
安装并配置snmp
[root@localhost ~]# yum install net-snmp –y
[root@localhost ~]# vim /etc/snmp/snmpd.conf
修改62、85行
62行 access notConfigGroup "" any noauth exact all none none
85行 view all included .1 80
[root@localhost ~]# service snmpd start
[root@localhost ~]# chkconfig snmpd on
配置MySQL服务器,让cacti所在机器能够访问MySQL服务器的状态信息,必须拥有”process”权限。如果要监控InnoDB状态,还必须有”SUPER”权限。
[root@localhost ~]# 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>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的模板:
[root@Eleven ~]# tar zxvf mysql-cacti-templates-1.1.2.tar.gz
[root@Eleven ~]# cd mysql-cacti-templates-1.1.2
[root@Eleven mysql-cacti-templates-1.1.2]# cp ss_get_mysql_stats.php /var/www/html/cacti/scripts/
2、修改ss_get_mysql_stats.php 文件:
[root@Eleven mysql-cacti-templates-1.1.2]# cd /var/www/html/cacti/scripts/
[root@Eleven 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、设置准备监控的数据库的账户相关信息:
[root@Eleven cacti]# mkdir /var/www/html/cacti/cache
[root@Eleven cacti]# chmod 777 -R /var/www/html/cacti/cache/
[root@Eleven cacti]# chown -R apache.apache /var/www/html/cacti/cache/
4.在web下新建设备
找到“console”下的“setting”将“snmp version”改为“Version 2“
保存。
找到“console”下的“dervices”单击“ADD”添加设备:
保存
单击“create”。
单击“create”
然后单击“Graph Trees”下的“ADD”,创建图形树。
将“linux-mysql”添加到“linux-server”树中
5、导入监控mysql的模板
通过web访问cacti并且点击 console à Import Templates à Browse
选择您要导入的模板cacti_host_template_x_db_server_ht_0.8.6i.xml
单击“import”后:
在“devices”下再次找到“linux-mysql”
单击“Save”
创建图形监控:
全部创建图形:
单击“graphs”
在树“linux-server”下单击“liunx-mysql”,可以查看mysql的相关的一些图形:
至此我们可以用cacti来监控mysql了。
下一篇续cacti监控windows server 2003(实验环境不变)