cacti监控的搭建

服务器监控 Cact的搭建

cacti监测的对象可以是 Linux 或Windows 服务器、路由器、交换机等网络设备。于 基于 SNMP (简单网络管理协议) 来 收集CPU  占用、内存使用、运行进程数、磁盘空间、网卡流量等各种数据

Cacti 的部署
cacti服务器 :192.168.2.11/24          LAMP 、net-snmp-tuils 、rrdtool 、cacti
client 客户机:192.168.2.12/24          mysql 、net-snmp-tuils

1 、安装测试 LAMP  环境,确保协调工作正常
[root@cacti ~]# yum -y install httpd mysql mysql-server mysql-devel
[root@cacti ~]# yum -y install php php-mysql php-gd
[root@cacti ~]# yum -y install zlib freetype libxml2 gd libjpeg // 安装依赖库
[root@cacti ~]# vim /etc/httpd/conf/httpd.conf
276 ServerName www.example.com:80  //去掉#
402 DirectoryIndex index.php index.html index.html.var
[root@cacti ~]# /etc/init.d/httpd start
[root@cacti ~]# chkconfig httpd on
[root@cacti ~]# /etc/init.d/mysqld start
[root@cacti ~]# chkconfig mysqld on
[root@cacti ~]# vim /var/www/html/test.php

<?php
phpinfo();
? >
浏览器访问测试:  http://192.168.2.11
http://192.168.2.11/test.php



2 、安装 net-snmp-utils  软件包, 用于提供 snmpget ,snmpwalk 等 等 snmp 
[root@cacti ~]# yum -y install net-snmp net-snmp-utils
[root@cacti ~]# /etc/init.d/snmpd start
[root@cacti ~]# chkconfig snmpd on


3 、安装 rrdtool  软件包
[root@cacti ~]# yum -y install cairo-devel zlib libxml2 libxml2-devel glib2 glib2-devel libpng
libpng-devel freetype freetype-devel libart_lgpl pango pango-devel perl-CPAN
[root@cacti ~]# tar xf rrdtool-1.4.8.tar.gz -C /usr/src/
[root@cacti ~]# cd /usr/src/rrdtool-1.4.8/
[root@cacti rrdtool-1.4.8]# ./configure --prefix=/usr/local/ && make && make install


4 、安装 Cacti ,配置连接数据库
[root@cacti ~]# tar xf cacti-0.8.8b.tar.gz
[root@cacti ~]# mv cacti-0.8.8b /var/www/html/cacti
[root@cacti ~]# useradd -M -s /sbin/nologin cacti
[root@cacti ~]# chown -R cacti.cacti /var/www/html/cacti/
于 创建用于 cacti 用 监测平台的数据库,并授权一个数据库用户,使用 cacti 的 目录下的 cacti.sql
脚本,导入预设的各种数据表。
[root@cacti ~]# mysql
mysql> create database cactidb default character set utf8;
mysql> grant all on cactidb.* to 'cacti'@localhost identified by 'cacti';
mysql> flush privileges;


调整 cacti  配置文件:修改 include/config.php  设置正确的数据库连接参数
[root@cacti cacti]# pwd
/var/www/html/cacti
[root@cacti cacti]# vim include/config.php
26 $database_type = "mysql";
27 $database_default = "cactidb";
28 $database_hostname = "localhost";
29 $database_username = "cacti";
30 $database_password = "cacti";
31 $database_port = "3306";
32 $database_ssl = false;
……
39 $url_path = "/";  #指定 cacti 目录相对于网站根目录的位置


调整 Apache  主配置文件,修改默认发布路径
[root@cacti ~]# vim /etc/httpd/conf/httpd.conf
292 DocumentRoot "/var/www/html/cacti"
317 <Directory "/var/www/html/cacti">
[root@cacti ~]# /etc/init.d/httpd restart

初始化安装 Cacti
浏览器访问:
http://192.168.2.11/install





客户端配置(被监控端)
Linux  客户端配置(192.168.2.12 )
被检测的无论是交换机,路由器等网络设备还是 linux windows 服务器主机的均需支持
snmp 协议,并允许 cacti 服务器采集数据,就能够集中检测,在 linux 中安装 net-snmp、
lm_sensors 等软件包,然后修改配置文件/etc/snmp/snmpd.conf,并启动 snmpd 服务,snmpd
默认在 UDP 协议 161 端口响应 SNMP 查询。


1> 安装 net-snmp  软件包
[root@client ~]# yum -y install net-snmp lm_sensors

2> 修改/etc/snmp/snmpd.conf  文件,设置 snmp  访问权限
[root@client ~]# cd /etc/snmp/
[root@client snmp]# cp -p snmpd.conf snmpd.conf.origin
[root@client snmp]# vim snmpd.conf
41 com2sec notConfigUser 192.168.2.11 public
62 access notConfigGroup "" any noauth exact all none none
85 view all included .1 80
第 41 行,将 default 修改为 cacti 服务器地址,public 表示 SNMP 共同体的名称,用来识别及
验证的,作用类似于密码
第 62 行,将 SystemView 修改为 all 或者 read,提供访问权限
第 85 行,去掉#,支持查询访问
[root@client ~]# /etc/init.d/snmpd start
[root@client ~]# chkconfig snmpd on
[root@client ~]# netstat -anpu |grep 161


3> 如果被检测 linux  主机有防火墙,需调整策略,允许 cacti  访问本级的 snmpd  服务
iptables -I INPUT -s 192.168.200.211 -p udp --dport 161 -j ACCEPT
iptables -I OUTPUT -s 192.168.200.211 -p udp --sport 161 -j ACCEPT



[root@ cacti ~] # vim /etc/php.ini +946
946 date.timezone = Asia/Shanghai
[root@
cacti ~] # /etc/init.d/httpd restart
[root@ cacti  ~ ]# /usr/bin/php /var/www/html/cacti/poller.php




[root@client ~]# yum -y install mysql mysql-server mysql-devel
[root@client ~]# /etc/init.d/mysqld start
[root@cacti ~]# crontab -ucacti -e
*/5 * * * * /usr/bin/php /var/www/html/cacti/poller.php
&> /dev/null
[root@cacti ~]# crontab -ucacti -l
*/5 *  *  *  *  /usr/bin/php /var/www/html/cacti/poller.php &> /dev/null
[root@cacti ~]# chkconfig crond on
[root@cacti ~]# /etc/init.d/crond status







  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值