开源中文网

您的位置: 首页 > Linux应用 > cacti > 正文

cacti整合nagios-cacti插件npc的使用

来源: cactifans  作者: 佚名

     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 rrdtool net-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;

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

 

Tags:插件
关于开源中文网 - 联系我们 - 广告服务 - 网站地图 - 版权声明