CentOs7上安装cacti
系统校时
TZ='Asia/Shanghai'; export TZ
ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
yum install ntpdate
ntpdate -u ntp.api.bz
cacti运行环境配置
yum install wget httpd mariadb mariadb-server mysql-devel php php-mysql -y
yum install cairo-devel libxml2-devel pango pango-devel rrdtool perl-CPAN -y
yum install net-snmp php-snmp net-snmp-devel net-snmp-utils openssl-devel -y
systemctl start mariadb && systemctl enable mariadb
systemctl start httpd && systemctl enable httpd
下载cacti源码包
wget http://www.cacti.net/downloads/cacti-0.8.8b.tar.gz
tar zxf cacti-0.8.8b.tar.gz && mv cacti-0.8.8b /var/www/html/cacti/
创建cacti数据库
mysql -uroot -p
mysql -u root;
mysql> use mysql;
mysql> update user set password = password ('new-password') where user = 'root';
mysql>create database cacti;
mysql>grant all on cacti.* to cacti@'localhost' identified by "new-password";
mysql>flush privileges;
把cacti数据导入到cacti数据库
mysql -u cacti -p new-password cacti < /var/www/html/cacti/cacti.sql
目录权限设置 chmod -R 777 /var/www/html/cacti/
修改cacti数据库连接文件 vi /var/www/html/cacti/include/config.php 访问cacti 对其进行安装,初始管理员admin的密码为admin , 按向导提示设置一个新的管理员密码 http://ip/cacti
初次访问提示 Forbidden You don't have permission to access /cacti/ on this server.
解决办法:
1. 修改apache 配置文件
<Directory />
AllowOverride none
Require all granted
</Directory>
2. 配置安全上下文
chcon -R -t httpd_sys_content_t /var/www/html/cacti
或
chcon -R --reference=/var/www/html/ /var/www/html/cacti
或
semanage fcontext -a -t httpd_sys_content_t "/var/www/html(/.*)?"
restorecon -Rv /var/www/html/cacti/
添加rrdtool抓图任务计划
crontab任务内容
*/5 * * * * /usr/bin/php /var/www/html/cacti/poller.php >>/tmp/cacti_rrdtool.log 2>&1
强制抓图
/usr/bin/php /var/www/html/cacti/poller.php --force
配置snmp
修改配置文件 /etc/snmp/snmpd.conf
com2sec notConfigUser default public 改成 com2sec notConfigUser 127.0.0.1 public
access notConfigGroup “” any noauth exact systemview none none
改成 access notConfigGroup “” any noauth exact all none none
view all included .1 80 前面的注释去掉
重启snmp服务 systemctl restart snmpd;systemctl enable snmpd
snmp 测试
snmpwalk -v 1 -c public localhost IP-MIB::ipAdEntIfIndex
显示信息说明snmp配置成功
安装spine
下载地址http://www.cacti.net/downloads/spine/cacti-spine-0.8.8b.tar.gz
tar zxvf cacti-spine-0.8.8b.tar.gz
cd cacti-spine-0.8.8b
./configure --with-static=/usr/lib64
make
make install
编辑spine配置文件
cd /usr/local/spine/etc/
mv spine.conf.dist spine.conf
vi spine.conf
DB_Host localhost
DB_Database cacti
DB_User cacti
DB_Pass new-password
DB_Port 3306
Cacti设置
1.Console-> Cacti Settings -> Paths ->Alternate Poller Path
写入spine路径: /usr/local/spine/bin/spine
2.Console-> Cacti Settings -> Poller > Poller Type 选择Spine
3.保存
php 优化配置
vi /etc/php.ini
date.timezone = PRC
重启httpd服务,执行 php /var/www/html/cacti/poller.php