Chinaunix首页 | 论坛 | 博客
  • 博客访问: 6724
  • 博文数量: 4
  • 博客积分: 175
  • 博客等级: 入伍新兵
  • 技术积分: 50
  • 用 户 组: 普通用户
  • 注册时间: 2010-10-29 21:35
文章分类

全部博文(4)

文章存档

2011年(4)

我的朋友
最近访客

分类: LINUX

2011-03-06 00:03:50

常见应用

服务器资源:CPU、内存、磁盘、进程、连接数等

服务器类型:WEBMailFTP、数据库、中间件

网络接口:流量、转发速度、丢包率

设备运行状态:风扇、电源、温度

机房运行环境:电流、电压、温湿度


快速安装cacti

测试平台:rhel 5.4     

cacti版本:0.8.7g

运行环境:LAMP环境

1.安装依赖包

yum -y install httpd php php-mysql php-snmp mysql mysql-server perl-DBD-MySQL php-pdo php-pear net-snmp net-snmp-libs net-snmp-utils net-snmp-devel ruby ruby-devel

2.设置开机启动snmpd,httpd,mysqld 服务

3.安装rrdtools

 到这里下载最新RRDTools rpm包:~wrl/rrdtool/

yum -y localinstall --nogpgcheck rrdtool-*.rpm

4.配置snmp

#  vi /etc/snmp/snmp.conf

 com2secnotConfigUser default public

 改为:com2secnotConfigUser 127.0.0.1 public    (这是监控本地,被监控主机设置)

 access  notConfigGroup “”  any   noauth    exact  systemview  none none

改为:access  notConfigGroup “” any noauth   exact   all none  none

#view all    included  .1         80

将前面的 # 注释去掉。

重新启动 snmp 服务

5.安装cacti数据以及模板

配置mysql数据库

# mysql

Mysql > CREATE DATABASE cacti;

Mysql > grant all privileges on cacti.* to cacti@localhost identified by cacti;

Mysql > grant all privileges on cacti.* to cacti@127.0.0.1 identified by cacti;

Mysql > grant all privileges on cacti.* to cacti@192.168.0.0 identified by cacti;

Mysql >flush privileges;

Mysql >quit

# tar xzvf  cacti-0.8.7g.tar.gz

# mv cacti-0.8.7g/ /var/www/html/cacti

# mysql -ucacti -pcacti cacti < /var/www/html/cacti/cacti.sql

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

修改成:

$database_type= mysql ;

$database_default = cacti ;

$database_hostname = localhost ;

$database_username = cacti ;

$database_password = cacti ;

useradd cacti

passwd cacti

cd   /var/www/html/cacti/

chown -R cacti rra/ log/

# crontab -e

*/5 * * * * php /var/www/html/cacti/poller.php > /dev/null 2>&1

访问  开始安装


注意:

1vim /etc/httpd/conf/httpd.conf

DirectoryIndex   index.php  index.html  index.html.var

2selinux=permissive

Service iptables stop

 

第一次登陆User Name Password 都为admin,并且需要强行修改。

第一次绘图比较慢。需要一定的时间,请耐心等待。

 

 

四、cacti常用插件安装

要安装别的插件前,先要安装cacti的一个patch--Plugin Architecture,才能支持插件

PA 2.8 = cacti 0.8.7g

# tar xvf cacti-plugin-0.8.7g-PA-v2.8.tar.gz

# cp -R cacti-plugin-arch/* /var/www/html/cacti/

cd /var/www/html/cacti/

mysql -ucacti -pcacti cacti

patch -p1 -N

vim  include/config.php

修改为$url_path = /cacti/;


回到web管理界面,找到console—Utilities—User Management—admin

并保存。

安装常用插件 Monitor,Settings,thold

# tar zxvf monitor-latest.tgz

# tar zxvf settings-latest.tgz

# tar zxvf thold-latest.tgz

# mv monitor-0.9  /var/www/html/cacti/plugins/monitor

# mv settings-0.6  /var/www/html/cacti/plugins/settings

# mv thold-0.41   /var/www/html/cacti/plugins/thold

回到web管理界面,找到console—Configuration—Plugin Management,你将看到

登陆安装启用对应的插件即可。

注意事项:

1.官方文档说要修改/var/www/html/cacti/include/global.php  里面的内容。我试验后发现,修改后反而不能找到插件。不修改即可找到插件。

