设为首页 收藏本站
查看: 1055|回复: 0

centos 7 下nagios 安装和配置

[复制链接]
累计签到:1 天
连续签到:1 天
发表于 2016-10-27 09:47:22 | 显示全部楼层 |阅读模式
一、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-devel  mariadb-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[check_swap]=/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_name  Servers ; The name of the hostgroup
                alias           Servers ; Long name of the group
                }
define hostgroup{
                hostgroup_name  backup ; 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[check_mysql_health]=/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        名字

spacer.jpg






运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-291893-1-1.html 上篇帖子: 实战Nagios网络监控(3)——Nagios 微信报警 下篇帖子: nagios CHECK_NRPE: Error - Could not complete SSL handshake
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表