Nagios 配置测试

Nagios 配置测试



Linux下Nagios的安装与配置
http://www.cnblogs.com/mchina/archive/2013/02/20/2883404.html

Nagios在线帮助中文版
http://nagios-cn.sourceforge.net/nagios-cn/index.html

Nagios--运维监控软件--简易安装与配置(已经在信工服务器实现)
http://www.cnblogs.com/sbaicl/archive/2012/09/12/2677268.html

Nagios官网,可以下载需要软件。包括nagios和nagios-plugins,nrpe两个插件软件包
https://www.nagios.org/



系统环境:
[root@localhost etc]# uname -a
Linux localhost.localdomain 2.6.18-194.el5 #1 SMP Fri Apr 2 14:58:35 EDT 2010 i686 athlon i386 GNU/Linux

[root@localhost objects]# ifconfig
eth0:0     inet addr:192.168.3.132  Bcast:192.168.3.255  Mask:255.255.255.0

虚拟系统是直接拷贝上次做的LAMP虚拟环境,这边就不重新安装apache,mysql,php了。

#tomcat版本
[root@localhost objects]# rpm -qa |grep  httpd
httpd-2.2.3-91.el5.centos
#php版本
[root@localhost objects]# rpm -qa |grep  php
php-mysql-5.1.6-45.el5_11
php-devel-5.1.6-45.el5_11
php-common-5.1.6-45.el5_11
php-5.1.6-45.el5_11
php-cli-5.1.6-45.el5_11
php-pdo-5.1.6-45.el5_11
#mysql版本
[root@localhost objects]# rpm -qa |grep  mysql
php-mysql-5.1.6-45.el5_11
mysql-5.0.95-5.el5_9
mysql-server-5.0.95-5.el5_9



目标:
nagios安装在192.168.3.132虚拟机上(使用现成的LAMP环境),然后监控本机和192.168.3.131、192.168.3.153虚拟机。


192.168.3.132虚拟机上开始
#创建nagios组
[root@localhost ~]# groupadd -g 1000 nagios

#创建nagios用户
[root@localhost ~]# useradd -m -u 1101 -g nagios -G nagios -d /home/nagios -s /bin/bash -c "nagios Software Owner" nagios

#创建文件夹
[root@localhost ~]# mkdir -p /usr/src/nagios
 
#文件夹分配权限
[root@localhost ~]# chown nagios:nagios /usr/src/nagios

[root@localhost ~]# chmod -R 775 /usr/src/nagios


#nagios用户设置密码
[root@localhost ~]# passwd nagios


#nagios依赖包的安装
[root@localhost ~]# yum -y install gd gd-devel openssl openssl-devel httpd php gcc glibc glibc-common make net-snmp wget

#nagios的安装,本次用nagios用户安装,不过试验表明应该用root用户安装比较好
[root@localhost ~]# su - nagios
[nagios@localhost ~]$ cd /mnt/hgfs/sharefiles/nagios/
[nagios@localhost nagios]$ ls
nagios-4.1.1.tar.gz  nagios-plugins-2.1.1.tar.gz
[nagios@localhost nagios]$ tar -xzf nagios-4.1.1.tar.gz  -C /usr/src/nagios/
[nagios@localhost nagios]$ cd /usr/src/nagios/
[nagios@localhost nagios]$ ls
nagios-4.1.1
[nagios@localhost nagios]$ cd ..
[nagios@localhost src]$ cd /mnt/hgfs/sharefiles/nagios/
[nagios@localhost nagios]$ tar -xzf nagios-plugins-2.1.1.tar.gz  -C /usr/src/nagios
[nagios@localhost nagios]$ cd /usr/src/nagios/
[nagios@localhost nagios]$ ls
nagios-4.1.1  nagios-plugins-2.1.1
[nagios@localhost nagios]$ 

#如果用root用户安装
[root@localhost nagios-4.1.1]  ./configure --with-nagios-user=nagios --with-nagios-group=nagios

