Cacti 安装配置 (中文版)
一.基本环境简介:
系统: Centos5.6 x64 软件: cacti-0.8.7e
二.软件准备与安装:
(1). 软件准备与安装:
01 Httpd web 服务器 (apache)
02 Mysql-server 数据库 mysql
03 Php Cacti 使用 php 来实现
04 Php-mysql Php 支持 mysql 依赖包
05 Rrdtool 用来生成 cacti 图表
06 Gd Rrdtool 绘制图像需要的图形库
07 Php-snmp Php 支持 snmp 依赖包
08 Net-snmp-utils Snmp 扩展命令
09 Net-snmp-devel/mysql-devel/openssl-devel Cactid/spine 依赖包
(2) 软件安装:
1. 批量安装包:(ps 最好多运行两三次, 避免批量执行, 有未响应的)
#yum -y install httpd mysql-server php php-mysql gd net-snmp php-snmp net-snmp-utils net-snmp-devel mysql-devel openssl-devel
由于 centos 的标准组件中是不带 rrdtool 的, 因此我们需要添加一个 dag 的 yum 源, 以安装 rrdtool.
2. 修改 yum 源
- # wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repo
- # wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-6.repo
3. 更新 yum
yum clean all yum list
4. 现在就可以安装 rrdtool
- #yum install rrdtool 设置开机自启动
- chkconfig httpd on
- chkconfig mysqld on chkconfig snmpd on
三. MySQL 数据设置
由于 cacti 依靠 mysql 来存储必要的变量, 我们有必要对 MySQL 做些设置.
1. 启动并初始化 mysql 数据库
#service mysqld start
2. 为 root 用户设置密码, 并更改登录权限, 默认密码为空
- # mysql -u root -p 直接回车, 密码为空
- mysql> use mysql
- mysql> update user set password=PASSWORD('123456') where user='root'; mysql> grant all privileges on *.* to root@192.168.45.10 identified by '123456' with grant option;
- mysql>flush privileges;
3. 添加 cacti 库和 cacti 用户, 并为其设置权限
- mysql> create database cacti default character set utf8; // 数据库字符集设置 utf8, 否则乱码
- mysql> grant all privileges on cacti.* to cacti@192.168.45.10 identified by '123456' with grant option;
- mysql> flush privileges;
四. 安装 Cacti
1. 下载并解压 cacti-0.8.7e-cn-utf8.tar.gz
地址为 http://pan.baidu.com/s/1geh8eg7
(这个链接是 tar.gz 格式的, 请下载后更改文件格式), 假设下载目录为 / opt/soft, 下面相同 #cd /opt
- #tar zxvf cacti-0.8.7e-cn-utf8.tar.gz
- #mv cacti-0.8.7e-cn-utf8 /var/www/cacti
2. 修改配置文件
- #vi /var/www/cacti/include/config.php 修改内容如下 $database_type = "mysql";
- $database_default = "cacti"; $database_hostname = "localhost"; $database_username = "cacti"; $database_password = "123456";
3. 创建并编辑 apache 的 cacti 配置文件
- #vi /etc/httpd/conf.d/cacti.conf 内容如下如果不存在, 我们就手工创建一个, 并加入下面代码:
- Alias /cacti "/var/www/cacti"
- <Location "/cacti">
Order Deny,Allow
- # Deny from all
- Allow from 127.0.0.1
- Allow from ::1
Options Indexes Includes FollowSymLinks
- </Location>
- # These directories do not require access over HTTP
- <Directory "/var/www/cacti">
AllowOverride Limit
- Options FollowSymLinks
- </Directory>
4. 导入数据库并启动服务 (Ps: 若失败请重复尝试重启服务)
- # mysql -ucacti -p123456 cacti <cacti.sql
- #service mysqld restart
- #service httpd restart
- #service snmpd restart
5. 创建用户并赋予权限
- #useradd cacti
- #chown -R cacti rra/ log/
- #chown -R root.root *
6. 配置 cacti 数据库连接
- # vim /var/www/cacti/include/global.php $database_type = "mysql"; $database_default = "cactidb"; $database_hostname = "localhost"; $database_username = "cacti"; $database_password = "123456";
- $database_port = "3306";
7. 关防火墙, 然后访问 http://ip/cacti 开始图形安装 cacti
- # chkconfig iptables off
- # service iptables stop
- http://192.168.45.10/cacti
请确认所有路径都已找到, 并选择 SNMP 应用程序版本为 5.x,RRDTool 版本为 1.3.x.
完成之后来到登录页面, 默认用户名 admin, 密码 admin
登录之后会提示你强制更改密码
五. 配置本机 snmp
1. 编辑 snmp 配置文件
# vi /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
2. 重启 snmp 服务并测试
service snmpd restart
snmpwalk -v 1 -c public localhost
- IP-MIB::ipAdEntIfIndex
- IP-MIB::ipAdEntIfIndex.127.0.0.1 = INTEGER: 1
- IP-MIB::ipAdEntIfIndex.xxx.xxx.xxx.xxx = INTEGER: 2
- IP-MIB::ipAdEntIfIndex.xxx.xxx.xxx.xxx = INTEGER: 3
显示以上信息, 则 snmp 配置成功,
xxx.xxx.xxx.xxx 会根据你本机的 IP 信息配置而不同.
如果配置正确, 隔几分钟, 我们的 cacti 就会有数据了
8. 设置计划任务
# crontab -e 追加以下内容 */5 * * * * php /var/www/cacti/poller.php>/dev/null &2>1
来源: http://www.bubuko.com/infodetail-2558086.html