CentOS 安装 Cacti
Cacti 是一款基于 PHP/MySQL 的开源网络监控和图形化工具,它使用 RRDTool 来存储所有必要的数据并绘制图形,Cacti 主要通过 SNMP 协议获取数据,适用于监控网络设备、服务器等,下面将详细介绍在 CentOS 系统上安装 Cacti 的过程。
一、前期准备
1. 更新系统包
yum update y
2. 安装基本依赖软件
yum install wget ntpdate y
3. 确保时间同步
systemctl start ntpdate systemctl enable ntpdate ntpdate ntp1.aliyun.com echo "59 23 * * * ntpdate ntp1.aliyun.com" > /var/spool/cron/root
4. 禁用 SELinux
setenforce 0 sed i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config
二、安装 LAMP 环境
1. 安装 EPEL Repo
yum install epelrelease y
2. 安装 Apache HTTP Server
yum install httpd y systemctl start httpd systemctl enable httpd
3. 安装 MariaDB
yum install mariadbserver mariadb y systemctl start mariadb systemctl enable mariadb mysql_secure_installation
4. 安装 PHP 及相关扩展
yum install php phpmysqlnd phpmbstring phpldap phpxml phpgd phpsnmp phppeclzip phpxml y sed i 's/;date.timezone =/date.timezone = Asia\/Shanghai/g' /etc/php.ini sed i 's/memory_limit = 128M/memory_limit = 512M/g' /etc/php.ini sed i 's/max_execution_time = 30/max_execution_time = 60/g' /etc/php.ini
5. 安装 NetSNMP 和 RRDTool
yum install netsnmp netsnmputils rrdtool y
三、下载并配置 Cacti
1. 下载 Cacti
cd /tmp wget https://www.cacti.net/downloads/cactilatest.tar.gz tar zxvf cactilatest.tar.gz mv cacti*/* /var/www/html/cacti/ chown R apache:apache /var/www/html/cacti
2. 创建数据库及用户
mysql u root p CREATE DATABASE cacti; GRANT ALL ON cacti.* TO 'cactiuser'@'localhost' IDENTIFIED BY 'password'; FLUSH PRIVILEGES; EXIT;
3. 导入 Cacti SQL 文件
cd /var/www/html/cacti/ mysql u cactiuser p cacti < cacti.sql
4. 修改配置文件
vim /var/www/html/cacti/include/config.php 修改以下内容以匹配你的数据库设置: $database_type = 'mysql'; $database_default = 'cacti'; $database_hostname = 'localhost'; $database_username = 'cactiuser'; $database_password = 'password'; $database_port = '3306'; $database_socket = ''; $database_tz = 'UTC';
四、配置自动发现(可选)
1. 定义 SNMP 选项
vim /var/www/html/cacti/include/snmp_options.php
添加如下内容:
$snmp_options['version'] = '2c'; // or '3' for SNMPv3 $snmp_options['community'] = 'public'; // replace with your community string if using v2c $snmp_options['seclevel'] = 'authPriv'; // for SNMPv3 only, adjust accordingly $snmp_options['authpass'] = 'yourAuthPassword'; // for SNMPv3 only, adjust accordingly $snmp_options['privpass'] = 'yourPrivPassword'; // for SNMPv3 only, adjust accordingly $snmp_options['timeout'] = '1'; // seconds before timing out the connection attempt $snmp_options['retries'] = '3'; // number of retry attempts on timeouts $snmp_options['port'] = '161'; // default port to use for SNMP queries
2. 定义扫描网段
vim /var/www/html/cacti/include/poller_options.php
添加如下内容:
$poller_options['scanning'] = array( 'enabled' => true, // set to false to disable auto discovery 'interval' => 3600, // interval in seconds between each scan (e.g., 3600 seconds) ); $poller_options['discovery'] = array( 'enabled' => true, // set to false to disable auto discovery 'interval' => 3600, // interval in seconds between each discovery (e.g., 3600 seconds) );
3. 定义规则(可选)
vim /var/www/html/cacti/include/graph_templates.php
添加或修改规则以适应你的需求。
五、安装 Spine(可选)
为了提高性能,可以安装 Spine,这是一个用 C 语言编写的数据采集器。
1. 安装依赖包
yum install gcc libtool make autoconf automake openssldevel y
2. 下载并编译 Spine
cd /tmp wget https://github.com/Cacti/cactispinnector/archive/master.zip O spine.zip unzip spine.zip cd cactispinnectormaster ./bootstrap.sh ./configure withreentrant prefix=/usr/local/spine enablemysql withmysqllib=/usr/lib64/mysql make && make install chown root:root /usr/local/spine/bin/spine chmod +s /usr/local/spine/bin/spine
3. 配置 Spine(可选)
cp /var/www/html/cacti/service/cactid.service /etc/systemd/system/cactid.service systemctl enable cactid systemctl start cactid systemctl status cactid
六、完成安装与访问 Cacti
启动 Cacti 服务后,可以通过浏览器访问 Cacti Web UI,默认 URL 为http://<你的服务器IP>/cacti
,初始管理员用户名和密码均为Admin
,首次登录时会要求更改密码,按照提示完成初始设置,包括主机名解析等。