#安装nagios
[nagios@localhost nagios-4.1.1]$ ./configure
checking for a BSD-compatible install... /usr/bin/install -c
checking build system type... i686-pc-linux-gnu
checking host system type... i686-pc-linux-gnu
checking for gcc... gcc
checking for C compiler default output file name... a.out
checking whether the C compiler works... yes
checking whether we are cross compiling... no
checking for suffix of executables... 
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether gcc accepts -g... yes
checking for gcc option to accept ISO C89... none needed
checking whether make sets $(MAKE)... yes
checking for strip... /usr/bin/strip
checking how to run the C preprocessor... gcc -E
checking for grep that handles long lines and -e... /bin/grep
checking for egrep... /bin/grep -E
checking for ANSI C header files... yes
checking whether time.h and sys/time.h may both be included... yes
checking for sys/wait.h that is POSIX.1 compatible... yes
checking for sys/types.h... yes
checking for sys/stat.h... yes
checking for stdlib.h... yes
checking for string.h... yes
checking for memory.h... yes
checking for strings.h... yes
checking for inttypes.h... yes
checking for stdint.h... yes
checking for unistd.h... yes
checking arpa/inet.h usability... yes
checking arpa/inet.h presence... yes
checking for arpa/inet.h... yes
checking ctype.h usability... yes
checking ctype.h presence... yes
checking for ctype.h... yes
checking dirent.h usability... yes
checking dirent.h presence... yes
checking for dirent.h... yes
checking errno.h usability... yes
checking errno.h presence... yes
checking for errno.h... yes
checking fcntl.h usability... yes
checking fcntl.h presence... yes
checking for fcntl.h... yes
checking getopt.h usability... yes
checking getopt.h presence... yes
checking for getopt.h... yes
checking grp.h usability... yes
checking grp.h presence... yes
checking for grp.h... yes
checking libgen.h usability... yes
checking libgen.h presence... yes
checking for libgen.h... yes
checking limits.h usability... yes
checking limits.h presence... yes
checking for limits.h... yes
checking math.h usability... yes
checking math.h presence... yes
checking for math.h... yes
checking netdb.h usability... yes
checking netdb.h presence... yes
checking for netdb.h... yes
checking netinet/in.h usability... yes
checking netinet/in.h presence... yes
checking for netinet/in.h... yes
checking pwd.h usability... yes
checking pwd.h presence... yes
checking for pwd.h... yes
checking regex.h usability... yes
checking regex.h presence... yes
checking for regex.h... yes
checking signal.h usability... yes
checking signal.h presence... yes
checking for signal.h... yes
checking socket.h usability... no
checking socket.h presence... no
checking for socket.h... no
checking stdarg.h usability... yes
checking stdarg.h presence... yes
checking for stdarg.h... yes
checking for string.h... (cached) yes
checking for strings.h... (cached) yes
checking sys/loadavg.h usability... no
checking sys/loadavg.h presence... no
checking for sys/loadavg.h... no
checking sys/mman.h usability... yes
checking sys/mman.h presence... yes
checking for sys/mman.h... yes
checking for sys/types.h... (cached) yes
checking sys/time.h usability... yes
checking sys/time.h presence... yes
checking for sys/time.h... yes
checking sys/resource.h usability... yes
checking sys/resource.h presence... yes
checking for sys/resource.h... yes
checking for sys/wait.h... (cached) yes
checking sys/socket.h usability... yes
checking sys/socket.h presence... yes
checking for sys/socket.h... yes
checking for sys/stat.h... (cached) yes
checking sys/timeb.h usability... yes
checking sys/timeb.h presence... yes
checking for sys/timeb.h... yes
checking sys/un.h usability... yes
checking sys/un.h presence... yes
checking for sys/un.h... yes
checking sys/ipc.h usability... yes
checking sys/ipc.h presence... yes
checking for sys/ipc.h... yes
checking sys/msg.h usability... yes
checking sys/msg.h presence... yes
checking for sys/msg.h... yes
checking sys/poll.h usability... yes
checking sys/poll.h presence... yes
checking for sys/poll.h... yes
checking syslog.h usability... yes
checking syslog.h presence... yes
checking for syslog.h... yes
checking uio.h usability... no
checking uio.h presence... no
checking for uio.h... no
checking for unistd.h... (cached) yes
checking locale.h usability... yes
checking locale.h presence... yes
checking for locale.h... yes
checking wchar.h usability... yes
checking wchar.h presence... yes
checking for wchar.h... yes
checking for an ANSI C-conforming const... yes
checking whether struct tm is in sys/time.h or time.h... time.h
checking for struct tm.tm_zone... yes
checking for mode_t... yes
checking for pid_t... yes
checking for size_t... yes
checking return type of signal handlers... void
checking for uid_t in sys/types.h... yes
checking type of array argument to getgroups... gid_t
checking for va_copy... yes
checking for vsnprintf... yes
checking for snprintf... yes
checking for asprintf... yes
checking for vasprintf... yes
checking for C99 vsnprintf... yes
checking for library containing getservbyname... none required
checking for library containing connect... none required
checking for initgroups... yes
checking for setenv... yes
checking for strdup... yes
checking for strstr... yes
checking for strtoul... yes
checking for unsetenv... yes
checking for type of socket size... size_t
checking for library containing nanosleep... none required
checking for mail... /bin/mail
checking for glibc at least version 2.4... yes
checking sys/epoll.h usability... yes
checking sys/epoll.h presence... yes
checking for sys/epoll.h... yes
checking sys/select.h usability... yes
checking sys/select.h presence... yes
checking for sys/select.h... yes
checking for main in -liconv... no
checking for gdImagePng in -lgd (order 1)... no
checking for gdImagePng in -lgd (order 2)... yes
GD library was found!
checking for gdImageCreateTrueColor in -lgd... yes
checking ltdl.h usability... no
checking ltdl.h presence... no
checking for ltdl.h... no
checking dlfcn.h usability... yes
checking dlfcn.h presence... yes
checking for dlfcn.h... yes
checking for dlopen in -ldl... yes
checking for extra flags needed to export symbols...  -Wl,-export-dynamic
checking for linker flags for loadable modules... -shared
checking for traceroute... /bin/traceroute
checking for type va_list... yes
checking for perl... /usr/bin/perl
configure: creating ./config.status
config.status: creating Makefile
config.status: creating lib/Makefile
config.status: creating subst
config.status: creating pkginfo
config.status: creating base/Makefile
config.status: creating common/Makefile
config.status: creating contrib/Makefile
config.status: creating cgi/Makefile
config.status: creating html/Makefile
config.status: creating module/Makefile
config.status: creating worker/Makefile
config.status: creating worker/ping/Makefile
config.status: creating xdata/Makefile
config.status: creating daemon-init
config.status: creating t/Makefile
config.status: creating t-tap/Makefile
config.status: creating include/config.h
config.status: creating lib/snprintf.h
config.status: creating lib/iobroker.h

