cacti (rrdtool是畫圖工具,)監控網設備佔優勢。
nagios 直觀一目瞭然,可以自已寫腳本,但是不支持歷史數據的查看。
zabbix,功能豐富。
安裝 cacti服務端 #樓主的系統是centenOS 6
首先現在如下rpm包,然後安裝對應的rpm包 epel源
centos5 32位epel源下載地址: www.lishiming.net/data/attachment/forum/epel-release-5-4_32.noarch.rpm
64位下載地址: www.lishiming.net/data/attachment/forum/epel-release-5-4_64.noarch.rpm
centos6
32位epel yum源下載地址: www.lishiming.net/data/attachment/forum/epel-release-6-8_32.noarch.rpm
64位下載地址: www.lishiming.net/data/attachment/forum/epel-release-6-8_64.noarch.rpm
2. (lamp)然後分別安裝httpd、php、mysql #搭建LAMP 的環境 (LAMP 環境搭建參見前面)
yum install -y httpd php php-mysql mysql mysql-server mysql-devel php-gd libjpeg libjpeg-devel libpng libpng-devel
3. 安裝cacti net-snmp rrdtool
yum install -y cacti net-snmp net-snmp-utils rrdtool
[root@OBird ~]# yum install -y cacti net-snmp net-snmp-utils rrdtool
4. 啓動服務:
[root@OBird ~]/etc/init.d/mysqld start
[root@OBird ~]/etc/init.d/httpd start
[root@OBird ~]/etc/init.d/snmpd start
說明:由於前面安裝過LNMP,用yum安裝LNMP後啓動httpd出問題
error1:Could not reliably determine the server's fully qualified domain name
原因:這是在/etc/httpd/conf/httpd.conf中確實對主機端口的指定
解決辦法:vim /etc/httpd/conf/httpd.conf 增加一條 ServerName localhost:80
error2:(98)Address already in use: make_sock: could not bind to address 0.0.0.0:80
原因:80端口被佔用
解決辦法:netstat -lnp |grep 80 ;發現nginx佔用80端口,使用kill -9 PID 結果nginx重啓了,使用killall nginx殺死成功。/etc/init.d/httpd start ok
--------------------------------------------------------------------
[root@OBird ~]# vim /etc/httpd/conf.d/cacti.conf #編輯配置文件。使apache能訪問cacti web頁面
把"Deny from all" 改爲 "Allow from all"。如果不改會訪問403
[root@OBird ~]# /etc/init.d/httpd restart #重啓apache 服務
Stopping httpd: [ OK ]
Starting httpd: httpd: Could not reliably determine the server's fully qualified domain name, using 10.72.4.39 for ServerName
[ OK ]
[root@OBird ~]# mysql -uroot -pzaq12wsx #進入數據庫,LAMP
mysql> create database cacti; #創建數據庫 cacti ;
mysql> show databases;
mysql> grant all on cacti.* to 'cacti'@'localhost' identified by 'cacti';
#設置數據庫權限,用戶名&密碼 .cacti.* 表示所有的示,用戶名和密碼一樣
生產環境中不建議這樣設置密碼。
導入sql文件 (注意文件路徑不要錯了)
[root@OBird ~]# mysql -uroot -pzaq12wsx cacti < /usr/share/doc/cacti-0.8.8h/cacti.sql
[root@OBird ~]# vim /usr/share/cacti/include/config.php #編輯cacti的配置文伯
/* make sure these values refect your actual database/host/user/password */
$database_type = "mysql";
$database_default = "cacti";
$database_hostname = "127.0.0.1"; #localhost更改爲 127.0.0.1
$database_username = "cacti"; #更改爲cacti,前面設置的
$database_password = "cacti"; #更改爲cacti
$database_port = "3306";
$database_ssl = false;
樓主localhost沒有改出了個小插曲:
更改後出現cacti 的安裝界面:
使用IE訪問:10.72.4.39/cacti
第一步 :點擊“NEXT”
第二步:選擇全新安裝
第三步:路徑保持黙認,點擊finish 完成。
第四步進入黙認登錄頁面:
輸入黙認的帳戶密碼,會提示更改。admin:zaq12wsx
點擊: graphs
執行poller.php, 生成圖形, 加入計劃任務
[root@OBird ~]# /usr/bin/php /usr/share/cacti/poller.php
#/usr/bin/php /usr/share/cacti/poller.php添加cron任務
#執行poller.php 會有報錯,因爲我們沒有設置 “timezone”
PHP Warning: strtotime(): It is not safe to rely on the system's timezone settings.
[root@OBird ~]# vim /etc/php.ini #設置 timezome = Asia/Chongqing
[root@OBird ~]# /usr/bin/php /usr/share/cacti/poller.php #再次執行,就不會有警告
[root@OBird ~]# crontab -e #加入任務計劃。每5分鐘執行一次
*/5 * * * * /usr/bin/php /usr/share/cacti/poller.php
-----------------------------------分割線-----------------------------------
安裝客戶端(增加一個linux服務器)
[root@LNMP ~]# yum install -y net-snmp #安裝 net-snmp
[root@LNMP ~]# vim /etc/snmp/snmpd.conf #編輯snmpd.conf 配置文件
#syslocation Unknown (edit /etc/snmp/snmpd.conf)
#syscontact Root <root@localhost> (configure /etc/snmp/snmp.local.conf)
更改以上爲以下
syslocation OBird.LNMP #此處自定義
syscontact Root [email protected] #管理員郵箱
[root@LNMP ~]# service snmpd start #啓動snmpd 服務
Starting snmpd: [ OK ]
[root@OBird ~]# netstat -lnp | grep 161 #查看服務端口是否啓動
udp 0 0 0.0.0.0:161 0.0.0.0:* 3298/snmpd
selinux 記的要關閉。
Iptables 記得要開啓udp161端口,當然直接關閉iptables也是可以的。
vi/etc/sysconfig/iptables #編輯防火牆配置(centos 6)
-AINPUT -m state --state NEW -m udp -p udp --dport 161 -j ACCEPT
在網頁端設置添加客戶端 ,參照以下步驟設置,最後點擊右下角 "Create "
添加另一臺linux _LNMP 到localhost
---------------------------------------------------
在網上查尋到要更改以下設置:才能看到被監控的客戶端。
[root@LNMP ~]# vim /etc/snmp/snmpd.conf
1. 查找以下字段
# sec.name source community
com2sec notConfigUser 10.72.4.39 public
將"comunity"字段改爲你要設置的密碼.比如"public".
將“default”改爲你想哪臺機器可以看到你的snmp信息,如10.72.4.39(服務端的IP)
2. 查找以下字段:
# group context sec.model sec.level prefix read write notif
#access notConfigGroup "" any noauth exact systemview none none
access notConfigGroup "" any noauth exact all none none
#將"read"字段值改爲all.
查找以下字段:
## incl/excl subtree mask
#view all included .1 80 # 將該行前面的"#"去掉. 保存關閉.