cacti 為一套免費的 SNMP monitoring soft 由 MRTG 演化而來 主要差別在於比 MRTG 簡易好上手許多 (不過其實也是挺麻煩的) 在我接觸 cacti 之前,我是使用 PRTG 的 如果你只是要小範圍的監控,100 個監視項目以內(其實也蠻多了) 我建議你到這裡打住,離開 使用 PRTG 來達成你的目的,畢竟商業軟體還是比較厲害 cacti 除了免費外,我找不到別的優點(監控成果有差) ============================================================================================================ 在這邊先講解一下 cacti 的核心由 web、php、sql、snmp 元件組成 其中也能掛附加元件的方式來擴充它 而既然是一個 SNMP monitoring soft 主要就是蒐集 port 的流量、設備運作狀況(CPU、RAM…) 這邊進入主題 這篇我使用 CentOS7 Minimal 架設 架設好後 先進行軟體的安裝動作 建議關閉 selinux #安裝 EPEL 擴充套件庫、工具 安裝新版 php7.3、mariadb、apache 、工具 Install EPEL Repository (Extra Packages for Enterprise Linux) 、Remi Repository (packaging PHP)、 mariadb Repository
rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
yum install -y epel-release
yum install http://rpms.remirepo.net/enterprise/remi-release-7.rpm
yum install -y yum-utils
yum-config-manager –disable remi-php54
yum-config-manager –enable remi-php73
curl -sS https://downloads.mariadb.com/MariaDB/mariadb_repo_setup | sudo bash
cd /etc/yum.repos.d && wget https://repo.codeit.guru/codeit.el`rpm -q –qf “%{VERSION}” $(rpm -q –whatprovides redhat-release)`.repo
yum update -y
yum install -y net-snmp net-snmp-utils net-snmp-libs rrdtool php php-xml php-session php-sockets php-ldap php-gd cacti* nano wget MariaDB-server galera MariaDB-client MariaDB-shared MariaDB-backup MariaDB-common
更改系統時區、啟動服務
timedatectl set-timezone Asia/Taipei
systemctl enable httpd
systemctl enable mariadb
systemctl start httpd
systemctl start mariadb
systemctl enable snmpd
systemctl start snmpd
mariadb 安全性設定
mysql_secure_installation
匯入 timezone 資料
mysql -u root -p mysql < /usr/share/mysql/mysql_test_data_timezone.sql
進入 mariadb(mysql)
mysql -u root -p
建立 DB cacti
create database cacti;
建立使用者、權限
GRANT ALL ON cacti.* TO cactiuser@localhost IDENTIFIED BY 'cactipassword'; GRANT SELECT ON mysql.time_zone_name TO cactiuser@localhost; flush privileges; exit;
匯入 Cacti 所需 table: 這邊注意路徑有版本號,記得照實修改
mysql -u root -p cacti < /usr/share/doc/cacti-1.2.3/cacti.sql
修改 apache 設定,才能從遠端連線 cacti (參考檔案上方說明,因部落格限制部分內容無法顯示)
nano /etc/httpd/conf.d/cacti.conf
# httpd 2.4
#Require host localhost
Require all granted
# httpd 2.2
Order deny,allow
Deny from all
Allow from all
#Allow from localhost
修改 PHP 時區
nano /etc/php.ini
[Date]
;date.timezone =
date.timezone = “Asia/Taipei”
接著修改 cacti 連線設定讓 cacti 能連線 mysql
nano /usr/share/cacti/include/config.php
$database_type = ‘mysql’;
$database_default = ‘cacti’;
$database_hostname = ‘localhost’;
$database_username = ‘cactiuser’;
$database_password = ‘cactipassword’;
$database_port = ‘3306’;
$database_ssl = false;
讓 cacti 每 1 分鐘做一次資料收集 (預設 5 分鐘)
nano /etc/cron.d/cacti */1 * * * * cacti php /usr/share/cacti/poller.php > /dev/null 2>&1
開通防火牆
firewall-cmd --permanent --add-service=http firewall-cmd --reload
優化 PHP
sed -e 's/memory_limit = 128M/memory_limit = 512M/' -i /etc/php.ini sed -e 's/max_execution_time = 30/max_execution_time = 300/' -i /etc/php.ini
優化 mariadb
echo character-set-server = utf8mb4 >> /etc/my.cnf.d/server.cnf echo collation_server = utf8mb4_unicode_ci >> /etc/my.cnf.d/server.cnf echo character_set_client = utf8mb4 >> /etc/my.cnf.d/server.cnf echo join_buffer_size = 30M >> /etc/my.cnf.d/server.cnf # innodb_file_format = Barracuda (mariadb 10 版以後不需修改) cacti 安裝過程建議修改項目自行決定是否修改
reboot 用無痕模式開啟安裝 http://192.168.43.21/cacti admin/admin