二、 为PHP添加GD库
Nagios组件的运行依赖于httpd,gcc和php,php的运行又依赖于GD库 1. 下载GD库和php相关组件
zlib-1.2.7.tar.gz
libpng-1.2.29.tar.gz
freetype-2.4.11.tar.gz
jpegsrc.v9.tar.gz
gd-2.0.33.tar.gz 2. 按顺序安装GD库 安装zlib:
tar zxvf zlib-1.2.7.tar.gz
cd zlib-1.2.7
./configure
make
make install
安装libpng:
tar zxvf libpng-1.2.29.tar.gz
cd libpng-1.2.29/scripts
mv makefile.linux ../makefile
cd ..
make
make install
注意:这里的makefile不是用./configure生成,而是直接从scripts/里拷贝一个!
安装freetype:
tar zxvf freetype-2.4.11.tar.gz
cd freetype-2.4.11
./configure
make
make install 安装jpeg:
tar zxvf jpegsrc.v9.tar.gz
cd jpeg-9
./configure –enable-shared
make
make test
make install
注意:这里configure一定要带--enable-shared参数,否则不会生成共享库!
安装GD:
tar zxvf gd-2.0.33.tar.gz
cd gd-2.0.33
./configure --with-png --with-freetype --with-jpeg
make
make install
[iyunv@nagios nagios]# cd software/
[iyunv@nagios software]# tar zxvf nagios-3.5.0.tar.gz
[iyunv@nagios software]# cd nagios
[iyunv@nagios nagios]# ./configure --prefix=/home/nagios/nagios
[iyunv@nagios nagios]# make all
[iyunv@nagios nagios]# make install 安装主要程序,CGI及HTML文件
[iyunv@nagios nagios]# make install-init 把nagios做成运行脚本,nagios随开机启动
[iyunv@nagios nagios]# make install-commandmode 给外部命令访问nagios配置文件的权限
[iyunv@nagios nagios]# make install-config 把配置文件的例子复制到nagios的安装目录
[root @nagios software]# tar zxvf httpd-2.2.24.tar.gz
[root @nagios software]# cd httpd-2.2.24
[iyunv@nagios httpd-2.2.24]# ./configure --prefix=/home/nagios/apache --with-apr=/usr/local/apr/ --with-apr-util=/usr/local/apr-util/ --with-pcre=/usr/local/pcre --with-included-apr --enable-so --enable-mods-shared=most
[iyunv@nagios httpd-2.2.24]# make
[iyunv@nagios httpd-2.2.24]# make install
六、 安装PHP运行环境
[iyunv@nagios ~]# cd /home/nagios/software/gd_software/
[iyunv@nagios gd_software]# tar zxvf php-5.4.13.tar.gz
[iyunv@nagios gd_software]# cd php-5.4.13
[iyunv@nagios php-5.4.13]# ./configure --prefix=/opt/php --with-config-file-path=/opt/php --with-apxs2=/home/nagios/apache/bin/apxs
[iyunv@nagios php-5.4.13]# make
[iyunv@nagios php-5.4.13]# make test
=====================================================================
You may have found a problem in PHP.
This report can be automatically sent to the PHP QA team at
http://qa.php.net/reports and http://news.php.net/php.qa.reports
This gives us a better understanding of PHP's behavior.
If you don't want to send the report immediately you can choose
option "s" to save it. You can then email it to qa-reports@lists.php.net later.
Do you want to send this report now? [Yns]: n
[iyunv@nagios php-5.4.13]# make install
#setting for nagios
ScriptAlias /nagios/cgi-bin /home/nagios/nagios/sbin
<Directory "/home/nagios/nagios/sbin">
AuthType Basic
Options ExecCGI
AllowOverride None
Order allow,deny
Allow from all
AuthName "Nagios Access"
AuthUserFile /home/nagios/nagios/etc/htpasswd
Require valid-user
</directory>
Alias /nagios /home/nagios/nagios/share
<Directory "/home/nagios/nagios/share">
AuthType Basic
Options None
AllowOverride None
Order allow,deny
Allow from all
AuthName "nagios Access"
AuthUserFile /home/nagios/nagios/etc/htpasswd
Require valid-user
</directory>
LoadModule php5_module modules/libphp5.so
AddType application/x-httpd-php .php .phtml
AddType applicatoin/x-httpd-php-source .phps
AddDefaultCharset utf-8
2. 生成用户验证文件
[iyunv@nagios nagios]# /home/nagios/apache/bin/htpasswd -c /home/nagios/nagios/etc/htpasswd jsbzb
New password:
Re-type new password:
Adding password for user jsbzb
修改生成的密码文件的用户和属组
[iyunv@nagios nagios]# cd nagios/etc/
[iyunv@nagios etc]# chown nagios:nagios htpasswd
[iyunv@localhost ~]# tar -zxvf nagios-plugins-1.4.16.tar.gz
[iyunv@localhost ~]# cd nagios-plugins-1.4.16
[iyunv@localhost nagios-plugins-1.4.16]# ./configure --prefix=/home/nagios/nagios
[iyunv@localhost nagios-plugins-1.4.16]# make
[iyunv@localhost nagios-plugins-1.4.16]# make install
[iyunv@localhost nagios-plugins-1.4.16]# chown -R nagios:nagios /home/nagios/nagios
安装nrpe插件
[iyunv@localhost ~]# tar -zxvf nrpe-2.14.tar.gz
[iyunv@localhost ~]# cd nrpe-2.14
[iyunv@localhost nrpe-2.14]# ./configure -- prefix=/home/nagios/nagios
[iyunv@localhost nrpe-2.14]# make all
[iyunv@localhost nrpe-2.14]# make install-plugin
[iyunv@localhost nrpe-2.14]# make install-daemon
[iyunv@localhost nrpe-2.14]# make install-daemon-config
[iyunv@ localhost nrpe-2.14]# make install-xinetd
打开防火墙规则
检查防火墙是否开启,哪果没有开启,则跳过此步
service iptables status
iptables -I RH-Firewall-1-INPUT -p tcp -m tcp --dport 5666 -j ACCEPT
service iptables save
安装Sys-Statistics-Linux-0.66.tar.gz
[iyunv@HomeUC-1 software]# tar zxvf Sys-Statistics-Linux-0.66.tar.gz
[iyunv@HomeUC-1 software]# cd Sys-Statistics-Linux-0.66
[iyunv@HomeUC-1 Sys-Statistics-Linux-0.66]# perl Makefile.PL
[iyunv@HomeUC-1 Sys-Statistics-Linux-0.66]# make
[iyunv@HomeUC-1 Sys-Statistics-Linux-0.66]# make test
[iyunv@HomeUC-1 Sys-Statistics-Linux-0.66]# make install
服务组:
[nagios@localhost objects]$ vi servicegroups.cfg
define servicegroup {
servicegroup_name zhangs-linux-services
alias Zhangs Linux Services
}
主机组
[nagios@localhost objects]$vi hostgroups.cfg
define hostgroup{
hostgroup_name zhangs-linux-servers ; The name of the hostgroup
alias Zhangs Linux Servers ; Long name of the group
members localhost
}
把主机组文件和服务组文件添加到nagios.cfg
[nagios@localhost etc]$ vi nagios.cfg
cfg_file=/home/nagios/nagios/etc/objects/hostgroups.cfg
cfg_file=/home/nagios/nagios/etc/objects/servicegroups.cfg
添加联系人和联系人组(首次)
[nagios@nagios objects]$ vi contacts.cfg
添加以下内容
define contact{
contact_name zhangs
use generic-contact
alias zhangs
email zhangs@zzb.com.cn
}
define contactgroup{
contactgroup_name zhangs-cg
alias zhangs-cg
members jsbzb,zhangs #添加值班邮箱和自己常用邮箱,多个联系人之间用逗号隔开
}
在zhangsan目录下创建对象
vi zhangs-rhel5-linux.cfg
说明:命名规则按 “负责人-机器名-系统类型” 定义,太长可以简写。
添加以下内容
define host{
use linux-server
host_name zhangs-rhel5-linux
alias zhangs-rhel5-linux
address 172.16.84.161
}
define service{
use generic-service
host_name zhangs-rhel5-linux
service_description Current Load
check_command check_nrpe!check_load
servicegroups zhangs_linux_services
contact_groups zhangs-cg
}
define service{
use generic-service
host_name zhangs-rhel5-linux
service_description Current Users
check_command check_nrpe!check_users
servicegroups zhangs_linux_services
contact_groups zhangs-cg
}
define service{
use generic-service
host_name zhangs-rhel5-linux
service_description Total Processes
check_command check_nrpe!check_total_procs
servicegroups zhangs_linux_services
contact_groups zhangs-cg
}
define service{
use generic-service
host_name zhangs-rhel5-linux
service_description Mem Usage
check_command check_nrpe!check_mem
servicegroups zhangs_linux_services
contact_groups zhangs-cg
}
define service{
use generic-service
host_name zhangs-rhel5-linux
service_description Disk Stat
check_command check_nrpe!check_diskstat_local
servicegroups zhangs_linux_services
contact_groups zhangs-cg
}
define service{
use generic-service
host_name zhangs-rhel5-linux
service_description Disk Stat
check_command check_nrpe!check_diskstat_nas
servicegroups zhangs_linux_services
contact_groups zhangs-cg
}
define service{
use generic-service
host_name zhangs-rhel5-linux
service_description Cpu Usage
check_command check_nrpe!check_cpu
servicegroups zhangs_linux_services
contact_groups zhangs-cg
}
vi /home/nagios/nagios/etc/nagios.cfg
添加刚创建的对象文件
#zhangs object config files
cfg_file=/home/nagios/nagios/etc/objects/zhangs/ zhangs-rhel5-linux.cfg
编辑主机组文件hostgroups.cfg添加新加主机
[nagios@localhost objects]$vi hostgroups.cfg
define hostgroup{
hostgroup_name zhangs-linux-servers ; The name of the hostgroup
alias Zhangs Linux Servers ; Long name of the group
members localhost, zhangs-rhel5-linux
}
验证nagios配置
[iyunv@localhost ~]# /home/nagios/nagios/bin/nagios -v /home/nagios/nagios/etc/nagios.cfg
………………
Total Warnings: 0
Total Errors: 0
Things look okay - No serious problems were detected during the pre-flight check
[nagios@localhost objects]$vi hostgroups.cfg
define hostgroup{
hostgroup_name zhangs-linux-servers ; The name of the hostgroup
alias Zhangs Linux Servers ; Long name of the group
members localhost, zhangs-rhel5-linux
}
define hostgroup{
hostgroup_name zhangs-windows-servers ; The name of the hostgroup
alias Zhangs Windows Servers ; Long name of the group
members zhangs-lenovopc-win7
}
编辑服务组文件servicegroups.cfg添加新服务
[nagios@localhost objects]$ vi servicegroups.cfg
define servicegroup {
servicegroup_name zhangs-linux_services
alias Zhangs Linux Services
}
define servicegroup {
servicegroup_name zhangs_windows_services
alias Zhangs Windows Services
}
编辑联系人文件,增加联系人和联系人组
define contact{
contact_name zhangs
use generic-contact
alias zhangs
email zhangs@zzb.com.cn
}
define contactgroup{
contactgroup_name zhangs-cg
alias zhangs-cg
members jsbzb,zhangs
}
在自己的目录(没有请创建)下创建对象配置文件
vi zhangs-lenovopc-win7.cfg
define host{
use windows-server
host_name zhangs-lenovopc-win7
alias zhangs-lenovopc-win7
address 192.168.16.157
}
define service {
host_name zhangs-lenovopc-win7
service_description Check Cpuload
use generic-service
check_command check_nt!CPULOAD!-l 5,70,80,10,80,90
servicegroups zhangs_windows_services
contact_groups zhangs-cg
}
define service {
host_name zhangs-lenovopc-win7
service_description Check Uptime
use generic-service
check_command check_nt!UPTIME
servicegroups zhangs_windows_services
contact_groups zhangs-cg
}
define service{
use generic-service;
host_name zhangs-cisco2950-switch
service_description Uptime
check_command check_snmp!-C public -o sysUpTime.0
servicegroups zhangs-switch-services
contact_groups zhangs-cg
}
define service{
use generic-service
host_name zhangs-cisco2950-switch
service_description Port 47 Link Status
check_command check_snmp!-C public -o ifOperStatus.47 -r 1 -m RFC1213-MIB
servicegroups zhangs-switch-services
contact_groups zhangs-cg
}
define service{
use generic-service
host_name zhangs-cisco2950-switch
service_description CPU Avg Load
check_command check_snmp_cisco_loadavg! -C public -w 70 -c 90
servicegroups zhangs-switch-services
contact_groups zhangs-cg
}
define service{
use generic-service
host_name zhangs-cisco2950-switch
service_description Port 47 traffic Status
check_command check_snmp_cisco_ifstatus! -C public -i "FastEthernet0/47"
servicegroups zhangs-switch-services
contact_groups zhangs-cg
}
define service{
use generic-service
host_name zhangs-cisco2950-switch
service_description System Info
check_command check_snmp! -C public -o sysDescr.0
servicegroups zhangs-switch-services
contact_groups zhangs-cg
}
define service{
use generic-service
host_name zhangs-cisco2950-switch
service_description Check Fan Ps Temp Status
check_command check_snmp_env! -C public
servicegroups zhangs-switch-services
contact_groups zhangs-cg
}
define service{
use generic-service
host_name zhangs-cisco2950-switch
service_description Vlan1 traffic status
check_command check_snmp_int! -C public -n Vlan1 -f
servicegroups zhangs-switch-services
contact_groups zhangs-cg
}
define service{
use generic-service
host_name zhangs-cisco2950-switch
service_description Check Port[41-47] status
check_command check_snmp_int! -C public -n "Fast.*0.4[1234567]"
servicegroups zhangs-switch-services
contact_groups zhangs-cg
}
4. 添加网络服务组
[nagios@nagios objects]$ vi servicegroups.cfg
define servicegroup {
servicegroup_name zhangs-switch-services
alias Zhangs Switch Services
}
5. 添加网络主机组
[nagios@nagios objects]$vi hostgroups.cfg
define hostgroup{
hostgroup_name zhangs-switch-servers ; The name of the hostgroup
alias Zhangs Switch Servers ; Long name of the group
members zhangs-cisco2950-switch
}
define contact{
contact_name zhangs
use generic-contact
alias zhangs
email zhangs@zzb.com.cn
}
define contactgroup{
contactgroup_name zhangs-cg
alias zhangs-cg
members jsbzb,zhangs
}
8. 检查配置正确性
[iyunv@localhost ~]# /home/nagios/nagios/bin/nagios -v /home/nagios/nagios/etc/nagios.cfg
………………
Total Warnings: 0
Total Errors: 0
Things look okay - No serious problems were detected during the pre-flight check
[iyunv@nagios ~]# php -v
PHP 5.4.13 (cli) (built: May 6 2013 17:41:39)
Copyright (c) 1997-2013 The PHP Group
Zend Engine v2.4.0, Copyright (c) 1998-2013 Zend Technologies
3. 安装pnp4nagios
[iyunv@nagios ~]# cd /home/nagios/software/pnp4nagios/
[iyunv@nagios pnp4nagios]# tar zxvf pnp4nagios-0.6.21.tar.gz
[iyunv@nagios pnp4nagios]# cd pnp4nagios-0.6.21
[iyunv@nagios pnp4nagios-0.6.21]# ./configure --prefix=/home/nagios/pnp4nagios --with-nagios-user=nagios --with-nagios-group=nagios
[iyunv@nagios pnp4nagios-0.6.21]# make all
[iyunv@nagios pnp4nagios-0.6.21]# make install
[iyunv@nagios pnp4nagios-0.6.21]# make install-webconf
[iyunv@nagios pnp4nagios-0.6.21]# make install-config
[iyunv@nagios pnp4nagios-0.6.21]# make install-init
[iyunv@zzbrac11 software]# tar zxvf DBI-1.609.tar.gz
[iyunv@zzbrac11 software]# cd DBI-1.609
[iyunv@zzbrac11 DBI-1.609]# perl Makefile.PL
[iyunv@zzbrac11 DBI-1.609]# make all
[iyunv@zzbrac11 DBI-1.609]# make install
[iyunv@zzbrac11 software]# tar zxvf DBD-Oracle-1.24a.tar.gz
[iyunv@zzbrac11 software]# cd DBD-Oracle-1.24
[iyunv@zzbrac11 DBD-Oracle-1.24]# perl Makefile.PL
[iyunv@zzbrac11 DBD-Oracle-1.24]# make all
[iyunv@zzbrac11 DBD-Oracle-1.24]# make install
5. 配置检测命令
[nagios@zzbrac11 ~]$ vi nagios/etc/nrpe.cfg
# The following is oracle command arguments
command[oracheck_conn_time]=/home/nagios/nagios/libexec/check_oracle_health --connect='(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=172.16.84.59)(PORT=1521))(CONNECT_DATA=(SID=zzbrac11)))' --username NEWSBLOG --password NEWSBLOG --mode connection-time
command[oracheck_tnsping]=/home/nagios/nagios/libexec/check_oracle_health --connect='(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=172.16.84.59)(PORT=1521))(CONNECT_DATA=(SID=zzbrac11)))' --mode tnsping
cannot connect to xxx.xxx.xxx.xxx. install_driver(Sybase) failed: Can't load '/usr/lib64/perl5/site_perl/5.8.8/x86_64-linux-thread-multi/auto/DBD/Sybase/Sybase.so' for module DBD::Sybase: libct.so.4: 无法打开共享对象文件: 没有那个文件或目录 at /usr/lib64/perl5/5.8.8/x86_64-linux-thread-multi/DynaLoader.pm line 230.
3. 安装DBI和DBD-Sybase
[iyunv@nagios Client]# tar zxvf DBI-1.609.tar.gz
[iyunv@nagios Client]# cd DBI-1.609
[iyunv@nagios DBI-1.609]# perl Makefile.PL
[iyunv@nagios DBI-1.609]# make
[iyunv@nagios DBI-1.609]# make test
[iyunv@nagios DBI-1.609]# make install
[iyunv@nagios mssqlserver]# tar zxvf DBD-Sybase-1.15.tar.gz
[iyunv@nagios mssqlserver]# cd DBD-Sybase-1.15
[iyunv@nagios DBD-Sybase-1.15]# perl Makefile.PL
[iyunv@nagios DBD-Sybase-1.15]# make
[iyunv@nagios DBD-Sybase-1.15]# make test
注意:此处会有如下错误,可以忽略
Failed 11/13 test scripts, 15.38% okay. 216/241 subtests failed, 10.37% okay.
make: *** [test_dynamic] 错误 9
[iyunv@nagios DBD-Sybase-1.15]# make install
4. 测试连接
[iyunv@nagios ~]# cd /home/nagios/nagios/libexec
[iyunv@nagios libexec]# ./check_mssql_health --server=serve_juyuan2 --username=sa --password=xxx --mode=connected-users
OK - 6 connected users | connected_users=6;50;80