www.cactifans.org上的几篇文章

http://bbs.cactifans.org/

http://dl.cactifans.org/

http://www.cactifans.org/index.php/2011/05/backtrack-5-release/#more-311

http://www.cactifans.org/index.php/2012/06/cactifans-v1-0%E4%B8%AD%E6%96%87%E7%89%88%E5%8F%91%E5%B8%83/#more-647

http://www.cactifans.org/index.php/2011/04/cacti%E6%8F%92%E4%BB%B6%E8%AF%A6%E8%A7%A3-weathermap/

http://www.cactifans.org/index.php/2012/02/cacti%E6%95%B4%E5%90%88nagios-cacti%E6%8F%92%E4%BB%B6npc%E7%9A%84%E4%BD%BF%E7%94%A8/

http://www.cactifans.org/index.php/2012/03/cacti%E6%8F%92%E4%BB%B6%E8%AF%A6%E8%A7%A3-syslog/

 

终于发发布了!在第一时刻下载,安装看了一下!最新的BT5有kde和gnome二种!并且都有32位和64位版本!下面上几张图!

启动过程中!

启动后:

msf!

内核!

工具

 

 

 

 

经过几个月来来的努力,CactiFans V1.0中文版终于发布了!仔细算起,自上次发布已经有一年多了,这个时间是有点长,主要的原因是我太忙了,事情太多了。做完这版本,我也要毕业了,离开学校了,大学也就这么上完了,也算毕业的纪念吧!进入正题。

CactiFans是我制作的一个cacti的集成全自动安装系统!

CactiFans v1.0中文版特性

  • 基于CentOS6.2构建,集成了cacti 0.8.8a 中文版(目前最新版),rrdtool 1.4.7(目前最新)
  • 集成nagios 3.3.1,nconf 1.3(管理nagios的一个工具)
  • 集成phpMyAdmin-3.5.0  webmin-1.580
  • 集成 syslog,npc.routerconfigs,weathermap,monitor,discovery等cacti常用的20个插件
  • 集成飞信机器人,可以配置短信报警
  • 包含FreeBSD,IIS,Nginx,apache,mysql,advance ping等实用模版
  • 解决weahermap插件的安全性问题
  • Patch官方所有补丁,解决目前已知bug
  • 集成最新spine高效轮询工具
  • 自动定期备份cacti和syslog数据
  • 优化系统服务

下载地址:

 

CactiFans-v1.0-i386.iso

CactiFans-v1.0-x86_64.iso

1
2
3
4
MD5 (CactiFans-v1.0-i386.iso) = f3953004b265eba310ad99c925e82e11
MD5 (CactiFans-v1.0-x86_64.iso) = 5c86ad369f10f3f653c98c529784a0ec
SHA256 (CactiFans-v1.0-i386.iso) = 616925fe49ffc0311c1f31bab66c49b0e225f89ce7f410cf544f0ebc6fd60e08
SHA256 (CactiFans-v1.0-x86_64.iso) = 168df927757ea638d2b1f4ef77f65dd79e7b99b7a546b40053dccc1c9a7d109a

QQ群:①185016501       ②61797150
登录系统密码:(建议尽快修改)

1
2
username: root
passpord: cactifans.org

第一次登录cacti的默认密码

1
2
username:admin 
password: admin

Webmin地址及默认密码(一定要修改)

1
2
3
http://192.168.1.10/nagios/
username: nagiosadmin
password: cactifans

nconf地址及默认密码

1
2
3
http://192.168.1.10/nconf/
username: admin
password: cactifans.org

weathermap编辑密码(编辑weathermap图形时会需要)

1
2
username:cactifans
password:cactifans.org

安装方法:
用iso引导后将会出现如下画面:

直接按回车开始自动安装:

安装过程需要5分钟左右,安装好之后(启动到进度条那里会卡以下,是由于网络ip问题,等待,会过去的)

安装后,默认使用静态ip,ip地址为192.168.1.10,登录系统,用户名:root 密码:cactifans.org
登录后输入
system-config-network
回车,出现如图修改ip

修改完,选ok,保存并退出
输入
/etc/init.d/network restart
重启网卡
打开浏览器http://xxx.xxx.xxx.xxx/
用户名:admin 密码:admin 登录后要强制修改密码,输入要设置的密码点ok,就进入系统了;

开始使用吧!
图形

NPC

syslog

nagios

nconf

wemin

phpmyadmin

模版

关于CactiFans我还会写一篇文章,详细讲述使用过程!

 

    Weathermap是cacti中大家最用的一个插件之一,用它可以画出漂亮的网络拓扑图!同时Weathermap也是一个独立工具,可以独立部署,不需要cacti的支持,也可以部署.下面首先来看一看用Weathermap画出来的拓扑图.

 

 

 

        这些漂亮的网络拓扑都是用weathermap画出来的!
