jane27 发表于 2019-1-10 13:27:59

RHEL5.9下cacti监控的部署详解

  cacti是一套基于php、mysql、snmp以及rrdtool开发的系统监控图形分析工具,它通过snmp来获取数据,使用rrdtool绘画图形而且完全可以不需要了解rrdtool复杂的命令参数,它提供了非常强大的数据和用户管理界面,可以指定每一个用户能查看树状结构以及主机的任何一张图,还可以与LDAP结合进行用户认证,同时也能添加自定义的监控模版,监控windows操作系统,功能强大,界面友好,现如今cacti应用相当广泛,比如一些门户网站、IDC数据中心,像北京铜牛信息数据中心、中国联通数据中心均已经使用cacti作为网络流量监控系统,当然我的公司也正在使用cacti完成部分监控角色,特整理一下与大家分享!
http://blog.运维网.com/attachment/201306/125446992.gif
  

  安装apache
tar xzvf httpd-2.2.24.tar.gz
cd httpd-2.2.24
./configure --prefix=/usr/local/apache --enable-so
make && make install
/usr/local/apache/bin/apachectl start
echo "/usr/local/apache/bin/apachectl start" >> /etc/rc.local  

  安装mysql
tar xzvf mysql-5.1.65.tar.gz
cd mysql-5.1.65
./configure --prefix=/usr/local/mysql --with-extra-charsets=gbk,gb2312,utf8
make && make install
cd /usr/src/mysql-5.1.65/
cp support-files/my-medium.cnf /etc/my.cnf
./scripts/mysql_install_db --user=mysql
mkdir -p /usr/local/mysql/data
chown -R mysql.mysql /usr/local/mysql/data
chown -R root.mysql /usr/local/mysql
/usr/local/mysql/bin/mysqld_safe --user=mysql &
/usr/local/mysql/bin/mysqladmin -uroot password 123456
echo "/usr/local/mysql/bin/mysqld_safe --user=mysql &" >> /etc/rc.local  安装php
yum install libpng libpng-devel libjpeg libjpeg-devel freetype freetype-devel gd gd-devel
tar xzvf php-5.4.11.tar.gz
cd php-5.4.11
./configure --prefix=/usr/local/php--with-apxs2=/usr/local/apache/bin/apxs --with-mysql=/usr/local/mysql -with-gd --with-freetype-dir --with-jpeg-dir --with-png-dir --enable-sockets
make && make install
ln -s /usr/local/php/bin/* /usr/local/bin
cp php.ini-dist /usr/local/php/lib/php.ini  

  编辑httpd.conf在配置文件中加入以下内容
http://blog.运维网.com/attachment/201306/121518978.png
  

http://blog.运维网.com/attachment/201306/121614229.png
  修改DirectoryIndex内容
http://blog.运维网.com/attachment/201306/104905199.png
  使用php探针测试
cd /usr/local/apache/htdocs/
cat test.phphttp://blog.运维网.com/attachment/201306/105251568.png
  安装rrdtool
yum install cairo-devel libxml2-devel pango pango-devel
tar xzvf rrdtool-1.4.6.tar.gz
cd rrdtool-1.4.6
./configure --prefix=/usr/local/rrdtool
make && make install
ln -s /usr/local/rrdtool/bin/* /usr/local/bin/  

  安装net-snmp
tar xzvf net-snmp-5.4.4.tar.gz
cd net-snmp-5.4.4
./configure --prefix=/usr/local/net-snmp
make && make install
cp EXAMPLE.conf /usr/local/net-snmp/share/snmp/snmpd.conf
ln -s /usr/local/net-snmp/bin/* /usr/local/bin/
/usr/local/net-snmp/sbin/snmpd -c /usr/local/net-snmp/share/snmp/snmpd.conf
echo "/usr/local/net-snmp/sbin/snmpd -c /usr/local/net-snmp/share/snmp/snmpd.conf" >> /etc/rc.local  

  安装cacti
tar xzvf cacti-0.8.8.tar.gz
mv cacti-0.8.8/*/usr/local/apache/htdocs/
mysql -uroot -p123456
mysql>create database cacti;
mysql>insert into mysql.user (host,user,password) values('localhost','cacti',password('cacti123'));
mysql>flush privileges;
mysql>grant all on cacti.* tocacti@'localhost' identified by 'cacti123';
cd /usr/local/apache/htdocs/
mysql -uroot -pcacti123 cacti < cacti.sql  viminclude/config.php
http://blog.运维网.com/attachment/201306/110526436.png
  修改完网站配置文件后打开浏览器,然后访问http://192.168.56.128/install/,如果以上操作全部正确会显示以下页面,如果有错误请根据实际情况修改(一般为路径问题,在这个页面上将程序路径重新指定即可)
