nagios配置全攻略
通过整合pnp4nagios,ndoutils,nconf提供了关于nagios的一套完整的配置方案
操作系统Centos5.5,目前最新版本的nagios3.3.1,装上之后界面变化了太难看,所以这里我还用3.2.3的版本来安装
首先把编译环境准备好,我们这里把开发库先都装上
yum groupinstall "Development Libraries" "Development Tools" "Legacy Software Development" "X Software Development" -y
#########################################################################
naigos安装配置:
安装需要的软件包
yum install mysql perl mysql-server perl-DBI perl-DBD-MySQL httpd gcc glibc glibc-common gd gd-devel ruby ruby-devel2 ruby-devel mysql-devel
yum install php53-* yum默认安装的是5.1版本的php,但是pnp4nagios-0.6.6需要5.2以上版本的php,我们这里就装5.3的
wget http://prdownloads.sourceforge.net/sourceforge/nagios/nagios-3.2.3.tar.gz
wget http://prdownloads.sourceforge.net/sourceforge/nagiosplug/nagios-plugins-1.4.15.tar.gz
useradd -m nagios
groupadd nagcmd
usermod -a -G nagcmd nagios
usermod -a -G apache nagios
tar zxf nagios-3.2.3.tar.gz
cd nagios-3.2.3
./configure --with-command-group=nagcmd
make all
make install
make install-init
make install-commandmode
make install-config
make install-webconf
htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin
输入密码并记住,因为这个同时也是网页访问nagios时要输入的密码。
chkconfig --add nagios
chkconfig nagios on
chkconfig httpd on
chkconfig mysqld on
tar nagios-plugins-1.4.15.tar.gz
cd nagios-plugins-1.4.15
./configure --with-nagios-user=nagios --with-nagios-group=nagios
make
make install
service nagios start
service httpd start
service mysqld start
使用http://localhost/nagios/来访问
##########################################################################
pnp4nagios的安装和配置
接下来我们来配置pnp4nagios,能够把nagios捕获到的数据绘制成图片
rrdtool依赖众多,这里我选择下载rrdtool的rpm包
rrdtool-perl-1.4.4-1.el5.wrl.i386.rpm rrdtool-devel-1.4.4-1.el5.wrl.i386.rpm rrdtool-1.4.4-1.el5.wrl.i386.rpm
rpm -ivh rrdtool-*
tar -xvf pnp4nagios-0.6.6.tar.gz
cd pnp4nagios-0.6.6
./configure --with-nagios-user=nagios --with-nagios-group=nagcmd
make all
make install
make install-webconf
make install-config
make isntall-init
make fullinstall
pnp4nagios官方提供了三种配置方法,我这里选取一种
vi /usr/local/nagios/etc/nagios.cfg
process_performance_data=1
#
# service performance data
#
service_perfdata_file=/usr/local/pnp4nagios/var/service-perfdata
service_perfdata_file_template=DATATYPE::SERVICEPERFDATA/tTIMET::$TIMET$/tHOSTNAME::$HOSTNAME$/tSERVICEDESC::$SERVICEDESC$/tSERVICEPERFDATA::$SERVICEPERFDATA$/tSERVICECHECKCOMMAND::$SERVICECHECKCOMMAND$/tHOSTSTATE::$HOSTSTATE$/tHOSTSTATETYPE::$HOSTSTATETYPE$/tSERVICESTATE::$SERVICESTATE$/tSERVICESTATETYPE::$SERVICESTATETYPE$
service_perfdata_file_mode=a
service_perfdata_file_processing_interval=15
service_perfdata_file_processing_command=process-service-perfdata-file
#
# host performance data starting with Nagios 3.0
#
host_perfdata_file=/usr/local/pnp4nagios/var/host-perfdata
host_perfdata_file_template=DATATYPE::HOSTPERFDATA/tTIMET::$TIMET$/tHOSTNAME::$HOSTNAME$/tHOSTPERFDATA::$HOSTPERFDATA$/tHOSTCHECKCOMMAND::$HOSTCHECKCOMMAND$/tHOSTSTATE::$HOSTSTATE$/tHOSTSTATETYPE::$HOSTSTATETYPE$
host_perfdata_file_mode=a
host_perfdata_file_processing_interval=15
host_perfdata_file_processing_command=process-host-perfdata-file
vi /usr/local/nagios/etc/objects/commands.cfg 修改最后两行为
define command{
command_name process-service-perfdata-file
command_line /usr/local/pnp4nagios/libexec/process_perfdata.pl --bulk=/usr/local/pnp4nagios/var/service-perfdata
}
define command{
command_name process-host-perfdata-file
command_line /usr/local/pnp4nagios/libexec/process_perfdata.pl --bulk=/usr/local/pnp4nagios/var/host-perfdata
}
cd /usr/local/pnp4nagios/share
mv install.php install.php.bak
访问测试 http://localhost/pnp4nagios
让nagios显示小太阳图标
在pnp4nagios的源码包下面执行
cp contrib/ssi/* /usr/local/nagios/share/ssi/
然后在服务或者主机定义里面添加action_url
define service{
use local-service ; Name of service template to use
host_name localhost
service_description PING
check_command check_ping!100.0,20%!500.0,60%
action_url /pnp4nagios/index.php/graph?host=$HOSTNAME$&srv=$SERVICEDESC$' class='tips' rel='/pnp4nagios/index.php/popup?host=$HOSTNAME$&srv=$SERVICEDESC$
}
define host{
use linux-server
host_name localhost
alias localhost
address 127.0.0.1
action_url /pnp4nagios/index.php/graph?host=$HOSTNAME$&srv=_HOST_' class='tips' rel='/pnp4nagios/index.php/popup?host=$HOSTNAME$&srv=_HOST_
}
效果如下:
###########################################################################
安装nconf实现nagios的图形化配置
tar -xvf nconf-1.2.6-0.tgz -C /var/www/html/
chown -R apache:apache /var/www/html/nconf
为nconf创建数据库
mysql -u root -p
create database nconf;
grant all privileges on 数据库名称.* to '用户名'@'localhost' identified by '密码' with grant option;
然后通过浏览器访问: http://localhost/nconf
根据提示进行安装 然后删除 INSTALL/ INSTALL.php UPDATE/ UPDATE.php重新刷新页面就可以使用了!
这里使用刚才建立的数据库
这里使用默认配置就好了
下面是安装完成后的界面
##############################################################################
安装配置ndoutils把nagios的数据导入mysql数据库
mysql -u root -p
mysql>CREATE DATABASE nagios;
mysql>GRANT ALL ON nagios.* TO nagios@localhost IDENTIFIED BY ‘nagios’ 授权nagios用户,密码为 Nagios
mysql>FLUSH PRIVILEGES;
wget http://prdownloads.sourceforge.net/sourceforge/nagios/ndoutils-1.4b9.tar.gz
wget http://svn.centreon.com/trunk/ndoutils-patch/ndoutils1.4b9_light.patch
tar -xvf ndoutils-1.4b9.tar.gz
cd ndoutils
patch -p1 -N < ../ndoutils1.4b9_light.patch
./configure --prefix=/usr/local/nagios/ --enable-mysql --disable-pgsql /
--with-ndo2db-user=nagios --with-ndo2db-group=nagios
make
cd db
./installdb ./installdb -u root -p 数据库密码 -d nagios
mysql -u root -p
mysql>USE nagios;
mysql>SHOW TABLES; 验证表已经生成
cd ndoutils-1.4b9
cp ./src/ndomod-3x.o /usr/local/nagios/bin/ndomod.o
cp ./src/ndo2db-3x /usr/local/nagios/bin/ndo2db
cp ./config/ndo2db.cfg-sample /usr/local/nagios/etc/ndo2db.cfg
cp ./config/ndomod.cfg-sample /usr/local/nagios/etc/ndomod.cfg
chmod 774 /usr/local/nagios/bin/ndo*
chown nagios:nagios /usr/local/nagios/bin/ndo*
chown nagios:nagios /usr/local/nagios/etc/ndo*
vi ndo2db.cfg
db_name=nagios
db_user=nagios
db_pass=nagios
vi /usr/local/nagios/etc/nagios.cfg
添加以下两行
broker_module=/usr/local/nagios/bin/ndomod.o config_file=/usr/local/nagios/etc/ndomod.cfg
修改
event_broker_options=-1 //我设置为1,测试也可以
cp ./daemon-init /etc/init.d/ndo2db
chmod +x /etc/init.d/ndo2db
chkconfig --add ndo2db
service nagios restart
service ndo2db start
tail -f /usr/log/nagios/var/nagios.log
作者“成长全记录”