监控系统是运维人员的一个重要工具,熟悉其的构建与应用必不可少。nagios与centreon的搭
配是开源软件最佳选择。现在将我的构建与应用过程记录如下。
一.环境预安装
1.获取主软件包
wget http://jaist.dl.sourceforge.net/project/nagios/nagios-3.x/nagios-3.5.0/nagios-3.5.0.tar.gzwget http://download.centreon.com/centreon/centreon-2.4.2.tar.gzwget http://nchc.dl.sourceforge.net/project/nagiosplug/nagiosplug/1.4.16/nagios-plugins-1.4.16.tar.gzwget http://nchc.dl.sourceforge.net/project/nagios/ndoutils-1.x/ndoutils-1.5.2/ndoutils-1.5.2.tar.gzwget http://svn.centreon.com/trunk/ndoutils-patch/ndoutils1.5.2_light.patchwget http://nchc.dl.sourceforge.net/project/nagios/nrpe-2.x/nrpe-2.14/nrpe-2.14.tar.gz |
2.安装第三方源
[root@localhost ~]# wget http://packages.sw.be/rpmforge-release/rpmforge-release-0.5.2-1.el6.rf.i686.rpm [root@localhost ~]#rpm -ivh rpmforge-release-0.5.2-1.el6.rf.i686.rpm |
如果不安装第三方源会导致相关软件包不能安装,进而导致主安装出现相关问题。
3.安装相关软件包
安装apache [root@localhost ~]# yum -y install httpd [root@localhost ~]# usermod -U apache [root@localhost ~]# service httpd start[root@localhost ~]# yum install mysql-devel openssl-devel mysql-server [root@localhost ~]# service mysqld start[root@localhost ~]# mysqladmin -u root password '123456'在/etc/my.conf中的[mysqld]加入 innodb_file_per_table=1 否则在web安装第七步时会有提示。 安装php [root@localhost ~]# yum -y install php php-mysql php-gd php-ldap php-xml php-mbstring[root@localhost ~]# yum -y install gd fontconfig-devel libjpeg-devel libpng-devel gd-devel perl-GDRRDTools [root@localhost ~]# yum -y install rrdtool perl-rrdtool安装perl [root@localhost ~]# yum -y install perl-Config-IniFiles perl-DBI perl-DBD-MySQL安装SNMP [root@localhost ~]# yum -y install perl-Crypt-DES perl-Digest-SHA1 perl-Digest-HMAC net-snmp-utils[root@localhost ~]# yum -y install perl-Socket6 perl-IO-Socket-INET6 net-snmp net-snmp-libs php-snmp dmidecode lm_sensors perl-Net-SNMP net-snmp-perl安装PEAR[root@localhost ~]# yum -y install php-pear[root@localhost ~]# pear channel-update pear.php.net[root@localhost ~]# pear install --force PEAR-1.9.1[root@localhost ~]# pear upgrade-all |
二. 主软件包安装
nagios主要监控系统与网络信息,同时监控远程与本地主机及相关服务,还提供信息异常功能
1.安装nagios
添加相关用户及组 [root@localhost ~]# useradd -m nagios [root@localhost ~]# passwd nagios更改用户 nagios 的密码 。新的 密码:无效的密码: 过于简单化/系统化无效的密码: 过于简单重新输入新的 密码:passwd: 所有的身份验证令牌已经成功更新。[root@localhost ~]# groupadd nagcmd[root@localhost ~]# usermod -G nagios,nagcmd nagios[root@localhost ~]# usermod -G nagios,nagcmd apache安装nagios [root@localhost monitor]# tar -zxvf nagios-3.5.0.tar.gz [root@localhost nagios]# ./configure --prefix=/usr/local/nagios --with-command-group=nagcmd --enable-nanosleep --enable-event-broker --enable-embedded-perl[root@localhost nagios]# make all[root@localhost nagios]# make install[root@localhost nagios]# make install-init[root@localhost nagios]# make install-commandmode[root@localhost nagios]# make install-config[root@localhost nagios]# /etc/init.d/nagios start |
nagios如果少了其插件,将什么也做不了,其功能主要通过插件来完成的。
2.nagios-pluigns安装
[root@localhost monitor]# tar -zxvf nagios-plugins-1.4.16.tar.gz [root@localhost nagios-plugins-1.4.16]# ./configure --with-nagios-user=nagios --with-nagios-group=nagios --with-openssl=/usr/bin/openssl --enable-perl-modules[root@localhost nagios-plugins-1.4.16]# make && make install |
3.ndoutils安装
ndoutils主要将相关数据存储到数据库,ndoutils非常重要。
[root@localhost ndoutils-1.5.2]# tar -zxvf ndoutils-1.5.2.tar.gz[root@localhost ndoutils-1.5.2]# patch -p1 -N < ndoutils1.5.2_light.patch[root@localhost ndoutils-1.5.2]# ./configure --prefix=/usr/local/nagios/ --enable-mysql --with-ndo2db-user=nagios --with-ndo2db-group=nagios[root@localhost ndoutils-1.5.2]# make && make install[root@localhost ndoutils-1.5.2]# cp daemon-init /etc/init.d/ndo2db[root@localhost ndoutils-1.5.2]# chmod 755 /etc/init.d/ndo2db[root@localhost ndoutils-1.5.2]# cp config/ndo2db.cfg-sample /usr/local/nagios/etc/ndo2db.cfg[root@localhost ndoutils-1.5.2]# /etc/init.d/ndoutils start |
4.centreon安装
centreon以web方式展现给用户,通过第三方软件实现对网络,应用程序,主机的监控。
注:如下安装过程只做参考,其不是第一次安装 ,与第一次安装可能有所不同,第一次安装时会更新相关模块。
文本安装
[root@localhost monitor]# tar -zxvf centreon-2.4.2.tar.gz[root@localhost centreon-2.4.2]# ./install.sh -i################################################################################ ## Centreon (www.centreon.com) ## Thanks for using Centreon ## ## v2.4.2 ## ## infos@centreon.com ## ## Make sure you have installed and configured ## sudo - sed - php - apache - rrdtool - mysql ## ################################################################################------------------------------------------------------------------------Checking all needed binaries------------------------------------------------------------------------rm OKcp OKmv OK/bin/chmod OK/bin/chown OKecho OKmore OKmkdir OKfind OK/bin/grep OK/bin/cat OK/bin/sed OK You will now read Centreon Licence. Press enter to continue.Do you accept GPL license ?[y/n], default to [n]:> y------------------------------------------------------------------------Please choose what you want to install------------------------------------------------------------------------Do you want to install : Centreon Web Front [y/n], default to [n]:> yDo you want to install : Centreon CentCore [y/n], default to [n]:> yDo you want to install : Centreon Nagios Plugins [y/n], default to [n]:> yDo you want to install : Centreon Snmp Traps process [y/n], default to [n]:> y------------------------------------------------------------------------ Start CentWeb Installation------------------------------------------------------------------------Where is your Centreon directory? default to [/usr/local/centreon]>Do you want me to create this directory ? [/usr/local/centreon] [y/n], default to [n]:> yPath /usr/local/centreon OKWhere is your Centreon log directory default to [/usr/local/centreon/log]>Do you want me to create this directory ? [/usr/local/centreon/log] [y/n], default to [n]:> yPath /usr/local/centreon/log OKWhere is your Centreon etc directory default to [/etc/centreon]> /usr/local/centreon/etcDo you want me to create this directory ? [/usr/local/centreon/etc] [y/n], default to [n]:> yPath /usr/local/centreon/etc OKWhere is your Centreon binaries directory default to [/usr/local/centreon/bin]>Do you want me to create this directory ? [/usr/local/centreon/bin] [y/n], default to [n]:> yPath /usr/local/centreon/bin OKWhere is your Centreon data informations directory default to [/usr/local/centreon/data]>Do you want me to create this directory ? [/usr/local/centreon/data] [y/n], default to [n]:> yPath /usr/local/centreon/data OKWhere is your Centreon generation_files directory? default to [/usr/local/centreon]> Path /usr/local/centreon OKWhere is your Centreon variable library directory? default to [/var/lib/centreon]> /usr/local/centreon/var/libDo you want me to create this directory ? [/usr/local/centreon/var/lib] [y/n], default to [n]:> yPath /usr/local/centreon/var/lib OKWhere is your CentPlugins Traps binary default to [/usr/local/centreon/bin]> Path /usr/local/centreon/bin OKWhere is the RRD perl module installed [RRDs.pm] default to [/usr/lib/perl5/RRDs.pm]> Path /usr/lib/perl5 OK/usr/bin/rrdtool OK/bin/mail OK/usr/bin/php OKWhere is PEAR [PEAR.php] default to [/usr/share/php/PEAR.php]> /usr/share/pear/PEAR.phpPath /usr/share/pear OK/usr/bin/perl OKFinding Apache user : apacheFinding Apache group : apacheWhat is the Centreon group ? [centreon] default to [centreon]>What is the Centreon user ? [centreon] default to [centreon]>What is the Monitoring engine user ? > nagiosWhat is the Broker user ? (optional) > nagiosWhat is the Monitoring engine log directory ? >/usr/local/nagios/var/Where is your monitoring plugins (libexec) directory ? default to [/usr/lib/nagios/plugins]> /usr/local/nagios/libexecPath /usr/local/nagios/libexec OKAdd group centreon to user apache OKAdd group centreon to user nagios OKAdd group nagios to user apache OKAdd group nagios to user centreon OK------------------------------------------------------------------------ Configure Sudo------------------------------------------------------------------------Where is sudo configuration file default to [/etc/sudoers]> /etc/sudoers OKWhat is the Monitoring engine init.d script ? >/etc/init.d/nagiosWhat is the Monitoring engine binary ? > /usr/local/nagios/bin/nagiosWhat is the Monitoring engine configuration directory ? > /usr/local/nagios/etc/Where is the configuration directory for broker module ? > /usr/local/nagios/etc/Where is the init script for broker module daemon ? > /etc/init.d/ndo2dbYour sudo has been configured previouslyDo you want me to reconfigure your sudo ? (WARNING) [y/n], default to [n]:> yConfiguring Sudo OK------------------------------------------------------------------------ Configure Apache server------------------------------------------------------------------------Finding Apache Centreon configuration file'/etc/httpd/conf.d/centreon.conf' : OKDo you want to update Centreon Apache sub configuration file ? [y/n], default to [n]:> yBackup Centreon Apache configuration completedCreate '/etc/httpd/conf.d/centreon.conf' OKConfiguring Apache OKDo you want to reload your Apache ? [y/n], default to [n]:> yReloading Apache service OKPreparing Centreon temporary filesChange right on /usr/local/centreon/log OKChange right on /usr/local/centreon/etc OKChange macros for insertBaseConf.sql OKChange macros for sql update files OKChange macros for php files OKChange right on /usr/local/nagios/etc OKAdd group nagios to user apache OKAdd group nagios to user nagios OKAdd group centreon to user nagios OKCopy CentWeb in system directoryInstall CentWeb (web front of centreon) OKChange right for install directoryChange right for install directory OKInstall libraries OKWrite right to Smarty Cache OKCopying libinstall OKChange macros for centreon.cron OKInstall Centreon cron.d file OKChange macros for centAcl.php OKChange macros for downtimeManager.php OKChange macros for eventReportBuilder.pl OKChange macros for dashboardBuilder.pl OKInstall cron directory OKChange right for eventReportBuilder.pl OKChange right for dashboardBuilder.pl OKChange macros for centreon.logrotate OKInstall Centreon logrotate.d file OKPrepare export-mysql-indexes OKInstall export-mysql-indexes OKPrepare import-mysql-indexes OKInstall import-mysql-indexes OKPrepare indexes schema OKInstall indexes schema OK------------------------------------------------------------------------ Pear Modules------------------------------------------------------------------------Check PEAR modulesPEAR 1.4.9 1.9.4 OKDB 1.7.6 1.7.14 OKDB_DataObject 1.8.4 1.11.2 OKDB_DataObject_FormBuilder 1.0.0RC4 1.0.2 OKMDB2 2.0.0 2.4.1 OKDate 1.4.6 1.4.7 OKHTML_Common 1.2.2 1.2.5 OKHTML_QuickForm 3.2.5 3.2.13 OKHTML_QuickForm_advmultiselect 1.1.0 1.5.1 OKHTML_Table 1.6.1 1.8.3 OKArchive_Tar 1.1 1.3.11 OKAuth_SASL 1.0.1 1.0.6 OKConsole_Getopt 1.2 1.3.1 OKNet_SMTP 1.2.8 1.6.1 OKNet_Socket 1.0.1 1.0.10 OKNet_Traceroute 0.21 0.21.3 OKNet_Ping 2.4.1 2.4.5 OKValidate 0.6.2 0.8.5 OKXML_RPC 1.4.5 1.5.5 OKSOAP 0.10.1 0.13.0 OKLog 1.9.11 1.12.7 OKArchive_Zip 0.1.2 0.1.2 OKAll PEAR modules OK------------------------------------------------------------------------ Centreon Post Install------------------------------------------------------------------------Create /usr/local/centreon/www/install/install.conf.php OKCreate /usr/local/centreon/etc/instCentWeb.conf OK------------------------------------------------------------------------ Start CentStorage Installation------------------------------------------------------------------------Where is your Centreon Run Dir directory? default to [/var/run/centreon]>/usr/local/centreon/var/runDo you want me to create this directory ? [/usr/local/centreon/var/run] [y/n], default to [n]:> yPath /usr/local/centreon/var/run OKWhere is your CentStorage binary directory default to [/usr/local/centreon/bin]> Path /usr/local/centreon/bin OKWhere is your CentStorage RRD directory default to [/var/lib/centreon]>/usr/local/centreon/var/libPath /usr/local/centreon/var/lib OKPreparing Centreon temporary files/tmp/centreon-setup exists, it will be moved...install www/install/createTablesCentstorage.sql OKCreating Centreon Directory '/usr/local/centreon/var/lib/stOKus'Creating Centreon Directory '/usr/local/centreon/var/lib/meOKics'Change macros for centstorage binary OKInstall CentStorage binary OKInstall library for centstorage OKChange right : /usr/local/centreon/var/run OKChange macros for centstorage init script OKDo you want me to install CentStorage init script ? [y/n], default to [n]:> yCentStorage init script installed OKDo you want me to install CentStorage run level ? [y/n], default to [n]:> yChange macros for logAnalyser OKInstall logAnalyser OKChange macros for logAnalyser-cbroker OKInstall logAnalyser-cbroker OKChange macros for nagiosPerfTrace OKInstall nagiosPerfTrace OKChange macros for purgeLogs OKInstall purgeLogs OKChange macros for purgeCentstorage OKInstall purgeCentstorage OKChange macros for centreonPurge.sh OKInstall centreonPurge.sh OKChange macros for centstorage.cron OKInstall CentStorage cron OKChange macros for centstorage.logrotate OKInstall Centreon Storage logrotate.d file OKCreate /usr/local/centreon/etc/instCentStorage.conf OK------------------------------------------------------------------------ Start CentCore Installation------------------------------------------------------------------------Where is your CentCore binary directory default to [/usr/local/centreon/bin]> Path /usr/local/centreon/bin OK/usr/bin/ssh OK/usr/bin/scp OKPreparing Centreon temporary files/tmp/centreon-setup exists, it will be moved...Change CentCore Macro OKCopy CentCore in binary directory OKChange right : /usr/local/centreon/var/run OKChange right : /usr/local/centreon/var/lib OKChange macros for centcore.logrotate OKInstall Centreon Core logrotate.d file OKReplace CentCore init script Macro OKDo you want me to install CentCore init script ?[y/n], default to [n]:> yCentCore init script installed OKDo you want me to install CentCore run level ? [y/n], default to [n]:> yCreate /usr/local/centreon/etc/instCentCore.conf OK------------------------------------------------------------------------ Start CentPlugins Installation------------------------------------------------------------------------Where is your CentPlugins lib directory default to [/var/lib/centreon/centplugins]> /usr/local/centreon/var/lib/centplugins/Do you want me to create this directory ? [/usr/local/centreon/var/lib/centplugins/] [y/n], default to [n]:> yPath /usr/local/centreon/var/lib/centplugins/ OKPreparing Centreon temporary files/tmp/centreon-setup exists, it will be moved...Change macros for CentPlugins OKInstalling the plugins OKChange right on centreon.conf OKCentPlugins is installed------------------------------------------------------------------------ Start CentPlugins Traps Installation------------------------------------------------------------------------Where is your SNMP configuration directory default to [/etc/snmp]> /etc/snmp OKWhere is your SNMPTT binaries directory default to [/usr/local/centreon/bin/]> /usr/local/centreon/bin/ OKFinding Apache user : apachePreparing Centreon temporary files/tmp/centreon-setup exists, it will be moved...Change macros for CentPluginsTraps OKChange macros for init scripts OKInstalling the plugins Trap binaries OKChange macros for snmptrapd.conf OKChange macros for snmptt.ini OKSNMPTT init script installed OKInstall : snmptrapd.conf OKInstall : snmp.conf OKInstall : snmptt.ini OKInstall : snmptt OKInstall : snmptthandler OKInstall : snmpttconvertmib OKCreate /usr/local/centreon/etc/instCentPlugins.conf OK################################################################################ ## Go to the URL : http://localhost/centreon/ ## to finish the setup ## ## Report bugs at http://forge.centreon.com ## ## Thanks for using Centreon. ## ----------------------- ## Contact : infos@centreon.com ## http://www.centreon.com ## ################################################################################ |
web安装
(1)centreon的欢迎界面
(2)检查依赖关系
(3)配置nagios信息
(4)配置ndoutils模块
(5)配置admin用户
(6)配置数据库信息
(7)安装
(8)安装完成
5.服务器端nrpe安装
nrpe是nagios组件,能够执行远程主机的本地检测脚本,监控运行状态。
[root@localhost monitor]# tar -zxvf nrpe-2.14.tar.gz[root@localhost nrpe-2.14]# ./configure[root@localhost nrpe-2.14]# make all && make install |
服务器端检测错误
[root@nodes01 nrpe-2.12]# /usr/local/nagios/libexec/check_nrpe -H 127.0.0.1CHECK_NRPE: Error - Could not complete SSL handshake |
在/usr/local/nagios/etc/nrpe.cfg加入
allowed_hosts=127.0.0.1,192.168.4.213 |
[root@nodes01 nrpe-2.12]# /usr/local/nagios/libexec/check_nrpe -H 127.0.0.1NRPE v2.12[root@nodes01 nrpe-2.12]# /usr/local/nagios/libexec/check_nrpe -H 192.168.4.213NRPE v2.12 |
三.后续登录错误
1.错误信息
2.日志信息
25/4/2013 18:36:01 - 25/4/2013 18:36:1 - DBI connect('database=centreon_storage;host=localhost:3306','centreon',...) failed: Access denied for user 'centreon'@'localhost' to database 'centreon_storage' at /usr/local/centreon/bin/logAnalyser line 596 |
3.解决方法
mysql> grant all on centreon.* to centreon@localhost identified by '123456';Query OK, 0 rows affected (0.07 sec) mysql> grant all on centreon_status.* to centreon@localhost identified by '123456'; Query OK, 0 rows affected (0.00 sec)mysql> grant all on centreon_storage.* to centreon@localhost identified by '123456'; Query OK, 0 rows affected (0.00 sec)mysql> flush privileges; Query OK, 0 rows affected (0.06 sec) |
成功页面如下
四.检查重新生成配置文件
(1)检查main.cfg的配置
(2)检查ndo2db.cfg的配置
(3)检查ndomod.cfg的配置
(4)生成nagios配置文件
web页面重启完成后,查看nagios相关日志
[root@localhost ~]# tail -f /usr/local/nagios/var/nagios.log | grep ndomod[1366898324] ndomod: Successfully connected to data sink. 122 queued items to flush.[1366898324] ndomod: Successfully flushed 122 queued items to data sink. |
如果有以上信息代表成功,因为ndoutils是nagios与centreon的纽带,必须保证其正常运行。
centreon的服务器端已经配置完成,对于其被监控主机上也安装nagios-plugins和nrpe软件包,这里就不再重复,centreon的应用配置及汉化后续再出。