Nagios 监控

一、Nagios服务器端安装

1、环境准备

1.1基础环境

[[email protected] yum.repos.d]# cat /etc/redhat-release

CentOS release 6.7 (Final)

[[email protected] yum.repos.d]# uname -r

2.6.32-573.el6.x86_64

[[email protected] 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

[[email protected] ~]# 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

[[email protected] ~]# cd /etc/yum.repos.d

[[email protected] yum.repos.d]# ls

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

CentOS-Debuginfo.repo  CentOS-Vault.repo

CentOS-fasttrack.repo  epel.repo

[[email protected] yum.repos.d]# /bin/mv CentOS-Base.repo  CentOS-Base.repo.oldboy.ori

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

[[email protected] 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 ~

[[email protected] ~]# echo‘export LC_ALL=C‘>>/etc/profile

[[email protected] ~]# tail -1/etc/profile

export LC_ALL=C

[[email protected] ~]# source/etc/profile

[[email protected] ~]# echo$LC_ALL

C

[[email protected] ~]# 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

关闭防火墙

[[email protected] ~]#/etc/init.d/iptables stop

[[email protected] ~]#/etc/init.d/iptables status

iptables: Firewall isnot running.

[[email protected] ~]# chkconfigiptables off

[[email protected] ~]# chkconfig--list iptables

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

关闭SElinux

[[email protected] ~]# sed -i‘s#SELINUX=enforcing#SELINUX=disabled#g‘ /etc/selinux/config

[[email protected] ~]#getenforce    查看

Disabled

[[email protected] ~]# setenforce0    临时生效

setenforce: SELinux isdisabled

[[email protected] ~]#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    ##Apache,PHP环境

rpm -qa mysql httpd php

(3个包)

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

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

[[email protected] ~]# 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

[[email protected] ~]#/usr/sbin/useradd nagios

[[email protected] ~]#/usr/sbin/useradd apache -M -s /sbin/nologin

useradd: user ‘apache‘already exists

[[email protected] ~]#/usr/sbin/groupadd nagcmd

[[email protected] ~]#/usr/sbin/usermod -a -G nagcmd nagios

[[email protected] ~]#/usr/sbin/usermod -a -G nagcmd apache

[[email protected] ~]# id -n -Gnagios

nagios nagcmd

[[email protected] ~]# id -n -Gapache

apache nagcmd

[[email protected] ~]#

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

mkdir -p /home/oldboy/tools/nagios

cd /home/oldboy/tools/nagios

rz

[[email protected] ~]# mkdir -p /home/oldboy/tools/nagios

[[email protected] ~]# cd /home/oldboy/tools/nagios/

[[email protected] 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 ′?

?[[email protected] nagios]# ll

total 7388

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

[[email protected] 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

[[email protected] 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服务

[[email protected] 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  ]

[[email protected] 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  ]

[[email protected] 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

[[email protected] httpd]# cd /home/oldboy/tools/nagios/

[[email protected] nagios]# pwd

/home/oldboy/tools/nagios

[[email protected] nagios]#tar xf nagios-3.5.1.tar.gz

[[email protected] 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

[[email protected] nagios]# cd nagios

[[email protected] nagios]#./configure --with-command-group=nagcmd

出现下面的说明编译成功

Review the options abovefor accuracy.  If they look okay,

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

[[email protected] nagios]# make all

出现这表示正常

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

Enjoy.

[[email protected] nagios]# make install

出现这表示成功了

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

[[email protected] 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 ***

[[email protected] 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.

[[email protected] 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)

[[email protected] 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 ***

[[email protected] nagios]# htpasswd -bc/usr/local/nagios/etc/htpasswd.users oldboy 123456

Adding password for useroldboy

重新加载Apache

[[email protected] nagios]# /etc/init.d/httpd reload

Reloading httpd:

[[email protected] nagios]#

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

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

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

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

[[email protected] tools]# tail -1 /etc/mail.rc

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

操作前先备份

[[email protected] nagios]# cp/usr/local/nagios/etc/objects/contacts.cfg{,.ori}

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

[[email protected] nagios]# sed-n ‘35p‘  /usr/local/nagios/etc/objects/contacts.cfg

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

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

[[email protected] 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就正常了

[[email protected] nagios]#/etc/init.d/httpd start

Starting httpd:

[[email protected] nagios]#/etc/init.d/httpd restart

Stopping httpd:                                           [  OK  ]

Starting httpd:                                            [ OK  ]

[[email protected] nagios]#chkconfig httpd on

[[email protected] 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(无内容就是正确的)

检查语法:

[[email protected] 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、基础环境

[[email protected] yum.repos.d]# cat /etc/redhat-release

CentOS release 6.7 (Final)

[[email protected] yum.repos.d]# uname -r

2.6.32-573.el6.x86_64

[[email protected] 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

检查

[[email protected] 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.cfg和service.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分钟)

时间: 2024-10-08 09:23:44

Nagios 监控的相关文章

Nagios监控Windows的网卡流量

Nagios监控Windows的网卡流量 使用/usr/local/nagios/libexec/中的check_traffic.sh,不但可以监控Linux的网卡流量,也可以监控Windows服务器的流量. 1 Check_traffic.sh用法用法 [[email protected] libexec]#/usr/local/nagios/libexec/check_traffic.sh -h Usage: ./check_traffic.sh [ -v ] [ -6 ] [ -r ] -

通过collectd工具获取虚拟机的nagios监控脚本简单例子

在宿主机上安装collectd工具后,可以通过collectd工具来获取宿主机上的虚拟机的cpu,memery,if-traffic等数据.可以通过nagios监控脚本来实现对这些数据监控. 以下是一个简单的监控虚拟机内存脚本: #!/bin/bash #Desc:to check memory about vm instance STATE_OK=0 STATE_WARNING=1 STATE_CRITICAL=2 STATE_UNKNOWN=3 COLLECTD_HOME=/usr/loca

Nagios监控系统

一.Nagios监控系统简介 1.Nagios工作原理 Nagios本身不包括监控主机和服务的功能.所有的监控.监测功能都是通过各种插件来完成的.安装完nagios之后,在nagios主目录下的/libexex里面放有nagios自带的插件,如:check_disk是检查磁盘空间的插件,check_load是检查cpu负载的插件,每一个插件可以通过运行./check_xxx -h命令来检查其使用方法和功能. 1.Nagios的四种监控状态 Nagios可以识别四种状态返回信息.0(OK)表示状态

Nagios监控远程主机

p.MsoNormal,li.MsoNormal,div.MsoNormal { margin: 0cm; margin-bottom: .0001pt; line-height: 150%; font-size: 13.5pt; font-family: "Calibri", "sans-serif" } h1 { margin-top: 17.0pt; margin-right: 0cm; margin-bottom: 16.5pt; margin-left:

Nagios监控系统主机与服务配置

配置环境: 监控服务器 :192.168.189.132 被监控客户端:192.168.189.131(linux) 192.168.1.152(windows) Nagios相关配置文件概述: # cd /usr/local/nagios/etc/   相关文件用途如下表: 文件名或目录名 用途 cgi.cfg 控制CGI访问的配置文件 nagios.cfg Nagios 主配置文件 resource.cfg 变量定义文件,又称为资源文件,在些文件中定义变量,以便由其他配置文件引用,如$USE

nagios监控详解(中小企业必备的监控设备) &lt;上&gt;

cacti和nagios 都是中小企业必备的监控软件,首先来一个回顾 cacti监控优缺点:主要是监控图形流量,通过web界面监控流量,(主要监控cpu内存硬盘,流量) 基于snmp(抓取数据)和rrdtool(rrdtool主要是将抓取的数据 绘制图像) nagios监控系统服务的,也能监控window,linux,unix的主机状态,不过主要还是监控系统服务. nagios监控客户端需要借助插件以及NRPE软件 [把之前写的一个关于cacti的博客地址也不要碧莲的贴出来]http://www

Nagios 监控系统架设全攻略

Nagios 全名为(Nagios Ain’t Goona Insist on Saintood),最初项目名字是 NetSaint.它是一款免费的开源 IT 基础设施监控系统,其功能强大,灵活性强,能有效监控 Windows .Linux.VMware 和 Unix 主机状态,交换机.路由器等网络设置等.一旦主机或服务状态出现异常时,会发出邮件或短信报警第一时间通知 IT 运营人员,在状态恢复后发出正常的邮件或短信通知.Nagios 结构简单,可维护性强,越来越受中小企业青睐,以及运维和管理人

nagios监控内出错NRPE: Unable to read output 解决!

 nagios监控内出错NRPE: Unable to read output 解决! 由于编写check_mem监控脚本,在监控机报警:NRPE: Unable to read output,其他监控项目正常 初步认定是nagios没有权限去实行check_mem脚本: 1.在监控主机监控客户机内存,遇到NRPE: Unable to read output # /usr/local/nagios/libexec/check_nrpe -H 1192.168.1.10 -c check_mem

nagios 监控 网卡流量 脚本

#!/bin/bash # #Time     : 2014-06-23 #Author   : ftlynx #Function : use NET-SNMP get NIC traffic on nagios. Usage(){ echo "Usage: check_traffic.sh [options]" echo "     -H     Host IP." echo "     -P     net-snmp community string.

nagios监控windows主机

一,编辑Nagios的主配置文件vi /usr/local/nagios/etc/nagios.cfg把下面这行最前面的#号去掉:#cfg_file=/usr/local/nagios/etc/objects/windows.cfg保存配置文件并退出.二,安装Windows代理程序  NSClient++外部构件1.从http://sourceforge.net/projects/nscplus站点下载最新稳定版的NSClient++软件包:2.解压软件包到一个目录下,如C:\\\\\\\\NS