########################################################################

一、安装nagios服务端安装

  1.修改机器名字,设置yum源,关闭防火墙,selinux,后面根据实际情况开启,我这用的163的源

  cd /etc/yum.repos.d

  

  mv CentOS-Base.repo CentOS-Base.repo.backup


  wget http://mirrors.163.com/.help/CentOS6-Base-163.repo


  mv CentOS6-Base-163.repo CentOS-Base.repo


  yum clean all

  

  2.解决perl编译问题

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

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

   [root@master ~]# echo $LC_ALL

  

  3.解决系统时间同步

   [root@master ~]# echo '*/10 * * * * /usr/sbin/ntpdate pool.ntp.org >/dev/null 2>&1' >/var/spool/cron/root 

   [root@master ~]# crontab -l

    */10 * * * * /usr/sbin/ntpdate pool.ntp.org >/dev/null 2>&1

   [root@master ~]# 

   

  4.安装nagios所需基础软件包

   [root@master ~]# yum install gcc glibc* gd* httpd php*


  5.添加nagios需要的用户及用户组

  [root@master ~]# /usr/sbin/useradd -m nagios

  [root@master ~]# /usr/sbin/useradd apache

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

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

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

   检查所属的用户及用户组

  [root@master ~]# id -n -G nagios

     nagios nagcmd

  [root@master ~]# id -n -G apache

     apache nagcmd

  [root@master ~]# 

  

  6.下载nagios源码

    https://www.nagios.org/downloads/nagios-core/thanks/

    https://www.nagios.org/downloads/nagios-plugins/

  

  7.开始安装

     (1)创建目录并上传包

[root@master ~]# mkdir -p /home/tangbo/tools/nagios

[root@master nagios]# ls

     nagios-4.1.1.tar.gz  nagios-plugins-2.1.1.tar.gz

 

    (2)开始解压

[root@master nagios]# tar -zxvf nagios-4.1.1.tar.gz

[root@master nagios]# cd nagios-4.1.1

    (3)开始编译及安装

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

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.  这样提示表示正确了

[root@master nagios-4.1.1]# make all

For more information on obtaining support for Nagios, visit:


       https://support.nagios.com


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


    Enjoy.   最后有Enjoy.表示编译正常

[root@master nagios-4.1.1]# make install

    (4)继续安装初始化

 [root@master nagios-4.1.1]# make install-init         这个表示安装初始化脚本

 [root@master nagios-4.1.1]# make install-commandmode   安装命令模式

 [root@master nagios-4.1.1]# make install-config        安装样例配置文件

 

   8.安装nagios web配置文件及创建登陆用户

    [root@master 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@master nagios-4.1.1]# 


  9.创建nagios web监控界面登陆时需要的用户名(唐波)及其密码

   [root@master nagios-4.1.1]# htpasswd -c /usr/local/nagios/etc/htpasswd.users tangbo

    New password: 

    Re-type new password: 

    Adding password for user tangbo

   [root@master nagios-4.1.1]# 

   [root@master nagios-4.1.1]# cat /usr/local/nagios/etc/htpasswd.users 

    tangbo:7mdQ02yZfJLjQ

   [root@master nagios-4.1.1]# 

   

  10.添加监控报警的接收email地址 

    [root@master nagios-4.1.1]# vim /usr/local/nagios/etc/objects/contacts.cfg +35

lt values from generic-contact template (defined above)

        alias                           Nagios Admin            ; Full name of user


        email                           79313760@qq.com  ; <<***** CHANGE THIS TO YOUR EMAIL ADDRESS ******

        }

 安装sendmail且启动它

 [root@master nagios-4.1.1]# yum install sendmail -y 

[root@master nagios-4.1.1]# service sendmail start

     Starting sendmail:                                         [  OK  ]

     Starting sm-client:                                        [  OK  ]

    [root@master nagios-4.1.1]# 

[root@master nagios-4.1.1]# netstat -tlnp | grep 25 |grep -v grep

如果sendmail启动慢,可以修改/etc/hosts,添加主机名hostname

  11.配置apache服务

     [root@master nagios-4.1.1]# service httpd start

[root@master nagios-4.1.1]# ps -ef | grep http

      root       431     1  0 14:07 ?        00:00:00 /usr/sbin/httpd

      apache     433   431  0 14:07 ?        00:00:00 /usr/sbin/httpd

     [root@master nagios-4.1.1]# 

 12.安装nagios插件软件包   yum install perl-devel perl-CPAN -y

      [root@master nagios]# tar -zxvf nagios-plugins-2.1.1.tar.gz 

      [root@master nagios]# cd nagios-plugins-2.1.1

 yum install perl-devel perl-CPAN -y 

      [root@master nagios-plugins-2.1.1]# ./configure --with-nagios-user=nagios --with-nagios-group=nagios --enable-perl-modules --with-mysql=/usr/local/mysql

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

      [root@master nagios-plugins-2.1.1]# make install

 13.添加nagios服务到开机自启动 

     [root@master nagios-plugins-2.1.1]# chkconfig nagios on


     [root@master nagios-plugins-2.1.1]# chkconfig --list nagios

      nagios         0:off 1:off 2:on 3:on 4:on 5:on 6:off

     [root@master nagios-plugins-2.1.1]# 


   14.验证nagios配置文件(语法检查)

   [root@master ~]# /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg 

   Checking misc settings...


   Total Warnings: 0

   Total Errors:   0

 一般看到都是0就成功了

 [root@master ~]# /etc/init.d/nagios checkconfig

       Running configuration check...

       OK.

     [root@master ~]# 


  15.启动nagios服务 

    [root@master ~]# /etc/init.d/nagios start      

        Starting nagios: done.

    [root@master ~]# ps -ef | grep nagios | grep -v grep