这么长时间了没有发出来,今天就写以下weathermap的用法,以下都是我自己的理解,如有错误之处请谅解!
weathermap是用来做网络拓扑图的,其中可以调用mrtg和cacti的流量图,可以生成静态的html页面。具体的例子大家可以中国科大的这个http://linux.ustc.edu.cn/
weathermap的官方网站为 http://www.network-weathermap.com/ weathermap有二种用法。第一种就是作为cacti的插件使用,第二种就是独立出来,可以独立安装一个weathermapm,当然要php,php-gd支持,weathermap最新版本为weathermap-0.97a.
 

一.weathermap作为cacti插件的用法

1.安装weathermap插件

1
2
3
4
5
wget http://www.network-weathermap.com/files/php-weathermap-0.97a.zip
unzip php-weathermap-0.97a.zip
mv weathermap/ /var/www/html/plugins/
chown -R apache:apache /var/www/html/plugins/weathermap/configs/
chown -R apache:apache /var/www/html/plugins/weathermap/output/
下面我们打开cacti,点console——Plugin Management,就可以看到weathermap了,点前面那个点就可以安装weathermap

 

 

点击安装weathermap后

至此,weathermap已经安装成功。

2.配置使用weathermap

安装好weathermap后,看到点Console在左边的列表里会看到weathermap的菜单,我们点击,会看到设置,因为我们还没有定义一个weathermap配置文件,所以我们点右上角的Add按钮,添加一个weathermap配置文件

点击Add之后,我们看到有二个文件,其实这个时候调用的就是weathermap的configs目录下的文件,simple.conf就是自带的一个配置文件,我们可以点击它前面的Add按钮,把他添加到默认配置文件里

至此我们添加了一个weathermap的配置文件,下面就是对weathermap进行配置了,点击weathermap,然后点击Editor对默认图形配置文件进行配置。

点击editor后我们会看到如下提示

 

The editor has not been enabled yet. You need to set ENABLED=true at the top of editor.php

Before you do that, you should consider using FilesMatch (in Apache) or similar to limit who can access the editor. There is more information in the install guide section of the manual.

 

我们按照他提示的编辑editor.php

1
vi /var/www/html/plugins/weathermap/editor.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
<php 
 
require_once 'editor.inc.php';
require_once 'Weathermap.class.php';
 
// so that you can't have the editor active, and not know about it.
$ENABLED=true;
 
if(! $ENABLED)
{
print "
 
The editor has not been enabled yet. You need to set ENABLED=true at the top of editor.php
 
";
print "
 
Before you do that, you should consider using FilesMatch (in Apache) or similar to limit who can access the editor. There is more information in the install guide section of the manual.
 
";
exit();
}
把上面的$ENABLED=false;改为$ENABLED=true;然后保存。之后我们刷新页面就可以看到如下页面

 

在这里我们可以创建配置文件,或者从一个配置文件创建一个新的配置文件,或者打开一个已有的配置文件进行编辑,这里我们就点击simple.conf文件做一个简单的weathermap配置。点击simple.conf可以看到下图
 
这里就是weathermap的编辑页面了,把上面那个几次菜单翻译下吧。
Change File可以会到前面的那个界面改变编辑的图形配置文件。
Add Node就是添加一个节点,点击之后鼠标会变成变成一个十字,在你想要放Node的地方点一下就可以创建一个Node。
Add Link 就是添加添加一条链接,可以把二个Node连接起来,点击Add Link后点击Node,再点击另外一个Node就可以把二个Node连接起来。
Position Legend是调整那个图列的位置,点击之后鼠标会编成十字,点击以下就可以移动到新的位置。
Postion Timestamp就是添加一个图片创建的时间啊什么信息的。
Map Style 可以调整这个图形的风格。比如图形名称、.图形大小、图形背景图片、输出图片目录、位置等
基本使用的也就这几个了。点击一个Node
 
这里可以改Node的大小,Node的名称和标签名称,Info URl是用户把鼠标放在这个Node后会出现一个流量图片,这个图片信息来自那里,Hover Graph URL 这里是当用户点击这个Node是会跳转到那个图,在这里可以选择点击Pick From Cacti,从cacti中选取,Icon Filename是图标的图像,这里可以有很多比如Router、Host、firewall。当然也可以自己添加,在weathermap的images里,设置好有点击Submit就可以提交更改了.
我们在设置以下Link,点击Link的那条线
 
 
 
