Chinaunix首页 | 论坛 | 博客
  • 博客访问: 3436811
  • 博文数量: 349
  • 博客积分: 5771
  • 博客等级: 大校
  • 技术积分: 4193
  • 用 户 组: 普通用户
  • 注册时间: 2009-07-06 11:52
个人简介

it

文章分类

全部博文(349)

文章存档

2019年(2)

2018年(2)

2017年(1)

2016年(2)

2015年(18)

2014年(36)

2013年(69)

2012年(100)

2011年(62)

2010年(57)

分类: LINUX

2013-05-13 13:48:20

原文地址:cacti 安装记录 作者:purcotton

1.最小化系统安装,并作好系统优化
2.安装所依赖包
  1. yum install gcc gcc-c++ autoconf libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel curl curl-devel openssl openssl-devel perl mysql-devel pango-devel libtool
3.安装mysql
  1. #rm -fr /etc/ld.so.conf.d/mysql*
  2. #tar -zxvf mysql-5.0.87.tar.gz
  3. #cd mysql-5.0.87
  4. #groupadd mysql
  5. #useradd -g mysql mysql
  6. #./configure --prefix=/usr/local/cacti/mysql --enable-local-infile --with-charset-gbk --with-extra-charsets=all --with-low-memory --with-mysqld-user=mysql --enable-thread-safe-client
  7. #make && make install
  8. #mv /etc/my.cnf /etc/my.cnf.bak
  9. #cp support-files/my-medium.cnf /etc/my.cnf
  10. #cd /usr/local/cacti/mysql/
  11. #chown -R mysql:mysql .
  12. #./bin/mysql_install_db --user=mysql
  13. #chown -R root .
  14. #chown -R mysql var
  15. #./bin/mysqld_safe --user=mysql &
  #echo "/usr/local/cacti/mysql/lib/mysql" >> /etc/ld.so.conf
  #rm -fr /etc/init.d/mysqld
  #cp /opt/cacti/mysql-5.0.87/support-files/mysql.server /etc/init.d/mysqld
  #ln -s /usr/local/cacti/mysql/bin/mysql /usr/local/bin/mysql
  #ldconfig -v
  #ldconfig -v | grep mysql

 
#chmod 755 /etc/init.d/mysqld
  #chkconfig --add mysqld
  #chkconfig mysqld on



4.安装apache
  1. #tar zxvf httpd-2.2.21.tar.gz
  2. #cd httpd-2.2.21
  3. #./configure --prefix=/usr/local/cacti/apache --enable-so --enable-rewrite --enable-ssl --with-ssl=/usr/bin/openssl --with-zlib --enable-mods-shared=all --enable-track-vars --with-mysql=/usr/local/cacti/mysql
  4. #make
  5. #make install
  6. #/usr/local/cacti/apache/bin/apachectl start
  7. #ln -s /usr/local/cacti/apache/bin/apachectl /etc/init.d/httpd
  8. #vi /etc/init.d/httpd

 
  #chkconfig: 235 98 98  #description:http server
  chkconfig --add httpd
  chkconfig httpd on
  1. #chkconfig --add httpd
  2. #vi /usr/local/cacti/apache/conf/httpd.conf  #支持php
  3. AddType application/x-httpd-php .php
    AddType application/x-httpd-php-source .phps

    DirectoryIndex index.php index.html

如果启动出现错误:
httpd: apr_sockaddr_info_get() failed for bogon
httpd: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1 for ServerName
只要hostname localhost即可
5.安装php
  1. #tar zxvf php-5.2.8.tar.gz
  2. #cd php-5.2.8
  3. #./configure --prefix=/usr/local/cacti/php --with-config-file-path=/usr/local/cacti/php --with-apxs2=/usr/local/cacti/apache/bin/apxs --with-zlib --with-bz2 --with-freetype-dir --enable-mbstring --with-mysql=/usr/local/cacti/mysql/ --with-mysqli=/usr/local/cacti/mysql/bin/mysql_config --with-gd --with-libxml-dir --with-jpeg-dir --enable-sockets --enable-fastcgi
  4. #make
  5. #make test
  6. #make install
  7. #cp php.ini-dist /usr/local/cacti/php/php.ini
  8. #ln -s /usr/local/cacti/php/bin/php /usr/bin/
