主机环境 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
[[email protected] Asia]# yum install rrdtool mysql-server php httpdphp-mysql php-xml net-snmp net-snmp-utils- y #安装cacti之前要安装的包
[[email protected] Asia]# cd /mnt/
[[email protected] 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
[[email protected] mnt]# rpm -vih php-snmp-5.3.3-26.el6.x86_64.rpm
[[email protected] mnt]# vim /etc/php.ini
946 date.timezone =Asia/Shanghai
[[email protected] mnt]# tar zxf cacti-0.8.8h.tar.gz -C/var/www/html/ #解压到/var/www/html/目录
[[email protected] mnt]# cd /var/www/html/
[[email protected] html]# ls
cacti-0.8.8h
[[email protected] html]# ln -s cacti-0.8.8h/ cacti #作软链接
[[email protected] html]# ls
cacti cacti-0.8.8h
[[email protected] include]# /etc/init.d/mysqld start #开启数据库
[[email protected] include]# mysql_secure_installation #初始化,默认没密码,这里将密码设置成了redhat
[[email protected] html]# cd cacti/
[[email protected] cacti]# mysql -predhat -e "create databasecacti" #创建名为cacti的数据库
[[email protected] cacti]# mysql -predhat cacti < cacti.sql #将cacti.sql文件导入到cacti数据库中
[[email protected] cacti]# mysql -predhat -e "grant all oncacti.* to [email protected] identified by ‘redhat‘" #创建本地cacti用户,并将cacti数据库的所有权限给cacti用户
[[email protected] html]# cd include/
[[email protected] include]# vim config.php #修改配置文件
29 $database_username ="cacti"; #刚创建的cacti数据库的用户名
30 $database_password ="redhat"; #用户cacti的密码
39 $url_path ="/cacti/";
42 $cacti_session_name ="Cacti";
[[email protected] cacti]# useradd -u 1000 cacti #在系统中创建cacti用户
[[email protected] 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
[[email protected] cacti]# su - cacti #切换到cacti用户
[[email protected] ~]$ crontab -e #创建定时任务
*/5 * * * * php /var/www/html/cacti/poller.php > /dev/null2>&1
[[email protected] ~]$ logout
[[email protected] ~]# /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,如图:
[[email protected] cacti]# cd rra #采集数据存放的位置
[[email protected] rra]# ls
等待5分钟之后
[[email protected] 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及配置
[[email protected] ~]# yum install net-snmp* -y #安装
[[email protected] ~]# cd /etc/snmp/
[[email protected] 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 <[email protected]> #出现问题时发送邮件的地址
331 disk / 10000 #允许监控磁盘
[[email protected] snmp]# /etc/init.d/snmpd start #开启
Starting snmpd: [ OK ]
[[email protected] 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测试,正常
[[email protected] ~]$ 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
[[email protected] ~]$ 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
[[email protected] mnt]# yum install -y net-snmp-devel mysql-developenssl-devel dos2unix autoconf binutils libtool gcc cpp glibc-headerskernel-headers gilbc-devel #安装安装cacti-spine之前所需要的包
[[email protected] 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
[[email protected] mnt]# tar zxf cacti-spine-0.8.8h.tar.gz
[[email protected] mnt]# cd cacti-spine-0.8.8h
[[email protected] cacti-spine-0.8.8h]# sh bootstrap #检查编译环境
[[email protected] cacti-spine-0.8.8h]# ./configure
[[email protected] cacti-spine-0.8.8h]# make
[[email protected] cacti-spine-0.8.8h]# make install
[[email protected] cacti-spine-0.8.8h]# cd /usr/local/spine/
[[email protected] spine]# ls
bin etc
[[email protected] spine]# cd etc/
[[email protected] etc]# cp spine.conf.dist /etc/spine.conf #配置文件
[[email protected] 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 #端口
[[email protected] etc]# cd ..
[[email protected] spine]# cd bin/
[[email protected] bin]# ls #启动脚本
spine
[[email protected] bin]# pwd
/usr/local/spine/bin
[[email protected] bin]# su - cacti
[[email protected] ~]$ /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)用命令行设置监控
[[email protected] mnt]# uptime | awk ‘{print$1,$(NF-2),$(NF-1),$(NF)}‘ | sed ‘s/,//g‘
15:16:15 0.00 0.00 0.00
[[email protected] mnt]# uptime | awk ‘{print$1,$(NF-2),$(NF-1),$(NF)}‘ | sed ‘s/,//g‘ >>/tmp/uptime
[[email protected] mnt]# cat /tmp/uptime
15:16:59 0.00 0.00 0.00
[[email protected] mnt]# vim /mnt/uptime.sh #写脚本
#!/bin/bash #create by 2016 uptime | awk ‘{print $1,$(NF-2),$(NF-1),$(NF)}‘ | sed ‘s/,//g‘>>/tmp/uptime
[[email protected] mnt]# chmod +x /mnt/uptime.sh #给执行权限
[[email protected] 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
[[email protected] mnt]# dd if=/dev/zero of=/dev/null & #加负载,制造峰值
[1] 7811
[[email protected] 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
[[email protected] mnt]# kill -9 dd #去掉负载
[[email protected] bin]# yum install -y gnuplot #安装绘图工具
[[email protected] 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
[[email protected] html]# vimindex.html #写测试页
<html> <h1>LOAD AVERAGE</h1> <a href="/loadavg.png">Load Average</a> </html>
B)测试 172.25.25.1
点击Load Average