1.Cacti环境安装1.1安装LAMP环境安装LAMP环境,当然,如果你有兴趣可以采用编译,我线上Mysql是编译的,其余是yum安装的。
在这次实验采用yum安装。
关闭iptables与selinux,如果有需要,后面再开启。
配置好yum源,开始安装。
yum -y install httpd http-devel httpd-manual mysql mysql-devel mysql-server php php-devel php-mysql php-common php-pdo php-gd lm_sensors net-snmp php-snmp net-snmp-utilschkconfig mysqld onchkconfig httpd onchkconfig snmpd onservice mysqld startservice httpd startservice snmpd start在浏览器中输入http://serverip,查看测试页有没有出现。
1.2配置snmpvim /etc/snmp/snmd.conf#/etc/init.d/snmpd restart验证snmp配置是否正确,# snmpwalk -v 2c -c public 127.0.0.1 if 表示正确IF-MIB::ifIndex.1 = INTEGER: 1IF-MIB::ifIndex.2 = INTEGER: 2IF-MIB::ifDescr.1 = STRING: lo如果提示Timeout: No Response from 127.0.0.1则配置不对。
1.3创建数据库存储cacti的数据# mysqladmin -u root password 'sky123'# mysql -u root -p:输入密码mysql> create database cacti;Query OK, 1 row affected (0.00 sec)mysql> grant all on cacti.* to cactiuser@localhost identified by 'cactiuser';Query OK, 0 rows affected (0.01 sec)mysql> flush privileges;Query OK, 0 rows affected (0.00 sec)mysql> exitTip:创建cacti数据库与cactiuser,可以省略在cacti配置文件中修改。
当然也可以创建别的名字,只是在cacti的配置文件需要多做两步。
1.4安装cacti1.4.1安装rrdtool需要的软件包yum -y install cairo-devel libxml2-devel pango pango-devel perl-CPAN1.4.2安装rrdtooltar zxf rrdtool-1.4.8.tar.gzcd rrdtool-1.4.8./configure --prefix=/usr/local/rrdtool;make;make install1.4.3安装cacti-0.8.8btar zxf cacti-0.8.8b.tar.gz -C /var/www/html/cd /var/www/html/mv cacti-0.8.8b cactichown -R apache:apache /var/www/html/cacti/cd /var/www/html/cacti/patch -p1 -N < /opt/security.patchTip:当我们打开浏览后,是apache用户来访问cacti,如果是编译的http,则不是apache用户,在http.conf有定义useradd cactiuserchown -R cactiuser:cactiuser cacti/{rra,log}1.4.4导入数据库mysql -ucactiuser -p cacti < cacti/cacti.sqlEnter password:1.4.5改配置文件,如下:vim cacti/include/global.phpvim include/config.php修改下面的数据库连接信息,基于不用修改。
$database_type = "mysql";$database_default = "cacti";$database_hostname = "localhost";$database_username = "cactiuser";$database_password = "cactiuser";$database_port = "3306";$database_ssl = false;1.4.6添加计划任务#echo "*/5 * * * * /usr/bin/php /var/www/html/cacti/poller.php &>/dev/null" >/var/spool/cron/cactiuser#/etc/init.d/crond restartTip:以cactiuser的身份定时执行这个脚本。
1.4.7初始化cacti将/usr/local/bin/rrdtool修改成正确的路径/usr/local/rrdtool/bin/rrdtool,点完成输入用户和密码都是admin,输入之后会要求强制修改密码。
打开http://192.168.187.110/cacti 打开Console-->setting-->Genernal--->修改下面两项RRDTool Utility Version选择RRDTOOL 1.4.x,SNMP Version选择version 2手动执行一次php /var/www/html/cacti/poller.php会提示下警告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 'America/New_York' for 'EST/-5.0/no DST' instead in /var/www/html/cacti/lib/functions.php on line 486#vim /etc/php.ini 启用下面并修改。
date.timezone = Asia/Chongqing/etc/init.d/httpd restart,再执行行php /var/www/html/cacti/poller.php没警告了,这下应该正常了。
等几钟应该会出图最后得到的结果如下所示。
Tip:1.初始化出现这种FATAL: Cannot connect to MySQL server on ‘localhost’. Please makesure you have specified a valid MySQL database name in ‘include/config.php’,则用cactiuser连接数据库,是否有权限完全控制cacti库。
2.如果不是cactiuser导致的,但是mysql是编译的,由于/var/www/html/cacti/poller.php使用的/var/lib/mysql/mysql.sock,因为编译的mysql的sock文件在tmp下,因此做一个软件链接ln -s /tmp/mysql.sock /var/lib/mysql/mysql.sock3. 初始化时,点击finished后又弹回初始化界面,则检查数据库配置文件是否有read-only=1,有则删除,并重启Mysql4. cacti图片显示的字体是方框,则需要安装字体,yum -y install dejavu-*,安装完后,刷新cacti界面就行。
5. 在Console--->Devices中显示localhost的状态为unknow,在rrd目录中没有生成文件,查看rra,log目录的权限是否正确,并手动执行php /var/www/html/cacti/poller.php。
注意调整时间,系统有两个时间,一个硬件时间和系统时间。
在虚拟机中往往要注意。
1.5安装spinetar zxf cacti-spine-0.8.8b.tar.gzcd cacti-spine-0.8.8b./configure --prefix=/usr/local/cacti-spineconfigure: error: Cannot find SNMP headers. Use --with-snmp= to specify non-default path.#yum -y net-snmp-devel#./configure --prefix=/usr/local/cacti-spine#Make && make install#cd /usr/local/cacti-spine/etc/#cp spine.conf.dist spine.conf#vim spine.confDB_Host localhostDB_Database cactiDB_User cactiuserDB_Pass cactiuserDB_Port 3306DB_PreG 0#/usr/local/cacti-spine/bin/spine --conf=/usr/local/cacti-spine/etc/spine.conf 测试spine安装是否正确,输出下面信息表示安装成功SPINE: Using spine config file [/usr/local/cacti-spine/etc/spine.conf]SPINE: Version 0.8.8a startingSPINE: Time: 0.1251 s, Threads: 5, Hosts: 2打开catcti网页。