mysql搭配php程序用来存储一些变量数据并对变量数据进行调用,如主机名,主机ip,snmp团体名,端口号,模版信息等变量。而snmp抓取到数据后不是存储在mysql中,而是存储在rrtdool生成的RRD文件中(在Cacti根目录的rra文件夹下)。rrdtool对数据的更新和存储就是对RRD文件的处理。RRD文件是大小固定的档案文件(Round Robin Archive),能够存储的数据量在创建时已经定义。
下图是cacti的架构:
首先我们借助yum安装的方式安装mysql,apache,php及相关插件:
yum install -y httpd php php-mysql mysql mysql-server mysql-devel php-gd libjpeg libjpeg-devel libpng libpng-devel 启动http,如下:
[root@lvs ~]# /etc/init.d/httpd start
Starting httpd: httpd: Could not reliably determine the server's fully qualified domain name, using 211.98.71.195 for ServerName
[ OK ]
/启动http的时候会出现如上问题,解决办法如下:
[root@lvs ~]# vim /etc/httpd/conf/httpd.conf
/打开这个文件,把其中的#ServerName 修改为 ServerName localhost:80
然后在重启一下:
[root@lvs ~]# /etc/init.d/httpd restart
Stopping httpd: [ OK ]
Starting httpd: [ OK ] 启动mysql:如下
[root@lvs ~]# /etc/init.d/mysqld start
Initializing MySQL database: Installing MySQL system tables...
160508 3:37:29 [Warning] '--skip-locking' is deprecated and will be removed in a future release. Please use '--skip-external-locking' instead.
OK
Filling help tables...
160508 3:37:29 [Warning] '--skip-locking' is deprecated and will be removed in a future release. Please use '--skip-external-locking' instead.
OK
To start mysqld at boot time you have to copy
support-files/mysql.server to the right place for your system
PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
To do so, start the server, then issue the following commands:
/usr/bin/mysqladmin -u root password 'new-password'
/usr/bin/mysqladmin -u root -h lvs password 'new-password'
Alternatively you can run:
/usr/bin/mysql_secure_installation
which will also give you the option of removing the test
databases and anonymous user created by default. This is
strongly recommended for production servers.
See the manual for more instructions.
You can start the MySQL daemon with:
cd /usr ; /usr/bin/mysqld_safe &
You can test the MySQL daemon with mysql-test-run.pl
cd /usr/mysql-test ; perl mysql-test-run.pl
Please report any problems with the /usr/bin/mysqlbug script!
[ OK ]
Starting mysqld: [ OK ] 安装cacti及其所需要的插件:(我们在这里部署的是主监控机,暂时并没有客户端)
[root@lvs ~]# yum install -y cacti net-snmp net-snmp-utils rrdtool net-snmp-devel net-snmp-libs lm-sensors php-xml zlib libpng freetype cairo-devel pango-devel gd
[root@lvs ~]# /etc/init.d/snmpd start /启动snmp服务
Starting snmpd: [ OK ]
[root@lvs ~]# mysql -u root /mysql数据库
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.1.73-log Source distribution
Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> create database cacti; /创建cacti数据库!
mysql> grant all on cacti.* to 'cactiuser'@'localhost' identified by 'cactiuser'; /创建用户,并且给用户授权。
Query OK, 0 rows affected (0.00 sec)
mysql> use cacti; /选择cacti数据库
Database changed
mysql> source /usr/share/doc/cacti-0.8.8b/cacti.sql; /导入sql文件
Query OK, 0 rows affected (0.01 sec)
Query OK, 1 row affected (0.00 sec)
Query OK, 1 row affected (0.00 sec)
Query OK, 1 row affected (0.00 sec)
Query OK, 1 row affected (0.00 sec)
Query OK, 1 row affected (0.00 sec)
Query OK, 1 row affected (0.00 sec)
Query OK, 0 rows affected (0.04 sec)
Query OK, 1 row affected (0.00 sec)
Query OK, 1 row affected (0.01 sec)
Query OK, 1 row affected (0.00 sec)
Query OK, 1 row affected (0.00 sec)
Query OK, 1 row affected (0.00 sec)
·········
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql> quit;
Bye 编辑cacti配置文件:
[root@lvs ~]# vim /usr/share/cacti/include/config.php
·····
$database_type = "mysql";
$database_default = "cacti";
$database_hostname = "localhost";
$database_username = "cactiuser"; /在数据库中授权时的名字及密码
$database_password = "cactiuser";
$database_port = "3306";
$database_ssl = false;
·····
[root@lvs ~]# vim /etc/httpd/conf.d/cacti.conf
Deny from all 修改为 Allow from all
[root@lvs ~]# /etc/init.d/httpd restart
Stopping httpd: [ OK ]
Starting httpd: [ OK ] 然后就是web访问,在浏览器中输入http://ip/cacti!在浏览器访问的时候,总会出现如下问题
FATAL: Cannot connect to MySQL server on 'localhost'. Please make sure you have specified a valid MySQL database name in 'include/config.php' 当初一直觉得是数据库授权的问题,然后各种检测也没有错误,后来一条命令解决了如下:
ln -s /tmp/mysql.sock /var/lib/mysql/mysql.sock 正常之后,在浏览器输入http://ip/cacti会出现如下界面:
[root@lvs ~]# /usr/bin/php /usr/share/cacti/poller.php
PHP Warning: strtotime(): It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected 'Asia/Chongqing' for 'CST/8.0/no DST' instead in /usr/share/cacti/include/global_constants.php on line 165
PHP Warning: date(): It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected 'Asia/Chongqing' for 'CST/8.0/no DST' instead in /usr/share/cacti/include/global_constants.php on line 165
tifier. We selected 'Asia/Chongqing' for 'CST/8.0/no DST' instead in /usr/share/cacti/include/global_constants.php on line 166
·······/过程很长,结束时我们可以查看一下命令返回值!
[root@lvs ~]# echo $?
0 /返回数字“0”说明,命令运行结果正确 这时候在查看一下监控图像会发现如下图: