RRDtool 是原 MRTG 作者另外開發的套件,它可將系統吐出來的資料做 logging 並繪製成圖表
而系統所吐出來的資料是 based on SNMP ( Simple Network Management Protocol ),所以只要是支援 SNMP 的設備都可以用 RRDtool 來做記錄與分析
不過仔細看了一下 RRDtool 操作的語法算小複雜,因此本篇教學會再搭配 Cacti 來協助控制 RRDtool 繪製報表
我的安裝環境如下
- FreeBSD 9.1 Release
- Apache + PHP + MySQL ( 可參考 【FreeBSD】用 Ports 安裝 Apache + PHP + MySQL )
- Net-SNMP 5.7
- RRDTool 1.4.5
- Cacti 0.8.8a
[ 安裝所需套件 ]
首先我們先安裝 RRDtool
# cd /usr/ports/databases/rrdtool
# make install clean
pkg_add -r gobject-introspection
接下來安裝 Net-SNMP
# cd /usr/ports/net-mgmt/net-snmp
# make install clean
[ ] AX_SOCKONLY
[ ] DMALLOC
不選
3 安裝 Cacti
# cd /usr/ports/net-mgmt/cacti
# make install clean
=======================================================================
Cacti is now installed. If you intall it for the first time,
you may have to follow this steps to make it work correctly:
1. Create the MySQL database:
# mysqladmin --user=root create cacti
2. Create a mysql user/password for cacti:
(change user and/or password if required)
# echo "GRANT ALL ON cacti.* TO cactiuser@localhost IDENTIFIED BY 'cactiuser'; FLUSH PRIVILEGES;" | mysql
3. Import the default cacti database:
# mysql cacti < /usr/local/share/cacti/cacti.sql
4. Edit /usr/local/share/cacti/include/config.php.
5. Add the line to cron jobs with the command:
# crontab -u cacti -e
*/5 * * * * /usr/local/bin/php /usr/local/share/cacti/poller.php > /dev/null 2>&1
6. Add alias in apache config for the cacti dir:
Alias /cacti "/usr/local/share/cacti/"
7. Be sure apache gives an access to the directory ('Allow from' keywords).
8. Open a cacti login page in your web browser and login with admin/admin.
If you update cacti, open a login page, an updating process
will start automatically.
=======================================================================
上述三個套件安裝完之後,就可以開始來設定囉!
[ 設定 SNMP ]
首先先來設定 SNMP 的部份
# cd /usr/local/share/snmp
# vi snmpd.conf
snmpd.conf 內容如下
rocommunity public // 設定 SNMP Read-Only 的 Community
syslocation MyOffice-at-work // 系統所在地
syscontact oscarxxx.xxx@gmail.com // 管理者 E-mail
syslocation MyOffice-at-work
syscontact oscarxxx.xxx@gmail.com
另外請在 /etc/rc.conf 加入一行 snmpd_enable="YES"
# echo ‘snmpd_enable=”yes”’ >> /etc/rc.conf
加好了之後就來啟動 SNMP 吧
# /usr/local/etc/rc.d/snmpd start
[ 設定 Cacti ]
設定 Cacti 這部份看個人習慣,如果您已經有 phpMyAdmin 的話可以在裡面操作,或是透過指令方式來新建
原則上我們需要新建一個 Database、User 讓 Cacti 可以存放相關資料
指令操作如下,新增一個 Database 名稱為 cacti
# mysqladmin -u root -p create cacti
Enter password: 輸入 Root 的密碼
新增一個 User 名叫 cacti 讓它可以存取 cacti 這個 Database,密碼設定為 cactiuser
[root@fb91-lab /usr/ports/net-mgmt/cacti]# mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 5
Server version: 5.5.28-log Source distribution
Copyright (c) 2000, 2012, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>
mysql> GRANT ALL ON cacti.* TO cacti@localhost IDENTIFIED BY 'cactiuser';
Query OK, 0 rows affected (0.02 sec)
mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)
mysql> quit
Bye
接下來我們要倒入 Database 相關的 Schema
# mysql -u cacti -p cacti < /usr/local/share/cacti/cacti.sql
Enter password: 以本教學為例輸入 justforcacti
Database 的 Schema 建好之後,接下來我們來去設定程式的部份
# cd /usr/local/share/cacti/include/
# vi /usr/local/share/cacti/include/config.php
config.php 內容如下,原則上要改的地方就只有 username 跟 password 而已
/* make sure these values refect your actual database/host/user/password */
$database_type = "mysql";
$database_default = "cacti";
$database_hostname = "localhost";
$database_username = "cacti";
$database_password = "cactiuser";
$database_port = "3306";
/* Default session name - Session name must contain alpha characters */
#$cacti_session_name = "Cacti";
接下來新增排程設定,固定每 5 分鐘讓 Cacti 去取得資料
# crontab -u cacti -e
加入這一行即可
*/5 * * * * /usr/local/bin/php /usr/local/share/cacti/poller.php > /dev/null 2>&1
# vi /usr/local/etc/apache22/httpd.conf
在 httpd.conf 加入下面這幾行
Alias /cacti "/usr/local/share/cacti/"
<Directory "/usr/local/share/cacti/">
Options None
AllowOverride None
Order allow,deny
Allow from all
</Directory>
/usr/local/share/cacti/
Allow from 127.0.0.1 192.168.0.0/16 .example.comss
好了之後要重新啟動 Apache 讓它生效
# /usr/local/etc/rc.d/apache22 restart
[ 初始化 Cacti ]
網址列請打入 http://您的 IP or Domain/cacti
FreeBSD 中文字型
# cd /usr/ports/chinese/font-std
# make install clean
沒有留言:
張貼留言