标签:监控 cacti的安装部署(监控本机及其他主机+支持多线程+命令行监控)
主机环境 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> <h1>LOAD AVERAGE</h1> <a href="/loadavg.png">Load Average</a> </html>
B)测试 172.25.25.1
点击Load Average
本文出自 “不忘初心,方得始终” 博客,请务必保留此出处http://12087746.blog.51cto.com/12077746/1868654
监控之cacti的安装部署(监控本机及其他主机+支持多线程+命令行监控)
标签:监控 cacti的安装部署(监控本机及其他主机+支持多线程+命令行监控)
原文地址:http://12087746.blog.51cto.com/12077746/1868654