一、Nagios服务器端安装

1、环境准备

1.1基础环境

[root@m01 yum.repos.d]# cat /etc/redhat-release

CentOS release 6.7 (Final)

[root@m01 yum.repos.d]# uname -r

2.6.32-573.el6.x86_64

[root@m01 yum.repos.d]# uname -m

x86_64

1.2准备3台服务器

管理IP           角色             备注

10.0.0.61  nagios          Nagios服务器端(管理服务器)

10.0.0.8    web01          被监控的客户端服务器

10.0.0.7    web02          被监控的客户端服务器

1.3设置yum源安装

ping www.baidu.com(确保可以上网)

cd /etc/yum.repos.d/

/bin/mv CentOS-Base.repo CentOS-Base.repo.oldboy.ori

wget -O /etc/yum.repos.d/CentOS-Base.repohttp://mirrors.aliyun.com/repo/Centos-6.repo

 

[root@m01 ~]# ping www.baidu.com

PING www.baidu.com (119.75.218.70) 56(84) bytes of data.

64 bytes from 119.75.218.70: icmp_seq=1 ttl=128 time=19.0ms

64 bytes from 119.75.218.70: icmp_seq=2 ttl=128 time=4.46ms

64 bytes from 119.75.218.70: icmp_seq=3 ttl=128 time=3.66ms

^C

--- www.baidu.com ping statistics ---

3 packets transmitted, 3 received, 0% packet loss, time2291ms

rtt min/avg/max/mdev = 3.666/9.070/19.078/7.084 ms

[root@m01 ~]# cd /etc/yum.repos.d

[root@m01 yum.repos.d]# ls

CentOS-Base.repo       CentOS-Media.repo  epel-testing.repo

CentOS-Debuginfo.repo  CentOS-Vault.repo

CentOS-fasttrack.repo  epel.repo

[root@m01 yum.repos.d]# /bin/mv CentOS-Base.repo  CentOS-Base.repo.oldboy.ori

[root@m01 yum.repos.d]# wget -O/etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repo

[root@m01 yum.repos.d]# cd ~

 

1.4解决Perl软件编译问题

cd ~

echo 'export LC_ALL=C'>>/etc/profile

tail -1 /etc/profile

source /etc/profile

echo $LC_ALL

cd ~

 

[root@m01 ~]# echo'export LC_ALL=C'>>/etc/profile

[root@m01 ~]# tail -1/etc/profile

export LC_ALL=C

[root@m01 ~]# source/etc/profile

[root@m01 ~]# echo$LC_ALL      

C

[root@m01 ~]# cd ~

1.5.关闭防火墙及selinux

在测试环境下为了方便,最好关掉防火墙及selinex,如果是生产环境中,因为有外部IP,所以在调试完毕后需要开启防火墙。

/etc/init.d/iptables stop

/etc/init.d/iptables status

chkconfig iptables off

chkconfig --list iptables   

sed -i 's#SELINUX=enforcing#SELINUX=disabled#g'/etc/selinux/config

getenforce

关闭防火墙

[root@m01 ~]#/etc/init.d/iptables stop

[root@m01 ~]#/etc/init.d/iptables status

iptables: Firewall isnot running.

[root@m01 ~]# chkconfigiptables off

[root@m01 ~]# chkconfig--list iptables   

iptables        0:off  1:off   2:off   3:off  4:off   5:off   6:off

关闭SElinux

[root@m01 ~]# sed -i's#SELINUX=enforcing#SELINUX=disabled#g' /etc/selinux/config

[root@m01 ~]#getenforce    查看

Disabled

[root@m01 ~]# setenforce0    临时生效

setenforce: SELinux isdisabled

[root@m01 ~]#getenforce 

Disabled

1.6解决系统时间同步问题

 利用NTP时间同步或者配合定时任务来执行

#time sync by oldboy at2010-2-1

*/5 * * * */usr/sbin/ntpdate time.nist.gov >/dev/null 2>&1  

 

1.7安装Nagios服务端所需安装包

Nagios服务器端需要有web界面展示监控效果,界面的展示主要使用PHP程序,因此,需要LAMP环境。

