您好,登錄后才能下訂單哦!
主機環境 redhat6.5 64位
實驗環境 服務端1 ip 172.25.25.1
服務端2 ip 172.25.25.2
安裝包 cacti-0.8.8h.tar.gz
php-snmp-5.3.3-26.el6.x86_64.rpm
cacti-spine-0.8.8g.tar.gz
防火墻狀態:關閉
Selinux狀態:Disabled
1.配置安裝cacti及測試
A)配置安裝cacti
[root@sever1 Asia]# yum install rrdtool mysql-server php httpdphp-mysql php-xml net-snmp net-snmp-utils- y #安裝cacti之前要安裝的包
[root@sever1 Asia]# cd /mnt/
[root@sever1 mnt]# ls
cacti-0.8.8h.tar.gz php-snmp-5.3.3-26.el6.x86_64.rpm
cacti-spine-0.8.8g.tar.gz
[root@sever1 mnt]# rpm -vih php-snmp-5.3.3-26.el6.x86_64.rpm
[root@sever1 mnt]# vim /etc/php.ini
946 date.timezone =Asia/Shanghai
[root@sever1 mnt]# tar zxf cacti-0.8.8h.tar.gz -C/var/www/html/ #解壓到/var/www/html/目錄
[root@sever1 mnt]# cd /var/www/html/
[root@sever1 html]# ls
cacti-0.8.8h
[root@sever1 html]# ln -s cacti-0.8.8h/ cacti #作軟鏈接
[root@sever1 html]# ls
cacti cacti-0.8.8h
[root@sever1 include]# /etc/init.d/mysqld start #開啟數據庫
[root@sever1 include]# mysql_secure_installation #初始化,默認沒密碼,這里將密碼設置成了redhat
[root@sever1 html]# cd cacti/
[root@sever1 cacti]# mysql -predhat -e "create databasecacti" #創建名為cacti的數據庫
[root@sever1 cacti]# mysql -predhat cacti < cacti.sql #將cacti.sql文件導入到cacti數據庫中
[root@sever1 cacti]# mysql -predhat -e "grant all oncacti.* to cacti@localhost identified by 'redhat'" #創建本地cacti用戶,并將cacti數據庫的所有權限給cacti用戶
[root@sever1 html]# cd include/
[root@sever1 include]# vim config.php #修改配置文件
29 $database_username ="cacti"; #剛創建的cacti數據庫的用戶名
30 $database_password ="redhat"; #用戶cacti的密碼
39 $url_path ="/cacti/";
42 $cacti_session_name ="Cacti";
[root@sever1 cacti]# useradd -u 1000 cacti #在系統中創建cacti用戶
[root@sever1 cacti]# ll
total 1068
-rw-rw-r-- 1 cacti cacti 5860 Feb 8 2016 about.php
-rw-rw-r-- 1 cacti cacti 5348 Feb 8 2016 auth_changepassword.php
-rw-rw-r-- 1 cacti cacti 14690 Mar 7 2016 auth_login.php
-rw-rw-r-- 1 cacti cacti 178349 Apr 10 2012 cacti.sql
-rw-rw-r-- 1 cacti cacti 20257 Feb 8 2016 cdef.php
[root@sever1 cacti]# su - cacti #切換到cacti用戶
[cacti@sever1 ~]$ crontab -e #創建定時任務
*/5 * * * * php /var/www/html/cacti/poller.php > /dev/null2>&1
[cacti@sever1 ~]$ logout
[root@sever1 ~]# /etc/init.d/httpd start #開啟httpd
Stopping httpd: [ OK ]
安裝cacti 172.25.25.1/cacti
點擊next
點擊next
點擊next
在測試之前,時間得同步
B)測試 172.25.25.1/cacti
登陸 用戶名:admin 密碼:admin
第一次登陸,會提示修改密碼
登陸之后,如圖:
點擊graphs,如圖:
[root@sever1 cacti]# cd rra #采集數據存放的位置
[root@sever1 rra]# ls
等待5分鐘之后
[root@sever1 rra]# ls #已經有數據了
localhost_load_1min_5.rrd localhost_mem_swap_4.rrd localhost_users_6.rrd
localhost_mem_buffers_3.rrd localhost_proc_7.rrd
查看圖像,如圖:
2.監控服務端2的資源及測試
A)在服務端2安裝net-snmp及配置
[root@sever2 ~]# yum install net-snmp* -y #安裝
[root@sever2 ~]# cd /etc/snmp/
[root@sever2 snmp]# vim snmpd.conf #進入配置文件
40 # sec.name source community
41 #com2secnotConfigUser default public
42 com2sec local localhost wen #添加本地資源,名字任意(wen)
43 com2sec mynetwork172.25.25.0/24 wen #允許25網段的監控
49 #group notConfigGroup v1 notConfigUser
50 #group notConfigGroup v2c notConfigUser
51 group MyRWGroupv1 local
52 group MyRWGroupv2c local
53 group MyRWGroupusm local
54 group MyROGroupv1 mynetwork
55 group MyROGroupv2c mynetwork
56 group MyROGroupusm mynetwork
62 view systemview included .1.3.6.1.2.1
63 view systemview included .1.3.6.1.2.1.25.1.1
64 view all included .1 80
69 #access notConfigGroup "" any noauth exact systemview none none
70 access MyROGroup"" any noauth exact all none none
71 access MyRWGroup"" any noauth exact all all none
170 syslocation RHEL6.5 #類型
171 syscontact Root <mi@server2.example.com> #出現問題時發送郵件的地址
331 disk / 10000 #允許監控磁盤
[root@sever2 snmp]# /etc/init.d/snmpd start #開啟
Starting snmpd: [ OK ]
[root@sever2 snmp]# snmpwalk -v 1 -c wen localhostIP-MIB::ipAdEntIfIndex #測試數據,正常
IP-MIB::ipAdEntIfIndex.127.0.0.1 = INTEGER: 1
IP-MIB::ipAdEntIfIndex.172.25.25.2 = INTEGER: 2
在服務端1測試,正常
[root@sever1 ~]$ snmpwalk -v 1 -c wen 172.25.25.2IP-MIB::ipAdEntIfIndex
IP-MIB::ipAdEntIfIndex.127.0.0.1 = INTEGER: 1
IP-MIB::ipAdEntIfIndex.172.25.25.2 = INTEGER: 2
[root@sever1 ~]$ snmpwalk -v 1 -c wen 172.25.25.2.1.3.6.1.4.1.2021.9
UCD-SNMP-MIB::dskIndex.1 = INTEGER: 1
UCD-SNMP-MIB::dskPath.1 = STRING: /
UCD-SNMP-MIB::dskDevice.1 = STRING:/dev/mapper/VolGroup-lv_root
UCD-SNMP-MIB::dskMinimum.1 = INTEGER: 10000
UCD-SNMP-MIB::dskMinPercent.1 = INTEGER: -1
UCD-SNMP-MIB::dskTotal.1 = INTEGER: 7853764
UCD-SNMP-MIB::dskAvail.1 = INTEGER: 6464416
UCD-SNMP-MIB::dskUsed.1 = INTEGER: 990400
UCD-SNMP-MIB::dskPercent.1 = INTEGER: 13
UCD-SNMP-MIB::dskPercentNode.1 = INTEGER: 6
UCD-SNMP-MIB::dskTotalLow.1 = Gauge32: 7853764
UCD-SNMP-MIB::dskTotalHigh.1 = Gauge32: 0
UCD-SNMP-MIB::dskAvailLow.1 = Gauge32: 6464416
UCD-SNMP-MIB::dskAvailHigh.1 = Gauge32: 0
UCD-SNMP-MIB::dskUsedLow.1 = Gauge32: 990400
UCD-SNMP-MIB::dskUsedHigh.1 = Gauge32: 0
UCD-SNMP-MIB::dskErrorFlag.1 = INTEGER: noError(0)
UCD-SNMP-MIB::dskErrorMsg.1 = STRING:
B)在圖形界面添加設備及測試
選擇add添加設備
依次填寫設備名、ip、類型;將默認的public改寫成文件里添加的名字(wen)選擇create
選擇create之后,如下圖,點擊Create Graphs for this Host
如下圖選擇,點擊create,設備添加成功
點擊Graph Trees之后,如圖,點擊Default Trees
如圖,點擊Add
在Tree ltem Type中選擇Host Host中選擇server2 Round Robin Archive中選擇5 Minute,點擊create
C)測試 點擊graphs
等5分鐘后刷新,如圖:
3.cacti支持多線程的配置
A)安裝配置cacti-spine
[root@sever1 mnt]# yum install -y net-snmp-devel mysql-developenssl-devel dos2unix autoconf binutils libtool gcc cpp glibc-headerskernel-headers gilbc-devel #安裝安裝cacti-spine之前所需要的包
[root@sever1 mnt]# ls
cacti-0.8.8h.tar.gz cacti-spine-0.8.8h.tar.gz
php-snmp-5.3.3-26.el6.x86_64.rpm
[root@sever1 mnt]# tar zxf cacti-spine-0.8.8h.tar.gz
[root@sever1 mnt]# cd cacti-spine-0.8.8h
[root@sever1 cacti-spine-0.8.8h]# sh bootstrap #檢查編譯環境
[root@sever1 cacti-spine-0.8.8h]# ./configure
[root@sever1 cacti-spine-0.8.8h]# make
[root@sever1 cacti-spine-0.8.8h]# make install
[root@sever1 cacti-spine-0.8.8h]# cd /usr/local/spine/
[root@sever1 spine]# ls
bin etc
[root@sever1 spine]# cd etc/
[root@sever1 etc]# cp spine.conf.dist /etc/spine.conf #配置文件
[root@sever1 bin]# vim /etc/spine.conf
33 DB_Host localhost #本地數據庫
34 DB_Database cacti #數據庫的名字
35 DB_User cacti #數據庫的用戶
36 DB_Pass redhat #密碼
37 DB_Port 3306 #端口
[root@sever1 etc]# cd ..
[root@sever1 spine]# cd bin/
[root@sever1 bin]# ls #啟動腳本
spine
[root@sever1 bin]# pwd
/usr/local/spine/bin
[root@sever1 bin]# su - cacti
[cacti@sever1 ~]$ /usr/local/spine/bin/spine #測試腳本,正常
SPINE: Using spine config file [/etc/spine.conf]
SPINE: Version 0.8.8h starting
SPINE: Time: 0.0820 s, Threads: 5, Hosts: 3
B)在圖形界面添加腳本路徑及更改poller的類型
點擊Setting中的Paths添加啟動sping腳本的路徑
將cmd.php換成spine就可以支持多線程了。(線程設置在Devices中將Host Template)
4.用命令行設置監控及測試
A)用命令行設置監控
[root@sever1 mnt]# uptime | awk '{print$1,$(NF-2),$(NF-1),$(NF)}' | sed 's/,//g'
15:16:15 0.00 0.00 0.00
[root@sever1 mnt]# uptime | awk '{print$1,$(NF-2),$(NF-1),$(NF)}' | sed 's/,//g' >>/tmp/uptime
[root@sever1 mnt]# cat /tmp/uptime
15:16:59 0.00 0.00 0.00
[root@sever1 mnt]# vim /mnt/uptime.sh #寫腳本
#!/bin/bash #create by 2016 uptime | awk '{print $1,$(NF-2),$(NF-1),$(NF)}' | sed 's/,//g'>>/tmp/uptime
[root@sever1 mnt]# chmod +x /mnt/uptime.sh #給執行權限
[root@sever1 mnt]# crontab –e #創建定時任務(每隔10秒鐘執行一次/mnt/uptime.sh腳本)
* * * * * /mnt/uptime.sh
* * * * * sleep 10;/mnt/uptime.sh
* * * * * sleep 20;/mnt/uptime.sh
* * * * * sleep 30;/mnt/uptime.sh
* * * * * sleep 40;/mnt/uptime.sh
* * * * * sleep 50;/mnt/uptime.sh
[root@sever1 mnt]# dd if=/dev/zero of=/dev/null & #加負載,制造峰值
[1] 7811
[root@sever1 mnt]# cat /tmp/uptime #查看,在增加
15:16:59 0.00 0.00 0.00
15:21:01 0.00 0.00 0.00
15:21:11 0.00 0.00 0.00
15:21:21 0.00 0.00 0.00
15:21:31 0.15 0.03 0.01
15:21:41 0.28 0.06 0.02
15:21:51 0.39 0.09 0.03
15:22:01 0.49 0.12 0.04
15:22:11 0.56 0.15 0.05
15:22:21 0.63 0.18 0.06
15:22:31 0.69 0.21 0.07
15:22:41 0.73 0.23 0.08
[root@sever1 mnt]# kill -9 dd #去掉負載
[root@sever1 bin]# yum install -y gnuplot #安裝繪圖工具
[root@sever1 html]# vim /mnt/uptime.sh #繼續編輯腳本
#!/bin/bash #create by 2016 uptime | awk '{print $1,$(NF-2),$(NF-1),$(NF)}' | sed 's/,//g'>>/tmp/uptime gnuplot<<EOF set terminal png tiny set output '/var/www/html/loadavg.png' set xdata time set timefmt '%H:%M:%S' set xlabel 'TIME' set format x '%H:%M' set xtics rotate set ylabel 'load average' plot '/tmp/uptime' u 1:2 t '1-min' with lines, '/tmp/uptime' u1:3 t '5-min' with lines, '/tmp/uptime' u 1:4 t '15-min' with lines EOF
[root@sever1 html]# vimindex.html #寫測試頁
<html> <h2>LOAD AVERAGE</h2> <a href="/loadavg.png">Load Average</a> </html>
B)測試 172.25.25.1
點擊Load Average
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。