nagios监控系统安装

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了nagios监控系统安装相关的知识,希望对你有一定的参考价值。


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

一、安装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编译问题

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

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

   [[email protected] ~]# echo $LC_ALL

  

  3.解决系统时间同步

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

   [[email protected] ~]# crontab -l

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

   [[email protected] ~]# 

   

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

   [[email protected] ~]# yum install gcc glibc* gd* httpd php*


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

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

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

  [[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 -G nagios

     nagios nagcmd

  [[email protected] ~]# id -n -G apache

     apache nagcmd

  [[email protected] ~]# 

  

  6.下载nagios源码

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

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

  

  7.开始安装

     (1)创建目录并上传包

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

[[email protected] nagios]# ls

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

 

    (2)开始解压

[[email protected] nagios]# tar -zxvf nagios-4.1.1.tar.gz

[[email protected] nagios]# cd nagios-4.1.1

    (3)开始编译及安装

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

[[email protected] nagios-4.1.1]# make all

For more information on obtaining support for Nagios, visit:


       https://support.nagios.com


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


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

[[email protected] nagios-4.1.1]# make install

    (4)继续安装初始化

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

 [[email protected] nagios-4.1.1]# make install-commandmode   安装命令模式

 [[email protected] nagios-4.1.1]# make install-config        安装样例配置文件

 

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

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


    [[email protected] nagios-4.1.1]# 


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

   [[email protected] nagios-4.1.1]# htpasswd -c /usr/local/nagios/etc/htpasswd.users tangbo

    New password: 

    Re-type new password: 

    Adding password for user tangbo

   [[email protected] nagios-4.1.1]# 

   [[email protected] nagios-4.1.1]# cat /usr/local/nagios/etc/htpasswd.users 

    tangbo:7mdQ02yZfJLjQ

   [[email protected] nagios-4.1.1]# 

   

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

    [[email protected] 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                           [email protected]  ; <<***** CHANGE THIS TO YOUR EMAIL ADDRESS ******

        }

 安装sendmail且启动它

 [[email protected] nagios-4.1.1]# yum install sendmail -y 

[[email protected] nagios-4.1.1]# service sendmail start

     Starting sendmail:                                         [  OK  ]

     Starting sm-client:                                        [  OK  ]

    [[email protected] nagios-4.1.1]# 

[[email protected] nagios-4.1.1]# netstat -tlnp | grep 25 |grep -v grep

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

  11.配置apache服务

     [[email protected] nagios-4.1.1]# service httpd start

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

     [[email protected] nagios-4.1.1]# 

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

      [[email protected] nagios]# tar -zxvf nagios-plugins-2.1.1.tar.gz 

      [[email protected] nagios]# cd nagios-plugins-2.1.1

 yum install perl-devel perl-CPAN -y 

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

      [[email protected] nagios-plugins-2.1.1]# make 

      [[email protected] nagios-plugins-2.1.1]# make install

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

     [[email protected] nagios-plugins-2.1.1]# chkconfig nagios on


     [[email protected] nagios-plugins-2.1.1]# chkconfig --list nagios

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

     [[email protected] nagios-plugins-2.1.1]# 


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

   [[email protected] ~]# /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg 

   Checking misc settings...


   Total Warnings: 0

   Total Errors:   0

 一般看到都是0就成功了

 [[email protected] ~]# /etc/init.d/nagios checkconfig

       Running configuration check...

       OK.

     [[email protected] ~]# 


  15.启动nagios服务 

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

        Starting nagios: done.

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

[[email protected] ~]# 

   

 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编译问题

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

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

   [[email protected] ~]# echo $LC_ALL

  

  3.解决系统时间同步

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

   [[email protected] ~]# crontab -l

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

   [[email protected] ~]# 

  

  4.安装nagios客户端插件 

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

    [[email protected] nagios]# ls

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

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

[[email protected] 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)[[email protected] 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.配置开发的几个基础插件 

   [[email protected] etc]# vim nrpe.cfg +79 

    allowed_hosts=192.168.11.34

   

 8.启动nagios client 

    [[email protected] etc]# /usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d

[[email protected] etc]# echo ‘/usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d‘ >>/etc/rc.local

[[email protected] etc]# ps -ef | grep nagios

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

[[email protected] 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跑的端口


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

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

   


本文出自 “山猫” 博客,谢绝转载!

以上是关于nagios监控系统安装的主要内容,如果未能解决你的问题,请参考以下文章

Nagios监控系统的安装

Nagios监控系统安装和配置

linux环境中nagios(nagios core)安装?nagios安装?

Nagios的安装

编译安装Nagios

Nagios4.x安装配置总结