Maximum Bandwidth Into这里是设置这条Link的最大带宽,这里根据你自己的具体配置设置了,这里端口是1G的端口,出口带宽是300MB因此我设置为300MB,Maximum Bandwidth out 是出去的最大流量带宽,可以根据自己的具体情况设置。Data source是流量从那里获取,这里可以引用mrtg的流量也可以点击Pick form Cacti从cacti里获取,Info URl是用户把鼠标放在这个Node后会出现一个流量图片,这个图片信息来自那里,Hover Graph URL 这里是当用户点击这个Node是会跳转到那个图,这个如果选择从cacti获取会自动取得。从mrtg要自己设置下。别的默认就成。这样我们就我完成了对一张拓扑图的编辑。如下就是我设计的weathermap图像
 
 

注意问题

1,中文显示,我们可以在配置文件里指定中中文字体的路径
1
2
vi /var/www/html/plugins/weathermap/configs/simple.conf
FONTDEFINE 100 /var/www/html/plugins/weathermap/msyh.ttf 10
msyh.ttf是中文字体的名字.需要用户自己加进去,指定路径,后面10字体是大小
2.每次对图形进行调整后,都是自动保存的,不用保存(也没有那个选项!嘿嘿),要在weathermap里看到修改后的效果要等到下次cacti采集器采集后才会绘图。
<div
>3.cacti的日志里可能会显示
WEATHERMAP: Poller[0] [Map 1] simple.conf: About to write image file. If this is the last message in your log, increase memory_limit in php.ini [WMPOLL01]
等信息,不过我修改php.ini里的设置也不起作用,不用管它!
4.可以在cacti的里进行设置,如图,一般默认就成
 

二.weathermap独立的使用。

通过在catci里的设置,大家会weathermap已经有了一个认识了,其实它就是用过一个配置文件,绘图,引用cacti或者mrtg的流量和图形就成了
 

1.安装基本环境

1
2
3
4
5
6
7
8
9
yum install httpd php php-gd  php-pear rrdtool -y
servie http start
chkconfig http on
service crond start
chkconfig crond on
wget http://www.network-weathermap.com/files/php-weathermap-0.97a.zip
unzip php-weathermap-0.97a.zip
mv weathermap/ /var/www/html/
chown -R apache:apache /var/www/html/weathermap/configs/

2.配置weathermap

 

我们要配置我们的图形配置文件
 
先编辑editor.php
1
vi /var/www/html/weathermap/editor.php
把里面的$ENABLED=false;改为$ENABLED=true;$ignore_cacti=False;改为$ignore_cacti=True;然后保存。
之后我们打开http://xxx.xxx.xxx.xxx/weathermap/editor.php
就可以像在cacti里一样设计自己的weathermap图形了,

 

特别注意:

 

1.在这里ICO的路径要选择绝对路径,不让路径会有错误,导致不能出图。
2.eidtor.php里可以设置拓扑图输出的路径Image的路径直接写名称,不用写路径,Html的路径路径要写绝对路径。
3.在weathermap目录里有个weathermap文件要设置rrdtools的路径。$rrdtool=”/usr/bin/rrdtool”;
关于配置文件的我们可以weathermap官网找到
weathermap官网的设置:http://www.network-weathermap.com/manual/latest/pages/config-reference.html 具体的参数这里都有
这里还有一个配置文件的范本http://www.network-weathermap.com/manual/latest/pages/main.html#example
这个是做好的图形;http://www.network-weathermap.com/manual/latest/example/example.html

 

3.生成图形

 

设置好图形配置文件后我们就要生成图形了,在cacti里这个是通过cacti的采集器实现的,在单独安装weathermap的后,需要利用系统的计划任务来实现
我们先执行一次
1
/usr/bin/php /var/www/html/weathermap/weathermap --config /var/www/html/weathermap/configs/simple.conf --image-uri ../weathermap/test.png
就可以在/下生成一个test.png图片,然后我们编辑
1
vi /etc/crontab
添加如下
1
*/5 * * * * root /usr/bin/php /var/www/html/weathermap/weathermap --config /var/www/html/weathermap/configs/simple.conf --image-uri ../weathermap/test.png
然后我们要做个硬链接不让png图片的路径会有错误
1
ln /test.png /var/www/html/weathermap/test.png
至此我们的weathermap已经做好我们可以打开http://xxx.xxx.xxx.xxx/weathermap/index.html查看拓扑图。
我最终的拓扑图

 

总结:

 

1.weathermap的用法就说到这里,基本就是这二种了,还有的是自己做一个html,再嵌套一个weathermap的页面就像刚开始给大家说的那个中国科大的,就是通过网页的嵌套做到的,嵌套了mrtg,weathermap的页面。
2.在单独使用weathermap时要特别注意路径问题,不出图形很有可能是路径问题,这个问题我也纠结了很久。

3.最重要的一点,就是关于weathermap的安全性问题,其实在它的官网也说明了。

地址:http://www.network-weathermap.com/manual/latest/pages/install-cacti-editor.html

 

When you are happy that the world can’t edit your maps, then enable the editor. This is done by editing the top of editor.php and changing $ENABLED=false; to $ENABLED=true;