2.在安装thold时,可能会出现 You are missing a dependency for thold, please install the 'Settings' plugin. 这样的警告。只需要先安装settings插件就OK

 

 

五、Cacti MSN,mail,飞信报警设置

1.E-mail报警设置。

2.MSN报警设置。

3.飞信报警设置。

更多见


1E-mail报警设置

回到web管理界面,找到console—Configuration—Settings—Alerting/Thold

并保存。

找到console—Configuration—Settings—Mail/DNS

并保存。

注意:此邮箱为为测试邮箱,点击右边,此邮箱将受到test mail

并且显示如下对话框。Root@localhost为任意地址,服务器不予与验证。

如果SMTP换为Sendmail,将可能出现错误信息。所有,最好选择SMTP。记得保存。


2.MSN报警设置

1)修改cacti插件thold目录下的thold_functions.php

vim /var/www/html/cacti/plugins/thold/thold_functions.php

thold_mail找到文件中的第一个这一句

if (trim($alert_emails) != "")

thold_mail($alert_emails, '', $subject, $msg, $file_array);

然后下面添加

exec("echo $subject >>/var/www/html/cacti/plugins/thold/alert.log");

exec("sh /var/www/html/cacti/plugins/thold/sendmessage.sh");

保存退出

3.然后编写个sendmessage.sh脚本,在/var/www/html/cacti/plugins/thold/这个目录下

脚本内容


#!/bin/sh

echo `echo -n "date:"&&date +%Y-%m-%d-%H:%M` >> /var/www/html/sendMsg/msn.txt.1

cat /var/www/html/cacti/plugins/thold/alert.log >>/var/www/html/sendMsg/msn.txt.1

now=`date +%Y-%m-%d-%H:%M`

SA=(test)

msnaddr=(pingsun2010@hotmail.com)

sendMsg()

{

num=0

while [ $num -lt 1 ];

do

wget —post-data "sender=pingsun2012@hotmail.com&password=123456&recipient=${1}&message=${2}" -O /var/www/html/sendMsg/index.php.1 >/dev/null 2>&1

if [ -f /var/www/html/sendMsg/index.php.1 ]; then

if cat /var/www/html/sendMsg/index.php.1 |grep -i successfully >/dev/null 2>&1;then

num=1

elif cat /var/www/html/sendMsg/index.php.1 |grep -i "The user appears to be offline" >/dev/null 2>&1;then

num=1

echo "The user is offline."

exit 0

elif cat /var/www/html/sendMsg/index.php.1 |grep -i "Something went wrong trying to connect to the server" >/dev/null 2>&1;then

num=1

echo "MSN server is online."

exit 0

else

num=0

fi

rm -f /var/www/html/sendMsg/index.php.1

else

num=0

fi

done

}

mv /var/www/html/sendMsg/msn.txt /var/www/html/sendMsg/bak/msn$now.txt -f 1>/dev/null 2>&1

mv /var/www/html/sendMsg/msn.txt.1 /var/www/html/sendMsg/msn.txt -f 1>/dev/null 2>&1

rm /var/www/html/cacti/plugins/thold/alert.log -f 1>/dev/null 2>&1

for i in 0

do

if cat /var/www/html/sendMsg/msn.txt ; then

messages=`cat /var/www/html/sendMsg/msn.txt `

sendMsg "${msnaddr[$i]}" "$messages"

else

continue

fi

done


然后保存退出。(发送和接受者必须互为好友)

4.手动运行sendmessage.sh这个脚本,如果没有问题,应该可以收到消息。

4.飞信报警功能实现

1.下载最新版飞信机器人。

%3D1

根据情况下载,因为会经常更新。 下载两个一个是fetion程序,一个是Linux下的库包linuxso-20101113.tar.gz

2.飞信机器人放置位置

cd /var/www/html

Mkdir sendsms

cp -a linuxso_20101113 /var/www/html/sendsms/linuxso

cp fetion /var/www/html/sendsms/linuxso/fetion

chmod 777 -R  /var/www/html/sendsms/linuxso

thold_mail找到文件中的第一个这一句

if (trim($alert_emails) != "")

thold_mail($alert_emails, '', $subject, $msg, $file_array);

然后下面添加

exec("echo $subject >>/var/www/html/cacti/plugins/thold/alert.log");

exec("/var/www/html/cacti/plugins/thold/sendsms.sh");

编写sendsms.sh脚本,内容如下:


#!/bin/sh

#send sms by fetion

#Write by pingsun2010@hotmail.com