root       336 28056  0 14:01 pts/0    00:00:00 vim /usr/local/nagios/etc/objects/contacts.cfg +35

nagios   15312     1  0 14:29 ?        00:00:00 /usr/local/nagios/bin/nagios -d /usr/local/nagios/etc/nagios.cfg

nagios   15314 15312  0 14:29 ?        00:00:00 /usr/local/nagios/bin/nagios --worker /usr/local/nagios/var/rw/nagios.qh

nagios   15315 15312  0 14:29 ?        00:00:00 /usr/local/nagios/bin/nagios --worker /usr/local/nagios/var/rw/nagios.qh

nagios   15316 15312  0 14:29 ?        00:00:00 /usr/local/nagios/bin/nagios --worker /usr/local/nagios/var/rw/nagios.qh

nagios   15317 15312  0 14:29 ?        00:00:00 /usr/local/nagios/bin/nagios --worker /usr/local/nagios/var/rw/nagios.qh

nagios   15318 15312  0 14:29 ?        00:00:00 /usr/local/nagios/bin/nagios -d /usr/local/nagios/etc/nagios.cfg

[root@master ~]# 

   

 16.打开浏览器开始验证    http://192.168.11.34/nagios/  出现输入账号密码即成功了。

   

 17.安装nrpe,客户端进程。

    tar -zxvf nrpe-2.15.tar.gz 

cd nrpe-2.15

./configure

make all

make install-plugin

make install-daemon

make install-daemon-config

提示:服务端也要安装nrpe,不然会缺少相关检查插件,另外可以监控自身的基本健康状态。

########################################################################################

二、nagios客户端安装

  1.修改机器名字,设置yum源,关闭防火墙,selinux,后面根据实际情况开启,我这用的163的源

  cd /etc/yum.repos.d


  mv CentOS-Base.repo CentOS-Base.repo.backup


  wget http://mirrors.163.com/.help/CentOS6-Base-163.repo


  mv CentOS6-Base-163.repo CentOS-Base.repo


  yum clean all

  

  2.解决perl编译问题

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

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

   [root@master ~]# echo $LC_ALL

  

  3.解决系统时间同步

   [root@master ~]# echo '*/10 * * * * /usr/sbin/ntpdate pool.ntp.org >/dev/null 2>&1' >/var/spool/cron/root 

   [root@master ~]# crontab -l

    */10 * * * * /usr/sbin/ntpdate pool.ntp.org >/dev/null 2>&1

   [root@master ~]# 

  

  4.安装nagios客户端插件 

    [root@master ~]# mkdir -p /home/tangbo/tools/nagios

    [root@master nagios]# ls

     nagios-4.1.1.tar.gz  nagios-plugins-2.1.1.tar.gz

开始安装nagios-plugins-2.1.1.tar.gz

[root@slave nagios]# useradd nagios -M -s /sbin/nologin

cd nagios-plugins-2.1.1

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

    make

    make install

 5.安装nrpe 

   tar -zxvf nrpe-2.15.tar.gz 

cd nrpe-2.15

./configure

make all

make install-plugin

make install-daemon

make install-daemon-config

提示:服务端也要安装nrpe,不然会缺少相关检查插件,另外可以监控自身的基本健康状态。

  

  6.安装其它相关的插件Params-Validate-0.91.tar.gz ,Class-Accessor-0.34.tar.gz,Config-Tiny-2.23.tgz,perl-Math-Calc-Units-1.07-6.el6.noarch.rpm,Regexp-Common-2016010801.tar.gz

    (1)tar -zxvf Params-Validate-0.91.tar.gz 

    cd Params-Validate-0.91

    perl Makefile.PL

    make

    make install

    cd ..

    (2)tar zxvf Class-Accessor-0.34.tar.gz 

    cd Class-Accessor-0.34

    perl Makefile.PL

    make 

    make install

(3)[root@slave nagios]# rpm -ivh perl-Math-Calc-Units-1.07-6.el6.noarch.rpm 

(4)tar -zvxf Config-Tiny-2.23.tgz 

   cd Config-Tiny-2.23

perl Makefile.PL

        make

        make install

(5) tar -zxvf Regexp-Common-2016010801.tar.gz 

   cd Regexp-Common-2016010801

   perl Makefile.PL

         make

        make install

(6)yum -y install sysstat

   

 7.配置开发的几个基础插件 

   [root@slave etc]# vim nrpe.cfg +79 

    allowed_hosts=192.168.11.34

   

 8.启动nagios client 

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

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

[root@slave etc]# ps -ef | grep nagios

    重新启动[root@slave etc]# pkill nrpe && /usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d

[root@slave etc]# netstat -tlnp

Active Internet connections (only servers)

Proto Recv-Q Send-Q Local Address               Foreign Address             State       PID/Program name   

tcp        0      0 0.0.0.0:22                  0.0.0.0:*                   LISTEN      22616/sshd          

tcp        0      0 127.0.0.1:25                0.0.0.0:*                   LISTEN      1258/master         

tcp        0      0 0.0.0.0:5666                0.0.0.0:*    这是nrpe跑的端口


###########################################################################################

安装完成。。。。。。。。。。。。。。。。。。。。