You should now be able to go to http://your.server/cacti/plugins/weathermap/editor.php in a browser, and get a welcome page that offers to load or create a config file. That’s it. All done. Please see the editor manual page for more about using the editor!

You can also edit an existing map from the Cacti web interface, by choosing Manage..Weathermaps and then clicking on the name of a config file in the list of active maps. The editor will open with that map loaded.

Important Security Note: The editor allows anyone who can access editor.php to change the configuration files for your network weathermaps. There is no authentication built-in for editing, even with the Cacti Plugin. This is why the configuration file doesn’t exist by default – the editor won’t work until you choose to make it work. It’s recommended that you either:

  • change the ownership of configuration files so that the editor can’t write to them once they are complete, or
  • use your webserver’s authentication and access control facilities to limit who can access the editor.php URL. On apache, this can be done using the FilesMatch directive and mod_access.
可以看到在默认情况下editor.php这个是没有做验证的,就是意味每个人都可以编辑你的weathermap图形配置文件!!!!发现很多使用weathermap都没做限制,有些还是直接到公网的,再次特别提醒,一定要做一个验证!
下面我提供一种方法。
修改httpd.conf配置文件
1
vi /etc/httpd/conf/httpd.conf
在文件最后添加
1
2
3
4
5
6
7
<Directory /var/www/html/weathermap>
   <Files editor.php>
            Order Deny,Allow
            Deny from all
            Allow from 127.0.0.1
        </Files>
</Directory>
 然后保存,这个路劲是weathermap的路径.这样就可以限制别人访问editor.php的访问.设置好后重启apache,再访问那个页面就会出现这个页面
当然也可以做一个基于.htaccess的验证。
 
本文内容都是本人自己理解,如有错误之处,请大牛指正啊,不胜感谢啊!
 
 

   Nagios是监控服务器的状态很强大,并且报警功能也不错,不过就是缺少直观的表示,在cacti的插件里有一个插件NPC,通过NDO可以把Nagios里的数据展示在NPC标签里,很直观的就可以看到各种信息如图:

图2

 

 

下面说一下我本次的安装环境;

1.软件环境

OS:CentOS6.2 i386(最小化安装,只安装开ssh-server)

cacti-0.8.7i-PIA-3.1

nagios-3.2.3-3.el6.rf.i686

ndoutils-1.4-0.beta8.1.el6.rf.i686  (nagios的数据库支持)

settings-v0.71-1 (cacti 插件)

npc-2.4     ( nagios plugin for cacti ,cacti插件)

2.环境支持

http mysql mysql-devel( ndoutils需要它的支持)php php-devel rrdtoolnet-snmp libtool

注:有人说要安装php-json,经过测试在CentOS5.5里是要安装的,在CentOS6里,这个包已经在php-common里了,所以在安装php的时候就一起安装了

3.安装cacti

A.关闭SElinux

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
vi /etc/sysconfig/selinux
# This file controls the state of SELinux on the system.
 
# SELINUX= can take one of these three values:
 
#       enforcing - SELinux security policy is enforced.
 
#       permissive - SELinux prints warnings instead of enforcing.
 
#       disabled - SELinux is fully disabled.
 
SELINUX=enforcing
 
# SELINUXTYPE= type of policy in use. Possible values are:
 
#       targeted - Only targeted network daemons are protected.
 
#       strict - Full SELinux protection.
 
SELINUXTYPE=targeted


把SELINUX=enforcing改为SELINUX=disabled并保存!在这个时候SElinux还在运行关闭

1
setenforce 0

B.防火墙

一般我都是把防火墙直接关掉省的好多事情(生产环境不建议这么搞啊!嘿嘿!)

1
2
3
4
/etc/init.d/iptables stop
/etc/init.d/ip6tables stop
chkconfig iptables off
chkconfig ip6tables off

C.由于一些包在官方的库中没有,因此我们要建立dag.repo,定义非官方库

1
2
3
4
5
6
7
vi /etc/yum.repos.d/dag.repo
[dag]
 
name=Dag RPM Repository for Red Hat Enterprise Linux
baseurl=http://apt.sw.be/redhat/el$releasever/en/$basearch/dag
gpgcheck=1
enabled=1

然后再导入非官方库的GPG:

1
 rpm --import http://dag.wieers.com/rpm/packages/RPM-GPG-KEY.dag.txt

安装cacti需要的环境包

1
2
3
yum install -y httpd mysql mysql-server  php php-mysql php-devel net-snmp net-snmp-utils
yum install -y zlib libpng freetype libjpeg fontconfig gd libxml2 patch wget
yum install -y rrdtool

下载cacti-0.8.7i-PIA-3.1.tar.gz(这个是整合了cacti 0.8.7和 cacti-plugin-arch3.1的)并解压

