【技术】Cacti的安装与配置

发布于 2019-07-19  127 次阅读


Cacti简介


Cacti是一套基于PHP,MySQL,SNMP及RRDTool开发的网络流量监测图形分析工具。

环境配置

系统环境为centos7+php5.6+MySQL5.6

设置时区

rm -rf /etc/localtime
cp  /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
yum install -y ntp
su - root -c "ntpdate tiger.sina.com.cn"

环境安装

检查系统中是否已安装 MySQL

rpm -qa | grep mysql

在新版本的CentOS7中,默认的数据库已更新为了Mariadb,而非 MySQL,所以执行 yum install mysql 命令只是更新Mariadb数据库,并不会安装 MySQL

查看已安装的 Mariadb 数据库版本

rpm -qa|grep -i mariadb

如果有返回值就卸载已安装的 Mariadb 数据库

rpm -qa|grep mariadb|xargs rpm -e --nodeps

安装额外的yum源

yum -y install epel-release
rpm -Uvh http://repo.mysql.com/mysql-community-release-el7-5.noarch.rpm
rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm

安装所需运行库

yum -y install php56w.x86_64 php56w-cli.x86_64 php56w-common.x86_64 php56w-gd.x86_64 php56w-ldap.x86_64 php56w-mbstring.x86_64 php56w-mcrypt.x86_64 php56w-mysql.x86_64 php56w-pdo.x86_64 php56w-process
yum -y install wget httpd mysql mysql-server mysql-devel zlib freetype libjpeg fontconfig libxml2 gd rrdtool net-snmp net-snmp-utils
yum -y install net-snmp-devel openssl-devel dos2unix autoconf automake binutils libtool gcc cpp glibc-headers kernel-headers glibc-devel help2man

重启服务并设置开机启动

service httpd restart
service snmpd restart
service mysqld restart
chkconfig httpd on
chkconfig mysqld on
chkconfig snmpd on

可以添加php探针看下安装的环境

vi /var/www/html/index.php添加以下内容

<?php
phpinfo();
?>

设置mysql密码

mysql -uroot
mysql> use mysql;
mysql> update user set password=PASSWORD("root") where User='root';
mysql> flush privileges; 
mysql> exit

安装cacti

下载cacti源码

wget https://www.cacti.net/downloads/cacti-0.8.8h.tar.gz
tar zxvf cacti-0.8.8h.tar.gz -C /var/www/html
cd  /var/www/html
mv  cacti-0.8.8h cacti
chown -R root:root /var/www/html/cacti/
chmod -R 777 /var/www/html/cacti/
useradd cacti
chown -R cacti:cacti /var/www/html/cacti/log/
chown -R cacti:cacti /var/www/html/cacti/rra/

修改数据库配置文件

vi /var/www/html/cacti/include/config.php修改如下部分:

$database_type = "mysql";
$database_default = "cacti";
$database_hostname = "localhost";
$database_username = "cacti";
$database_password = "cacti";
$database_port = "3306";

创建mysql用户并导入数据库

mysql -uroot -p
mysql> create database cacti default character set utf8;
mysql> grant all on cacti.* to 'cacti'@'localhost' identified by 'cacti';
mysql> flush privileges;
mysql> exit
mysql -u cacti -pcacti cacti < /var/www/html/cacti/cacti.sql

修改php时区

vi /etc/php.ini修改如下部分:

date.timezone = Asia/Shanghai

浏览器访问ip/cacti安装,默认用户名密码为admin

snmp配置

vi /etc/snmp/snmpd.conf修改如下部分:

com2sec notConfigUser  ip       public
access  notConfigGroup ""      any       noauth    exact  all none none
view all    included  .1                               80

重启snmp服务

service snmpd restart

snmp测试

snmpwalk -c public -v 2c ip

开始同步数据

php /var/www/html/cacti/poller.php

设置crond任务,使其每隔1分钟执行一次

crontab -e

*/1 * * * * /usr/bin/php /var/www/html/cacti/poller.php > /var/www/html/cacti/log/poller.log 2>&1?

重启crond服务并设置开机启动

chkconfig crond on
service crond restart

cacti系统时间不正确修改时区

vi /var/www/html/cacti/include/global.php添加以下内容

date_default_timezone_set('Asia/shanghai');

cacti出图精度5分钟修改为1分钟

参考教程:https://www.idcyunwei.org/post/135.html

插件安装

安装spine插件

wget https://www.cacti.net/downloads/spine/cacti-spine-0.8.8h.tar.gz
tar zxvf cacti-spine-0.8.8h.tar.gz
mv cacti-spine-0.8.8h /usr/local/spine
cd /usr/local/spine
./configure
make && make install
chown root:root /usr/local/spine/bin/spine
chmod +s /usr/local/spine/bin/spine

spine配置

cp /usr/local/spine/etc/spine.conf.dist /usr/local/spine/etc/spine.conf
vi /usr/local/spine/etc/spine.conf修改如下部分:

DB_Host 127.0.0.1
DB_Database cacti
DB_User cacti
DB_Pass cacti
DB_Port 3306

Cacti设置

Console -> Cacti Settings 
Paths:Spine Poller File Path设置为/usr/local/spine/bin/spine
Poller:Poller Type选择Spine

没有你,良辰美景更与何人说