Creating sample config files in sample-config/ ...

*** Configuration summary for nagios 4.1.1 08-19-2015 ***:

 General Options:
 -------------------------
        Nagios executable:  nagios
        Nagios user/group:  nagios,nagios
       Command user/group:  nagios,nagios
             Event Broker:  yes
        Install ${prefix}:  /usr/local/nagios
    Install ${includedir}:  /usr/local/nagios/include/nagios
                Lock file:  ${prefix}/var/nagios.lock
   Check result directory:  ${prefix}/var/spool/checkresults
           Init directory:  /etc/rc.d/init.d
  Apache conf.d directory:  /etc/httpd/conf.d
             Mail program:  /bin/mail
                  Host OS:  linux-gnu
          IOBroker Method:  epoll

 Web Interface Options:
 ------------------------
                 HTML URL:  http://localhost/nagios/
                  CGI URL:  http://localhost/nagios/cgi-bin/
 Traceroute (used by WAP):  /bin/traceroute

Review the options above for accuracy.  If they look okay,
type 'make all' to compile the main program and CGIs.

[nagios@localhost nagios-4.1.1]$ make


#太多了,省略中间的编译过程
*** Compile finished ***


If the main program and CGIs compiled without any errors, you
can continue with installing Nagios as follows (type 'make'
without any arguments for a list of all possible options):


  make install
     - This installs the main program, CGIs, and HTML files


  make install-init
     - This installs the init script in /etc/rc.d/init.d


  make install-commandmode
     - This installs and configures permissions on the
       directory for holding the external command file


  make install-config
     - This installs *SAMPLE* config files in /usr/local/nagios/etc
       You'll have to modify these sample files before you can
       use Nagios.  Read the HTML documentation for more info
       on doing this.  Pay particular attention to the docs on
       object configuration files, as they determine what/how
       things get monitored!


  make install-webconf
     - This installs the Apache config file for the Nagios
       web interface


  make install-exfoliation
     - This installs the Exfoliation theme for the Nagios
       web interface


  make install-classicui
     - This installs the classic theme for the Nagios
       web interface




*** Support Notes *******************************************


If you have questions about configuring or running Nagios,
please make sure that you:


     - Look at the sample config files
     - Read the documentation on the Nagios Library at:
           https://library.nagios.com


before you post a question to one of the mailing lists.
Also make sure to include pertinent information that could
help others help you.  This might include:


     - What version of Nagios you are using
     - What version of the plugins you are using
     - Relevant snippets from your config files
     - Relevant error messages from the Nagios log file


For more information on obtaining support for Nagios, visit:


       https://support.nagios.com


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


Enjoy.


[nagios@localhost nagios-4.1.1]$ 