写一个phpinfo 放在/usr/local/cacti/apache/htdocs
然后重启apache
[root@bogon modules]# /usr/local/cacti/apache/bin/apachectl restart
如果提示错误:
/usr/local/cacti/apache/bin/apachectl restart
httpd: Syntax error on line 106 of /usr/local/cacti/apache/conf/httpd.conf: Cannot load /usr/local/cacti/apache/modules/libphp5.so into server: /usr/local/cacti/apache/modules/libphp5.so: cannot restore segment prot after reloc: Permission denied
那么需要关闭selinux
setenforce 0

6.安装rrdtool
  1. #tar -zxvf rrdtool-1.3.9.tar.gz
  2. #cd rrdtool-1.3.9
  3. #./configure --prefix=/usr/local/cacti/rrdtool
  4. #make
  5. #make install
7.安装snmp
yum安装(成功)
  1. #yum install net-snmp
  2. #yum install net-snmp-*
编译安装(未成功,可能是没删除原来的snmp)
  1. #tar -zxvf net-snmp-5.4.2.1.tar.gz
  2. #cd net-snmp-5.4.2.1
  3. #./configure --prefix=/usr/local/cacti/snmp
  4. #make
  5. #make install
  6. #ln -s /usr/local/cacti/snmp/bin/* /usr/local/bin/
  7. #cp EXAMPLE.conf /usr/local/cacti/snmp/share/snmp/snmpd.conf
  8. #echo "/usr/local/cacti/snmp/sbin/snmpd" >> /etc/rc.local
切换下用户看下变量

8.安装spine
  1. #tar zxvf cacti-spine-0.8.7h.tar.gz
  2. #cd cacti-spine-0.8.7h
  3. #./configure --prefix=/usr/local/cacti/spine
  4.  --with-snmp=/usr/local/cacti/snmp/如果编译安装的snmp加上此参数
  5. #make
  6. #make isntall
看下spine的信息
cat /usr/local/cacti/spine/etc/spine.conf.dist
  1. DB_Host localhost
  2. DB_Database cacti
  3. DB_User cactiuser
  4. DB_Pass cactiuser
  5. DB_Port 3306
  6. DB_PreG 0
9.创建cacti的数据库
  1. #groupadd cactiuser
  2. #useradd cacti -g cactiuser
  3. #/usr/local/bin/mysql
  4. mysql> create database cacti;
  5. Query OK, 1 row affected (0.02 sec)

  6. mysql> grant all privileges on cacti.* to cactiuser@localhost identified by "cactiuser";
  7. Query OK, 0 rows affected (0.04 sec)
10.安装cacti
  1. #tar zxvf cacti-0.8.7h.tar.gz
  2. #mv cacti-0.8.7h /usr/local/cacti/apache/htdocs/cacti
  3. #cat /usr/local/cacti/apache/htdocs/cacti/include/config.php
  4. $database_type = "mysql";
    $database_default = "cacti";
    $database_hostname = "localhost";
    $database_username = "cactiuser";
    $database_password = "cactiuser";
    $database_port = "3306";
    $database_ssl = false;
添加cacti数据库
  1. #cd /usr/local/cacti/apache/htdocs/cacti
  2. #/usr/local/bin/mysql cacti < cacti.sql
自动执行任务
  1. #crontab -u cacti -e
  2. */5 * * * * /usr/local/cacti/php/bin/php -q /usr/local/cacti/apache/htdocs/cacti/poller.php > /var/log/poller.log 2>&1

  3. #touch /var/log/poller.log
  4. #chown cacti:cactiuser /var/log/poller.log

#vi /usr/local/cacti/apache/htdocs/cacti/poller.php

fwrite(fopen("/home/cacti/php.txt","w"),date("Y-m-d H:i:s"));
放在 ?> 前面
在crontab中不要添加用户,否则会报错

  1. # cd /usr/local/cacti/apache/htdocs/cacti/
  2. # chmod 755 poller.php cmd.php

  1. #chown -R cacti:cactiuser /usr/local/cacti/apache/htdocs/cacti/
  2. #/usr/local/cacti/php/bin/php /usr/local/cacti/apache/htdocs/cacti/poller.php
如果在poller.log出现POLLER: Poller[0] WARNING: Cron is out of sync with the Poller Interval!  The Poller Interval is '300' seconds, with a maximum of a '300' second Cron, but 515 seconds have passed since the last poll
为添加

