zoukankan      html  css  js  c++  java
  • nagios安装及监控Linux主机

    服务端的操作:
    ##################################安装lamp环境及依赖包##########################
       24  rpm -ivh gd-devel-2.0.35-11.el6.x86_64.rpm --nodeps  # 加不加都可以
       25  cd /media/Packages/
       26   yum -y install httpd gcc glibc glibc-common gd gd-devel php php-mysql mysql mysql-devel mysql-server
    ################################添加用户,组,apache用户赋予nagios用户权限#####
       27   groupadd  nagios
       28  useradd -g nagios nagios  # 27和28部 可以写为 useradd nagios 默认用户的组为nagios
       29  passwd nagios
       30  usermod (-a) -G nagios apache
       31  cd /root/Desktop/
       32  ls
    #############################安装nagios主程序####################################
       33  tar -xzvf nagios-4.0.3.tar.gz
       34  cd nagios-4.0.3
       35  ls
       36  ./configure --with-command-group=nagios --enable-event-broker
       37  make all  # 编译所有
       38  make install   //安装主程序,CGI和HTML文件
       39  make install-init   //在/etc/rc.d/init.d安装启动脚本
       39  make install-commandmode   //配置目录权限
       40  make install-config   //安装示例配置文件
       41  make install-webconf   //安装nagios的web接口,会在/etc/httpd/conf.d目录中创建       nagios.conf文件。
    #####################################创建用户访问控制用户和密码##################
        配置apache
        找到apache 的配置文件,修改httpd.conf
        找到:
        User daemon
        
    Group daemon
        修改为?
        User nagios
        
    Group nagios
        然后找到?
        <IfModule dir_module>
        
    DirectoryIndex index.html
        
    </IfModule>
        修改为?
        <IfModule dir_module>
        
    DirectoryIndex index.html index.php
        
    </IfModule>
        接着增加如下内容:?
        AddType application/x-httpd-php .php
        为了安全起见,一般情况下要让nagios 的web 监控页面必须经过授权才能访问,这需要增加验证配置,即在httpd.conf 文件最后添加如下信息:?

        #setting for nagios

        ScriptAlias /nagios/cgi-bin "/usr/local/nagios/sbin"

        <Directory "/usr/local/nagios/sbin">
         
        AuthType Basic
         
        Options ExecCGI
         
        AllowOverride None
         
        Order allow,deny
         
        Allow from all
         
        AuthName "Nagios Access"
         
        AuthUserFile /usr/local/nagios/etc/htpasswd             //用于此目录访问身份验证的文件
         
        Require valid-user

        </Directory>


        Alias /nagios "/usr/local/nagios/share"

        <Directory "/usr/local/nagios/share">
         
        AuthType Basic
         
        Options None
         
        AllowOverride None
         
        Order allow,deny
         
        Allow from all
         
        AuthName "nagios Access"
         
        AuthUserFile /usr/local/nagios/etc/htpasswd
         
        Require valid-user

        </Directory>

       42   htpasswd -c /usr/local/nagios/etc/htpasswd  nagiosadmin         #nagiosadmin为用户名 htpasswd为用户设置密码
       43  service httpd restart
       44  ifup eth0
       45  service iptables stop
       46  setenforce 0
       47  ifconfig
       48  cd /root/Desktop
    ####################################安装nagios-Plugin插件#############################
       49  tar -xzvf nagios-plugins-1.5.tar.gz
       50  cd nagios-plugins-1.5
       51  ls
       52   ./configure --with-nagios-user=nagios --with-nagios-group=nagios
       53  make &&make install
       54  chkconfig --add nagios  # 把nagios添加到开机系统中
       55  chkconfig nagios on   #把nagios设置为开机启动
       56  /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg             检查nagios的配置文件 出现两个 0 就正确
       57  service nagios start
       58  cd /root/Desktop
       59  ls



       监控windows 时 安装windows的插件
       1: 进入nagios的配置文件下的nagios.cfg里面
       vim /usr/local/nagios/etc/nagios.cfg
       cfg-file把# 注释去掉
       2:vim etc/objects/windows.cfg
          改为虚拟机的IP  address         172.18.9.122    ; IP address of the     host
       3:windows 下安装插件NSClient++ IP设为虚拟机的IP
         
       

    监控linux安装nrep插件
    ###############################安装nrpe插件########################################
       60  tar -xzvf nrpe-2.12.tar.gz
       61  cd nrpe-2.12
       62  ./configure --with-nrpe-user=nagios --with-nrpe-group=nagios --with-nagios-user=nagios --with-nagios-group=nagios --enable-command-args --enable-ssl
       63  make all
       64  make install-plugin
    ####################创建监控linux主机的配置文件linuxserver.cfg#######################
       65  cd /usr/local/nagios/
       66  ls
       67  cd etc/objects/
       68  ls
       69  vim linuxserver.cfg

    添加:

    define host{
            use linux-server
            host_name linuxserver
            alias my linux server
            address 172.18.9.98 (客户端ip)
    }
    define service{
            use                     local-service
            host_name               linuxserver
            service_description     Current Users
            check_command           check_nrpe!check_users
            }
    define service{
            use                     local-service
            host_name               linuxserver
            service_description     Current Load
            check_command           check_nrpe!check_load
            }
    define service{
            use                             local-service
            host_name                       linuxserver
            service_description             Swap Usage
            check_command                   check_local_swap!20!10
            }
    define service{
            use                             local-service
            host_name                       linuxserver
            service_description             http
            check_command                   check_http
            }

    #######################在命令文件里添加命令调用linuxserver.cfg里面的服务############
       70  vim commands.cfg
       71  cd ..
       72  ls

          添加:
          在commands.cfg中增加对check_nrpe的定义
    define command{
            command_name    check_nrpe        
            command_line    $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$       
            }

    ###################在主配置文件里面添加调用linuxserver.cfg配置文件的命令############
       73  vim nagios.cfg
    去掉#号 进入vim /usr/local/nagios/etc/nagios.cfg
    添加:
    cfg_file=/usr/local/nagios/etc/objects/linuxserver.cfg


    ######################重启服务测试############################################
       74  service nagios restart










    客户端操作:
    ###################################安装依赖环境####################################
       67  rpm -ivh gd-devel-2.0.35-11.el6.x86_64.rpm --nodeps
       68  cd /media/Packages/
       69  yum -y install httpd gcc glibc glibc-common gd gd-devel php php-   mysql mysql mysql-devel mysql-server openssl*
    ######################################创建默认不能登录系统的nagios用户############
       70  useradd -s /sbin/nologin nagios
       71  cd /root/Desktop
       72  ls
    ########################安装nagios-plugin插件######################################
       73  tar -xzvf nagios-plugins-1.5.tar.gz
       74  cd nagios-plugins-1.5
       75  ls
       76  ./configure --with-nagios-user=nagios --with-nagios-group=nagios
       77  make all
       78  make install
       79  cd /root/Desktop
    #########################安装nrpe插件##############################################
       80  tar -xzvf nrpe-2.12.tar.gz
       81  cd nrpe-2.12
       82  ./configure --with-nrpe-user=nagios --with-nrpe-group=nagios --with-nagios-user=nagios --with-nagios-group=nagios --enable-command-args --enable-ssl
       83  make all
       84  make install-plugin && make install-daemon &&make install-daemon-config
    #############################修改nrpe配置文件使其与服务器建立连接####################
       85  vim /usr/local/nagios/etc/nrpe.cfg
    修改参数:
    allowed_hosts=172.16.100.1(服务器ip)

    ##########################启动nrpe插件#####################################
       86  /usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d
       87  ifup eth0
       88  service iptables stop
       89  setenforce 0
       90  ifconfig
    ####################################开启http服务#################################
       91  service httpd restart



  • 相关阅读:
    前端 JS 原生JS实现一个单页应用的路由 router
    Gitbook 使用笔记
    EF Core 抓取SQL语句
    .NET5.0 MVC Session 的使用
    SQL Server 实用语句
    .NET5.0 MVC 生成发布(问题+技巧)
    服务器 SQL Sserver2012 开启远程连接
    windows 安装 Redis5.0 并运行
    前端 JS 学习笔记(知识点记录)
    CentOS 7 单机安装Redis Cluster(3主3从)
  • 原文地址:https://www.cnblogs.com/yueminghai/p/6390824.html
Copyright © 2011-2022 走看看