主機環(huán)境 redhat6.5 64位
站在用戶的角度思考問題,與客戶深入溝通,找到石阡網(wǎng)站設(shè)計與石阡網(wǎng)站推廣的解決方案,憑借多年的經(jīng)驗,讓設(shè)計與互聯(lián)網(wǎng)技術(shù)結(jié)合,創(chuàng)造個性化、用戶體驗好的作品,建站類型包括:成都網(wǎng)站設(shè)計、成都做網(wǎng)站、企業(yè)官網(wǎng)、英文網(wǎng)站、手機端網(wǎng)站、網(wǎng)站推廣、域名注冊、網(wǎng)站空間、企業(yè)郵箱。業(yè)務(wù)覆蓋石阡地區(qū)。
實驗環(huán)境 服務(wù)端1 ip 172.25.25.1
服務(wù)端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
防火墻狀態(tài):關(guān)閉
Selinux狀態(tài):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 #開啟數(shù)據(jù)庫
[root@sever1 include]# mysql_secure_installation #初始化,默認(rèn)沒密碼,這里將密碼設(shè)置成了redhat
[root@sever1 html]# cd cacti/
[root@sever1 cacti]# mysql -predhat -e "create databasecacti" #創(chuàng)建名為cacti的數(shù)據(jù)庫
[root@sever1 cacti]# mysql -predhat cacti < cacti.sql #將cacti.sql文件導(dǎo)入到cacti數(shù)據(jù)庫中
[root@sever1 cacti]# mysql -predhat -e "grant all oncacti.* to cacti@localhost identified by 'redhat'" #創(chuàng)建本地cacti用戶,并將cacti數(shù)據(jù)庫的所有權(quán)限給cacti用戶
[root@sever1 html]# cd include/
[root@sever1 include]# vim config.php #修改配置文件
29 $database_username ="cacti"; #剛創(chuàng)建的cacti數(shù)據(jù)庫的用戶名
30 $database_password ="redhat"; #用戶cacti的密碼
39 $url_path ="/cacti/";
42 $cacti_session_name ="Cacti";
[root@sever1 cacti]# useradd -u 1000 cacti #在系統(tǒng)中創(chuàng)建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 #創(chuàng)建定時任務(wù)
*/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 #采集數(shù)據(jù)存放的位置
[root@sever1 rra]# ls
等待5分鐘之后
[root@sever1 rra]# ls #已經(jīng)有數(shù)據(jù)了
localhost_load_1min_5.rrd localhost_mem_swap_4.rrd localhost_users_6.rrd
localhost_mem_buffers_3.rrd localhost_proc_7.rrd
查看圖像,如圖:
2.監(jiān)控服務(wù)端2的資源及測試
A)在服務(wù)端2安裝net-snmp及配置
[root@sever2 ~]# yum install net-snmp* -y #安裝
[root@sever2 ~]# cd /etc/snmp/
[root@sever2 snmp]# vim snmpd.conf #進(jìn)入配置文件
40 # sec.name source community
41 #com2secnotConfigUser default public
42 com2sec local localhost wen #添加本地資源,名字任意(wen)
43 com2sec mynetwork172.25.25.0/24 wen #允許25網(wǎng)段的監(jiān)控
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
331 disk / 10000 #允許監(jiān)控磁盤
[root@sever2 snmp]# /etc/init.d/snmpd start #開啟
Starting snmpd: [ OK ]
[root@sever2 snmp]# snmpwalk -v 1 -c wen localhostIP-MIB::ipAdEntIfIndex #測試數(shù)據(jù),正常
IP-MIB::ipAdEntIfIndex.127.0.0.1 = INTEGER: 1
IP-MIB::ipAdEntIfIndex.172.25.25.2 = INTEGER: 2
在服務(wù)端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)在圖形界面添加設(shè)備及測試
選擇add添加設(shè)備
依次填寫設(shè)備名、ip、類型;將默認(rèn)的public改寫成文件里添加的名字(wen)選擇create
選擇create之后,如下圖,點擊Create Graphs for this Host
如下圖選擇,點擊create,設(shè)備添加成功
點擊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 #檢查編譯環(huán)境
[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 #本地數(shù)據(jù)庫
34 DB_Database cacti #數(shù)據(jù)庫的名字
35 DB_User cacti #數(shù)據(jù)庫的用戶
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就可以支持多線程了。(線程設(shè)置在Devices中將Host Template)
4.用命令行設(shè)置監(jiān)控及測試
A)用命令行設(shè)置監(jiān)控
[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 #給執(zhí)行權(quán)限
[root@sever1 mnt]# crontab –e #創(chuàng)建定時任務(wù)(每隔10秒鐘執(zhí)行一次/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 & #加負(fù)載,制造峰值
[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 #去掉負(fù)載
[root@sever1 bin]# yum install -y gnuplot #安裝繪圖工具
[root@sever1 html]# vim /mnt/uptime.sh #繼續(xù)編輯腳本
#!/bin/bash #create by 2016 uptime | awk '{print $1,$(NF-2),$(NF-1),$(NF)}' | sed 's/,//g'>>/tmp/uptime gnuplot<[root@sever1 html]# vimindex.html #寫測試頁
LOAD AVERAGE
Load AverageB)測試 172.25.25.1
點擊Load Average
文章題目:監(jiān)控之cacti的安裝部署(監(jiān)控本機及其他主機+支持多線程+命令行監(jiān)控)
轉(zhuǎn)載來源:http://weahome.cn/article/jpiihs.html