11.安装plugin
  1. #tar zxvf cacti-plugin-0.8.7h-PA-v3.0.tar.gz
  2. #cd cacti-plugin-arch/
  3. #/usr/local/bin/mysql cacti < pa.sql
  4. #cp cacti-plugin-0.8.7h-PA-v3.0.diff /usr/local/cacti/apache/htdocs/cacti/
  5. #cd /usr/local/cacti/apache/htdocs/cacti/
  6. #patch -p1 -N < cacti-plugin-0.8.7h-PA-v3.0.diff

  7. #vi /usr/local/cacti/apache/htdocs/cacti/include/global.php
  8. 注释####$config['url_path']=$url_path; -- 修改为--> $config['url_path']='/cacti/';
12.安装setting
  1. #tar zxvf settings-v0.71-1.tgz
  2. #mv settings /usr/local/cacti/apache/htdocs/cacti/plugins/
13.安装weathermap
  1. #unzip php-weathermap-0.97a.zip
  2. #mv weathermap/ /usr/local/cacti/apache/htdocs/cacti/plugins/
  3. #cd /usr/local/cacti/apache/htdocs/cacti/plugins/weathermap/
  4. #chown cacti output/
  5. #cp editor-config.php-dist editor-config.php
  6. #chown daemon configs/
  7. #chmod u+w configs/
  8. #vi editor-config.php修改下面
  9. $cacti_base = "/usr/local/cacti/apache/htdocs/cacti";
  10. $cacti_url = "";
  11. $mapdir= $cacti_base.'/plugins/weathermap/configs';
  12. $ignore_cacti = FALSE;   #如果为FALSE则不需要修改

  13. #vi editor.php

  14. $ENABLED=false; 改成 $ENABLED=true;
14.安装monitor
  1. #tar zxvf monitor-latest.tgz
  2. #mv monitor /usr/local/cacti/apache/htdocs/cacti/plugins/
15.安装thold
  1. #tar zxvf thold-v0.4.9-3.tgz
  2. #mv thold /usr/local/cacti/apache/htdocs/cacti/plugins/
16.安装ntop
  1. #tar zxvf libpcap-1.1.1.tar.gz
  2. #cd libpcap-1.1.1
  3. #./configure
  4. #make
  5. #make install
如果出现
configure: error: Your operating system's lex is insufficient to compile
 libpcap.  flex is a lex replacement that has many advantages, including
 being able to compile libpcap.  For more information, see
  .

configure: WARNING: don't have both flex and bison; reverting to lex/yacc
输入
即可
  1. # yum install bison flex

  1. #yum install GeoIP-* (否则会报错)
  2. #tar zxvf ntop-4.1.0.tar.gz
  3. #cd ntop-4.1.0
  4. #./autogen.sh --with-rrd-home=/usr/local/cacti/rrdtool --disable-snmp
  5. #./configure --prefix=/usr/local/ntop --with-rrd-home=/usr/local/cacti/rrdtool --disable-snmp
  6. #make
  7. #make install
如果出现错误
ERROR: gdbm header or library routines are missing
  1. yum install gdbm gdbm-devel


配置ntop
  1. #groupadd ntop
  2. #useradd ntop -g ntop
  3. #mkdir /var/log/ntop
  4. #cp packages/RedHat/ntop.conf.sample /etc/ntop.conf
  5. #chown -R ntop.ntop /usr/local/ntop/share/ntop/
  6. #chown -R ntop.ntop /var/log/ntop/
  7. #ln -s /usr/local/lib/libpcap.so.1.1.1 /lib/libpcap.so.1
  8. #ldconfig
  9. #/usr/local/ntop/bin/ntop -A  #设定密码


  1. #/usr/local/ntop/bin/ntop -p /var/log/ntop启动ntop  错误如下
  2. Wed Nov 23 11:46:02 2011 **ERROR** RRD: Disabled - unable to create base directory (err 13, /usr/local/ntop/var/ntop/rrd)
因为缺少数据存储路径,执行
  1. #mkdir /usr/local/ntop/var/ntop/rrd
  2. #chmod -R 777 /usr/local/ntop/var/ntop/rrd/

  1. #tar zxvf ntop-v0.2-1.tgz
  2. #mv ntop /usr/local/cacti/apache/htdocs/cacti/plugins
  3. 注意这是两个包
17.安装syslog
  1. #tar zxvf syslog-v1.22-1.tgz
  2. #mv syslog /usr/local/cacti/apache/htdocs/cacti/plugins/
建立syslog数据库
  1. #/usr/local/bin/mysql
  2. mysql> create database syslog;
