溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

nagios監(jiān)控系統(tǒng)的快速部署

發(fā)布時間:2020-06-27 20:48:28 來源:網(wǎng)絡 閱讀:618 作者:chengxcwl 欄目:移動開發(fā)

最近有需求又搞了下nagios記錄下備忘,采用快速安裝lamp方式

1、快速安裝lamp

yum groupinstall "Web Server"

yum groupinstall "MySQL Database"
yum install php-mysql
2、安裝nagios
tar -xjvf nagios-cn-3.2.3.tar.bz2
cd nagios-cn-3.2.3
./configure --prefix=/usr/local/nagios --with-gd-lib=/usr/lib --with-gd-inc=/usr/include --with-nagios-user=nagios --with-nagios-group=nagios
make all && make install
make install-init && make install-commandmode
make install-config
/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
3、修改/etc/httpd/conf/httpd.conf
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.users
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.users
Require valid-user
</Directory>
 重啟httpd: service httpd restart
4、插件及客戶端安裝
#!/bin/sh
set -x
#if [ -d /usr/local/nagios ]; then
#        rm -rf /usr/local/nagios*
#fi
if [ -d /usr/local/nrpe ]; then
        rm -rf /usr/local/nrpe*
fi
useradd   nagios
yum -y install xinetd
wget -c http://sourceforge.net/projects/nagiosplug/files/nagiosplug/1.4.14/nagios-plugins-1.4.14.tar.gz/download
tar zxvf nagios-plugins-1.4.14.tar.gz
cd nagios-plugins-1.4.14
./configure --prefix=/usr/local/nagios --enable-redhat-pthread-workaround
make && make install
chown -R nagios.nagios /usr/local/nagios
cd ../
wget -c http://cdnetworks-kr-1.dl.sourceforge.net/project/nagios/nrpe-2.x/nrpe-2.12/nrpe-2.12.tar.gz
tar zxvf nrpe-2.12.tar.gz
cd nrpe-2.12
./configure --prefix=/usr/local/nagios --enable-command-args
make all
make install-plugin
make install-daemon
make install-daemon-config
make install-xinetd
cd /etc/xinetd.d/
sed  -i 's/127.0.0.1/127.0.0.1 192.168.120.7/g' nrpe
echo "nrpe            5666/tcp                        # nrpe" >> /etc/services
service xinetd restart
6、添加配置文件在nagios.cfg中
cfg_file=/usr/local/nagios/etc/objects/hosts.cfg
cfg_file=/usr/local/nagios/etc/objects/services.cfg
注釋#cfg_file=/usr/local/nagios/etc/objects/localhost.cfg
7、定義hosts.cfg文件
# Define a host for the local machine
define host{
        use                     standard-server
        host_name               localhost-220
        alias                         localhost
        address                   127.0.0.1
define host{
        use                     standard-server
        host_name          DB
        alias                   192.168.120.3
        address                 192.168.120.3
        }
 
8、定義模版文件templates.cfg
define service{
        name                       service-all
        use                        generic-service 
        contact_groups             admingroup
        register                          0 
        }
define service{
        name                                 generic-service              
        active_checks_enabled                    1                     
        passive_checks_enabled                   1                            
        parallelize_check                        1                          
        obsess_over_service                      1                            
        check_freshness                          0                    
        notifications_enabled                    1                      
        event_handler_enabled                    1                    
        flap_detection_enabled                   1                     
        failure_prediction_enabled               1                    
        process_perf_data                        1                    
        retain_status_information                1                   
        retain_nonstatus_information             1                      
        is_volatile                              0                     
        check_period                            24x7                
        max_check_attempts                       3                      
        normal_check_interval                    3                     
        retry_check_interval                     1                     
        contact_groups                        admingroup                   
        notification_options                   w,c,r                 
        notification_interval                    0                     
        notification_period                     24x7                 
        register                                 0                  
        }

define host{
        name                            generic-host    ; The name of this host template
        notifications_enabled           1               ; Host notifications are enabled
        event_handler_enabled           1               ; Host event handler is enabled
        flap_detection_enabled          1               ; Flap detection is enabled
        failure_prediction_enabled      1               ; Failure prediction is enabled
        process_perf_data               1               ; Process performance data
        retain_status_information       1               ; Retain status information across program restarts
        retain_nonstatus_information    1               ; Retain non-status information across program restarts
        notification_period             24x7            ; Send host notifications at any time
        register                        0               ; DONT REGISTER THIS DEFINITION - ITS NOT A REAL HOST, JUST A TEMPLATE!
        }

define host{
        name                            standard-server
        use                             generic-host
        check_period                    24x7
        check_interval                  3              
        retry_interval                  1
        max_check_attempts              5              
        check_command                   check-host-alive
        notification_period             24x7                                                       
        notification_interval           0              
        notification_options            d,u,r          
        contact_groups                  admingroup     
        }
9、定義時間文件
# 24x7 monitor
define timeperiod{
        timeperiod_name 24x7
        alias           24 Hours A Day, 7 Days A Week
        sunday          00:00-24:00
        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
        saturday        00:00-24:00
        }
# workhours monitor
define timeperiod{
        timeperiod_name workhours
        alias           Normal Work Hours
        monday          09:00-17:00
        tuesday         09:00-17:00
        wednesday       09:00-17:00
        thursday        09:00-17:00
        friday          09:00-17:00
        }
# custom monitor time
define timeperiod{
        timeperiod_name smsworkhours
        alias           no sleep time
        sunday          08:30-23:00
        monday          07:00-23:00
        tuesday         07:00-23:00
        wednesday       07:00-23:00
        thursday        07:00-23:00
        friday          07:00-23:00
        saturday        08:30-23:00
        }
10、定義服務配置文件
define service {
        use                        service-all
        host_name                  localhost-220
        service_description        check-http
        check_command              check_http
        }
define service {
        use                        service-all
        host_name                  localhost-220
        service_description        check-disk
        check_command              check_nrpe!check_disk
        }
define service {
        use                        service-all
        host_name                  localhost-220
        service_description        check-alive
        check_command              check-host-alive
        }
define service {
        use                        service-all
        host_name                  localhost-220
        service_description        check-load
        check_command              check_nrpe!check_load
11、錯誤處理總結
①#如果提示“Whoops!   Error: Could not read object configuration data! ”,這是因為沒有啟動nagios后臺進程,執(zhí)行以下命令
/usr/local/nagios/bin/nagios -d /usr/local/nagios/etc/nagios.cfg 或者service nagios restart
②It appears as though you do not have permission to view information for any of the services you requested…
解決:打開cgi.cfg配置文件,里面有個參數(shù):
use_authentication=1
為了保障系統(tǒng)的安全性,nagios設置了這個參數(shù),默認為1,改為0即可

 

向AI問一下細節(jié)

免責聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權內(nèi)容。

AI