http://blog.运维网.com/attachment/201306/111534878.png
  点击NEXT
http://blog.运维网.com/attachment/201306/111615367.png
  点击NEXT
http://blog.运维网.com/attachment/201306/111733837.png
  点击Finish
http://blog.运维网.com/attachment/201306/111820373.png
  默认用户名和密码均为admin,第一次登录强制要求修改密码
http://blog.运维网.com/attachment/201306/111938513.png
  为监控对象生成数据文件
/usr/local/php/bin/php /usr/local/apache/htdocs/poller.phphttp://blog.运维网.com/attachment/201306/122934879.png
  rra目录用来存放cacti监控对象生成的监控对象文件
  设置cacti数据采集轮询时间加入到计划任务里
  crontab-e加入以下内容,让cacti每五分钟采集一次数据
*/5 * * * */usr/local/bin/php /usr/local/apache/htdocs/poller.php >/dev/null 2>&1  这样我们就可以通过cacti添加模版,监控nginx服务器资源了
http://blog.运维网.com/attachment/201306/112817485.png
  查看监控nginx服务器的负载
http://blog.运维网.com/attachment/201306/112817147.png
  

  监控nginx服务器的网卡流量
http://blog.运维网.com/attachment/201306/124516779.png
  

  增加被监控主机
  编辑/etc/snmp/snmpd.conf
#将下边这行中的default
com2secnotConfigUser default public
#改为192.168.112.130(cacti)服务器的地址)
com2secnotConfigUser 192.168.112.130 public
#将下边这行中的systemview
access notConfigGroup "" any noauth exact systemview none none
#改为all
access notConfigGroup "" any noauth exact all none none
#将下边这行的注释“#”号去掉
#view all included .1 80#将下边这行中的default
com2secnotConfigUser default public
#改为192.168.112.130(cacti)服务器的地址)
com2secnotConfigUser 192.168.112.130 public
#将下边这行中的systemview
access notConfigGroup "" any noauth exact systemview none none
#改为all
access notConfigGroup "" any noauth exact all none none
#将下边这行的注释“#”号去掉
#view all included .1 80  重启snmp服务
serivce snmpd restart  在监控端执行命令检查是否可以抓取数据
snmpwalk -c public -v 2c 192.168.56.129http://blog.运维网.com/attachment/201306/163922828.png说明snmpd是正确的,如果不能返回数据,那么可以检查iptables和selinux
  

  页面上创建新的主机
http://blog.运维网.com/attachment/201306/164537136.png
  填写被监控主机的相关信息
http://blog.运维网.com/attachment/201306/164714368.png
  修改模版配置
http://blog.运维网.com/attachment/201306/165536748.png
http://blog.运维网.com/attachment/201306/165018934.png
  如果出现SNMPERROR说明snmp配置错误或者防火墙端口没有开放
http://blog.运维网.com/attachment/201306/165355382.png
  最后用graphtree可以看到被监控主机puppetclient已经添加进来,可以完成正常的监控了
http://blog.运维网.com/attachment/201306/165755657.png
  puppetclient主机的网络流量
http://blog.运维网.com/attachment/201306/165907298.png
  puppetclient主机的内存使用率
http://blog.运维网.com/attachment/201306/165935803.png



页: [1]
查看完整版本: RHEL5.9下cacti监控的部署详解