注意:yum安装LAMP环境是配合Nagios服务端展示界面的最佳环境。(不要安装LNMP环境)

yum install gcc glibc glibc-common -y    编译软件升级

yum install gd gd-devel -y          用于后面PNP出图的包

yum install mysql-server -y     ##非必须的,如果有监控数据库,那么需要先安装mysql,否则mysql的相关插件不会被安装

yum install httpd php php-gd -y    ##ApachePHP环境

rpm -qa mysql httpd php

3个包)

提示:通过yum工具安装上述所有软件包,且这些环境一般不需要在Nagios客户端安装。

上面软件包安装好了之后的版本为:Apache2.2.15PHP5.3.3mysql5.1.73

[root@m01 ~]# rpm -qa mysql httpd php

httpd-2.2.15-47.el6.centos.4.x86_64

php-5.3.3-46.el6_7.1.x86_64

mysql-5.1.73-5.el6_7.1.x86_64

 

1.8、创建Nagios服务器端需要的用户及组

/usr/sbin/useradd nagios    ###这个地方最好创建家目录,否则,启动Nagios会提醒没家目录

/usr/sbin/useradd apache -M -s /sbin/nologin

/usr/sbin/groupadd nagcmd                  

/usr/sbin/usermod -a -G nagcmd nagios

/usr/sbin/usermod -a -G nagcmd apache

id -n -G nagios      

id -n -G apache

 

[root@m01 ~]#/usr/sbin/useradd nagios

[root@m01 ~]#/usr/sbin/useradd apache -M -s /sbin/nologin

useradd: user 'apache'already exists

[root@m01 ~]#/usr/sbin/groupadd nagcmd 

[root@m01 ~]#/usr/sbin/usermod -a -G nagcmd nagios

[root@m01 ~]#/usr/sbin/usermod -a -G nagcmd apache

[root@m01 ~]# id -n -Gnagios

nagios nagcmd

[root@m01 ~]# id -n -Gapache

apache nagcmd

[root@m01 ~]#

 

1.9上传软件包到指定目录或通过URL下载

mkdir -p /home/oldboy/tools/nagios

cd /home/oldboy/tools/nagios

rz

 

 

[root@m01 ~]# mkdir -p /home/oldboy/tools/nagios

[root@m01 ~]# cd /home/oldboy/tools/nagios/

[root@m01 nagios]# rz

rz waiting to receive.

???a? zmodem ??? °′ Ctrl+C ???

????oldboy_training_nagios_soft.zip...

  100%    7387 KB 7387 KB/s 00:00:01       0 ?

 

?[root@m01 nagios]# ll

total 7388

-rw-r--r-- 1 root root 7564715 May 22 16:05oldboy_training_nagios_soft.zip

[root@m01 nagios]# unzip oldboy_training_nagios_soft.zip

Archive: oldboy_training_nagios_soft.zip

  inflating:check_memory.pl        

  inflating:check_mysql            

  inflating:Class-Accessor-0.31.tar.gz 

 extracting:Config-Tiny-2.12.tar.gz 

  inflating:libart_lgpl-2.3.17.tar.gz 

  inflating:Math-Calc-Units-1.07.tar.gz 

  inflating:Nagios-Plugin-0.34.tar.gz 

  inflating:nrpe-2.12.tar.gz       

  inflating:Params-Validate-0.91.tar.gz 

  inflating:pnp-0.4.14.tar.gz      

  inflating:Regexp-Common-2010010201.tar.gz 

  inflating:rrdtool-1.2.14.tar.gz  

  inflating:check_iostat           

  inflating:nagios-3.5.1.tar.gz    

  inflating:nagios-plugins-1.4.16.tar.gz 

  inflating:rrdtool-1.2.30.tar.gz  

[root@m01 nagios]# tree

.

|-- Class-Accessor-0.31.tar.gz

|-- Config-Tiny-2.12.tar.gz

|-- Math-Calc-Units-1.07.tar.gz

|-- Nagios-Plugin-0.34.tar.gz

|-- Params-Validate-0.91.tar.gz

|-- Regexp-Common-2010010201.tar.gz