1
2
3
4
5
6
7
8
9
10
11
cd /var/www/html/
yum install wget -y
wget http://www.cacti.net/downloads/cacti-0.8.7i-PIA-3.1.tar.gz
tar zxvf cacti-0.8.7i-PIA-3.1.tar.gz
wget http://www.cacti.net/downloads/patches/0.8.7i/settings_checkbox.patch
cd cacti-0.8.7i-PIA-3.1
patch -p1 -N < ../settings_checkbox.patch
cd ..
mv -f cacti-0.8.7i-PIA-3.1/* /var/www/html/
rm -rf cacti-0.8.7i-PIA-3.1
chown -R apache:apache /var/www/html/

D.为cacti创建数据库和用户

1
2
3
service mysqld start
/usr/bin/mysqladmin --user=root create cacti
mysql -e "GRANT ALL ON cacti.* TO cactiuser@localhost IDENTIFIED BY 'cactifans.org'"

我们再导入cacti的数据库

1
mysql -ucactiuser -pcactifans.org cacti < /var/www/html/cacti.sql

修改cacti的配置文件并保存

1
2
3
4
5
6
7
8
9
vi /var/www/html/include/config.php
 
/* make sure these values refect your actual database/host/user/password */
$database_type = "mysql";
$database_default = "cacti";
$database_hostname = "localhost";
$database_username = "cactiuser";
$database_password = "cactifans.org";
$database_port = "3306";

设置crontab定时任务
由于我们是最小系统安装没有安装定时任务,因此我们首先安装

1
yum install vixie-cron

然后我们添加定时任务

1
echo '*/5 * * * * root /usr/bin/php /var/www/html/poller.php' >> /etc/crontab

设置服务开机自启动,重启服务

1
2
3
4
5
6
7
8
chkconfig snmpd on
chkconfig httpd on
chkconfig mysqld on
chkconfig crond on
service httpd restart
service snmpd restart
service mysqld restart
service crond restart

E.WEB页完成安装
浏览http://xxx.xxx.xxx.xxx/index.php
就可以出再Cacti Installation Guide的页面了。NEXT–NEXT–FINISH。
用户名和密码为:admin/admin,之后输入新的密码,就完成了最基本的安装。
F.由于我们安装的这个版本已经在整合了cacti-plugin-3.1,所以我们只要在cacti里启用就成了,点console–User Management–admin

可以看到Plugin Management ,选中它点save就可以启用cacti-plugin

3.安装ngios

nagios我通过yum进行安装

1
yum install nagios nagios-plugin nagios-nrpe

这样就把ngios安装好了,安装好之后有几个地方需要配置一下,

A.设置nagios的访问用户及密码,默认用户为nagiosadmin

1
htpasswd -c /etc/nagios/htpasswd.users nagiosadmin

如果你设置的用户不是nagios还需要修改cgi.cfg(yum 安装会将nagios的配置文件放在/etc/nagios下)

1
2
3
4
5
6
7
authorized_for_system_information=nagiosadmin
authorized_for_configuration_information=nagiosadmin
authorized_for_system_commands=nagiosadmin
authorized_for_all_services=nagiosadmin
authorized_for_all_hosts=nagiosadmin
authorized_for_all_service_commands=nagiosadmin
authorized_for_all_host_commands=nagiosadmin

修改以上几个的nagiosadmin为自定义的用户名,否则你将没有权限看见服务器的信息。
nagios的安装到到此结束了,至于详细的配置网上也有很多例子。Nagios的配置无非就是主机,服务,报警的配置,可以写成简单的脚本来实现快速添加。

4.安装ndoutils

ndoutils我也是通过yum安装的,比较方便这个需要用到mysql的mysql-lib及mysql-inc,
因此需要安装mysql-devel(yum install mysql-devel)

1
yum install ndoutils -y

然后我们配置ndo2db.cfg (yum默认安装的路径为 /etc/nagios/ndo2db.cfg)

1
2
3
4
5
6
7
8
9
vi /etc/nagios/ndo2db.cfg
socket_type=tcp
socket_name=/var/nagios/rw/ndo.sock
db_name=cacti
db_prefix=npc_
db_user=cactiuser
db_pass=cactifans.org
debug_level=1
debug_file=/var/nagios/ndo2db.debug

用的数据库为cacti的数据库,别的根据你自己的具体设置就成了
配置ndomod.cfg  (yum默认安装的路径为 /etc/nagios/ndomod.cfg)

1
2
3
4
vi /etc/nagios/ndomod.cfg
output_type=tcpsocket
output=127.0.0.1
buffer_file=/var/nagios/ndomod.tmp

配置nagios.cfg   (yum安装的默认路径为 /etc/nagios/nagios.cfg)

1
2
3
4
5
check_external_commands=1
command_check_interval = -1
event_broker_options = -1
broker_module=/usr/libexec/ndomod-3x.o config_file=/etc/nagios/ndomod.cfg
process_performance_data=1

