本例在CentOS 6.5 64位系统测试
rpm -ivh http://pkgs.repoforge.org/rpmforge-release/rpmforge-release-0.5.3-1.el6.rf.x86_64.rpm yum update yum upgrade
关闭防火墙和SELINUX
chkconfig --level 35 iptables off vi /etc/selinux/config
将SELINUX=enforcing 修改为:SELINUX=disabled
然后重启系统
reboot
首先安装APACHE 也可根据情况安装NGINX
yum install httpd usermod -U apache
安装GD库
yum install gd fontconfig-devel libjpeg-devel libpng-devel gd-devel perl-GD
安装MySQL数据库
yum install openssl-devel perl-DBD-MySQL mysql-server mysql-devel
安装PHP和扩展
yum install php php-mysql php-gd php-ldap php-xml php-mbstring
安装Perl扩展
yum install perl-Config-IniFiles perl-DBI
安装RRDtool
yum install rrdtool perl-rrdtool
安装SNMP
yum install perl-Crypt-DES perl-Digest-SHA1 perl-Digest-HMAC net-snmp-utils yum install perl-Socket6 perl-IO-Socket-INET6 net-snmp yum install php-snmp dmidecode lm_sensors perl-Net-SNMP net-snmp-perl
安装开发库
yum groupinstall "Development Tools"
其他库
yum install fping glib2-devel
安装PEAR
yum install php-pear pear channel-update pear.php.net pear upgrade-all
现在我们下载所需用的的软件
wget http://jaist.dl.sourceforge.net/project/nagios/nagios-4.x/nagios-4.0.4/nagios-4.0.4.tar.gz wget http://jaist.dl.sourceforge.net/project/nagios/ndoutils-2.x/ndoutils-2.0.0/ndoutils-2.0.0.tar.gz wget http://nagios-plugins.org/download/nagios-plugins-2.0.tar.gz wget http://download.centreon.com/centreon/centreon-2.5.0.tar.gz wget http://downloads.sourceforge.net/project/nagios/nrpe-2.x/nrpe-2.15/nrpe-2.15.tar.gz
centreon-clapi-1.5.2 下载地址 http://download.centreon.com/index.php?id=4296
安装Nagios
[root@jk soft]# useradd nagios [root@jk soft]# groupadd nagcmd [root@jk soft]# usermod -G nagios,nagcmd nagios [root@jk soft]# tar xvzf nagios-4.0.4.tar.gz [root@jk soft]# cd nagios-4.0.4 [root@jk nagios-4.0.4]# ./configure --prefix=/usr/local/nagios --with-command-group=nagcmd --enable-nanosleep --enable-event-broker --enable-embedded-perl [root@jk nagios-4.0.4]# make all&&make install&&make install-init&&make install-commandmode&&make install-config&&make install-webconf
安装Nagios插件
[root@jk nagios-4.0.4]# cd .. [root@jk soft]# tar xvzf nagios-plugins-2.0.tar.gz [root@jk nagios-plugins-2.0]# ./configure --with-nagios-user=nagios --with-nagios-group=nagios --with-openssl=/usr/bin/openssl --enable-perl-modules [root@jk nagios-plugins-2.0]# make&&make install
如果出现类似如下错误:
Working in: /soft/nagios-plugins-2.0/perlmods/Test-Simple-0.98 Using Makefile.PL Can‘t locate ExtUtils/MakeMaker.pm in @INC (@INC contains: /soft/nagios-plugins-2.0/perlmods/Test-Simple- 0.98/blib/lib /soft/nagios-plugins-2.0/perlmods/Test-Simple-0.98/blib/arch /usr/local/lib64/perl5 /usr/local/share/perl5 /usr/lib64/perl5/vendor_perl /usr/share/perl5/vendor_perl /usr/lib64/perl5 /usr/share/perl5 .) at Makefile.PL line 6. BEGIN failed--compilation aborted at Makefile.PL line 6. make[3]: Entering directory `/soft/nagios-plugins-2.0/perlmods/Test-Simple-0.98‘ make[3]: *** No targets specified and no makefile found. Stop. make[3]: Leaving directory `/soft/nagios-plugins-2.0/perlmods/Test-Simple-0.98‘ Can‘t run make. Please rm -rf /soft/nagios-plugins-2.0/perlmods/Test-Simple-0.98 to remake from this point) at ../tools/build_perl_modules line 235. make[2]: *** [all-local] Error 2 make[2]: Leaving directory `/soft/nagios-plugins-2.0/perlmods‘ make[1]: *** [all-recursive] Error 1 make[1]: Leaving directory `/soft/nagios-plugins-2.0‘ make: *** [all] Error 2
这个是缺少Perl模块导致 安装
yum install perl-ExtUtils-MakeMaker
然后再次make&&make install
安装Nrpe
[root@jk nagios-plugins-2.0]# cd .. [root@jk soft]# tar xvzf nrpe-2.15.tar.gz [root@jk soft]# cd nrpe-2.15 [root@jk nrpe-2.15]# ./configure [root@jk nrpe-2.15]# make all&&make install-plugin&&make install-daemon&&make install-daemon-config
安装Ndoutils
[root@jk nrpe-2.15]# cd .. [root@jk soft]# tar xvzf ndoutils-2.0.0.tar.gz [root@jk soft]# cd ndoutils-2.0.0 [root@jk ndoutils-2.0.0]# ./configure --prefix=/usr/local/nagios/ --enable-mysql --with-ndo2db-user=nagios --with-ndo2db-group=nagios [root@jk ndoutils-2.0.0]# make&&make install [root@jk ndoutils-2.0.0]# cp ./config/ndo2db.cfg-sample /usr/local/nagios/etc/ndo2db.cfg [root@jk ndoutils-2.0.0]# cp ./config/ndomod.cfg-sample /usr/local/nagios/etc/ndomod.cfg [root@jk ndoutils-2.0.0]# cp daemon-init /etc/init.d/ndo2db
修改启动脚本killproc_ndo2db()和 stop)的内容 修改成以下内容:
[root@jk ndoutils-2.0.0]# vi /etc/init.d/ndo2db killproc_ndo2db () { kill `pidof ndo2db |cut -f1 -d " "` >/dev/null 2>&1 kill `pidof ndo2db |cut -f1 -d " "` >/dev/null 2>&1 } stop) echo "Stopping $servicename..." killproc_ndo2db ;; [root@jk ndoutils-2.0.0]# chmod +x /etc/init.d/ndo2db [root@jk ndoutils-2.0.0]# chkconfig --add ndo2db [root@jk ndoutils-2.0.0]# chkconfig --level 345 ndo2db on
安装Centreon
[root@jk ndoutils-2.0.0]# cd ../ [root@jk soft]# tar xvzf centreon-2.5.0.tar.gz [root@jk soft]# cd centreon-2.5.0 [root@jk centreon-2.5.0]# ./install.sh -i
------------------------------------------------------------------------ Checking all needed binaries ------------------------------------------------------------------------ rm OK cp OK mv OK /bin/chmod OK /bin/chown OK echo OK more OK mkdir OK find OK /bin/grep OK /bin/cat OK /bin/sed OK You will now read Centreon Licence. Press enter to continue. 安装回车和Q键 然后按Y 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]: > y Do you want to install : Centreon CentCore [y/n], default to [n]: > y Do you want to install : Centreon Nagios Plugins [y/n], default to [n]: > y Do 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]: > y Path /usr/local/centreon OK Where 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]: > y Path /usr/local/centreon/log OK Where is your Centreon etc directory default to [/etc/centreon] > Do you want me to create this directory ? [/etc/centreon] [y/n], default to [n]: > y Path /etc/centreon OK Where 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]: > y Path /usr/local/centreon/bin OK Where 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]: > y Path /usr/local/centreon/data OK Where is your Centreon variable library directory? default to [/var/lib/centreon] > Do you want me to create this directory ? [/var/lib/centreon] [y/n], default to [n]: > y Path /var/lib/centreon OK /usr/bin/rrdtool OK /bin/mail OK /usr/bin/php OK Where is PEAR [PEAR.php] default to [/usr/share/php/PEAR.php] > /usr/share/pear/PEAR.php Path /usr/share/pear OK /usr/bin/perl OK Finding Apache user : apache Finding Apache group : apache What is the Centreon group ? [centreon] default to [centreon] > Do you want me to create this group ? [centreon] [y/n], default to [n]: > y What is the Centreon user ? [centreon] default to [centreon] > Do you want me to create this user ? [centreon] [y/n], default to [n]: > y What is the Monitoring engine user ? > nagios What is the Broker user ? (optional) > nagios What is the Monitoring engine log directory ? > /usr/local/nagios/var/log Where is your monitoring plugins (libexec) directory ? default to [/usr/lib/nagios/plugins] > /usr/local/nagios/libexec Path /usr/local/nagios/libexec OK Add group centreon to user apache OK Add group centreon to user nagios OK Add group nagios to user apache OK Add group nagios to user centreon OK ------------------------------------------------------------------------ Configure Sudo ------------------------------------------------------------------------ Where is sudo configuration file default to [/etc/sudoers] > /etc/sudoers OK What is the Monitoring engine init.d script ? > /etc/init.d/nagios What is the Monitoring engine binary ? > /usr/local/nagios/bin/nagios What 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/ndo2db Your sudo is not configured Do you want me to configure your sudo ? (WARNING) [y/n], default to [n]: > y Configuring Sudo OK Configure Apache server ------------------------------------------------------------------------ Do you want to add Centreon Apache sub configuration file ? [y/n], default to [n]: > y Create ‘/etc/httpd/conf.d/centreon.conf‘ OK Configuring Apache OK Do you want to reload your Apache ? [y/n], default to [n]: > y Reloading Apache service FAIL Preparing Centreon temporary files Change right on /usr/local/centreon/log OK Change right on /etc/centreon OK Change macros for insertBaseConf.sql OK Change macros for sql update files OK Change macros for php files OK Change macros for perl binary OK Change right on /usr/local/nagios/etc OK Add group nagios to user apache OK Add group nagios to user nagios OK Add group centreon to user nagios OK Copy CentWeb in system directory Install CentWeb (web front of centreon) OK Change right for install directory Change right for install directory OK Install libraries OK Write right to Smarty Cache OK Copying libinstall OK Change macros for centreon.cron OK Install Centreon cron.d file OK Change macros for centAcl.php OK Change macros for downtimeManager.php OK Install cron directory OK Change right for eventReportBuilder OK Change right for dashboardBuilder OK Change macros for centreon.logrotate OK Install Centreon logrotate.d file OK Prepare centFillTrapDB OK Install centFillTrapDB OK Prepare centreon_trap_send OK Install centreon_trap_send OK Prepare centreon_check_perfdata OK Install centreon_check_perfdata OK Prepare centreonSyncPlugins OK Install centreonSyncPlugins OK Prepare centreonSyncArchives OK Install centreonSyncArchives OK Install generateSqlLite OK Install changeRrdDsName.pl OK Prepare export-mysql-indexes OK Install export-mysql-indexes OK Prepare import-mysql-indexes OK Install import-mysql-indexes OK Centreon Web Perl lib installed OK ------------------------------------------------------------------------ Pear Modules ------------------------------------------------------------------------ Check PEAR modules PEAR 1.4.9 1.9.4 OK DB 1.7.6 NOK DB_DataObject 1.8.4 NOK DB_DataObject_FormBuilder 1.0.0RC4 NOK MDB2 2.0.0 NOK Date 1.4.6 NOK HTML_Common 1.2.2 NOK HTML_QuickForm 3.2.5 NOK HTML_QuickForm_advmultiselect 1.1.0 NOK HTML_Table 1.6.1 NOK Archive_Tar 1.1 1.3.11 OK Auth_SASL 1.0.1 NOK Console_Getopt 1.2 1.3.1 OK Net_SMTP 1.2.8 NOK Net_Socket 1.0.1 NOK Net_Traceroute 0.21 NOK Net_Ping 2.4.1 NOK Validate 0.6.2 NOK XML_RPC 1.4.5 1.5.5 OK SOAP 0.10.1 NOK Log 1.9.11 NOK Archive_Zip 0.1.2 NOK Do you want me to install/upgrade your PEAR modules [y/n], default to [y]: > y Upgrading PEAR modules Installing PEAR modules DB_DataObject_FormBuilder 1.0.0RC4 1.0.2 OK Check PEAR modules PEAR 1.4.9 1.9.4 OK DB 1.7.6 1.7.14 OK DB_DataObject 1.8.4 1.11.2 OK DB_DataObject_FormBuilder 1.0.0RC4 1.0.2 OK MDB2 2.0.0 2.4.1 OK Date 1.4.6 1.4.7 OK HTML_Common 1.2.2 1.2.5 OK HTML_QuickForm 3.2.5 3.2.13 OK HTML_QuickForm_advmultiselect 1.1.0 1.5.1 OK HTML_Table 1.6.1 1.8.3 OK Archive_Tar 1.1 1.3.11 OK Auth_SASL 1.0.1 1.0.6 OK Console_Getopt 1.2 1.3.1 OK Net_SMTP 1.2.8 1.6.2 OK Net_Socket 1.0.1 1.0.14 OK Net_Traceroute 0.21 0.21.3 OK Net_Ping 2.4.1 2.4.5 OK Validate 0.6.2 0.8.5 OK XML_RPC 1.4.5 1.5.5 OK SOAP 0.10.1 0.13.0 OK Log 1.9.11 1.12.7 OK Archive_Zip 0.1.2 0.1.2 OK All PEAR modules OK ------------------------------------------------------------------------ Centreon Post Install ------------------------------------------------------------------------ Create /usr/local/centreon/www/install/install.conf.php OK Create /etc/centreon/instCentWeb.conf OK ------------------------------------------------------------------------ Start CentStorage Installation ------------------------------------------------------------------------ Where is your Centreon Run Dir directory? default to [/var/run/centreon] > Do you want me to create this directory ? [/var/run/centreon] [y/n], default to [n]: > y Path /var/run/centreon OK Where is your CentStorage binary directory default to [/usr/local/centreon/bin] > Path /usr/local/centreon/bin OK Where is your CentStorage RRD directory default to [/var/lib/centreon] > Path /var/lib/centreon OK Preparing Centreon temporary files /tmp/centreon-setup exists, it will be moved... install www/install/createTablesCentstorage.sql OK Creating Centreon Directory ‘/var/lib/centreon/status‘ OK Creating Centreon Directory ‘/var/lib/centreon/metrics‘ OK Install CentStorage binary OK Change right : /var/run/centreon OK Change macros for centstorage init script OK Replace CentStorage sysconfig script Macro OK Do you want me to install CentStorage init script ? [y/n], default to [n]: > y CentStorage init script installed OK CentStorage sysconfig script installed OK Do you want me to install CentStorage run level ? [y/n], default to [n]: > y CentStorage Perl lib installed OK Install logAnalyser OK Install logAnalyserBroker OK Install nagiosPerfTrace OK Change macros for centstorage.cron OK Install CentStorage cron OK Change macros for centstorage.logrotate OK Install Centreon Storage logrotate.d file OK Create /etc/centreon/instCentStorage.conf OK ------------------------------------------------------------------------ Start CentCore Installation ------------------------------------------------------------------------ Where is your CentCore binary directory default to [/usr/local/centreon/bin] > Path /usr/local/centreon/bin OK Preparing Centreon temporary files /tmp/centreon-setup exists, it will be moved... Copy CentCore in binary directory OK Change right : /var/run/centreon OK Change right : /var/lib/centreon OK Change macros for centcore.logrotate OK Install Centreon Core logrotate.d file OK Replace CentCore init script Macro OK Replace CentCore sysconfig script Macro OK Do you want me to install CentCore init script ? [y/n], default to [n]: > y CentCore init script installed OK CentCore sysconfig script installed OK Do you want me to install CentCore run level ? [y/n], default to [n]: > y CentCore Perl lib installed OK Create /etc/centreon/instCentCore.conf OK ------------------------------------------------------------------------ Start CentPlugins Installation ------------------------------------------------------------------------ Where is your CentPlugins lib directory default to [/var/lib/centreon/centplugins] > /usr/local/nagios/libexec Path /usr/local/nagios/libexec OK Preparing Centreon temporary files /tmp/centreon-setup exists, it will be moved... Change macros for CentPlugins OK Installing the plugins OK Change right on centreon.conf OK CentPlugins is installed ------------------------------------------------------------------------ Start CentPlugins Traps Installation ------------------------------------------------------------------------ Where is your SNMP configuration directory default to [/etc/snmp] > /etc/snmp OK Where is your CentreonTrapd binaries directory default to [/usr/local/centreon/bin] > /usr/local/centreon/bin OK Finding Apache user : apache Preparing Centreon temporary files /tmp/centreon-setup exists, it will be moved... Change macros for snmptrapd.conf OK Replace CentreonTrapd init script Macro OK Replace CentreonTrapd sysconfig script Macro OK Do you want me to install CentreonTrapd init script ? [y/n], default to [n]: > y CentreonTrapd init script installed OK CentreonTrapd sysconfig script installed OK Do you want me to install CentreonTrapd run level ? [y/n], default to [n]: > y trapd Perl lib installed OK Install : snmptrapd.conf OK Install : centreontrapdforward OK Install : centreontrapd OK Create /etc/centreon/instCentPlugins.conf OK
安装完后,启动服务
[root@jk centreon-2.5.0]# /etc/init.d/httpd start Starting httpd: [ OK ] [root@jk centreon-2.5.0]# /etc/init.d/mysqld start Starting mysqld: [ OK ] [root@jk centreon-2.5.0]# mysqladmin -u root -p password ‘mysqlpasswd‘ [root@jk centreon-2.5.0]# /etc/init.d/ndo2db start Starting ndo2db: done.
启动nrpe
修改/usr/local/nagios/etc/nrpe.cfg
#allowed_hosts=127.0.0.1 这句修改为
allowed_hosts=127.0.0.1,192.168.1.225
command[check_hda1]=/usr/local/nagios/libexec/check_disk -w 20% -c 10% -p /dev/hda1这句修改如下
command[check_disk]=/usr/local/nagios/libexec/check_disk -w 20% -c 10% -p /
启动
/usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d
把上面这句加到/etc/rc.d/rc.loal
这个步骤完成后,我们进行网页端安装
http://192.168.1.225/centreon 打开安装程序
如图:
填写正确的路径
填写管理员密码和邮箱
填写数据库用户名和密码
在/etc/my.cn 的MYSQLD段添加下面一句
innodb_file_per_table=1
然后重新启动MYSQL
service mysqld restart
Configuration->Monitoring Engines->Generate 勾选所有,然后点击Export
先把默认服务删除
添加一个check_ping命令
$USER1$/check_ping -H $HOSTADDRESS$ -w $ARG1$ -c $ARG2$ -p $ARG3$
Configuration->Commands->Add
$USER1$/check_ping -H $HOSTADDRESS$ -w $ARG1$ -c $ARG2$ -p $ARG3$
接着添加一个服务模板
Configuration->Services-Templates->Add
检查是否正确并生成配置:管理-》nagios 勾选所有动作-》导出
再添加一个命令check_nrpe ,Configuration->Commands->Add
$USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$
下面添加服务
配置-》服务-》模板-》增加
添加check_load
添加check_users
添加check_ disk
添加check_zombie_procs
添加check_total_procs
关联模板:因为 Centreon-Server继承的是Servers-Linux主机模板,所以我们在Servers-Linux模板里将刚才的服务模板都关联上
检查是否正确并生成配置:管理-》nagios 勾选所有动作-》导出
过一会 如下图
下面说说nrpe监控WINDOWS
首先现在NRPE客户端 下载地址如下:
http://nsclient.org/nscp/downloads
在这里我们下载的是NSCP-0.4.2.88-x64.msi
然后安装这个软件
由于系统自带check_nt_cpu /check_nt_disk/check_memuse 我们再添加两个
添加一个check_nt_uptime命令
$USER1$/check_nt -H $HOSTADDRESS$ -p $ARG1$ -v UPTIME -s $ARG2$
再添加一个check_nt_service命令
$USER1$/check_nt -H $HOSTADDRESS$ -p $ARG1$ -v SERVICESTATE -d SHOWALL -l $ARG2$ -s $ARG3$
添加完成后我们依次添加服务模板
添加check_nt_cpu
添加check_nt_disk
添加check_nt_mem
添加check_nt_uptime
添加check_nt_services
添加完成后我们添加一台WINDOWS主机
添加完成后我们关联模板
检查是否正确并生成配置:管理-》nagios 勾选所有动作-》导出
过一会儿如下:
我们现在说说批量添加 这个要用脚本
脚本名称 add_host.pl
内容如下:
#!/usr/bin/perl ## ==================================================== use strict; use warnings; use DBI; use DBD::mysql; # ---------------------------------------------------- my $DB_HOST = "127.0.0.1"; //数据IP my $DB_USER = "root"; //数据库用户名 my $DB_PASSWD = "passwd"; //数据库密码 my $DB_NAME = "centreon"; //数据库名称 my $dbh = DBI->connect("DBI:mysql:database=$DB_NAME;host=$DB_HOST", "$DB_USER", "$DB_PASSWD", { RaiseError => 1 }); # ---------------------------------------------------- my $file_path = "./hosts"; //HOST文件 my $tpl_name = "Servers-Linux"; //模板 my $nagios_name = "Central"; foreach my $arg (@ARGV) { # == file of hostname and ipaddress == if ($arg eq ‘-f‘) { $file_path = shift; } # == name of template == elsif ($arg eq ‘-t‘) { $tpl_name = shift; } # == name of nagios name == elsif ($arg eq ‘-n‘) { $nagios_name = shift; } else { &print_help(); exit 1; } } # ----------------------------------------------------- open (HOST, "$file_path") || die "Cannot open $file_path for read"; my $sql; my $sth; my $line; my ($host, $ipaddr); my ($host_id, $tpl_id, $nagios_id) = (0, 0, 0); while (defined($line = <HOST>)) { # == skip blank lines ================= next if ($line =~ /^\s*$/); # == skip if # ======================== next if ($line =~ /^\s*#/); # == get host and ipaddress =========== ($ipaddr, $host) = split(/\s+/, $line); next if ($ipaddr eq ‘‘ || $host eq ‘‘); # == insert the host to table host ==== $sql = "insert host set host_template_model_htm_id=‘2‘,host_name=‘$host‘,host_alias=‘$host‘,host_address=‘$ipaddr‘,host_active_checks_ enabled=‘2‘,host_passive_checks_enabled= ‘2‘,host_checks_enabled=‘2‘,host_event_handler_enabled=‘2‘,host_flap_detection_enabled=‘2‘,host_process_perf_ data=‘2‘,host_retain_status_information= ‘2‘,host_retain_nonstatus_information=‘2‘,host_notifications_enabled=‘2‘,host_register=‘1‘,host_activate=‘1‘"; $sth = $dbh->do($sql); sleep(1); # == get host_id ====================== $sql = "select host_id from host where host_name=‘$host‘"; $sth = $dbh->prepare($sql); $sth->execute(); while (my $ref = $sth->fetchrow_hashref()) { $host_id = $ref->{‘host_id‘}; print "host_id is $host_id\n"; } next if ($host_id == 0); # == insert extended_host_information == $sql = "insert extended_host_information set host_host_id=‘$host_id‘"; $sth = $dbh->do($sql); # == insert host_template_relation ===== $sql = "select host_id from host where host_name=‘$tpl_name‘"; $sth = $dbh->prepare($sql); $sth->execute(); while (my $ref = $sth->fetchrow_hashref()) { $tpl_id = $ref->{‘host_id‘}; print "template id is $tpl_id\n"; } next if ($tpl_id == 0); $sql = "insert host_template_relation set host_host_id=‘$host_id‘,host_tpl_id=‘$tpl_id‘,`order`=‘1‘"; $sth = $dbh->prepare($sql); $sth->execute(); # == insert ns_host_relation =========== $sql = "select id from nagios_server where name=‘$nagios_name‘"; $sth = $dbh->prepare($sql); $sth->execute(); while (my $ref = $sth->fetchrow_hashref()) { $nagios_id = $ref->{‘id‘}; print "nagios id is $nagios_id\n"; } next if ($nagios_id == 0); $sql = "insert ns_host_relation set host_host_id=‘$host_id‘,nagios_server_id=‘$nagios_id‘"; $sth = $dbh->prepare($sql); $sth->execute(); # == insert complete == print "insert $host to centreon complete\n"; } close(HOST); $dbh->disconnect(); exit 0; # -------------------------------------------------------------------------------- sub print_help { print "Usage ./insert_host.pl [-f path of host file] [-n nagios name] [-t template name]\n"; print "\n"; }
hosts文件格式如下:
192.168.1.222webserver1
192.168.1.223webserver2
.........
这个脚本只能批量添加主机无法添加服务,所以我们还得安装centreon-clapi
[root@jk soft]# tar xvzf centreon-clapi-1.5.2.tar.gz [root@jk soft]# cd centreon-clapi-1.5.2 [root@jk centreon-clapi-1.5.2]# ./install.sh -i ############################################################################## # # # # Module : Centreon CLAPI version 1.5 # # # ############################################################################## # ------------------------------------------------------------------------ Checking all needed binaries ------------------------------------------------------------------------ rm OK cp OK mv OK /bin/chmod OK /bin/chown OK echo OK more OK mkdir OK find OK /bin/grep OK /bin/cat OK /bin/sed OK ------------------------------------------------------------------------ Load parameters ------------------------------------------------------------------------ Please specify the directory that contains "instCentWeb.conf" > /etc/centreon/ ------------------------------------------------------------------------ Centreon CLAPI Module Installation ------------------------------------------------------------------------ Replacing macros OK Setting right OK Setting owner/group OK Create module directory OK Copying module OK Delete temp install directory OK The centreon-clapi.1.5 installation is finished OK [root@jk centreon-clapi-1.5.2]# cd /usr/local/centreon/www/modules/centreon-clapi/core/ vi centreon
require_once
"$centreon_etc/centreon.conf.php"
;
改为
require_once "/etc/centreon/centreon.conf.php";
查看主机
[root@jk core]# ./centreon -uadmin -p111222 -o HOST -a show
id;name;alias;address;activate
14;Centreon-Server;Monitoring Server;127.0.0.1;1
16;windows;windows;192.168.1.254;1
应用关联模板 对WebServer1应用模板
./centreon -uadmin -p111111 -o HOST -a applytpl -v "WebServer1"
设置引导自动启动服务
[root@jk ~]# chkconfig --level 345 nagios on
[root@jk ~]# chkconfig --level 345 centcore on
[root@jk ~]# chkconfig --level 345 centstorage on
[root@jk ~]# chkconfig --level 345 ndo2db on
[root@jk ~]# chkconfig --level 345 httpd on
[root@jk ~]# chkconfig --level 345 mysqld on
[root@jk var]# service centstorage restart
Stopping centstorage: [FAILED]
Starting centstorage: [ OK ]
这个服务一直启动不起来,多方测试均不可以 如下方法解决
/usr/bin/perl /usr/local/centreon/bin/centstorage --logfile=/usr/local/centreon/log/centstorage.log --severity=error
--config=/etc/centreon/conf.pm &
这样启动
如果要查看Nagios的页面要新建一个用户 如下 用户名必须是nagiosadmin
[root@jk ~]# htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin
New password:
Re-type new password:
Adding password for user nagiosadmin
[root@jk ~]#
现在可以通过http://www.xxx.com/nagios访问
如果Poller States 红色状态,请查看/var/log/message
jk ndo2db: mysql_error: ‘Unknown column ‘importance‘ in ‘field list‘‘
如果有类似上面的错误,请重新新建一个nagios的数据库
到ndoutils-2.0.0的安装目录的 db目录
本例是/soft/ndoutils-2.0.0/db执行
./installdb -u root -p passwd -h localhost -d nagios
改成自己的mysql的用户名和密码
改完之后请在NDO2DB.CFG修改数据库名为nagios
查看/usr/local/centreon/log/sql-error.log文件 如果有以下错误
2014-04-10 13:36|0|0|DB Error: no such table QUERY : DELETE FROM centreon_acl WHERE group_id NOT IN (SELECT
DISTINCT acl_group_id FROM centreon.acl_res_group_relations)
这个是缺少个字段 解决办法如下:
mysql -u root -p
use nagios;
CREATE TABLE IF NOT EXISTS `centreon_acl` (
`id` int(11) NOT NULL auto_increment,
`host_name` varchar(255) default NULL,
`service_description` varchar(255) default NULL,
`group_id` int(11) default NULL,
PRIMARY KEY (`id`),
KEY `host_name` (`host_name`),
KEY `service_description` (`service_description`),
KEY `group_id` (`group_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
如果系统日志不显示NOD2DB的相关日志 系统日志提示如下:
ndo2db: Warning: Retrying message send. This can occur because you have too few messages allowed or too few
total bytes allowed in message queues. You are currently using 64 of 3739 messages and 65536 of 65536 bytes in the
queue. See README for kernel tuning options.
那么修改 /etc/sysctl.conf
如果没有则添加,如果有则修改数值
kernel.msgmnb = 431072000
kernel.msgmni = 100000
kernel.msgmax = 6553600
修改完成之后 sysctl -p
如果还有其他错误 请检查nagios配置一些路径 在网页端对照一下