|-- check_iostat

|-- check_memory.pl

|-- check_mysql

|-- libart_lgpl-2.3.17.tar.gz

|-- nagios-3.5.1.tar.gz

|-- nagios-plugins-1.4.16.tar.gz

|-- nrpe-2.12.tar.gz

|-- oldboy_training_nagios_soft.zip

|-- pnp-0.4.14.tar.gz

|-- rrdtool-1.2.14.tar.gz

`-- rrdtool-1.2.30.tar.gz

 

0 directories, 17 files

 

启动LAMP环境的HTTP服务

 

[root@m01 nagios]# /etc/init.d/httpd start

Startinghttpd: httpd: Could not reliably determine the server's fully qualified domainname, using 172.16.1.61 for ServerName   ##可忽略或表示httpd.conf中缺少ServerName配置,可在/etc/httpd/conf/httpd.conf中加入ServerName127.0.0.1:80

                                                          [  OK  ]

[root@m01 nagios]# /etc/init.d/httpd restart

Stopping httpd:                                           [  OK  ]

Starting httpd: httpd: Could not reliably determine theserver's fully qualified domain name, using 172.16.1.61 for ServerName

                                                          [  OK  ]

[root@m01 nagios]# lsof -i :80

COMMAND  PID   USER  FD   TYPE DEVICE SIZE/OFF NODENAME

httpd   5527   root   4u  IPv6  46082     0t0  TCP *:http (LISTEN)

httpd   5529apache    4u  IPv6 46082      0t0  TCP *:http (LISTEN)

httpd   5530apache    4u  IPv6 46082      0t0  TCP *:http (LISTEN)

httpd   5531apache    4u  IPv6 46082      0t0  TCP *:http (LISTEN)

httpd   5532apache    4u  IPv6 46082      0t0  TCP *:http (LISTEN)

httpd   5533apache    4u  IPv6 46082      0t0  TCP *:http (LISTEN)

httpd   5534apache    4u  IPv6 46082      0t0  TCP *:http (LISTEN)

httpd   5535apache    4u  IPv6 46082      0t0  TCP *:http (LISTEN)

httpd   5536apache    4u  IPv6 46082      0t0  TCP *:http (LISTEN)

 

 

2、安装Nagios服务器端

unzip -q oldboy_training_nagios_soft.zip

tar xf nagios-3.5.1.tar.gz

cd nagios

./configure --with-command-group=nagcmd

make all

make install

make install-init

make install-config

make install-commandmode

 

 

[root@m01 httpd]# cd /home/oldboy/tools/nagios/

[root@m01 nagios]# pwd

/home/oldboy/tools/nagios

 [root@m01 nagios]#tar xf nagios-3.5.1.tar.gz

 [root@m01 nagios]#ls 

Class-Accessor-0.31.tar.gz       libart_lgpl-2.3.17.tar.gz

Config-Tiny-2.12.tar.gz          nagios

Math-Calc-Units-1.07.tar.gz      nagios-3.5.1.tar.gz

Nagios-Plugin-0.34.tar.gz        nagios-plugins-1.4.16.tar.gz

Params-Validate-0.91.tar.gz      nrpe-2.12.tar.gz

Regexp-Common-2010010201.tar.gz  oldboy_training_nagios_soft.zip

check_iostat                     pnp-0.4.14.tar.gz

check_memory.pl                  rrdtool-1.2.14.tar.gz

check_mysql                      rrdtool-1.2.30.tar.gz

[root@m01 nagios]# cd nagios

[root@m01 nagios]#./configure --with-command-group=nagcmd

出现下面的说明编译成功

Review the options abovefor accuracy.  If they look okay,

type 'make all' tocompile the main program and CGIs.

 

[root@m01 nagios]# make all

出现这表示正常

*************************************************************

Enjoy.

[root@m01 nagios]# make install

出现这表示成功了

make[1]: Leaving directory`/home/oldboy/tools/nagios/nagios'

 

[root@m01 nagios]# make install-init     ##安装初始化脚本到/etc/rc.d/init.d

/usr/bin/install -c -m755 -d -o root -g root /etc/rc.d/init.d