5.安装NPC

我在npc的官网没有下载到,下载的地址貌似已经不能用了,最后发现有svn的,于是我用svn check了一份(我已打包传到我的空间,点此下载

1
2
3
wget http://www.cactifans.org/plugins/npc.tar.gz
tar zxvf npc*.tar.gz -C /var/www/html/plugins
chown -R apache:apache /var/www/html/plugins/npc

然后进入cacti,点Console–Plugin Management–并启用npc插件就是了

接着在右侧栏目中选择settings,点选npc的标签

钩选Remote Commands

1
Nagios Command File Path:      /var/nagios/rw/nagios.cmd

这个文件启动nagios后会产生,根据实际的位置写,yum安装的在默认在 /var/nagios/rw/nagios.cmd

1
Nagios URL:]http://yourserver/nagios/

保存就可以了。

接着启动nagios ndoutils

1
2
3
4
5
service mysqld restart
service httpd restart
/usr/sbin/ndo2db-3x -c /etc/nagios/ndo2db.cfg
service nagios start
chkconfig nagios on

安装好之后在npc里只看到nagios status是on 别的主机信息却是没有查看日志发现有如下信息

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
tail -100 /var/log/messages
 
Feb 24 12:02:37 localhost ndo2db-3x: Error: mysql_query() failed for 'INSERT INTO npc_servicestatus SET instance_id='1'
 
, service_object_id='5', status_update_time=FROM_UNIXTIME(1330055656), output='HTTP OK: HTTP/1\.1 200 OK - 1916 bytes i
 
n 0\.083 second response time', long_output='', perfdata='time=0\.083463s;;;0\.000000 size=1916B;;;0', current_state='0
 
', has_been_checked='1', should_be_scheduled='1', current_check_attempt='1', max_check_attempts='4', last_check=FROM_UN
 
IXTIME(1330055520), next_check=FROM_UNIXTIME(1330055820), check_type='0', last_state_change=FROM_UNIXTIME(1330011420),
 
last_hard_state_change=FROM_UNIXTIME(1330011420), last_hard_state='0', last_time_ok=FROM_UNIXTIME(1330055520), last_tim
 
e_warning=FROM_UNIXTIME(0), last_time_unknown=FROM_UNIXTIME(0), last_time_critical=FROM_UNIXTIME(1330011120), state_typ
 
e='1', last_notification=FROM_UNIXTIME(0), next_notification=FROM_UNIXTIME(0), no_more_notifications='0', notifications
 
_enabled='1', problem_has_been_acknowledged='0', acknowledgement_type='0', current_notification_number='0', passive_che
 
cks_enabled='1', active_checks_enabled='1', event_handler_enabled='1', flap_detection_enabled='1', is_flapping='0', per
 
cent_state_change='0.000000', latency='0.027000', execution_time='0.094000', scheduled_downtime_depth='0', failure_pred
 
iction_enabled='1', process_performance_data='1', obsess_over_service='1', modified_service_attributes='1', event_handl
 
er='', check_command='check_http', normal_check_interval='5.000000', retry_check_interval='1.000000', check_timeperiod_
 
object_id='2' ON DUPLICATE KEY UPDATE instance_id='1', service_object_id='5', status_update_time=FROM_UNIXTIME(13300556
 
56), output='HTTP OK: HTTP/1\.1 200 OK - 1916 bytes in 0\.083 second response time', long_output='', perfdata='time=0\.
 
083463s;;;0\.000000 size=1916B;;;0', current_state='0', has_been_checked='1', should_be_scheduled='1', current_check_at
 
tempt='1', max_check_attempts='4', last_check=FROM_UNIXTIME(1330055520), next_check=FROM_UNIXTIME(1330055820), check_ty
 
pe='0', last_state_change=FROM_

很多类似的错误,最后在cacti的论坛里找到了,是缺少一个表因此进入mysql执行如下语句

1
2
3
4
5
6
7
8
9
10
11
mysql -ucactiuser -pcactifans.org
use cacti;
ALTER TABLE `npc_hostchecks` ADD COLUMN `long_output` varchar(8192) NOT NULL default '' AFTER `output`;
ALTER TABLE `npc_hoststatus` ADD COLUMN `long_output` varchar(8192) NOT NULL default '' AFTER `output`;
ALTER TABLE `npc_servicechecks` ADD COLUMN `long_output` varchar(8192) NOT NULL default '' AFTER `output`;
ALTER TABLE `npc_servicestatus` ADD COLUMN `long_output` varchar(8192) NOT NULL default '' AFTER `output`;
ALTER TABLE `npc_statehistory` ADD COLUMN `long_output` varchar(8192) NOT NULL default '' AFTER `output`;
ALTER TABLE `npc_eventhandlers` ADD COLUMN `long_output` varchar(8192) NOT NULL default '' AFTER `output`;
ALTER TABLE `npc_systemcommands` ADD COLUMN `long_output` varchar(8192) NOT NULL default '' AFTER `output`;
ALTER TABLE `npc_notifications` ADD COLUMN `long_output` varchar(8192) NOT NULL default '' AFTER `output`;
exit;

