美文网首页
nagios安装配置

nagios安装配置

作者: iceriot | 来源:发表于2017-10-25 13:53 被阅读0次
    nagios安装简介

    nagios本身并没有监控的功能,所有的监控是由插件完成的,插件将监控的结果返回给nagios,nagios分析这些结果以web的方式展现给我们,同时提供相应的报警功能(这个报警的功能也是由插件完成的)。

    nagios core 完成核心功能比如调用插件执行任务
    nagios plugins 完成具体的某个任务比如检查远程主机是否存活
    apache,php 前端页面展示和cgi脚本执行
    nrpe 远程插件执行,监控远程linux主机需要安装

    系统及环境

    centos==7.3.1611 (Core)
    nagios==4.3.2
    nagios-plugins==2.2.1
    nrpe==2.12
    apr==1.4.5
    apr-util==1.3.12
    pcre==8.33
    httpd==2.4.28
    php==5.6.25

    用户创建
    /usr/sbin/groupadd nagios
    /usr/sbin/groupadd nagcmd
    /usr/sbin/groupadd apache
    /usr/sbin/useradd  nagios -g nagios -s /sbin/nologin
    /usr/sbin/useradd  apache -g apache -s /sbin/nologin
    /usr/sbin/usermod -a -G nagcmd nagios
    /usr/sbin/usermod -a -G nagcmd apache
    
    安装系统依赖
    yum remove -y apr-util-devel apr apr-util-mysql \
                        apr-docs apr-devel apr-util \
                        apr-util-docs
    yum install gcc glibc glibc-common  gcc-c++ \
                      gd gd-devel openssl openssl-devel \
                      unzip  bzip2  libxml2 libxml2-devel
    
    编译安装apache,php
    #安装apr
    wget http://archive.apache.org/dist/apr/apr-1.4.5.tar.gz
    tar -xf apr-1.4.5.tar.gz
    cd apr-1.4.5
    ./configure  --prefix=/usr/local/apr
    make && make install
    
    #安装apr-util
    wget http://archive.apache.org/dist/apr/apr-util-1.3.12.tar.gz
    tar -xf apr-util-1.3.12.tar.gz
    cd apr-util-1.3.12
    ./configure  --prefix=/usr/local/apr-util \
       --with-apr=/usr/local/apr/bin/apr-1-config
    make && make install
    
    #安装pcre
     wget http://jaist.dl.sourceforge.net/project/pcre/pcre/8.33/pcre-8.33.tar.gz
    tar -xf pcre-8.33.tar.gz
    cd  pcre-8.33
    ./configure  --prefix=/usr/local/pcre
    make && make install
    
    #安装httpd
    wget http://mirror.bit.edu.cn/apache//httpd/httpd-2.4.28.tar.gz
    tar -xf httpd-2.4.28.tar.gz
    cd httpd-2.4.28
    ./configure  --prefix=/usr/local/apache2 \
      --with-apr=/usr/local/apr \
      --with-apr-util=/usr/local/apr-util \
      --with-pcre=/usr/local/pcre
    make && make install
    
    #安装php
    wget http://cn2.php.net/distributions/php-5.6.25.tar.gz
    tar -xf php-5.6.25.tar.gz
    cd php-5.6.25
    ./configure  --prefix=/usr/local/php \
       --with-apxs2=/usr/local/apache2/bin/apxs
    make && make install
    
    编译安装nagios
    #安装nagios core
    tar -xf nagios-4.3.2.tar.gz
    cd nagios-4.3.2
    ./configure --with-command-group=nagcmd         
    make all                                     
    make install                                 
    make install-init                          
    make install-config                         
    make install-commandmode
    #添加apache nagios配置
    cp sample-config/httpd.conf /usr/local/apache2/conf/extra/httpd-nagios.conf 
    #添加web界面管理用户
    /usr/local/apache2/bin/htpasswd -bc /usr/local/nagios/etc/htpasswd.users nagiosadmin admin 
    #设置开机自启动
    chkconfig --add nagios                        
    chkconfig nagios on    
    
    ###################################
    #安装nagios-plugin
    tar -xf nagios-plugins-2.2.1.tar.gz
    cd nagios-plugins-2.2.1
    ./configure --with-nagios-user=nagios  --with-nagios-group=nagios
    make && make install
    
    ###################################
    #安装nrpe
    tar -xvf nrpe-2.12.tar.gz 
    cd nrpe-2.12
    ./configure 
    make all
    make install-plugin
    
    配置apache和nagios
    #!/bin/bash
    
    conf=/usr/local/apache2/conf/httpd.conf
    
    #1开启apache cgi模块,解决点击页面下载cgi情况
    sed -i "s+^#LoadModule cgid_module+LoadModule cgid_module+g" $conf
    
    #2.开启apache php模块,解决403禁止访问问题
    sed -i "s/DirectoryIndex index.html/& index.php/g"  $conf
    sed -i "/application\/x-gzip/aAddType application\/x-httpd-php .php" $conf
    
    #3.添加apache nagios配置文件
    echo "Include conf/extra/httpd-nagios.conf" >> $conf
    
    #4.设置apache 运行用户和组为apache"
    sed -i "s/^User.*$/User apache/g"   $conf
    sed -i "s/^Group.*$/Group apache/g" $conf
    
    启动nagios apache
    service nagios start
    /usr/local/apache2/bin/apachectl start
    

    至此nagios的基本安装已经完成,登录浏览器访问ip/nagios即可。

    相关文章

      网友评论

          本文标题:nagios安装配置

          本文链接:https://www.haomeiwen.com/subject/djfqpxtx.html