/usr/bin/install -c -m755 -o root -g root daemon-init /etc/rc.d/init.d/nagios

 

*** Init scriptinstalled ***

 

 

[root@m01 nagios]# make install-config   ##生成Nagios模块配置文件到/usr/local/nagios/etc

出现下面表示安装成功了

Remember, these are *SAMPLE* config files.  You'll need to read

the documentation for more information on how to actuallydefine

services, hosts, etc. to fit your particular needs.

 

[root@m01 nagios]# make install-commandmode   #安装配置目录许可外部命令文件

/usr/bin/install -c -m 775 -o nagios -g nagcmd -d/usr/local/nagios/var/rw

chmod g+s /usr/local/nagios/var/rw

 

*** External command directory configured ***

2.1、安装Nagios Web配置文件及创建登录用户

make install-webconf

htpasswd -bc /usr/local/nagios/etc/htpasswd.users oldboy123456

cat /usr/local/nagios/etc/htpasswd.users

/etc/init.d/httpd start

 

创建nagios web监控界面后,登录时会需要用户和名,密码(用户:oldboy密码:123456

[root@m01 nagios]# makeinstall-webconf   ##生成/etc/httpd/conf.d/nagios.conf配置文件

/usr/bin/install -c -m644 sample-config/httpd.conf /etc/httpd/conf.d/nagios.conf

 

*** Nagios/Apache conffile installed ***

 

[root@m01 nagios]# htpasswd -bc/usr/local/nagios/etc/htpasswd.users oldboy 123456

Adding password for useroldboy

重新加载Apache

[root@m01 nagios]# /etc/init.d/httpd reload

Reloading httpd:

[root@m01 nagios]#

 

2.2、添加监控报警信息接受的Email地址

cp /usr/local/nagios/etc/objects/contacts.cfg{,.ori}

sed -i 's#nagios@localhost#[email protected]#g'/usr/local/nagios/etc/objects/contacts.cfg

使用第三方邮件服务商提供的邮箱,把下列一行添加达到/etc/mail.rc

[root@m01 tools]# tail -1 /etc/mail.rc 

set [email protected] smtp=smtp.163.comsmtp-auth-user=13265571477 smtp-auth-password=DA62073621 smtp-auth=login

操作前先备份

[root@m01 nagios]# cp/usr/local/nagios/etc/objects/contacts.cfg{,.ori}

[root@m01 nagios]# sed-i 's#nagios@localhost#[email protected]#g'/usr/local/nagios/etc/objects/contacts.cfg        

[root@m01 nagios]# sed-n '35p'  /usr/local/nagios/etc/objects/contacts.cfg        

        email                          [email protected]        ;<<***** CHANGE THIS TO YOUR EMAIL ADDRESS ******

使用第三方邮件服务商提供的邮箱,把下列一行添加达到/etc/mail.rc

[root@m01 tools]# tail -1 /etc/mail.rc 

[email protected] smtp=smtp.163.com smtp-auth-user=13265571477smtp-auth-password=DA62073621 smtp-auth=login

 

2.3、配置Apache服务并加入系统开机自启动

/etc/init.d/httpd start

/etc/init.d/httpd restart

chkconfig httpd on

netstat -lntup|grep httpd

lsof -i :80

在浏览器登录

10.0.0.61/nagios

输入用户名和密码

oldboy

123456

显示nagios core就正常了

 

[root@m01 nagios]#/etc/init.d/httpd start

Starting httpd:

[root@m01 nagios]#/etc/init.d/httpd restart

Stopping httpd:                                           [  OK  ]

Starting httpd:                                            [ OK  ]

[root@m01 nagios]#chkconfig httpd on

[root@m01 nagios]#netstat -lntup|grep httpd

tcp        0     0 :::80                      :::*                        LISTEN      10922/httpd        

在浏览器输入

10.0.0.61/nagios

输入用户名和密码

oldboy

123456

显示nagios core就正常了



2.4、安装Nagios插件软件包

安装基础依赖包

yum install perl-devel openssl-devel -y

安装Nagiospluginx插件包

cd ..

ls nagios-plugins-1.4.16.tar.gz

tar xf nagios-plugins-1.4.16.tar.gz

cd nagios-plugins-1.4.16

./configure --with-nagios-user=nagios --with-nagios-group=nagios--enable-perl-modules --with-mysql

make

make install

 

2.5、安装nrpe软件

cd /home/oldboy/tools/nagios

ls nrpe-2.12.tar.gz

tar xf nrpe-2.12.tar.gz

cd nrpe-2.12

./configure

make all

make install-plugin

make install-daemon

make install-daemon-config

ls /usr/local/nagios/libexec/check_nrpe

ls /usr/local/nagios/libexec/|wc -l

 

 

 

到此为止Nagios服务器端的软件安装部分就配置完成了

2.6、配置并启动Nagios服务

添加Nagios服务到开机自启动

echo "/etc/init.d/nagiosstart">>/etc/rc.local

tail -1 /etc/rc.local

/etc/init.d/nagios checkconfig

 

启动Nagios服务

/etc/init.d/nagios start

检查Nagios服务器端进程及端口

ps -ef |grep nagios|grep -v grep

netstat -lntup|grep nagios(无内容就是正确的)

检查语法:

[root@m01 nrpe-2.12]#/etc/init.d/nagios checkconfig 

Running configurationcheck... OK.

 

2.7最后在浏览器输入http://10.0.0.61/nagios/,出现下面结果表明正确


 

有关出错问题看书(p570

1、出现Forbidden403一般是由服务器端权限引起的,解决办法执行:yum install php -y

 

二、Nagios客户端安装

2.1Nagios客户端无需安装LAMP环境,

2.安装前准备

2.1、基础环境

[root@m01 yum.repos.d]# cat /etc/redhat-release

CentOS release 6.7 (Final)

[root@m01 yum.repos.d]# uname -r

2.6.32-573.el6.x86_64

[root@m01 yum.repos.d]# uname -m

x86_64

2.2、准备2台服务器

管理IP           角色             备注

10.0.0.8    web01          被监控的客户端服务器

10.0.0.7    web02          被监控的客户端服务器

2.3.解决Perl软件编译问题

echo 'export LC_ALL=C'>>/etc/profile

tail -1 /etc/profile

source /etc/profile

echo $LC_ALL

 

2.4.关闭防火墙及selinux

getenforce #(显示Disabled下面就不用执行了)

/etc/init.d/iptables stop

/etc/init.d/iptables status

chkconfig --list iptables   

sed -i 's#SELINUX=enforcing#SELINUX=disabled#g'/etc/selinux/config

修改配置文件则永久生效,但是必须重启系统

getenforce

2.5、解决系统时间同步问题

crontab -l

也可以做NTP时间同步

 

3、正式安装

1、安装基础系统软件

yum install gcc glibc glibc-common -y

yum install mysql-server -y

rpm -qa mysql

2、上传软件包到指定目录或通过URL下载

mkdir -p /home/oldboy/tools/nagios

cd /home/oldboy/tools/nagios

rz

 

unzip -q oldboy_training_nagios_soft.zip

3、添加Nagios用户

useradd nagios-M -s /sbin/nologin

id nagios

 

4、安装nagios-plugins插件

yum install perl-devel perl-CPAN openssl-devel -y

tar xf nagios-plugins-1.4.16.tar.gz

cd nagios-plugins-1.4.16

./configure --with-nagios-user=nagios --with-nagios-group=nagios--enable-perl-modules --with-mysql

make

make install

cd ..

ls /usr/local/nagios/libexec/|wc -l

5、安装nagios客户端nrpe软件

cd ..

ls /usr/local/nagios/libexec/check_nrpe

tar xf nrpe-2.12.tar.gz

cd nrpe-2.12

 ./configure

 make all

make install-plugin

make install-daemon

make install-daemon-config

ls /usr/local/nagios/libexec/check_nrpe

ls /usr/local/nagios/libexec/|wc -l

 

6、安装其他相关的插件

cd ..

#----------Dear,我是分隔符---------------------

tar zxf Params-Validate-0.91.tar.gz

cd Params-Validate-0.91

perl Makefile.PL

make

make install

cd ..

#----------Dear,我是分隔符---------------------

tar zxf Class-Accessor-0.31.tar.gz

cd Class-Accessor-0.31

perl Makefile.PL

make

make install

cd ..

#----------Dear,我是分隔符---------------------

tar zxf Config-Tiny-2.12.tar.gz

cd Config-Tiny-2.12

perl Makefile.PL

make

make install

cd ..

#----------Dear,我是分隔符---------------------

tar zxf Math-Calc-Units-1.07.tar.gz

cd Math-Calc-Units-1.07

perl Makefile.PL

make

make install

cd ..

#----------Dear,我是分隔符---------------------

tar zxf Regexp-Common-2010010201.tar.gz

cd Regexp-Common-2010010201

perl Makefile.PL

make

make install

cd ..

#----------Dear,我是分隔符---------------------

tar zxf Nagios-Plugin-0.34.tar.gz

cd Nagios-Plugin-0.34

perl Makefile.PL

make

make install

cd ..

#----------Dear,我是分隔符---------------------

yum install sysstat -y

 

如果报错就是前面的perl环境变量没提前设置好

 

7、配置监控内存、磁盘I/O脚本插件

yum install dos2unix -y

/bin/cp /home/oldboy/tools/nagios/check_memory.pl/usr/local/nagios/libexec/

/bin/cp /home/oldboy/tools/nagios/check_iostat  /usr/local/nagios/libexec/

chmod 755 /usr/local/nagios/libexec/check_memory.pl

chmod 755 /usr/local/nagios/libexec/check_iostat

dos2unix /usr/local/nagios/libexec/check_memory.pl

dos2unix /usr/local/nagios/libexec/check_iostat

 

8、配置Nagios客户端nrpe服务

cd /usr/local/nagios/etc/

sed -n '79p' nrpe.cfg

sed -i's#allowed_hosts=127.0.0.1#allowed_hosts=127.0.0.1,172.16.1.61#g' nrpe.cfg 

sed -n '79p' nrpe.cfg

 

 

 

9、然后在命令模式下执行shift+g命令道结尾。并进行如下操作

vim nrpe.cfg

第一步,注释掉199-203

#command[check_users]=/usr/local/nagios/libexec/check_users-w 5 -c 10

#command[check_load]=/usr/local/nagios/libexec/check_load-w 15,10,5 -c 30,25,20

#command[check_hda1]=/usr/local/nagios/libexec/check_disk-w 20% -c 10% -p /dev/hda1

#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_load]=/usr/local/nagios/libexec/check_load-w 15,10,5 -c 30,25,20

command[check_mem]=/usr/local/nagios/libexec/check_memory.pl-w 10% -c 3%

command[check_disk]=/usr/local/nagios/libexec/check_disk-w 15% -c 7% -p /

command[check_swap]=/usr/local/nagios/libexec/check_swap-w 20% -c 10%

command[check_iostat]=/usr/local/nagios/libexec/check_iostat-w 6 -c 10

10、启动Nagiosclient nrpe守护进程

/usr/local/nagios/bin/nrpe -c/usr/local/nagios/etc/nrpe.cfg -d

netstat -lntup|grep nrpe

ps -ef |grep nrpe |grep -v grep

 

重启技巧(这里不用重启)

#pkill nrpe

#/usr/local/nagios/bin/nrpe-c /usr/local/nagios/etc/nrpe.cfg -d

 

11、加入开机自启

echo "#nagios nrpe process cmd by wangtian2016-5-22">>/etc/rc.local

echo "/usr/local/nagios/bin/nrpe -c/usr/local/nagios/etc/nrpe.cfg -d">>/etc/rc.local

tail -2 /etc/rc.local

三、Nagios服务器端监控

3.1修改主配置文件(新手不需要,需要的话自己加上去书上582页)

 

cp /usr/local/nagios/etc/nagios.cfg{,.ori}

vim /usr/local/nagios/etc/nagios.cfg +34

增加如下主机和服务的配置文件

cfg_file=/usr/local/nagios/etc/objects/hosts.cfg

cfg_file=/usr/local/nagios/etc/objects/services.cfg

cfg_dir=/usr/local/nagios/etc/objects/services/

然后注释下列

# Definitions for monitoring the local (Linux) host

#cfg_file=/usr/local/nagios/etc/objects/localhost.cfg

 

根据已有数据生成hosts.cfg

cd /usr/local/nagios/etc/objects/

head -51 localhost.cfg >hosts.cfg

chown -R nagios.nagios/usr/local/nagios/etc/objects/hosts.cfg

touch services.cfg

chown -R nagios.nagios /usr/local/nagios/etc/objects/services.cfg

mkdir services    

chown -R nagios.nagios/usr/local/nagios/etc/objects/services

ls -lrt

total 60

 

3配置Nagios服务器端监控项

1、定义要监控的Nagios客户端主机

cd /usr/local/nagios/etc/objects/

cp hosts.cfg{,.ori1}

egrep -v "#|^$" hosts.cfg.ori1 >hosts.cfg

vim hosts.cfg

检查

 

[root@m01 objects]# cat hosts.cfg

define host{

        use                     linux-server

       host_name               web01

        alias                   web01

       address                172.16.1.8

        }

define host{

        use                     linux-server

       host_name               web02

        alias                   web02

       address                 172.16.1.7

        }

define host{

        use                     linux-server

       host_name               backup

        alias                   backup

       address                172.16.1.41

        }

define host{

        use                     linux-server

       host_name               nfs01

        alias                   nfs01

        address                172.16.1.31

        }

define host{

        use                     linux-server

       host_name               db01

        alias                   db01

       address                 172.16.1.51

        }

define host{

        use                     linux-server

       host_name               lb01

        alias                   lb01

       address                172.16.1.5

        }

define host{

        use                     linux-server

       host_name               lb02

        alias                   lb02

       address                172.16.1.6

        }

define hostgroup{

       hostgroup_name  linux-servers

        alias           Linux Servers

       members        web01,web02,backup,nfs01,db01,lb01,lb02    

        }

 

2、配置services.cfg,定义要监控的资源服务

cp services.cfg{,.ori}

vim services.cfg

cat services.cfg                          

define service {

        use                         generic-service

       host_name                  web01,web02,backup,nfs01,db01,lb01,lb02

       service_description         DiskPartition

       check_command              check_nrpe!check_disk

        }

define service {

        use                         generic-service

       host_name                  web01,web02,backup,nfs01,db01,lb01,lb02

       service_description         SwapUseage

       check_command              check_nrpe!check_swap

        }

define service {

        use                         generic-service

       host_name                  web01,web02,backup,nfs01,db01,lb01,lb02

       service_description         MEMUseage

       check_command              check_nrpe!check_mem

        }

define service {

        use                         generic-service

       host_name                  web01,web02,backup,nfs01,db01,lb01,lb02

       service_description        Current Load

       check_command              check_nrpe!check_load

        }

define service {

        use                         generic-service

       host_name                  web01,web02,backup,nfs01,db01,lb01,lb02

       service_description         DiskIostat

       check_command              check_nrpe!check_iostat!5!11

        }

define service {

        use                         generic-service

       host_name                   web01,web02,backup,nfs01,db01,lb01,lb02

       service_description         PING

       check_command              check_ping!100.0,20%!500.0,60%

        }

         

3、调试hosts.cfgservice.cfg的所有配置

cp commands.cfg{,.ori}

vim commands.cfg

tail -5 commands.cfg

# 'check_nrpe' command definition

define command{

       command_name    check_nrpe

       command_line    $USER1$/check_nrpe-H $HOSTADDRESS$ -c $ARG1$

        }

         

4、权限问题

cd /usr/local/nagios/etc/            

sed -i 's#nagiosadmin#oldboy#g' cgi.cfg            

         

5、检查语法

/etc/init.d/nagioscheckconfig

出现OK就可以启动了

/etc/init.d/nagios start

如果已经启动了,就执行/etc/init.d/nagios reload

 

 

 

 

在网页输入服务器端IP/nagios就可以看到结果啦(请耐心等待5-10分钟)