这样操作之后刷新一次就可以了,现在已经正常了

 

 
 
 
 
 

cacti中syslog插件,是通过rsyslog或syslog-ng与mysql的交互,将日志存放到mysql数据库中,cacti中的syslog插件从mysql中检索查看日志数据。因此,首先要配置一台rsyslog与mysql的日志中心服务器来接收客户机的日志;其次,配置cacti的syslog插件,通过该插件检索与查询mysql中的日志。可以收集来自linux、windows等服务器和交换机路由器的日志。做到集中和分类查看。

 
说下软件环境
os:centos6.2×86
cacti-0.8.7i-PIA-3.1.tar.gz
syslog-v1.22-2.tgz
rsyslog-4.6.2-12.el6.i686
 
关于cacti的安装我这里就不详细讲了,可以在我的另外二篇文章
 

 

Cacti 0.8.7g在CentOS5.5上的安装(1)

 

Cacti 0.8.7g在CentOS5.5上的安装(2)

由于我们此次安装的是集成PIA的cacti,因此不用单独安装PIA,安装好cacti以后要启用Plugin Management,然后我们下载syslog插件

 

1.设置接收日志

要想接收日志信息,并在cacti的syslog插件中显示接收到的日志,首先是接收日志,有二种办法:

1.使用syslog-ng,在centos5.5及以下系统上,系统默认有syslog,可以发送日志,但不能接受日志,因此要借助于syslog-ng,来接收发送过来的日志,并规范成一个模版,再通过自己写的脚本,插入到mysql数据库里

2.使用rsyslog,rsyslog是在centos6以上系统自带的,rsyslog不仅能接收日志,还可以发送日志,因此要是在centos6以上系统就不需要额外安装syslog-ng接收日志了,用自带的rsylog就可以接收日志,再用rsyslog-mysql就可以把接收到的日志写入mysql数据库

下面我分别说明:

A.使用rsyslog

我用的是centos6.2使用的是rsyslog,配置下就可以用来接受日志。在centos5.5版本自带syslog,可是要收集日志就还要安装syslog-ng用来接受日志。另外还要安装rsyslog-mysql来把接受到的日志插入到mysql数据库里 
1
yum install -y rsyslog rsyslog-mysql
下面我们要对rsyslog进行设置
1
vi /etc/rsyslog.conf
在文件最后添加
1
2
3
4
5
$ModLoad imudp.so
$UDPServerRun 514
$ModLoad ommysql
$template cacti_syslog,"INSERT INTO syslog_incoming(facility, priority, date, time, host, message) values (%syslogfacility%, %syslogpriority%, '%timereported:::date-mysql%', '%timereported:::date-mysql%', '%HOSTNAME%', '%msg%')", SQL
*.* &gt;localhost,syslog,cactiuser,cactifans.org;cacti_syslog

然后保存,重新启动rsyslog,并设置rsyslog开机启动

1
2
chkconfig rsyslog on
service rsyslog restart

B.使用syslog-ng

syslog-ng在默认的源里没有,可以编译安装,在这里我用yum安装syslog-ng
首先添加一个第三方源

1
2
rpm -Uvh http://dl.fedoraproject.org/pub/epel/5/i386/epel-release-5-4.noarch.rpm
yum install -y syslog-ng



安装好后我们配置syslog-ng

1
vi /etc/syslog-ng/syslog-ng.conf

在文件最后加入如下

1
2
3
4
5
6
7
8
9
10
11
12
13
14
source net {
 
udp();
};
 
destination d_mysql {
pipe("/tmp/mysql.pipe"
template("INSERT INTO syslog_incoming (host, facility, priority, date, time, message) VALUES ( '$HOST', '$FACILITY', '$PRIORITY', '$YEAR-$MONTH-$DAY', '$HOUR:$MIN:$SEC', '$MSG' );\n")
template-escape(yes)
);
};
 
log { source(net); destination(d_mysql); };
log { source(s_sys); destination(d_mysql); };

加入后保存,退出。

我们需要写一个脚本把syslog-ng接受到的数据写入到mysql数据库里
1
vi /sbin/syslogtomysql
内容如下
1
2
3
4
5
6
7
8
9
#!/bin/bash
if [ ! -e /tmp/mysql.pipe ]; then
        mkfifo /tmp/mysql.pipe
fi
 
while [ -e /tmp/mysql.pipe ]
do
        mysql -u cactiuser --password=cactifans.org syslog < /tmp/mysql.pipe