导入syslog表
  1. #/usr/local/bin/mysql syslog < /usr/local/cacti/apache/htdocs/cacti/plugins/syslog/syslog.sql
给权限
  1. # /usr/local/bin/mysql
  2. mysql> grant all privileges on syslog.* to cactiuser@localhost identified by "cactiuser";
  3. Query OK, 0 rows affected (0.02 sec)

  4. mysql> flush privileges;
  5. Query OK, 0 rows affected (0.03 sec)

  1. #service syslog stop
安装syslog-ng
  1. #yum install syslog-ng
配置syslog-ng
  1. #vi /etc/syslog-ng/syslog-ng.conf #在最低下添加
  2. source net {
  3. udp();
  4. };
  5. destination d_mysql {
  6. pipe("/tmp/mysql.pipe"
  7. template("INSERT INTO syslog_incoming (host,facility,priority,date,time,massage)
  8. VALUES ('$HOST','$FACILITY','$PRIORITY', '$YEAR-$MONTH-$DAY', '$HOUR:$MIN:$SEC', '$MSG' );\n")
  9. template-escape(yes)
  10. );
  11. };
  12. log { source(net); destination(d_mysql); };
  13. log { source(s_sys); destination(d_mysql); };
创建syslogtomysql
  1. #vi /sbin/syslogtomysql

  2. #!/bin/bash
  3. if [ ! -e /tmp/mysql.pipe ]; then
  4. mkfifo /tmp/mysql.pipe
  5. fi
  6. while [ -e /tmp/mysql.pipe ]
  7. do
  8. mysql -u cactiuser --password=cactiuser syslog < /tmp/mysql.pipe
  9. done

  1. #chmod 755 /sbin/syslogtomysql
  2. # echo "/sbin/syslogtomysql &" >> /etc/rc.local
  3. # /sbin/syslogtomysql &


  1. #ps aux|grep mysqld
  2. #kill掉mysql
  3. #service mysqld start
  4. #service syslog-ng start
如果syslog-ng启动提示错误这个是属于mysql的错误,重新加一遍上面syslog的权限试下
ERROR 1054 (42S22) at line 1: Unknown column 'massage' in 'field list'

重新
添加随机启动
  1. # chkconfig syslog off
  2. # chkconfig --del syslog
  3. # chkconfig syslog-ng on
  4. # chkconfig --add syslog-ng

18.安装discovery
  1. #tar zxvf discovery-v1.3-1.tgz
  2. #mv discovery /usr/local/cacti/apache/htdocs/cacti/plugins/discover
19.修改snmp.comf

  1. #vi /etc/snmp/snmpd.conf
  2. com2sec notConfigUser  127.0.0.1       public #允许的IP
    com2sec notConfigUser  192.168.10.223       public

  3. com2sec notConfigUser default public--->com2sec notConfigUser your_snmpd_server_ip public

  4. #view all included .1 80---->view all included .1 80

  5. access notConfigGroup "" any noauth exact systemview none none-->
  6. access notConfigGroup "" any noauth exact all none none
20.打开161端口,并重启防火墙
  1. # vi /etc/sysconfig/iptables
  2. -A INPUT -p tcp -m tcp --dport 161 -j ACCEPT
  3. # service iptables restart
  4. Flushing firewall rules: [ OK ]
  5. Setting chains to policy ACCEPT: filter [ OK ]
  6. Unloading iptables modules: [ OK ]
  7. Applying iptables firewall rules: [ OK ]
  8. Loading additional iptables modules: ip_conntrack_netbios_n[ OK ]
21.打开浏览器输入地址 下一步,下一步 


修改rrdtool地址为:/usr/local/cacti/rrdtool/bin/rrdtool


点击User Management

点击admin



勾选Plugin Management 并save


选择Settings


选择paths标签页,补全命令路径
/usr/local/cacti/rrdtool/bin/rrdtool
/usr/local/cacti/apache/htdocs/cacti/poller.php
保存


点击Deeices,右上角选择ADD


写上一个名字,添加上ip地址,模板类型选择ucd/net Snmp Host,version2,然后点击Create



观察snmp无错误



添加SNMP-Get Mounted Patitions  ,然后点击右上角的


再有边可以选择需要监控的项目 打勾 然后添加

左边选择Graph Trees ,然后选贼Default Tree 添加图

add添加


如图选择刚才添加的IP 点击保存


图像出来了


过一会数据也出来了

阅读(1972) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~