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

Linux系统搭建Nagios监控平台

[复制链接]

尚未签到

发表于 2019-1-13 11:12:57 | 显示全部楼层 |阅读模式
  

  一、首先在Nagios监控的服务器部署
# 安装Nagios软件及其依赖的软件
[root@nagios ~]# yum install -y httpd php gcc glibc glibc-common net-snmp nagios nagios-plugins nagios-plugins-all nrpe nagios-plugins-nrpe gd gd-devel openssl openssl-devel
# 定义Nagios登陆的账号与密码
[root@nagios ~]# htpasswd -c /etc/nagios/passwd nagiosadmin
New password:
Re-type new password:
Adding password for user nagiosadmin
# 对配置文件进行检测
[root@nagios ~]# nagios -v /etc/nagios/nagios.cfg
Nagios Core 3.5.1
Copyright (c) 2009-2011 Nagios Core Development Team and Community Contributors
Copyright (c) 1999-2009 Ethan Galstad
Last Modified: 08-30-2013
License: GPL
Website: http://www.nagios.org
Reading configuration data...
   Read main config file okay...
Processing object config file '/etc/nagios/objects/commands.cfg'...
Processing object config file '/etc/nagios/objects/contacts.cfg'...
Processing object config file '/etc/nagios/objects/timeperiods.cfg'...
Processing object config file '/etc/nagios/objects/templates.cfg'...
Processing object config file '/etc/nagios/objects/localhost.cfg'...
Processing object config directory '/etc/nagios/conf.d'...
   Read object config files okay...
Running pre-flight check on configuration data...
Checking services...
        Checked 8 services.
Checking hosts...
        Checked 1 hosts.
Checking host groups...
        Checked 1 host groups.
Checking service groups...
        Checked 0 service groups.
Checking contacts...
        Checked 1 contacts.
Checking contact groups...
        Checked 1 contact groups.
Checking service escalations...
        Checked 0 service escalations.
Checking service dependencies...
        Checked 0 service dependencies.
Checking host escalations...
        Checked 0 host escalations.
Checking host dependencies...
        Checked 0 host dependencies.
Checking commands...
        Checked 24 commands.
Checking time periods...
        Checked 5 time periods.
Checking for circular paths between hosts...
Checking for circular host and service dependencies...
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
[root@nagios ~]# service httpd start
正在启动 httpd:                                           [确定]
[root@nagios ~]# service nagios start
Starting nagios: done.  通过浏览器进行访问,输入之前设定账号与密码,进行登陆

  

  登陆成功后,我们可以分别查看主机,以及所监控的服务


  

  监控的主机,默认的只有监控服务器主机一台

  

  监控的服务

  

  

  二、监控服务器的基本架构以及搭建起来,接下来我们开始配置被监控主机,看一下如何添加主机
# 在客户端安装必要的软件
[root@web1 ~]# yum install -y nagios-plugins nagios-plugins-all nrpe nagios-plugins-nrpe openssl openssl-devel
[root@web1 ~]# vim /etc/nagios/nrpe.cfg
................................
# 这里需要添加允许访问的主机地址
allowed_hosts=127.0.0.1,192.168.1.132
.................................
# 启动服务
[root@web1 ~]# service nrpe start
Starting nrpe:                                             [确定]
# nagios的主机是以配置文件进行划分主机的,所以我们只要创建对应主机的配置文件
[root@nagios ~]# cd /etc/nagios/objects/
# 这个目录下有很多的配置文件,功能各不相同,我们会以本机默认配置为模板,定义主机配置文件
[root@nagios objects]# ls
commands.cfg  contacts.cfg  localhost.cfg  printer.cfg  switch.cfg  templates.cfg  timeperiods.cfg  windows.cfg
[root@nagios ~]# vim /etc/nagios/conf.d/web1.cfg
# 基本监测服务配置形态
efine host{
        use                     linux-server
        host_name               web1
        alias                   web1.com
        address                 192.168.1.130
        }
define service{
        use                             generic-service
        host_name                       web1
        service_description             PING
        check_command                   check_ping!100.0,20%!500.0,60%
        max_check_attempts 5
        normal_check_interval 1
        notification_interval           60
        }
define service{
        use                             generic-service
        host_name                       web1
        service_description             SSH
        check_command                   check_ssh
        notifications_enabled           0
        }