if [ ! -e "/var/www/html/cacti/plugins/thold/alert.log" ];then

echo "Usage:alert.log does not exist"

exit

fi

if [ -n "`cat /var/www/html/cacti/plugins/thold/alert.log`" ]; then

admin="150382XXXX"

echo "sms $admin "`cat /var/www/html/cacti/plugins/thold/alert.log` >>/var/www/html/cacti/plugins/thold/sms.txt

echo "exit" >> /var/www/html/cacti/plugins/thold/sms.txt

else

echo "Usage:no alert"

exit

fi

if [ -n "`cat /var/www/html/cacti/plugins/thold/sms.txt`" ] ; then

LD_LIBRARY_PATH=/var/www/html/sendsms/linuxso /var/www/html/sendsms/linuxso/fetion --mobile=158038XXX90 --pwd=123xxx   --to=$admin --file-utf8=/var/www/html/cacti/plugins/thold/sms.txt

rm -f /var/www/html/cacti/plugins/thold/sms.txt 1>/dev/null 2>&1

rm -f /var/www/html/cacti/plugins/thold/alert.log 1>/dev/null 2>&1

else

echo "Usgae:no message to send"

exit

fi


保存,退出。测试一下。

可以新建alert.log以及sms.txt,其中在alert.log中添加一个内容。

然后运行脚本

./sendsms.sh

会返回以下结果,表示成功。 同时对方收到短信。

[root@station1 thold]# ./sendsms.sh

图形验证码已经生成,文件名为:15803826990.jpg请识别后输入图形验证码:

Nm8p     #一般第一次会让你输入验证码。这个图片,在你的fetion的目录下。

您输入的识别码是:nm8p

SIP-C/4.0 280 Send SMS OK

T: sip:759885962@fetion.com.cn;p=9283

I: 3

Q: 1 M

L: 115

D: Mon, 22 Nov 2010 15:28:45 GMT

XI: 516723D0200B5C60F8747A8E9B4CFF55

[root@station1 thold]#

5.本次实验,难点是飞信这个地方,网上没有最新的解决方案。这里经过好久尝试,最终测试出可行的办法。如果有问题,欢迎大家反馈。

 

六、常见故障排除

安装完毕在浏览器上无法看到数据的png图片。看apachelog

如果出现:


[Thu Feb 09 15:12:24 2006] [error] [client 127.0.0.1] File does not exist: /var/www/html/favicon.ico

ERROR: opening '/var/www/html/cacti/rra/localhost_mem_buffers_3.rrd': Permission denied

PS:解决办法:关闭selinux,即可解决问题。

PS:以上无法获取数据图大多和poller.phpcmd.php权限有关。

cacti 有图没有数据时,而且状态为nan的错误

PS:这个很可能是snmp的问题,执行以下命令,没有得到如图的结果。就说明snmp不支持64MIB库。重新编译安装snmp

# snmpwalk -c public -v 2c 127.0.0.1 IF-MIB::ifHCInOctets

IF-MIB::ifHCInOctets.1 = Counter64: 7437357

IF-MIB::ifHCInOctets.2 = Counter64: 353773IF-MIB::ifHCInOctets.3 = Counter64: 0

PS:被监控主机无法获得snmp信息,还有可能是对方主机snmp版本和当前主机的snmp版本不一致导致的。

PSrrdtools版本要一致,特别是在升级cacti时候。版本不一致,可能rra数据格式不同。就无法处理。


排错思路

1,查看log下的日志文件。一般那里会有提示

 2,测试SNMP是不是工作正常 snmpwalk -v 2c -c public hostIP   if正常的话会出现一些数据。不正常会出现一些错误,也会有对应的错误提示。

3,自动运行poller.php没有。有没有加入cacti的的用户。。有没有给cacti用户写入rra/ log/的权限。。

4crontab u cactiuser e cactiuser加上自动运行poller.php的任务:

*/5 * * * *  root /usr/local/bin/php /usr/local/share/cacti/poller.php /dev/null 2>&1

5分钟刷新一次数据。你也可以根据需要还设置。

5,把cacti目录里的cmd.phppoller.php文件加下运行的权限。


本文摘自,严重感谢“疯狂的小蜗牛”同学辛勤劳动成果。

 

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

chinaunix网友2011-03-27 18:42:52

很好的, 收藏了 推荐一个博客,提供很多免费软件编程电子书下载: http://free-ebooks.appspot.com