zoukankan      html  css  js  c++  java
  • nagios环境部署(rhel6.5)

    系统环境:RHEL6 x86_64
    selinux and iptables disabled
    nagios 主机:192.168.0.71
    mysql 主机: 192.168.0.36

    依赖性及环境

    yum install httpd gcc make gd-devel  -y
    gd-devel 如果yum源中没有可自行下载与gd版本一致的开发包
    yum install mysql-devel openssl-devel -y
    useradd nagios
    usermod -G nagios apache

    运行 nagios 服务的用户
    使 apache 用户对 nagios 目录具有写权限,不然 web 页面操作失败

    nagios 软件安装

    tar jxf nagios-cn-3.2.3.tar.bz2
    cd nagios-cn-3.2.3
    ./configure            #编译
    make all
    make install
    make install-init
    make install-commandmode
    make install-config
    make install-webconf

    安装编译所需软件包编译时 缺什么装什么

    插件安装

    tar zxf nagios-plugins-1.4.15.tar.gz            #nagios 插件安装
    cd nagios-plugins-1.4.15
    ./configure  
    make
    make install

    相关配置文件

    vim /usr/local/nagios/etc/nagios.cfg
    #nagios 配置
    #新建 hosts.cfg 文件,存放主机与主机组定义
    cfg_file=/usr/local/nagios/etc/objects/hosts.cfg
    
    #新建 services.cfg 文件,存放服务与服务组定义
    cfg_file=/usr/local/nagios/etc/objects/services.cfg
    
    #cfg_file=/usr/local/nagios/etc/objects/localhost.cfg
    #注释 localhost.cfg 文件
    
    #vim /usr/local/nagios/etc/objects/host.cfg
    #定义本地主机
    define host{
            use                             linux-server            
            host_name                       server471.example.com
            alias                           manager
            address                         127.0.0.1
            icon_image                  server.gif
            statusmap_image             server.gd2
            2d_coords                   500,200
            3d_coords                   500,200,100
            }
    #定义远程主机
    define host{
            use                             linux-server            
            host_name                   server472.example.com
            parents                         server471.example.com
            alias                           mysql
            address                         172.25.47.2
            icon_image                  server.gif
            statusmap_image             server.gd2
            2d_coords                   100,200
            3d_coords                   100,100,0
                        }
    #主机组并不是必须的,这是配合 nagios 的监控页面的显示
    #定义主机组
    define hostgroup{
            hostgroup_name          linux-servers 
            alias                       Linux Servers 
            members                 *   
                        }
    
    vim  /usr/local/nagios/etc/objects/services.cfg
    
    #定义服务组
    define servicegroup{
            servicegroup_name   系统负荷检查
            alias                       负荷检查
            members                 server471.example.com,进程总数,server471.example.com,登录用数,server471.example.com,根分区,server471.example.com,交换空间利用率
            }
    #定义服务
    define service{
            use                     local-service       
            host_name           *
            service_description   PING
            check_command  check_ping!100.0,20%!500.0,60%                               }
    
    执行:
    /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg 
    显示:
    Total Warnings: 0
    Total Errors:   0
    #校验 nagio配置文件的正确性
    无报错 重启服务
    
    htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin 
    #设置nagios 监控页面访问用户和密码
    
    service nagios start 
    service httpd start
    #启动 nagios 和 httpd 服务
    
    http://192.168.0.71/nagios #访问 nagios 监控页面,输入上面添加的用户名和密码

    这里写图片描述

    监控 mysql 主机

    mysql 主机上运行有 mysql 服务,在其上创建监控检测帐户
    mysql> create database nagdb;
    mysql> grant select on nagdb.* to nagdb@'192.168.0.71';
    mysql> flush privileges;
    
    
    在 nagios 主机上检测是否可以连接 mysql 主机上的 mysql 服务
    
    /usr/local/nagios/libexec/check_mysql -H 192.168.0.36 -u nagdb -d nagdb
    
    Uptime: 73 Threads: 1 Questions: 7 Slow queries: 0 Opens: 15 Flush tables: 1 Open tables: 8
    Queries per second avg: 0.95
    
    在 nagios 主机上添加对 mysql 服务监控的定义
    #vim /usr/local/nagios/etc/objects/hosts.cfg 
    添加如下行
    #define host{
            use                             linux-server            
            host_name                   server472.example.com
            parents                         server471.example.com
            alias                           mysql
            address                         172.25.47.2
            icon_image                  server.gif
            statusmap_image             server.gd2
            2d_coords                   100,200
    
    #vim /usr/local/nagios/etc/objects/services.cfg 添加如下行
    define service{
    use                     local-service
    host_name               mysql 主机
    servce_groups           mysql 服务组
    service_description mysql 服务
    check_command       check_mysql
    }
    
    define servicegroup{
    servicegroup_name    mysql 服务组
    alias                           mysql 服务器
    }
    vim /usr/local/nagios/etc/objects/commands.cfg 添加如下行
    # 'check_mysql' command definition
    define command{
            command_name    check_mysql
            command_line    $USER1$/check_mysql -H $HOSTADDRESS$ -u $ARG1$ -p $ARG2$ -d $ARG3$
            }
    执行:
    /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
    显示:
    Total Warnings: 0
    Total Errors:   0
    重启服务
    
    Nagios 通过 NRPE 监控远程主机系统状况
    Nagios实现远程监控server2 系统状况

    配置Server2

    tar zxf nrpe-2.15.tar.gz
    cd nrpe-2.15
    
    yum install gcc 
    yum install openssl-devel     #解决软件依赖性
    
    usreadd nagios
    
    ./configure         #编译后按提示操作  缺什么装什么
    
    make all
    make install-plugin
    useradd nagios
    make install-plugin
    make install-daemon
    make install-daemon-config
    make install-xinetd
    
    yum install -y xinetd
    vim /etc/xinetd.d/nrpe
    
    disable         = no
    only_from       = 172.25.47.1       #监控端IP
    
    vim /etc/services
    
    nrpe            5666/tcp            #添加端口
    
    /etc/init.d/xinetd restart
    netstat -antlp      #检查是否添加成功
    
    
    
    
     scp /usr/local/nagios/libexec/check_nrpe  root@172.25.47.1:/usr/local/nagios/libexec/  
    #将被监控端安装的 check_nrpe 发送至监控端的同目录下也可以在监控端自己安装
    *在监控端要将check_nrpe 所属组和用户改为 nagios
    
    安装plugins模块
     tar zxf nagios-plugins-2.1.1.tar.gz
     cd nagios-plugins-2.1.1
     ./configure
     make
     make install
     cd /usr/local/nagios/etc/
    
     vim nrpe.cfg
    #################################
    command[check_users]=/usr/local/nagios/libexec/check_users -w 5 -c 10
    command[check_load]=/usr/local/nagios/libexec/check_load -w 15,10,5 -c 30,25,20
    command[check_disk]=/usr/local/nagios/libexec/check_disk -w 20% -c 10% -p /
    ###################################
    监控端可监控服务
    
    
    监控端server1下 进行如下测试:
    
    cd /usr/local/nagios/libexec
    
    ./check_nrpe -H 172.25.47.2     # -H 指定被监控端IP
    NRPE v2.15                      #得到NRPE 版本号 即可
    
    
    命令行监控方法
    ./check_nrpe -H 172.25.47.2 -c check_users
    
    图形实时监控方法
    
    配置监控端server1中nagios的文件
    /usr/local/nagios/etc/objects
    vim commands.cfg
    
    # 'check_nrpe' command definition
    define command{
            command_name    check_nrpe
            command_line    $USER1$/check_nrpe -H $HOSTADDRESS$ -u $ARG1$ -c $ARG1$
            }
    
    vim services.cfg
    
    define service{
            use                             local-service
            host_name                       server472.example.com
            service_description             根分区
            check_command                   check_nrpe!check_disk
            }
    
    
    vim hosts.cfg
    
    define host{
            use                     linux-server          
            host_name              server472.example.com
            parents                 server471.example.com
            alias                       mysql
            address                 172.25.47.2
            icon_image              server.gif
            statusmap_image         server.gd2
            2d_coords               100,200
            3d_coords               100,100,0
                    }
    
    执行:
    /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
    显示:
    Total Warnings: 0
    Total Errors:   0
    重启服务
  • 相关阅读:
    slf4j的使用
    hashMap
    HBase
    HBase应用快速开发
    初学MongoDB 遇到提示由于目标计算机积极拒绝,无法连接
    Flask学习中运行“helloworld”出现UnicodeDecodeError: 'utf-8' codec can't decode问题
    doGet或doPost方法没有调用的一个原因
    markdown测试
    tomcat集成到IDEA与部署项目
    tomcat部署项目的方式
  • 原文地址:https://www.cnblogs.com/aallenn/p/6700615.html
Copyright © 2011-2022 走看看