define service{
        use                             generic-service
        host_name                       web1
        service_description             HTTP
        check_command                   check_http
        notifications_enabled           1
        contact_groups                  admins
        notification_period   24x7
        notification_options            w,u,c,r
        }
# 对配置文件的正确性进行检查        
[root@nagios ~]# nagios -v /etc/nagios/nagios.cfg
Nagios Core 3.5.1
Copyright (c) 2009-2011 Nagios Core Development Team and Community Contributors
Copyright (c) 1999-2009 Ethan Galstad
Last Modified: 08-30-2013
License: GPL
Website: http://www.nagios.org
Reading configuration data...
   Read main config file okay...
Processing object config file '/etc/nagios/objects/commands.cfg'...
Processing object config file '/etc/nagios/objects/contacts.cfg'...
Processing object config file '/etc/nagios/objects/timeperiods.cfg'...
Processing object config file '/etc/nagios/objects/templates.cfg'...
Processing object config file '/etc/nagios/objects/localhost.cfg'...
Processing object config file '/etc/nagios/objects/windows.cfg'...
Processing object config directory '/etc/nagios/conf.d'...
Processing object config file '/etc/nagios/conf.d/web1.cfg'...
   Read object config files okay...
Running pre-flight check on configuration data...
Checking services...
        Checked 25 services.
Checking hosts...
        Checked 3 hosts.
Checking host groups...
        Checked 2 host groups.
Checking service groups...
        Checked 0 service groups.
Checking contacts...
        Checked 1 contacts.
Checking contact groups...
        Checked 1 contact groups.
Checking service escalations...
        Checked 0 service escalations.
Checking service dependencies...
        Checked 0 service dependencies.
Checking host escalations...
        Checked 0 host escalations.
Checking host dependencies...
        Checked 0 host dependencies.
Checking commands...
        Checked 25 commands.
Checking time periods...
        Checked 5 time periods.
Checking for circular paths between hosts...
Checking for circular host and service dependencies...
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
[root@nagios ~]# /etc/init.d/nagios restart
Running configuration check...done.
Stopping nagios: done.
Starting nagios: done.  到主机选项中查看,增加了一个web1的主机

  

图:一

  


图:二

  基本形态已经完成

  功能增加:
  1、监控负载与硬盘状态
# 在监控服务器上修改配置
[root@nagios ~]# vim /etc/nagios/objects/commands.cfg
..............................
# 在配置中增加以下内容
define command{
        command_name    check_nrpe
        command_line    $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$
        }
..............................

[root@nagios ~]# vim /etc/nagios/conf.d/web1.cfg
# 增加监控系统负载和硬盘的状态
....................................
define service{
        use     generic-service
        host_name                       web1
        service_description             check_load
        check_command                   check_nrpe!check_load
        max_check_attempts 5
        normal_check_interval 1
        }

define service{
        use                             generic-service
        host_name                       web1
        service_description             check_disk_hda1
        check_command                   check_nrpe!check_hda1
        max_check_attempts 5
        normal_check_interval 1
        }
[root@nagios ~]# nagios -v /etc/nagios/nagios.cfg
..........................................
Checking for circular paths between hosts...
Checking for circular host and service dependencies...
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
[root@nagios ~]# /etc/init.d/nagios restart
Running configuration check...done.
Stopping nagios: done.
Starting nagios: done.  

  修改被监控主机的配置

[root@web ~]# vim /etc/nagios/nrpe.cfg
..........................................
# 后面的/dev/hda1修改为/dev/sda1
command[check_hda1]=/usr/lib/nagios/plugins/check_disk -w 20% -c 10% -p /dev/sda1
.........................................
[root@web ~]# /etc/init.d/nrpe restart
Shutting down nrpe:                                        [确定]
Starting nrpe:                                             [确定]  

  再次查看浏览器,刚才配置的两个监控项目,可以了
  


  

  2、配置告警
# 修改监控服务器配置
[root@nagios ~]# vim /etc/nagios/objects/contacts.cfg
define contact{
        contact_name                    nagiosadmin            
        use                             generic-contact        
        alias                           Nagios Admin        
        email                           nagios@localhost

运维网声明 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-662683-1-1.html 上篇帖子: 一键搭建nagios监控系统之一 脚本篇 下篇帖子: Nagios NRPE超时问题
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

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

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

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

扫描微信二维码查看详情

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


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


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


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



合作伙伴: 青云cloud

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