Cacti 是一套开源的网络监测工具, 并以网页接口管理。Cacti 也是以 PHP 开发, 读取 RRDTool 的资料后, 可以显示像 CPU 及网络使用等资料。以下是在 RHEL 及 CentOS 7 架设 Cacti 的方法:
执行以下指令, 透过 YUM 安装 Apache, MariaDB, PHP
然后安装 PHP 相关模组, SNMP 及 RRDTool
在 firewalld 开启 httpd 埠号:
# firewall-cmd –reload
安装好后, 启动 Apache, MariaDB 及 SNMPD, 并设定开机自动执行:
# systemctl start mariadb
# systemctl start snmpd
# systemctl enable httpd
# systemctl enable mariadb
# systemctl enable snmpd
MariaDB Server 默认 root 密码为空密码, 要重设 root 密码有两种方法, 一种是传统的方法, 登入 mysql 后修改密码, 另一种是用 mysql_secure_installation, 这个方法只要在指令模式输入 mysql_secure_installation, 跟着步骤回答问题就可以, 以下会看看登入 mysql 修改密码:
然后会看到类似 “MariaDB [(none)]>”, 输入以下指令修改:
update user set password=PASSWORD(“new_password”) where User=’root’;
flush privileges;
quit
现在设定 Cacti 的 MySQL 数据库及权限:
MariaDB [(none)]> create database cacti;
MariaDB [(none)]> GRANT ALL ON cacti.* TO cacti@localhost IDENTIFIED BY ‘cactipasswd’;
MariaDB [(none)]> FLUSH privileges;
MariaDB [(none)]> quit;
设定好 Cacti 所需套件后, 可以透过 YUM 安装 Cacti:
# yum install cacti
用 YUM 安装好 Cacti 后, 将 Cacti 的初始化料库表汇入 MariaDB, SQL 档的位置是:
/usr/share/doc/cacti-[version]/cacti.sql
汇入 SQL 档后, 开启 /etc/cacti/db.php 设定 MariaDB 的登入资料:
|
1 2 3 4 5 |
$database_type = "mysql"; $database_default = "cacti"; $database_hostname = "localhost"; $database_username = "cacti"; $database_password = "cactipasswd"; |
默认 Cacti 在 Apache 不是对外开放, 开启 /etc/httpd/conf.d/cacti.conf, 将 “Allow From” 设成开放浏览的 IP, 或者 ALL 是完全对外开放:
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
Alias /cacti /usr/share/cacti <Directory /usr/share/cacti/> <IfModule mod_authz_core.c> # httpd 2.4 Require host ALL </IfModule> <IfModule !mod_authz_core.c> # httpd 2.2 Order deny,allow Deny from all Allow from ALL </IfModule> </Directory> |
修改了以上设定, 需要重新启动 Apache:
下一步是设定 Cacti 在 Crontab 每 5 分钟自动执行, 开启 /etc/cron.d/cacti, 将以下一行的注解清除, 即改成:
*/5 * * * * cacti /usr/bin/php /usr/share/cacti/poller.php > /dev/null 2>&1
最后一步是执行 Cacti 的网页安装, 例如服务器的 ip 是 192.168.1.100, 只要透过以下网页存取, 跟着步骤做就可以:
http://192.168.1.100/cacti/
默认的用户名称及密码均为 admin, 首次登入需要修改密码, 之后便完成了。