虚幻0516 发表于 2019-1-12 14:44:39

centos 7 下nagios 安装和配置

  http://blog.运维网.com/e/u261/themes/default/images/spacer.gifcentos 7 下nagios 安装和配置
  一、yum -y install httpd gcc glibc glibc-common *gd* php php-mysql mysql mysql-server mysql-devel php-snmp net-snmp net-snmp-libs net-snmp-utils php-pdo perl-DBD-MySQL rrd-tool
  perl-rrdtool             rrdtool-develmariadb-server mariadb-devel
  

  二、yum -y install gcc gcc-c++ autoconf libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel libidn libidn-devel openssl openssl-devel
  上面在cacti 安装配置中已经安装,这里就不再进行安装了
centos 7 yum 安装nagios
yum install nagios
yum install nagios-plugins-all
  

  1、tar -zxvf nagios ...tar.gz
  #useradd nagios
  #passwd nagios
  #cd nagios..
  #./configure --prefix=/usr/local/nagios
  #make all
                                                                       #make install
                                                                       #make install-init
                                                                    
                                                                       #make install-commandmode
                                                                       #make install-config
                                                                    #make install-webconf 安装到了Apache目录下conf.d目录了
                                                                     #make install-exfoliation
                                                                     #make install-classicui
  #修改httpd.conf里的User 和Group 为nagios 改了之后cacti注意,能不能使用cacti了
  

  2、编译安装nagios-plugins-2.0   #./configure--prefix=/usr/local/nagios

  #make&&make install
  
  3、安装nrpe,#tar –zxvf nrpe-2.9.tar.gz

  #./configure –prefix=/usr/local/nagios
  #make all
  #make install-pluhin
  #make install-daemon
  #make install-daemon-config
  #chown–R nagios:nagios /usr/local/nagios
  #更改/usr/local/nagios/etc/cgi.cfg 里面nagiosadmin 改成nagios
  #service nagios start
  #service httpd start
  #service mysql start
  # htpasswd -c /usr/local/nagios/etc/htpasswd.users nagios
  #vim nagios/etc/objects/command.cfg 添加
      define command{
        command_name    check_nrpe
        command_line    $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$ -t 30
        }
  # /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
  #/usr/local/nagios/bin/nagios -d /usr/local/nagios/etc/nagios.cfg
      被监控主机配置:
  4、安装nrpe
  #./configure --prefix=/usr/loca/nagios
  #make all && make install-plugin && make install-daemon && make install-daemon-conig
  #vim /usr/local/nagios/etc/nrpe.conf 添加监控服务器IP
     allowed_hosts=127.0.0.1,10.1.13.176
  #/usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.conf -d 开启的端口是5666
  #安装nagios-plugin
  5、添加需要监控的插件和程序
  #vim nrpe.conf         ##例:
  command=/usr/local/nagios/libexec/check_swap -w 50% -c 20%
  6、yum install net-snmp-libs net-snmp-utils net-snmp
  

  
  监控主机配置nrpe service
  

  #mkdir server
  #vim nagios.conf 添加cfg_dir=/usr/local/nagios/etc/server
  #vim /usr/local/nagios/etc/server/group.cfg
      define hostgroup{
                  hostgroup_nameServers ; The name of the hostgroup
                  alias         Servers ; Long name of the group
                  }
   define hostgroup{
                  hostgroup_namebackup ; The name of the hostgroup
                  alias         backup ; Long name of the group
                  }
  

  #cd /usr/local/nagios/etc/server && vim 10.1.13.213.cfg
  



define host{
                use                     linux-server            ; Name of host template to use
                                                                ; This host definition will inherit all                                                                                                variables that are defined
                hostgroups            Servers
                                                                ; in (or inherited by) the linux-server                                                                                                host template definition.
                host_name               10.1.13.213
                alias                   backup
                address               10.1.13.213
                }
