一、安装环境LAMP

#yum -y install gcc* glibc* gd* 

#yum -y install httpdmysql-server perl-DBI perl-DBD-MySQL php php-devel php-mysql php-snmp php-pdophp-gd lm_sensors net-snmp net-snmp-libs net-snmp-utils net-snmp-devel 

# chkconfig mysqld on

# chkconfig httpd on

# chkconfig snmpd on

# service mysqld start

# service httpd start

# service snmpd start

#vim /var/www/html/index.php

<?php

phpinfo();

?>

访问http://localhost/index.php

171545554.png


mysqladmin -u rootpassword '123'

报错处理: # export PATH=$PATH:/usr/local/mysql/bin 


# mysql -u root –p

:输入密码

mysql>createdatabase cacti default character set utf8;

mysql>drop database cacti;

Query OK, 1 row affected (0.00 sec)


mysql>grantall on cacti.* to cacti@localhost identified by '123';

mysql>revoke all on cacti.* fromcacti@localhost;

Query OK, 0 rows affected (0.01 sec)


mysql>flushprivileges;

Query OK, 0 rows affected (0.00 sec)


mysql> \q


二、安装cacti
1、安装rrdtool需要的软件包
# yum -y installcairo-devel libxml2-devel pango pango-devel

2、安装rrdtool

# tar xf rrdtool-1.4.4.tar.gz

# cd rrdtool-1.4.4

# ./configure --prefix=/usr/local/rrdtool && make&& make install

# ln -s /usr/local/rrdtool/bin/* /usr/local/bin/#此步非常重要


3、安装cacti-0.8.7.e中文版

#wget http://blogimg.chinaunix.net/blog/upfile2/090815172648.gz

# tar xvf090815172648.gz -C /var/www/html

# cd /var/www/html

# mv cacti-0.8.7e-cn-utf8/cacti

# mysql -ucacit –p cacti <cacti/cacti.sql /导入数据库

Enter password:


4、创建cacti用户

# useradd -s /sbin/nologin cacti

# chown -R cacti:cacti /var/www/html/cacti/

# chmod -R 777 /var/www/html/cacti/


5、修改cacti配置文件,连接数据库

# vim /var/www/html/cacti/include/config.php

$database_username = "cacti";

$database_password = "123";


6、添加计划任务

# crontab –e

*/5 * * * * /usr/bin/php /var/www/html/cacti/poller.php >/dev/null2>&1

# service crond restart


三、被监控端配置
1
、安装snmp服务
#yum install lm_sensorsnet-snmp

2、修改配置文件如下:(这里我省略掉了#行和空行)

只改了下面三行,(下面的地址是cacti服务器地址,由于是本机测试,所以是127.0.0.1

#vim /etc/snmp/snmpd.conf

41 com2sec notConfigUser 127.0.0.1 public 

62 access notConfigGroup"" any noauth exact all none none

85 view all included .1 80

3、重启服务

# service httpd restart

# service mysqld restart

# service snmpd restart


#
到此就差不多了,我们可以做些检测在服务器上,有信息返回说名正常:

#snmpwalk -cpublic -v 2c localhost

# snmpwalk -v 1 -c public localhost IP-MIB::ipAdEntIfIndex


4、浏览器输入http://192.168.163.143/cacti/install初始化cacti,最后如下:

如果打开网页,页面出现空白,那么说明数据库没有导入进去,重新导入数据库后重启httpd服务即可

RRDTOOLS版本,默认为1.0.x,改为1.3.x就行了

171907149.png


如果打开未看到生成图像,请手动执行下面命令

#/usr/bin/php/var/www/cacti/poller.php &>/dev/null手动生成图像

171920487.png

5、字体在图形中显示不正常的解决方法

下载并安装中文字体,我用的是微米黑字体

wgethttp://sourceforge.net/projects/wqy/files/wqy-microhei/0.2.0-beta/wqy-microhei-0.2.0-beta.tar.gz

#tar zxvf wqy-microhei-0.2.0-beta.tar.gz
# cd wqy-microhei
# cp wqy-microhei.ttc /usr/share/fonts/wqy-microhei.ttc


安装完成后注意在"设置"中更改下面两个必改项.
常规->RRDTool应用程序版本改为1.3.x,默认为1.0.x.不改可能图像不能正常显示出来.
路径->RRDTool默认字体路径改为上面安装的文件路径,如/usr/share/fonts/wqy-microhei.ttc


6、安装插件cacti-plugin

#wget http://blogimg.chinaunix.net/blog/upfile2/090818213852.gz

# mv 090818213852.gzcacti-plugin-0.8.7d-PA-v2.4-cn-utf8.diff.gz

# gunzipcacti-plugin-0.8.7d-PA-v2.4-cn-utf8.diff.gz

# mv cacti-plugin-0.8.7d-PA-v2.4-cn-utf8.diff/var/www/html/cacti/

# cd /var/www/html/cacti/

# patch -p1 -N<cacti-plugin-0.8.7d-PA-v2.4-cn-utf8.diff

# mysql -ucacti -p123 cacti <pa.sql


7、修改配置文件,如下:

# vim /var/www/html/cacti/include/config.php

$config['url_path'] = "/cacti/";; 3306下一行添加,记住一定不要写成/cacti


9、页面设置 

控制面板—用户管理—admin

171939185.png

插件管理打钩—保存

171952685.png

看到控制面板—配置,多个了插件管理

172303444.png


9、安装monitor扩展插件如下:

wget http://cactiusers.org/downloads/monitor.tar.gz

# wget http://cactiusers.org/downloads/thold.tar.gz

# wget http://cactiusers.org/downloads/settings.tar.gz

# tar xvf monitor.tar.gz -C/var/www/Cacti/plugins

# tar xvf thold.tar.gz -C/var/www/Cacti/plugins

# tar xvf settings.tar.gz -C /var/www/Cacti/plugins

# cd /var/www/html/cacti/plugins

# mysql -ucacti -p123 cacti < monitor/monitor.sql

# mysql -ucacti -p123 cacti < thold/thold.sql

# vim /var/www/html/cacti/include/config.php

$plugins[] "monitor"; //添加此行

$plugins[] = "thold";

$plugins[] = "settings";


刷新网页即可

172006584.png

如果出现空白页,请查看apache日志

/var/log/httpd/error_log