Cacti安裝詳細步驟
前提LNMP或LAMP架構已搭建完成
一、cacti概述
1. cacti是用php語言實現的一個軟件,它的主要功能是用snmp服務獲取數據,然后用rrdtool儲存和更新數據,當用戶需要查看數據的時候用rrdtool生成圖表呈現給用戶。因此,snmp和rrdtool是cacti的關鍵。Snmp關系着數據的收集,rrdtool關系着數據存儲和圖表的生成。
2. Mysql配合PHP程序存儲一些變量數據並對變量數據進行調用,如:主機名、主機ip、snmp團體名、端口號、模板信息等變量。
3. snmp抓到數據不是存儲在mysql中,而是存在rrdtool生成的rrd文件中(在cacti根目錄的rra文件夾下)。rrdtool對數據的更新和存儲就是對rrd文件的處理,rrd文件是大小固定的檔案文件(Round Robin Archive),它能夠存儲的數據筆數在創建時就已經定義。
二、安裝rrdtool
先試試這個:
yum install rrdtool rrdtool-perl -y
如果不行,可能是在主監控機上安裝rrdtool,rrdtool依賴的包過多,所以選擇增加源,然后用yum安裝,試試下邊的:
[root@localhost /]# vi /etc/yum.repos.d/dag.repo [dag] name=Dag RPM Repository for Red Hat Enterprise Linux baseurl=http://apt.sw.be/redhat/el$releasever/en/$basearch/dag gpgcheck=1 gpgkey=http://dag.wieers.com/rpm/packages/RPM-GPG-KEY.dag.txt enabled=1 然后yum安裝:
三、安裝配置net-snmp
3.1、安裝net-snmp
yum install net-snmp net-snmp-libs net-snmp-utils
3.2、配置net-snmp
vim /etc/snmp/snmpd.conf 41行 1將default 改為監控服務器ip;2 將public 改成復雜些的識別的字符串 com2sec notConfigUser 127.0.0.1 public 62行 1將systemview 改為all,供所有snmp 訪問權限 access notConfigGroup "" any noauth exact all none none 85行 將#注釋符號去掉 view all included .1 80
3.3、測試net-snmp
# service snmpd start
snmpd 使用 tcp/udp 161 端口,驗證snmpd 服務
使用snmpwalk 命令驗證
snmpwalk -v 2c -c public 127.0.0.1 -v是指版本,-c 是指密鑰,獲取到系統信息則正常! 如果cacti搭建好后很久還是沒出圖,用這個命令試試看能否獲取到數據。 正常情況下,執行完這個命令后會有很多數據出現!
四、安裝cacti
1、下載cacti
cd /tmp wget http://www.cacti.net/downloads/cacti-0.8.8a.tar.gz tar xzf cacti-0.8.8a.tar.gz mv cacti-0.8.8a /var/www/html/cacti cd /var/www/html/cacti
2、創建數據庫
mysqladmin --user=root -p create cacti
3、導入數據庫
mysql -uroot -p cacti < cacti.sql
4、創建數據庫用戶
shell> mysql -uroot -p mysql mysql> GRANT ALL ON cacti.* TO cactiuser@localhost IDENTIFIED BY 'cactipassword'; mysql> flush privileges;
5、配置include/config.php
$database_type = "mysql"; $database_default = "cacti"; $database_hostname = "localhost"; $database_username = "cactiuser"; $database_password = "cactipassword"; 打開注釋掉的: $url_path = "/cacti/";
配置include/global.php
/* Default database settings*/ $database_type = "mysql"; $database_default = "cacti"; $database_hostname = "localhost"; $database_username = "cactiuser"; $database_password = "cactipassword"; $database_port = "3306"; $database_ssl = false;
6、設置目錄權限
useradd cactiuser chown -R cactiuser rra/ log/
7、配置計划任務
#crontab -e */5 * * * * /usr/bin/php /var/www/html/cacti/poller.php > /dev/null 2>&1 //讓系統每5分鍾收集
service crond restart
8、完成cacti的安裝
注意關閉防火牆或者允許80端口,關閉selinux
1) 在瀏覽器中輸入:http://監控服務器IP/cacti/
默認用戶名:admin 密碼:admin
2)設置cacti用到的命令路徑
3) 更改密碼
登陸成功戶 next>> next>>
上圖有益處紅色錯誤,表示安裝未成功。
安裝成功如下:
如果用的是經典版的,出現了亂碼
解決辦法:
yum -y install fontforge
或:
安裝完cacti,刷新頁面是亂碼,這里記錄解決問題的方法,感謝原文作者,亂碼問題是因為系統少了一些字符,那我們需要下載相應的字符放在/usr/share/fonts/下即可。
這里提供一個字體simsun,下載地址如下:
這里提供一個字體simsun,下載地址如下:
http://fendou.sinaapp.com/fendou_soft/2012-07-12.simsun.ttc.zip
http://fendou.sinaapp.com/fendou_soft/2012-07-12.simsun.ttf.zip
下載這兩個字體,解壓,把文件放在/usr/share/fonts下,重啟apache,查看頁面正常顯示!