define service{
                use                     generic-service
                host_name               10.1.13.213
                service_description   Ping
                check_command         check_ping!100.0,20%!150.0,60%
                }
      define service{
                use                           generic-service         ; Name of service template to u                                                                                             se
                host_name                     10.1.13.213
                service_description             Root Partition
                check_command                   check_nrpe!check_sda1
                }
      define service{
                use                           generic-service         ; Name of service template to u                                                                                             se
                host_name                     10.1.13.213
                service_description             Current Users
                check_command                   check_nrpe!check_users
                }
      define service{
                use                           generic-service         ; Name of service template to u                                                                                             se
                host_name                     10.1.13.213
                service_description             Total Processes
                check_command                   check_nrpe!check_total_procs
                }
      define service{
                use                           generic-service         ; Name of service template to u                                                                                             se
                host_name                     10.1.13.213
                service_description             Current Load
                check_command                   check_nrpe!check_load
                }
      define service{
                use                           generic-service         ; Name of service template to u                                                                                             se
                host_name                     10.1.13.213
                service_description             Swap Usage
                check_command                   check_nrpe!check_swap
                }
      define service{
                use                           generic-service         ; Name of service template to u                                                                                             se
                host_name                     10.1.13.213
                service_description             SSH
                check_command                   check_ssh!-p 2222!10.1.13.213
                }








      define service{
                use                           generic-service         ; Name of service template to u                                                                                             se
                host_name                     10.1.13.213
                service_description             HTTP
                check_command                   check_nrpe!check_http
                }


      define service{
                use                           generic-service         ; Name of service template to u                                                                                             se
      host_name                     10.1.13.213
      service_description             zombie_proces
      check_command                   check_nrpe!check_zombie_procs
      }


#上面的红色字体,在被监控主机的nrpe.conf 的command 中要定义
监控mysql
#cd check_mysql_health
#./configure --prefix=/usr/local/nagios
#make && make install
#./usr/local/nagios/libexec/check_mysql_health 出现Can't locate Time/HiRes.pm in @INC 的perl 错误 ,解决办法:安装
#yum install -y perl-Time-HiRes
#vim 10.1.1.13.213.cfg
define service{
      use   local-service
      host_name 10.1.13.213
      service_description   mysql
      check_command check_nrpe!check_mysql_health
}
在被监控的主机上:#vim nrpe.conf添加:command=/var/www/nagios/libexec/check_mysql_health --hostname localhost --username root --port 3306 --password 910218 --mode threads-connected
#mysql -u root -p
>grant all privileges on *.* to 'root'@'%' identified by '910218';
>flush privileges;
>quit
在主监控服务器上测试被监控机上的mysql连接:mysql -u root -p 10.1.13.213


定义时间段和联系人
#vim timeperiods.cfg
define timeperiod{
      name            workday
      timeperiod_name workday
      alias         workday
      monday          00:00-24:00
      tuesday         00:00-24:00
      wednesday       00:00-24:00
      thursday      00:00-24:00
      friday          00:00-24:00
      }
define timeperiod {
      name            weekends
      timeperiod_name weekends
      alias         weekends
      saturday      00:00-24:00
      sunday          00:00-24:00
      }


#vim templates.cfg
define contact{
      name    kobe
      service_notification_period   workday
      host_notification_period      workday
      service_notification_options    w,u,r,f,s
      host_notification_options       d,u,r,f,s
      host_notification_commands      notify-service-by-email
      service_notification_commands   notify-service-by-email
      }


#vim contacts.cfg
define contact{
      contact_name            kobe
      use                     kobe
      alias                   bryant
      host_notification_period workday
      service_notification_period   workday
      email                   root@localhost
      }





#service group服务组
#vim object/servicegroup.cfg
define servicegroup{
            servicegroup_name    kobeservicegroup
            alias                           kobeservicegroup
    }
define servicegroup{
      servicegroup_name      bryantservicegroup
      alias                              bryantservicegroup
            }


#vim conf.d/10.1.13.213.cfg添加servicegroups      名字
http://blog.运维网.com/e/u261/themes/default/images/spacer.gif










  




页: [1]
查看完整版本: centos 7 下nagios 安装和配置