done
保存退出,我们赋予执行权限
1
chmod +x /sbin/syslogtomysql
上面的mysql -u syslog (syslog为用户名 密码为syslogpwd,数据库名为syslog)
我们执行
1
/sbin/syslogtomysql &
再启动syslog-ng
1
/etc/init.d/syslog-ng start
写好后我们把这个脚本写到开机启动里
1
vi /etc/rc.local
添加如下
1
/sbin/syslogtomysql &
设置syslog-ng开机启动
1
chkconfig syslog-ng on

至此syslog的设置完成

syslog-ng和rsyslog的设置就说到这里,基本都是差不多,不过rsyslog好设置一点不用独立写脚本就成。在centos6以上版本中也可以用syslog-ng来接收日志。以下的安装步骤就一样了。

 

2.配置syslog的数据库

 
1
2
3
mysql -uroot -p
create database syslog;
GRANT ALL ON syslog.* TO cactiuser@localhost IDENTIFIED BY 'cactifans.org; quit;
设置的数据库名:syslog 用户名:cactiuser 密码:cactifans.org 可以自行设定
 

3.安装syslog插件

 
1
2
3
wget http://docs.cacti.net/_media/plugin:syslog-v1.22-2.tgz -O syslog.tgz
tar zxvf syslog*.tgz -C /var/www/html/plugins
chown -R apache:apache /var/www/html/plugins/syslog
接下来我们进行一下配置
1
vi /var/www/html/plugins/syslog/config.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
......
global $config, $database_type, $database_default, $database_hostname;
global $database_username, $database_password, $database_port;
 
/* revert if you dont use the Cacti database */
$use_cacti_db = false;
 
if (!$use_cacti_db) {
        $syslogdb_type     = 'mysql';
        $syslogdb_default  = 'syslog';
        $syslogdb_hostname = 'localhost';
        $syslogdb_username = 'cactiuser';
        $syslogdb_password = 'cactifans.org';
        $syslogdb_port     = 3306;
         }else{
        $syslogdb_type     = $database_type;
        $syslogdb_default  = $database_default;
       $syslogdb_hostname = $database_hostname;
       $syslogdb_username = $database_username;
       $syslogdb_password = $database_password;
       $syslogdb_port     = $database_port;
}
.......
可以看到以上设置$use_cacti_db = false;这个是设置syslog是否要使用cacti的数据库,我在这里不使用cacti的数据,因为syslog往往比较多,日志比较多,为了便于备份和使用,还是选择用一个独立的数据库。因此要在下面设置连接数据库的用户名,密码,数据库名等。设置好后我们打开cacti,点console——Plugin Management,可以看到syslog还没有被启用
 
我们点syslog前面的那个先下箭头的小原点,会出现如下图
 

 

这里是对syslog数据的一些设置第分别为Database Storage Engine(数据库存储引擎)、Database Architecutre(数据库架构)这二项在一般默认,如果你的mysql数据库为5.1.6后者以上可以选择InnoDB Storage 和Partitioned Table,可以提高syslog的性能最后一项是Retention Policy(保留策略)就是要在syslog存储多长的时间,这个可以根据自己的需求设定,最后我们点install
 

就可以看到syslog已经安装,但是还没有启用,我们点那个绿色箭头就可以启用syslog

启用后我们可以看到syslog了

 

4.被监控端设置

 
A.Linux服务器设置
 
如果系统用的是syslog或者sysklog可以添加如下到/etc/syslog.conf(具体位置可能有所不同)
1
*.*     @192.168.0.111
 @后面为你的cacti服务器IP地址
 设置完毕后重启syslog或者sysklog服务,并在防火墙上允许upd 514端口
 
 如果用的是rsyslog可以在rsylog的配置文件里添加如下(配置文件一般为rsyslog.conf)
1
 *.*       @@192.168.0.111:514
 @@后面为你的cacti服务器IP地址一般端口为514
 
设置完毕后重启rsyslog服务,并在防火墙上允许upd 514端口
 
通过以上设置就可以把服务器的所有日志发送到cacti服务器
 
B.网络设备
1
logging 192.168.0.111
在设备上指定logging 为cacti的服务器就成了。(设备不通设置方法可能有所不同,可以参考设备说明书)
 
网络设备包括路由器,防火墙交换机。这样就可以在cacti里看到接受到的日志
 
效果图
 
 
syslog可以接受到防火墙,路由器,交换机,服务器的日志,并自动分为7个等级,并用不通的颜色表示,看起来直观,也做到的日志的集中收集与查看.另外还可以在cacti里对的setting里对syslog插件进行一些设置。
本人菜鸟一个,如有错误之处,欢迎大家指正.
 
 
 
posted @ 2012-08-23 15:08  陳聽溪  阅读(867)  评论(0)    收藏  举报