LNMP之前已安装
1、Nginx对Perl的CGI支持
<span style="color:#333333">tar xzf FCGI-0.74.tar.gz
cd FCGI-0.74
perl Makefile.PL
make && make install
cd ../
tar xzf FCGI-ProcManager-0.24.tar.gz
cd FCGI-ProcManager-0.24
perl Makefile.PL
make && make install
cd ../
wget http://search.cpan.org/CPAN/authors/id/G/GB/GBARR/IO-1.25.tar.gz
tar zxvf IO-1.25.tar.gz
cd IO-1.25
perl Makefile.PL
make && make install
cd ../
#安装 perl-IO-String
yum install perl-IO-String
#安装IO::ALL模块
wget http://search.cpan.org/CPAN/authors/id/I/IN/INGY/IO-All-0.41.tar.gz
tar zxvf IO-All-0.41.tar.gz
cd IO-All-0.41
perl Makefile.PL
make && make install
cd ../
wget http://www.mike.org.cn/wp-content/uploads/2011/07/perl-fcgi.zip
unzip perl-fcgi.zip
cp perl-fcgi.pl /usr/local/nginx/
#修改脚本权限
chmod 755 /usr/local/nginx/perl-fcgi.pl
vim /usr/local/nginx/start_perl_cgi.sh
#!/bin/bash
#set -x
dir=/usr/local/nginx/
stop ()
{
#pkill -f $dir/perl-fcgi.pl
kill $(cat $dir/logs/perl-fcgi.pid)
rm $dir/logs/perl-fcgi.pid 2>/dev/null
rm $dir/logs/perl-fcgi.sock 2>/dev/null
echo "stop perl-fcgi done"
}
start ()
{
rm $dir/now_start_perl_fcgi.sh 2>/dev/null
chown www.www $dir/logs
echo "$dir/perl-fcgi.pl -l $dir/logs/perl-fcgi.log -pid $dir/logs/perl-fcgi.pid -S $dir/logs/perl-fcgi.sock" >>$dir/now_start_perl_fcgi.sh
chown www.www $dir/now_start_perl_fcgi.sh
chmod u+x $dir/now_start_perl_fcgi.sh
sudo -u www $dir/now_start_perl_fcgi.sh
echo "start perl-fcgi done"
}
case $1 in
stop)
stop
;;
start)
start
;;
restart)
stop
start
;;
esac
#修改脚本权限
chmod 755 /usr/local/nginx/start_perl_cgi.sh
#启动脚本
/usr/local/nginx/start_perl_cgi.sh start
</span>
<span style="color:#333333"><strong>2、安装nagios</strong>
groupadd nagcmd
usermod -a -G nagcmd nagios
usermod -a -G nagcmd www
tar xzf nagios-3.5.0.tar.gz
cd nagios
yum -y install gd-devel
./configure --prefix=/usr/local/nagios --with-command-group=nagcmd
make all
make install #用于安装主要的程序、CGI及HTML文件
make install-init #用于生成init启动脚本
make install-config #用于安装示例配置文件
make install-commandmode</span>
3、安装插件
tar xzf nagios-plugins-1.4.16.tar.gz
cd nagios-plugins-1.4.16
./configure --prefix=/usr/local/nagios --with-nagios-user=nagios --with-nagios-group=nagios
make && make install
cd ../
tar xzf nrpe-2.14.tar.gz
cd nrpe-2.14
./configure
make && make install
cp sample-config/nrpe.cfg /usr/local/nagios/etc/
chown nagios.nagios /usr/local/nagios/etc/nrpe.cfg
cd ../
tar xzf nagios-plugins-1.4.16.tar.gz
cd nagios-plugins-1.4.16
./configure --prefix=/usr/local/nagios --with-nagios-user=nagios --with-nagios-group=nagios
make && make install
cd ../
tar xzf nrpe-2.14.tar.gz
cd nrpe-2.14
./configure
make && make install
cp sample-config/nrpe.cfg /usr/local/nagios/etc/
chown nagios.nagios /usr/local/nagios/etc/nrpe.cfg
cd ../
4、安装pnp4nagios
yum install rrdtool gd gd-devel php-gd
#tar -zxvf php4nagios-*.tar.gz
#cd php4nagios
#./configure –with-nagios-user=nagios –with-nagios-group=nagios (如果单独编译安装的rrdtoool,则使用–with-rrdtool=/usr/local/rrdtool-1.2.xx/bin/rrdtool这样的形式)
#make all
#make install
#make install-webconf
#make install-config
#make install-init
yum install rrdtool gd gd-devel php-gd
#tar -zxvf php4nagios-*.tar.gz
#cd php4nagios
#./configure –with-nagios-user=nagios –with-nagios-group=nagios (如果单独编译安装的rrdtoool,则使用–with-rrdtool=/usr/local/rrdtool-1.2.xx/bin/rrdtool这样的形式)
#make all
#make install
#make install-webconf
#make install-config
#make install-init
5、配置pnp4nagios
使用 Bulk Mode方式
vim /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
<span style="color:#333333">vim /usr/local/nagios/etc/objects/commands.cfg
define command{
command_name check_nrpe
command_line $USER1$/check_nrpe-H $HOSTADDRESS$ -c $ARG1$
} #这一段放在上面即可
如下:同步模式设定方法添加到末尾就可以,记住在这个配置文件里面, 默认有这个配置,需要找到注释掉,然后将下面的配置添加,如果不注释掉,在你检查nagios的配置文件的时候会报错
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
}
vim /usr/local/nagios/etc/objects/templates.cfg
define host {
name host-pnp
action_url /pnp4nagios/index.php/graph?host=$HOSTNAME$&srv=_HOST_
register 0
}
define service {
name service-pnp
action_url /pnp4nagios/index.php/graph?host=$HOSTNAME$&srv=$SERVICEDESC$
register 0
}</span>
<span style="color:#333333"><strong>6、配置nginx</strong>
server {
listen 80;
server_name nagios.zhibo.tv;
auth_basic "Nagios Access";
auth_basic_user_file /usr/local/nagios/etc/htpasswd.users;
root /usr/local/nagios/share;
location / {
root /usr/local/nagios/share;
index index.html index.htm index.php;
}
location ~ .*\.(php|php5)?$
{
root /usr/local/nagios/share;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi.conf;
}
location /nagios {
alias /usr/local/nagios/share;
}
location /cgi-bin/images {
alias /usr/local/nagios/share/images;
}
location /cgi-bin/stylesheets {
alias /usr/local/nagios/share/stylesheets;
}
location /cgi-bin {
alias /usr/local/nagios/sbin;
}
location ~ .*\.(cgi|pl)?$
{
gzip off;
root /usr/local/nagios/sbin;
rewrite ^/nagios/cgi-bin/(.*)\.cgi /$1.cgi break;
fastcgi_pass unix:/usr/local/nginx/logs/perl-fcgi.sock;
fastcgi_index index.cgi;
include fastcgi.conf;
fastcgi_read_timeout 60;
}
location /pnp4nagios {
alias /usr/local/pnp4nagios/share;
index index.php;
try_files $uri $uri/ @pnp4nagios;
}
location @pnp4nagios {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_split_path_info ^(.+\.php)(.*)$;
fastcgi_param PATH_INFO $fastcgi_path_info;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME /usr/local/pnp4nagios/share/index.php;
}
}
</span>
<span style="color:#333333"> 指定SSH监控端口号 :
check_command check_ssh! -p 38383!192.168.1.16</span>
<span style="color:#333333"><strong>7、在被监控机上</strong>
a.增加用户
#useradd nagios -s /sbin/nologin
b.安装Nagios插件
# tar zxvf nagios-plugins-1.4.16.tar.gz
# cd nagios-plugins-1.4.16
# ./configure --prefix=/usr/local/nagios --with-nagios-user=nagios --with-nagios-group=nagios
# make && make install
这一步完成后会在/usr/local/nagios/下生成三个目录include、libexec和share。
c.安装NRPE
# wget http://prdownloads.sourceforge.net/sourceforge/nagios/nrpe-2.13.tar.gz
# tar zxvf nrpe-2.13.tar.gz
# cd nrpe-2.13
# ./configure
make all
接下来安装NRPE插件,daemon和示例配置文件
c.1 安装check_nrpe 监控机需要安装check_nrpe这个插件,被监控机并不需要,我们在这里安装它只是为了测试目的。
[root@node2 nrpe-2.13]# make install-plugin
c.2 安装deamon
[root@node2 nrpe-2.13]# make install-daemon
c.3 安装配置文件
[root@node2 nrpe-2.13]# make install-daemon-config
按照安装文档的说明,是将NRPE deamon作为xinetd下的一个服务运行的。在这样的情况下xinetd就必须要先安装好,不过一般系统已经默认安装了。
yum install -y xinetd
d.安装xinetd脚本
[root@node2 nrpe-2.13]# make install-xinetd
可以看到创建了这个文件/etc/xinetd.d/nrpe
编译这个脚本:添加监控服务器IP,监控和被监控端都添加
[root@node2 ~]# vi /etc/xinetd.d/nrpe
only_from = 192.168.11.164 127.0.0.1
vi /usr/local/nagios/etc/nrpe.cfg
allowed_hosts=192.168.1.115,127.0.0.1,192.168.1.113
编辑/etc/services文件,增加NRPE服务
[root@node2 ~]# tail -n 4 /etc/services
iqobject 48619/tcp # iqobject
iqobject 48619/udp # iqobject
# Local services
nrpe 5666/tcp #nrpe
重启xinetd服务
[root@node2 ~]# service xinetd restart
Stopping xinetd: [ OK ]
Starting xinetd: [ OK ]
查看NRPE是否已经启动
[root@node2 ~]# netstat -an|grep 5666
tcp 0 0 0.0.0.0:5666 0.0.0.0:* LISTEN
使用上面在被监控机上安装的check_nrpe 这个插件测试NRPE 是否工作正常。
# /usr/local/nagios/libexec/check_nrpe -H 127.0.0.1</span>
<span style="color:#333333"><strong>CPU警告</strong>
vi /usr/local/nagios/etc/nrpe.cfg
command[check_total_procs]=/usr/local/nagios/libexec/check_procs -w 300 -c 500
</span>
添加CPU、内存、网卡使用率监控
cd /usr/local/nagios/libexec/ 添加监控脚本到目录
chmod +x 添加执行权限
vi /usr/local/nagios/etc/nrpe.cfg #添加命令
command[check_used_mem]=/usr/local/nagios/libexec/check_used_mem.sh -w 75 -c 85
command[check_cpu]=/usr/local/nagios/libexec/check_cpu.sh -w 60 -c 80
command[check_traffic]=/usr/local/nagios/libexec/check_traffic.sh -V 2c -C cool
you -H 127.0.0.1 -I 2 -w20,30 -c40,50 -K -B
command[check_users]=/usr/local/nagios/libexec/check_users -w 4 -c 6
command[check_load]=/usr/local/nagios/libexec/check_load -w 10,5,3 -c 15,10,5
command[check_zombie_procs]=/usr/local/nagios/libexec/check_procs -w 5 -c 10 -s Z
command[check_total_procs]=/usr/local/nagios/libexec/check_procs -w 150 -c 200
command[check_disk]=/usr/local/nagios/libexec/check_disk -w 20% -c 10% -p /dev/vda1
command[check_disk_data]=/usr/local/nagios/libexec/check_disk -w 20% -c 10% -p /dev/vdb
command[check_used_mem]=/usr/local/nagios/libexec/check_used_mem.sh -w 75 -c 85
command[check_cpu]=/usr/local/nagios/libexec/check_cpu.sh -w 60 -c 80
command[check_traffic]=/usr/local/nagios/libexec/check_traffic.sh -V 2c -C coolyou -H 127.0.0.1 -I 2 -w1000,1000 -c1500,1500 -K -B
command[check_ping]=/usr/local/nagios/libexec/check_ping -H 123.59.82.243 -w 100.0,20% -c 200.0,50%
服务器端添加php文件到cd /usr/local/pnp4nagios/share/templates.dist/
cd /usr/local/pnp4nagios/share/templates.dist/
网卡使用率监控需snmp
yum install -y net-snmp*
vi /etc/snmp/snmpd.conf #替换内容 ,第二行为设置密码
pass .1.3.6.1.4.1.4413.4.1 /usr/bin/ucd5820stat
com2sec local localhost coolyou
group MyRWGroup v1 local
group MyRWGroup v2c local
group MyRWGroup usm local
group MyROGroup v1 lan
group MyROGroup v2c lan
group MyROGroup usm lan
view all included .1 80
access MyROGroup "" any noauth exact all none none
access MyRWGroup "" any noauth exact all all all
/etc/init.d/snmpd start
./check_traffic.sh -V 2c -C coolyou -H 127.0.0.1 -L #检查网卡号
./check_traffic.sh -V 2c -C coolyou -H 127.0.0.1 -I 2 -w200,300 -c400,500 -K -B #-I加网卡号 -C加密码
chown nagios:nagios /var/tmp/check_traffic ...
chkconfig snmpd --level 2345 on
pass .1.3.6.1.4.1.4413.4.1 /usr/bin/ucd5820stat
com2sec local localhost coolyou
group MyRWGroup v1 local
group MyRWGroup v2c local
group MyRWGroup usm local
group MyROGroup v1 lan
group MyROGroup v2c lan
group MyROGroup usm lan
view all included .1 80
access MyROGroup "" any noauth exact all none none
access MyRWGroup "" any noauth exact all all all
/etc/init.d/snmpd start
./check_traffic.sh -V 2c -C coolyou -H 127.0.0.1 -L #检查网卡号
./check_traffic.sh -V 2c -C coolyou -H 127.0.0.1 -I 2 -w200,300 -c400,500 -K -B #-I加网卡号 -C加密码
chown nagios:nagios /var/tmp/check_traffic ...
chkconfig snmpd --level 2345 on
添加主机和服务
vi /usr/local/nagios/etc/nagios.cfg
cfg_dir=/usr/local/nagios/etc/servers #取消注释
vi /usr/local/nagios/etc/servers/192.168.1.16.cfg
define host{
use linux-server,host-pnp
host_name 192.168.1.16
alias 192.168.1.16
address 192.168.1.16
}
define service{
use generic-service,service-pnp
host_name 192.168.1.16
service_description check_ping
check_command check_ping!100.0,20%!200.0,50%
max_check_attempts 5
normal_check_interval 1
}
define service{
use generic-service,service-pnp
host_name 192.168.1.16
service_description check_ssh
check_command check_ssh! -p 38383!192.168.1.16
max_check_attempts 5
normal_check_interval 1
}
define service{
use generic-service,service-pnp
host_name 192.168.1.16
service_description check_http
check_command check_http
max_check_attempts 5
normal_check_interval 1
}
define service{
use generic-service,service-pnp
host_name 192.168.1.16
service_description check_users
check_command check_nrpe!check_users
max_check_attempts 5
normal_check_interval 1
}
define service{
use generic-service,service-pnp
host_name 192.168.1.16
service_description check_load
check_command check_nrpe!check_load
max_check_attempts 5
normal_check_interval 1
}
define service{
use generic-service,service-pnp
host_name 192.168.1.16
service_description check_hda1
check_command check_local_disk!20%!10%!/
max_check_attempts 5
normal_check_interval 1
}
define service{
use generic-service,service-pnp
host_name 192.168.1.16
service_description check_zombie_procs
check_command check_nrpe!check_zombie_procs
max_check_attempts 5
normal_check_interval 1
}
define service{
use generic-service,service-pnp
host_name 192.168.1.16
service_description check_total_procs
check_command check_nrpe!check_total_procs
max_check_attempts 5
normal_check_interval 1
}
define service {
use generic-service,service-pnp
host_name 192.168.1.16
service_description used_mem
check_command check_nrpe!check_used_mem
max_check_attempts 5
normal_check_interval 1
}
define service {
use generic-service,service-pnp
host_name 192.168.1.16
service_description cpu
check_command check_nrpe!check_cpu
max_check_attempts 5
normal_check_interval 1
}
define service {
use generic-service,service-pnp
host_name 192.168.1.16
service_description net
check_command check_nrpe!check_traffic
max_check_attempts 5
normal_check_interval 1
}
/usr/local/nagios/etc/servers/192.168.1.16.cfg
define host{
use linux-server,host-pnp
host_name 192.168.1.16
alias 192.168.1.16
address 192.168.1.16
}
define service{
use generic-service,service-pnp
host_name 192.168.1.16
service_description check_ping
check_command check_ping!100.0,20%!200.0,50%
max_check_attempts 5
normal_check_interval 1
}
define service{
use generic-service,service-pnp
host_name 192.168.1.16
service_description check_ssh
check_command check_ssh! -p 38383!192.168.1.16
max_check_attempts 5
normal_check_interval 1
}
define service{
use generic-service,service-pnp
host_name 192.168.1.16
service_description check_http
check_command check_http
max_check_attempts 5
normal_check_interval 1
}
define service{
use generic-service,service-pnp
host_name 192.168.1.16
service_description check_users
check_command check_nrpe!check_users
max_check_attempts 5
normal_check_interval 1
}
define service{
use generic-service,service-pnp
host_name 192.168.1.16
service_description check_load
check_command check_nrpe!check_load
max_check_attempts 5
normal_check_interval 1
}
define service{
use generic-service,service-pnp
host_name 192.168.1.16
service_description check_hda1
check_command check_local_disk!20%!10%!/
max_check_attempts 5
normal_check_interval 1
}
define service{
use generic-service,service-pnp
host_name 192.168.1.16
service_description check_zombie_procs
check_command check_nrpe!check_zombie_procs
max_check_attempts 5
normal_check_interval 1
}
define service{
use generic-service,service-pnp
host_name 192.168.1.16
service_description check_total_procs
check_command check_nrpe!check_total_procs
max_check_attempts 5
normal_check_interval 1
}
define service {
use generic-service,service-pnp
host_name 192.168.1.16
service_description used_mem
check_command check_nrpe!check_used_mem
max_check_attempts 5
normal_check_interval 1
}
define service {
use generic-service,service-pnp
host_name 192.168.1.16
service_description cpu
check_command check_nrpe!check_cpu
max_check_attempts 5
normal_check_interval 1
}
define service {
use generic-service,service-pnp
host_name 192.168.1.16
service_description net
check_command check_nrpe!check_traffic
max_check_attempts 5
normal_check_interval 1
}
<span style="color:#333333"><strong>更改图形数据目录</strong>
/usr/local/pnp4nagios/etc/config_local.php conifg.php config.php.0.6.14
$conf['rrdbase'] = "/usr/local/pnp4nagios/var/perfdata/"
更改目录路径</span>
更改邮件报警时间间隔
vi vi objects/templates.cfg
notification_interval 5 #更改所有的
vi objects/templates.cfg
notification_interval 5 #更改所有的
<span style="color:#333333"><strong>更改接收邮箱</strong>
vi objects/contacts.cfg</span>
发送邮件:
默认使用mail命令发送,需要安装并修改配置文件
vim /etc/mail.rc
set from=bug@zhibo.tv smtp=smtp.exmail.qq.com
set smtp-auth-user=bug@zhibo.tv smtp-auth-password=Coolyou@2015
set smtp-auth=login
网卡监报错 Unknown - Read or Write File /var/tmp/check_traffic_192.168.0.156_2__itnms.hist_dat_64 Error with user uid=542(nagios) gid=543(nagios) groups=543(nagios),544(nagcmd)
Unknown - Read or Write File /var/tmp/check_traffic_192.168.0.156_2__itnms.hist_dat_64 Error with user uid=542(nagios) gid=543(nagios) groups=543(nagios),544(nagcmd)
/var/tmp/check_traffic_192.168.0.156_2__itnms.hist_dat_64 :更改文件属主属组