Cacti搭建完成以后,出现无法生成图片的方式,观察cacti.log正常执行poller.php脚本生产数据,查看
查看apache的error日志,一直出现如下报错:
ERROR: opening '*.rrd': No such file or directory
很明显是没有在rra下创建文件图片数据文件,但是rra的权限已经给到777了啊,对于这类头疼的问题只能一点点的试
检查是否运行正常!
插件的错误访问http://forums.cacti.net网站寻找解决方式
安装Nagios
下载地址:
http://sourceforge.jp/projects/sfnet_nagios/releases/
最新nagios-plugin地址:
http://www.nagios.org/download/plugins/
nrpe下载地址:
wget http://sourceforge.net/projects/nagios/files/nrpe-2.x/nrpe-2.9/nrpe-2.9.tar.gz
目前能获取的最新版本:
nagios-4.0.8.tar.gz
nagios-plugins-2.0.3.tar.gz
nrpe-2.9.tar.gz
tar zxf nagios-4.0.8.tar.gz
./configure --with-nagios-user=nagios \
--with-nagios-group=nagios \
--with-command-user=nagios \
--with-command-group=nagios \
--with-httpd-conf=/usr/local/apache2/conf
make all make install
- This installs the main program, CGIs, and HTML files
make install-init
- This installs the init script in /etc/rc.d/init.d
make install-commandmode
- This installs and configures permissions on the
directory for holding the external command file
make install-config
- This installs *SAMPLE* config files in /usr/local/nagios/etc
You'll have to modify these sample files before you can
use Nagios. Read the HTML documentation for more info
on doing this. Pay particular attention to the docs on
object configuration files, as they determine what/how
things get monitored!
make install-webconf
- This installs the Apache config file for the Nagios
web interface
make install-exfoliation
- This installs the Exfoliation theme for the Nagios
web interface
make install-classicui
- This installs the classic theme for the Nagios
web interfacetar zxf nagios-plugins-2.0.3.tar.gz
./configure --with-nagios-user=nagios --with-nagios-group=root --enable-redhat-pthread-workaround
make && make install./configure --with-nrpe-user=nagios \
--with-nrpe-group=nagios \
--with-nagios-user=nagios \
--with-nagios-group=nagios \
--enable-command-args
General Options:
-------------------------
NRPE port: 5666 #默认端口为5666
make all
make install-plugin
make install-daemon
make install-daemon-config
make install-xinetdScriptAlias /nagios/cgi-bin "/usr/local/nagios/sbin"
Options ExecCGI
AllowOverride None
Order allow,deny
Allow from all
AuthName "Nagios Access"
AuthType Basic
AuthUserFile /usr/local/nagios/etc/htpasswd.users
Require valid-user
Alias /nagios "/usr/local/nagios/share"
Options None
AllowOverride None
Order allow,deny
Allow from all
AuthName "Nagios Access"
AuthType Basic
AuthUserFile /usr/local/nagios/etc/htpasswd.users
Require valid-user
Alias /pub/images "/usr/local/nagios/share/docs/images"
Options None
AllowOverride None
Order allow,deny
Allow from all
AuthName "Nagios Access"
AuthType Basic
AuthUserFile /usr/local/nagios/etc/htpasswd.users
Require valid-user
在http的配置文件中添加上面的内容后,通过http的秘钥命令在nagios配置目录中生产秘钥文件。
htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin 修改NRPE配置
vi /usr/local/nagios/etc/nrpe.cfg
allowed_hosts=10.x.0.0/24
vi /etc/xinetd.d/nrpe
service nrpe
{
flags = REUSE
socket_type = stream
port = 5666
wait = no
user = nagios
group = nagios
server = /usr/local/nagios/bin/nrpe
server_args = -c /usr/local/nagios/etc/nrpe.cfg --inetd
log_on_failure += USERID
disable = no
only_from = 127.0.0.1 10.28.7.127
}
vi /etc/services
nrpe 5666/tcp # NRPE
service xinetd restart
netstat -anltp | grep 5666
/usr/local/nagios/libexec/check_nrpe -H 10.x.x.127 #测试
NRPE v2.15 在启动nagios之后发现部分监控报警没启动,启动时发现如下报错:
Error: Could not open command file '/usr/local/nagios/var/rw/nagios.cmd' for update!
在nagios.cfg中对该命令进行解释,参考了网上的解决方式,发现修改命令权限为777时,无报错,判断一定是权限的问题。但此方法仅临时解决问题,当nagios重启后,该命令重新创建,问题依然存在。看到解释中提到 “It is also where the command CGI will write commands that are submitted by users”,觉得应该是apache的用户需要有对该文件具有写的权限,因此修改apache的所属可选组为nagios,问题彻底解决。
usermod -G apache,nagios nagios 关于nagios的配置内容,需要另开篇详述。这里就不在说明
双剑合璧Nagios+Cacti
Cacti通过npc(Nagios plugin for Cacti)插件将Nagios集成在一起。
wget http://prdownloads.sourceforge.net/sourceforge/nagios/ndoutils-2.0.0.tar.gz
tar xvf ndoutils-2.0.0.tar.gz
./configure --prefix=/usr/local/nagios \
--mandir=/usr/local/share/man \
--enable-mysql \
--disable-pgsql \
--with-ndo2db-user=nagios \
--with-ndo2db-group=nagios \
--with-mysql
这里需要特别注意的是,仔细观察编译内容,当出现如下情况时说明mysql的库文件没有找到,虽然可以正常安装该软件,但启动时最终会导致"Support for the specified database server is either not yet supported, or was not found on your system."这样的错误信息:
*** MySQL library could not be located... **************************
You chose to compile NDOutils with MySQL support, but I was unable to
locate the MySQL library on your system. If the library is
installed, use the --with-mysql-lib argument to specify the
location of the MySQL library.
installed, use the --with-mysql=DIR argument to specify the
location of the MySQL library, We assume mysql_config is in DIR/dir
NOTE: After you install the necessary libraries on your system:
1. Make sure /etc/ld.so.conf has an entry for the directory in
which the MySQL libraries are installed.
2. Run 'ldconfig' to update the run-time linker options.
3. Run 'make devclean' in the NDBXT distribution to clean out
any old references to your previous compile.
4. Rerun the configure script.
TIP: Try the following....
./configure --with-mysql=/usr/lib/mysql
********************************************************************
如果出现如下报错信息:
In file included from io.c:11:
../include/config.h:261:25: error: mysql/mysql.h: No such file or directory
../include/config.h:262:26: error: mysql/errmsg.h: No such file or directory
修改include/config.h中第261行的内容去掉mysql/,这是因为生产的编译文件路径指定错误。
make && make install
cd config
cp ndo2db.cfg-sample /usr/local/nagios/etc/ndo2db.cfg
cp ndomod.cfg-sample /usr/local/nagios/etc/ndomod.cfg
vi /usr/local/nagios/etc/ndo2db.cfg
socket_name=/usr/local/nagios/var/ndo.sock
db_name=cactidb
db_prefix=npc_
db_user=cacti
db_pass=cacti
debug_level=1
debug_file=/usr/local/nagios/var/ndo2db.debug
vi /usr/local/nagios/etc/nagios.cfg
broker_module=/usr/local/nagios/bin/ndomod.o config_file=/usr/local/nagios/etc/ndomod.cfg 到这步需要做个小改动,因为ndoutils的数据库脚本中定义的表名为nagios_,而配置文件中定义为npc_,需要手动改一下脚本nstalldb,upgradedb及mysql.sql的内容将nagios替换为npc。替换的方式用vi在command模式下:
%s/nagios_/npc_/ 除此之外还有perl的相关包也需要安装,主要是DBI,Data::ShowTables,DBD::mysql,一般通过perl的CPAN项目(类似YUM)安装。涉及的相关包如lynx,ncftp,ftp
cpan源地址使用
http://mirrors.163.com/cpan/
CPAN> o conf urllist push http://mirrors.163.com/cpan/
CPAN> o conf prerequisites_policy follow
CPAN> o conf commit
CPAN> install DBD::mysql 一切就绪后运行ndoutil的升级库脚本:
cd ndoutils-2.0.0/db
./installdb -u cacti -p cacti -h 10.x.x.127 -d cactidb #for a new installation
./upgradedb -u cacti -p cacti -h 10.x.x.127 -d cactidb #for an existing one
解压NPC移置cacti的plugins目录下修改cacti配置文件
vi /usr/local/apache/htdocs/cacti/include/plugins.php
$plugins[] = 'npc'; #第30行,$plugins = array();下方添加该语句(目前看该步骤非必要)
一切就绪开启ndoutils服务:
/usr/local/nagios/bin/ndo2db -c /usr/local/nagios/etc/ndo2db.cfg 查看一下nagios的日志记录
tail -100 /usr/local/nagios/var/nagios.log
ndomod: Successfully connected to data sink. 4160 queued items to flush. #出现如下提示表示ndo正常连接数据库,把nagios的数据写入到cactidb库中了。
Dec 13 00:55:37 021Y-SH-BKAP ndo2db: Error: max retries exceeded sending message to queue. Kernel queue parameters may neeed to be tuned. See README
ALTER TABLE `npc_hostchecks` MODIFY COLUMN `long_output` varchar(8192) NOT NULL default '' AFTER `output`;
ALTER TABLE `npc_hoststatus` MODIFY COLUMN `long_output` varchar(8192) NOT NULL default '' AFTER `output`;
ALTER TABLE `npc_servicechecks` MODIFY COLUMN `long_output` varchar(8192) NOT NULL default '' AFTER `output`;
ALTER TABLE `npc_servicestatus` MODIFY COLUMN `long_output` varchar(8192) NOT NULL default '' AFTER `output`;
ALTER TABLE `npc_statehistory` MODIFY COLUMN `long_output` varchar(8192) NOT NULL default '' AFTER `output`;
ALTER TABLE `npc_eventhandlers` MODIFY COLUMN `long_output` varchar(8192) NOT NULL default '' AFTER `output`;
ALTER TABLE `npc_systemcommands` MODIFY COLUMN `long_output` varchar(8192) NOT NULL default '' AFTER `output`;
ALTER TABLE `npc_notifications` MODIFY COLUMN `long_output` varchar(8192) NOT NULL default '' AFTER `output`;