[nagios@localhost nagios-4.1.1]$ make install
cd ./base && make install
make[1]: Entering directory `/usr/src/nagios/nagios-4.1.1/base'
make install-basic
make[2]: Entering directory `/usr/src/nagios/nagios-4.1.1/base'
/usr/bin/install -c -m 775 -o nagios -g nagios -d /usr/local/nagios/bin
/usr/bin/install: cannot create directory `/usr/local/nagios': Permission denied
make[2]: *** [install-basic] Error 1
make[2]: Leaving directory `/usr/src/nagios/nagios-4.1.1/base'
make[1]: *** [install] Error 2
make[1]: Leaving directory `/usr/src/nagios/nagios-4.1.1/base'
make: *** [install] Error 2



#报没有权限创建文件,干脆切换到root用户进行安装
#安装主程序,CGI及HTML文件
[root@localhost nagios-4.1.1]# make install

#安装启动脚本
[root@localhost nagios-4.1.1]# make install-init
/usr/bin/install -c -m 755 -d -o root -g root /etc/rc.d/init.d
/usr/bin/install -c -m 755 -o root -g root daemon-init /etc/rc.d/init.d/nagios


*** Init script installed ***


#安装与配置目录权限
[root@localhost nagios-4.1.1]# make install-commandmode
/usr/bin/install -c -m 775 -o nagios -g nagios -d /usr/local/nagios/var/rw
chmod g+s /usr/local/nagios/var/rw


*** External command directory configured ***


#安装配置文件模板
[root@localhost nagios-4.1.1]# make install-config
/usr/bin/install -c -m 775 -o nagios -g nagios -d /usr/local/nagios/etc
/usr/bin/install -c -m 775 -o nagios -g nagios -d /usr/local/nagios/etc/objects
/usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/nagios.cfg /usr/local/nagios/etc/nagios.cfg
/usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/cgi.cfg /usr/local/nagios/etc/cgi.cfg
/usr/bin/install -c -b -m 660 -o nagios -g nagios sample-config/resource.cfg /usr/local/nagios/etc/resource.cfg
/usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/template-object/templates.cfg /usr/local/nagios/etc/objects/templates.cfg
/usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/template-object/commands.cfg /usr/local/nagios/etc/objects/commands.cfg
/usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/template-object/contacts.cfg /usr/local/nagios/etc/objects/contacts.cfg
/usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/template-object/timeperiods.cfg /usr/local/nagios/etc/objects/timeperiods.cfg
/usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/template-object/localhost.cfg /usr/local/nagios/etc/objects/localhost.cfg
/usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/template-object/windows.cfg /usr/local/nagios/etc/objects/windows.cfg
/usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/template-object/printer.cfg /usr/local/nagios/etc/objects/printer.cfg
/usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/template-object/switch.cfg /usr/local/nagios/etc/objects/switch.cfg


*** Config files installed ***


Remember, these are *SAMPLE* config files.  You'll need to read
the documentation for more information on how to actually define
services, hosts, etc. to fit your particular needs.

#安装ngios插件
[root@localhost nagios-4.1.1]# make install-webconf
/usr/bin/install -c -m 644 sample-config/httpd.conf /etc/httpd/conf.d/nagios.conf


*** Nagios/Apache conf file installed ***


[root@localhost nagios-4.1.1]# cd ..
[root@localhost nagios]# ls
nagios-4.1.1  nagios-plugins-2.1.1
[root@localhost nagios]# cd nagios-plugins-2.1.1/
[root@localhost nagios-plugins-2.1.1]# 

#安装nagios-plugins
[root@localhost nagios-plugins-2.1.1]# ./configure --prefix=/usr/local/nagios/

[root@localhost nagios-plugins-2.1.1]# make

[root@localhost nrpe-2.15]# make install


#安装nrpe
[root@localhost nagios-plugins-2.1.1]# cd ..
[root@localhost nagios]# ls
nagios-4.1.1  nagios-plugins-2.1.1  nrpe-2.15
[root@localhost nagios]# cd nrpe-2.15/


[root@localhost nrpe-2.15]# ./configure


....
*** Configuration summary for nrpe 2.15 09-06-2013 ***:


 General Options:
 -------------------------
 NRPE port:    5666
 NRPE user:    nagios
 NRPE group:   nagios
 Nagios user:  nagios
 Nagios group: nagios


Review the options above for accuracy.  If they look okay,
type 'make all' to compile the NRPE daemon and client.


[root@localhost nrpe-2.15]# make all

[root@localhost nrpe-2.15]# make install-plugin

[root@localhost nrpe-2.15]# make install-daemon
cd ./src/ && make install-daemon
make[1]: Entering directory `/usr/src/nagios/nrpe-2.15/src'
/usr/bin/install -c -m 775 -o nagios -g nagios -d /usr/local/nagios/bin
/usr/bin/install -c -m 775 -o nagios -g nagios nrpe /usr/local/nagios/bin
make[1]: Leaving directory `/usr/src/nagios/nrpe-2.15/src'

[root@localhost nrpe-2.15]# make install-daemon-config
/usr/bin/install -c -m 775 -o nagios -g nagios -d /usr/local/nagios/etc
/usr/bin/install -c -m 644 -o nagios -g nagios sample-config/nrpe.cfg /usr/local/nagios/etc

[root@localhost nrpe-2.15]# make install-xinetd
/usr/bin/install -c -m 644 sample-config/nrpe.xinetd /etc/xinetd.d/nrpe 

[root@localhost nrpe-2.15]# chown -R nagios.nagios /usr/local/nagios
[root@localhost nrpe-2.15]# setenforce 0
[root@localhost nrpe-2.15]# sed -i 's/=enforcing/=permissive/' /etc/sysconfig/selinux



#关闭防火墙
[root@localhost nrpe-2.15]# vi /etc/selinux/config 
# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
#       enforcing - SELinux security policy is enforced.
#       permissive - SELinux prints warnings instead of enforcing.
#       disabled - SELinux is fully disabled.
#SELINUX=permissive
SELINUX=disabled          #设置为disabled
# SELINUXTYPE= type of policy in use. Possible values are:
#       targeted - Only targeted network daemons are protected.
#       strict - Full SELinux protection.
SELINUXTYPE=targeted


"/etc/selinux/config" 11L, 467C written


#如果不关闭防火墙
[root@localhost] iptables -I INPUT -p tcp --dport 80 -j ACCEPT
[root@localhost] service iptables server


#设置密码
[root@localhost nrpe-2.15]# htpasswd -c /usr/local/nagios/etc/htpasswd.users tomcat
New password: 
Re-type new password: 
Adding password for user tomcat

用户名:tomcat
密码:


[root@localhost nrpe-2.15]# 


#验证是否正确安装,nagios安装完成后,在/nsr/local/nagios目录下会生成若干子目录。
[root@localhost nrpe-2.15]# cd /usr/local/nagios
[root@localhost nagios]# ls
bin  etc  include  libexec  sbin  share  var


#启动服务:
[root@localhost nrpe-2.15]# /etc/init.d/httpd start
Starting httpd:                                            [  OK  ]

[root@localhost nrpe-2.15]# /etc/init.d/nagios start
Starting nagios: done.

[root@localhost nrpe-2.15]# chkconfig httpd on
[root@localhost nrpe-2.15]# chkconfig --add nagios
[root@localhost nrpe-2.15]# chkconfig nagios on

#附:centos Apache、php、mysql默认安装路径
apache:
 如果采用RPM包安装,安装路径应在 /etc/httpd目录下
 apache配置文件:/etc/httpd/conf/httpd.conf
 Apache模块路径:/usr/sbin/apachectl
 web目录:/var/www/html
 如果采用源代码安装,一般默认安装在/usr/local/apache2目录下
 php:
 如果采用RPM包安装,安装路径应在 /etc/目录下
 php的配置文件:/etc/php.ini
 如果采用源代码安装,一般默认安装在/usr/local/lib目录下
 php配置文件: /usr/local/lib/php.ini
 或/usr/local/php/etc/php.ini
 mysql:
 如果采用RPM包安装,安装路径应在/usr/share/mysql目录下
 mysqldump文件位置:/usr/bin/mysqldump
 mysqli配置文件:
 /etc/my.cnf或/usr/share/mysql/my.cnf
 mysql数据目录在/var/lib/mysql目录下
 如果采用源代码安装,一般默认安装在/usr/local/mysql目录下


[root@localhost conf]# pwd
/etc/httpd/conf

#修改Apache的配置
[root@localhost conf]# vi httpd.conf

配置apache 
找到apache 的配置文件/usr/local/apache2/conf/httpd.conf 
找到:
User daemon 
Group daemon 
修改为 
User nagios 
Group nagios 
然后找到 

<IfModule dir_module> 
  DirectoryIndex index.html 
</IfModule> 
修改为 

<IfModule dir_module> 
  DirectoryIndex index.html index.php 
</IfModule> 
接着增加如下内容: 
AddType application/x-httpd-php .php 




#nagios配置

[root@localhost conf]# cd /usr/local/nagios/etc
[root@localhost etc]# ls
cgi.cfg  htpasswd.users  nagios.cfg  nrpe.cfg  objects  resource.cfg


#添加用于监控两台oracle虚拟机,oracle1.cfg和oracle2.cfg需要手工生成,后面会处理的
[root@localhost etc]# vi nagios.cfg
# Definitions for monitoring the local (Linux) host 192.168.3.131
cfg_file=/usr/local/nagios/etc/objects/oracle1.cfg

# Definitions for monitoring the local (Linux) host 192.168.3.150
cfg_file=/usr/local/nagios/etc/objects/oracle2.cfg


#将访问WEB页面的账号(tomcat)加进去
[root@localhost etc]# vi cgi.cfg

# REFRESH RATE
# This option allows you to specify the refresh rate in seconds
# of various CGIs (status, statusmap, extinfo, and outages).

refresh_rate=90
:?authorized_for_system_information
# SYSTEM/PROCESS INFORMATION ACCESS
# This option is a comma-delimited list of all usernames that
# have access to viewing the Nagios process information as
# provided by the Extended Information CGI (extinfo.cgi).  By
# default, *no one* has access to this unless you choose to
# not use authorization.  You may use an asterisk (*) to
# authorize any user who has authenticated to the web server.

authorized_for_system_information=nagiosadmin,tomcat

# CONFIGURATION INFORMATION ACCESS
# This option is a comma-delimited list of all usernames that
# can view ALL configuration information (hosts, commands, etc).
# By default, users can only view configuration information
# for the hosts and services they are contacts for. You may use
# an asterisk (*) to authorize any user who has authenticated
# to the web server.

authorized_for_configuration_information=nagiosadmin,tomcat

# SYSTEM/PROCESS COMMAND ACCESS
# This option is a comma-delimited list of all usernames that
# can issue shutdown and restart commands to Nagios via the
# command CGI (cmd.cgi).  Users in this list can also change
# the program mode to active or standby. By default, *no one*
# has access to this unless you choose to not use authorization.
# You may use an asterisk (*) to authorize any user who has
# authenticated to the web server.

authorized_for_system_commands=nagiosadmin,tomcat

# GLOBAL HOST/SERVICE VIEW ACCESS
# These two options are comma-delimited lists of all usernames that
# can view information for all hosts and services that are being
# monitored.  By default, users can only view information
# for hosts or services that they are contacts for (unless you
# you choose to not use authorization). You may use an asterisk (*)
# to authorize any user who has authenticated to the web server.

authorized_for_all_services=nagiosadmin,tomcat
authorized_for_all_hosts=nagiosadmin,tomcat

# GLOBAL HOST/SERVICE COMMAND ACCESS
# These two options are comma-delimited lists of all usernames that
# can issue host or service related commands via the command
# CGI (cmd.cgi) for all hosts and services that are being monitored.
# By default, users can only issue commands for hosts or services
# that they are contacts for (unless you you choose to not use
# authorization).  You may use an asterisk (*) to authorize any
# user who has authenticated to the web server.

authorized_for_all_service_commands=nagiosadmin,tomcat
authorized_for_all_host_commands=nagiosadmin,tomcat


[root@localhost objects]# cd objects/
[root@localhost objects]# ls
commands.cfg  localhost.cfg  switch.cfg     timeperiods.cfg
contacts.cfg  printer.cfg    templates.cfg  windows.cfg

#修改命令配置文件
[root@localhost objects]# vi commands.cfg 
# 'nrpe' command definition
define command{
        command_name    check_nrpe
        command_line    $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$ 
        }


#修改nrpe配置文件
[root@localhost etc]# pwd
/usr/local/nagios/etc
[root@localhost etc]# vi nrpe.cfg 

#add
command[check_disk]=/usr/local/nagios/libexec/check_disk -w 20% -c 10%


#创建远程监控配置文件oracle1.cfg 和 oracle2.cfg,用localhost.cfg作为参考模板。
[root@localhost objects]# pwd
/usr/local/nagios/etc/objects
[root@localhost objects]# ls
commands.cfg  localhost.cfg    switch.cfg     timeperiods.cfg
contacts.cfg     printer.cfg  templates.cfg  windows.cfg

[root@localhost objects]# cp localhost.cfg oracle1.cfg

#修改host_name,address,hostgroup_name
#这里去掉部分注释
[root@localhost objects]# vi oracle1.cfg 

[root@localhost objects]# cat oracle1.cfg
# Define a host for the local machine
define host{
        use                     linux-server            ; Name of host template to use
                                                        ; This host definition will inherit all variables that are defined
                                                        ; in (or inherited by) the linux-server host template definition.
        host_name               oracle1
        alias                   localhost
        address                 192.168.3.131
        }

# Define an optional hostgroup for Linux machines
#oracle2.cfg 这部分需要注释掉,hostgroup不能重复定义
define hostgroup{
        hostgroup_name  generic-servers ; The name of the hostgroup
        alias           Linux Servers ; Long name of the group
        members         localhost     ; Comma separated list of hosts that belong to this group
        }

# Define a service to "ping" the local machine
define service{
        use                             local-service         ; Name of service template to use
        host_name                       oracle1
        service_description             PING
        check_command                   check_ping!100.0,20%!500.0,60%
        }

# Define a service to check the disk space of the root partition
# on the local machine.  Warning if < 20% free, critical if
# < 10% free space on partition.
define service{
        use                             local-service         ; Name of service template to use
        host_name                       oracle1
        service_description             Root Partition
        check_command                   check_local_disk!20%!10%!/
        }

# Define a service to check the number of currently logged in
# users on the local machine.  Warning if > 20 users, critical
# if > 50 users.
define service{
        use                             local-service         ; Name of service template to use
        host_name                       oracle1
        service_description             Current Users
        check_command                   check_local_users!20!50
        }

# Define a service to check the number of currently running procs
# on the local machine.  Warning if > 250 processes, critical if
# > 400 users.
define service{
        use                             local-service         ; Name of service template to use
        host_name                       oracle1
        service_description             Total Processes
        check_command                   check_local_procs!250!400!RSZDT
        }

# Define a service to check the load on the local machine. 
define service{
        use                             local-service         ; Name of service template to use
        host_name                       oracle1
        service_description             Current Load
        check_command                   check_local_load!5.0,4.0,3.0!10.0,6.0,4.0
        }

# Define a service to check the swap usage the local machine. 
# Critical if less than 10% of swap is free, warning if less than 20% is free
define service{
        use                             local-service         ; Name of service template to use
        host_name                       oracle1
        service_description             Swap Usage
        check_command                   check_local_swap!20!10
        }

# Define a service to check SSH on the local machine.
# Disable notifications for this service by default, as not all users may have SSH enabled.
define service{
        use                             local-service         ; Name of service template to use
        host_name                       oracle1
        service_description             SSH
        check_command                   check_ssh
        notifications_enabled           0
        }

# Define a service to check HTTP on the local machine.
# Disable notifications for this service by default, as not all users may have HTTP enabled.
define service{
        use                             local-service         ; Name of service template to use
        host_name                       oracle1
        service_description             HTTP
        check_command                   check_http
        notifications_enabled           0
        }


#这里要注意,需要注释掉hostgroup_name,后面有详细说明
[root@localhost objects]# cp oracle1.cfg oracle2.cfg
[root@localhost objects]# vi oracle2.cfg 


#检查nagios配置
[root@localhost etc]# /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg

#出现错误,Duplicate definition found for hostgroup 'linux-servers',提示在oracle2.cfg文件中hostgroup重复定义了
[root@localhost objects]# /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
Nagios Core 4.1.1
Copyright (c) 2009-present Nagios Core Development Team and Community Contributors
Copyright (c) 1999-2009 Ethan Galstad
Last Modified: 08-19-2015
License: GPL

Website: https://www.nagios.org
Reading configuration data...
   Read main config file okay...
Warning: Duplicate definition found for hostgroup 'generic-servers' (config file '/usr/local/nagios/etc/objects/oracle2.cfg', starting on line 45)
Error: Could not add object property in file '/usr/local/nagios/etc/objects/oracle2.cfg' on line 46.
   Error processing object config files!

***> One or more problems was encountered while processing the config files...

     Check your configuration file(s) to ensure that they contain valid
     directives and data defintions.  If you are upgrading from a previous
     version of Nagios, you should be aware that some variables/definitions
     may have been removed or modified in this version.  Make sure to read
     the HTML documentation regarding the config files, as well as the
     'Whats New' section to find out what has changed.

#注释掉oracle2.cfg中的hostgroup定义

# Define an optional hostgroup for Linux machines


#define hostgroup{
#        hostgroup_name  generic-servers ; The name of the hostgroup
#        alias           Linux Servers ; Long name of the group
#        members         localhost     ; Comma separated list of hosts that belong to this group
#        }

#再次检查
[root@localhost objects]# /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
Nagios Core 4.1.1
Copyright (c) 2009-present Nagios Core Development Team and Community Contributors
Copyright (c) 1999-2009 Ethan Galstad
Last Modified: 08-19-2015
License: GPL

Website: https://www.nagios.org
Reading configuration data...
   Read main config file okay...
   Read object config files okay...

Running pre-flight check on configuration data...

Checking objects...
        Checked 24 services.
        Checked 3 hosts.
        Checked 2 host groups.
        Checked 0 service groups.
        Checked 1 contacts.
        Checked 1 contact groups.
        Checked 25 commands.
        Checked 5 time periods.
        Checked 0 host escalations.
        Checked 0 service escalations.
Checking for circular paths...
        Checked 3 hosts
        Checked 0 service dependencies
        Checked 0 host dependencies
        Checked 5 timeperiods
Checking global event handlers...
Checking obsessive compulsive processor commands...
Checking misc settings...

Total Warnings: 0
Total Errors:   0

Things look okay - No serious problems were detected during the pre-flight check


#重启nagios
[root@localhost objects]# /etc/init.d/nagios restart
Running configuration check...
Stopping nagios: done.
Starting nagios: done.


#重启Nagios
当修改了配置文件让其生效时,需要重启/重载Nagios服务。
a. 通过初始化脚本关闭nagios服务
# /etc/init.d/nagios stop
or
# service nagios stop
b. 通过web监控页停止nagios
还可以通过web监控页的 "Process Info" -> "Shutdown the Nagios process"来停止nagios


//--------------------------配置客户端,即被监控主机------------------------------------//
192.168.3.131虚拟机
[root@localhost ~]# yum -y install opensel openssl-devel
[root@localhost ~]# groupadd nagios
[root@localhost ~]# useradd -g nagios -s /sbin/nologin nagios
[root@localhost ~]# mkdir /usr/src/nagios
[root@localhost ~]# cd /mnt/hgfs/sharefiles/nagios/
[root@localhost nagios]# ls
nagios-4.1.1.tar.gz  nagios-plugins-2.1.1.tar.gz  nrpe-2.15.tar.gz
[root@localhost nagios]# tar -xzf nagios-plugins-2.1.1.tar.gz  -C /usr/src/nagios
[root@localhost nagios]# tar -xzf nrpe-2.15.tar.gz -C /usr/src/nagios/
[root@localhost nagios]# cd /usr/src/nagios
[root@localhost nagios]# ls
nagios-plugins-2.1.1  nrpe-2.15
[root@localhost nagios]# cd nagios-plugins-2.1.1/
[root@localhost nagios-plugins-2.1.1]# ./configure --with-nagios-user=nagios --with-nagios-group=nagios --prefix=/usr/local/nagios
[root@localhost nagios-plugins-2.1.1]# make
[root@localhost nagios-plugins-2.1.1]# make install
[root@localhost nagios-plugins-2.1.1]# chown -R nagios.nagios /usr/local/nagios
[root@localhost nagios-plugins-2.1.1]# cd ..
[root@localhost nagios]# cd nrpe-2.15/
[root@localhost nrpe-2.15]# ./configure
[root@localhost nrpe-2.15]# make all
[root@localhost nrpe-2.15]# make install-plugin
[root@localhost nrpe-2.15]# make install-daemon
[root@localhost nrpe-2.15]# make install-daemon-config
#编辑NRPE配置文件
[root@localhost nrpe-2.15]# cd /usr/local/nagios/etc
[root@localhost etc]# ls
nrpe.cfg
[root@localhost etc]# vi nrpe.cfg 
#修改allowed_hosts
allowed_hosts=127.0.0.1,192.168.3.132
#增加下面的command[check_disk]
command[check_disk]=/usr/local/nagios/libexec/check_disk -w 20% -c 10%


[root@localhost etc]# /usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d

[root@localhost etc]# echo "/usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d" >> /etc/rc.local

[root@localhost etc]# netstat -nutlp | grep 5666
tcp        0      0 0.0.0.0:5666                0.0.0.0:*                   LISTEN      26795/nrpe          
tcp        0      0 :::5666                     :::*                        LISTEN      26795/nrpe          

[root@localhost etc]# 


#关闭防火墙:
[root@localhost etc]# vi /etc/selinux/config 

SELINUX=disabled   


#如果不关闭防火墙:
[root@localhost etc]# iptables -I INPUT -p tcp --dport 5666 -j ACCEPT
[root@localhost etc]# service iptables save



192.168.3.153虚拟机
[root@localhost ~]# yum -y install opensel openssl-devel
[root@localhost ~]# groupadd nagios
[root@localhost ~]# useradd -g nagios -s /sbin/nologin nagios
[root@localhost ~]# mkdir /usr/src/nagios
[root@localhost ~]# cd /mnt/hgfs/sharefiles/nagios/
[root@localhost nagios]# ls
nagios-4.1.1.tar.gz  nagios-plugins-2.1.1.tar.gz  nrpe-2.15.tar.gz
[root@localhost nagios]# tar -xzf nagios-plugins-2.1.1.tar.gz  -C /usr/src/nagios
[root@localhost nagios]# tar -xzf nrpe-2.15.tar.gz -C /usr/src/nagios/
[root@localhost nagios]# cd /usr/src/nagios
[root@localhost nagios]# ls
nagios-plugins-2.1.1  nrpe-2.15
[root@localhost nagios]# cd nagios-plugins-2.1.1/
[root@localhost nagios-plugins-2.1.1]# make
[root@localhost nagios-plugins-2.1.1]# make install
[root@localhost nagios-plugins-2.1.1]# chown -R nagios.nagios /usr/local/nagios
[root@localhost nagios-plugins-2.1.1]# cd ..
[root@localhost nagios]# cd nrpe-2.15/
[root@localhost nrpe-2.15]# ./configure
[root@localhost nrpe-2.15]# make all
[root@localhost nrpe-2.15]# make install-plugin
[root@localhost nrpe-2.15]# make install-daemon
[root@localhost nrpe-2.15]# make install-daemon-config
#编辑NRPE配置文件
[root@localhost nrpe-2.15]# cd /usr/local/nagios/etc
[root@localhost etc]# ls
nrpe.cfg
[root@localhost etc]# vi nrpe.cfg 
#修改allowed_hosts
allowed_hosts=127.0.0.1,192.168.3.132
#增加下面的command[check_disk]
command[check_disk]=/usr/local/nagios/libexec/check_disk -w 20% -c 10%

[root@localhost etc]# /usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d

[root@localhost etc]# echo "/usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d" >> /etc/rc.local

[root@localhost etc]# netstat -nutlp | grep 5666
tcp        0      0 0.0.0.0:5666                0.0.0.0:*                   LISTEN      26795/nrpe          
tcp        0      0 :::5666                     :::*                        LISTEN      26795/nrpe          

#关闭防火墙:
[root@localhost etc]# vi /etc/selinux/config 

SELINUX=disabled   

#如果不关闭防火墙:

[root@localhost etc]# iptables -I INPUT -p tcp --dport 5666 -j ACCEPT
[root@localhost etc]# service iptables save


上图:








---END

测试结束,下次说数据库试验时可以用来看看性能。
不过机器上开三个虚拟机,要是再开数据库,估计跑起来会比较卡。





  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值