實戰Nagios NSCA方式監控Linux系統資源使用方式,nagiosnsca
關於nrpe的方式網上已經有很多很好的總結,我現在說說在我們系統中如何是用NSCA方式來擷取我們需要的被監控節點的資源使用方式資訊。
先講講Nagios Server端的基本配置:
1. nagios web gui 訪問配置,系統中使用的是nagios core中推薦的配置方式,通過apache httpd訪問nagios web,安裝nagios的時候會自動尋找系統中安裝的httpd,把nagios的httpd檔案放到httpd的conf.d目錄下,這樣,只要產生一次nagios web訪問的密碼就可以通過http://localhost/nagios/訪問nagios web.
htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin
2. 添加要監控的機器和要監控的服務2.1 /usr/local/nagios/etc/nagios.cfg: 增加要配置的OBJECT CONFIGURATION FILEs
cfg_file=/usr/local/nagios/etc/objects/localhost.cfgcfg_file=/usr/local/nagios/etc/objects/system_1.cfg
cfg_file=/usr/local/nagios/etc/objects/system_2.cfg
......
nagios_user=nagios
nagios_group=nagios
lock_file=/usr/local/nagios/var/nagios.lock
status_update_interval=10
2. 2添加被監聽節點需要被監聽的服務,例如:/usr/local/nagios/etc/objects/system_1.cfg
## define hosts
# system_1 oam_1define host{ use linux-server,host-pnp host_name system_1_oam_1 address <ip>contact_groupssystem_1_admins,systems_admins }......# system_1 traffic_1define host{ use linux-server,host-pnp host_name system_1_traffic_1 address <ip>contact_groupssystem_1_admins,systems_admins }......
## define services
# system_1 oam_1define service{ use passive_service,srv-pnp service_description CPU_Status host_name system_1_oam_1contact_groups system_1_admins,systems_admins }define service{ use passive_service,srv-pnp service_description Memory_Status host_name system_1_oam_1contact_groups system_1_admins,systems_admins }......# system_1 traffic_1define service{ use passive_service,srv-pnp service_description CPU_Status host_name system_1_traffic_1contact_groups system_1_admins,systems_admins }
Note:
host-pnp和srv-pnp是pnp4nagios要用的配置,後面再介紹pnp4nagios的其它配置
3. 對不同的系統添加系統監控管理員
3.1 /usr/local/nagios/etc/objects/contactgroups.cfg
define contactgroup{ contactgroup_name system_1_admins alias system_1_admins members oam-1,traffic-1 }......
3.2 /usr/local/nagios/etc/objects/contacts.cfg
define contact{ contact_name oam-1 ; Short name of user use generic-contact ; Inherit default values from generic-contact template (defined above) alias oam-1 ; Full name of user service_notification_options c host_notification_options d email nobody@localhost.com ; <<***** CHANGE THIS TO YOUR EMAIL ADDRESS ****** }define contact{ contact_name traffic-1 ; Short name of user use generic-contact ; Inherit default values from generic-contact template (defined above) alias traffic-1 ; Full name of user email nobody@localhost.com ; <<***** CHANGE THIS TO YOUR EMAIL ADDRESS ****** }......
Note:
service_notification_options: This directive is used to define the service states for which notifications can be sent out to this contact. Valid options are a combination of one or more of the following: w = notify on WARNING service states, u = notify on UNKNOWN service states, c = notify on CRITICAL service states, r = notify on service recoveries (OK states), and f = notify when the service starts and stopsflapping. If you specify n (none) as an option, the contact will not receive any type of service notifications.
host_notification_options:This directive is used to define the host states for which notifications can be sent out to this contact. Valid options are a combination of one or more of the following:
d = notify on DOWN host states,
u = notify on UNREACHABLE host states,
r = notify on host recoveries (UP states),
f = notify when the host starts and stopsflapping, and
s = send notifications when host or servicescheduled downtime starts and ends. If you specify
n (none) as an option, the contact will not receive any type of host notifications.
4. NSCA如果沒有連接埠衝突之類的問題,直接使用預設配置
5. 查看Nagios GUI中新加的host和service已經存在,狀態UNKNOWN.
6. 添加pnp4nagios bulk+npcd 模式監聽系統
6.1 修改/usr/local/nagios/etc/nagios.cfg
#處理performance資料process_performance_data=1#host_perfdata_command=process-host-perfdata#service_perfdata_command=process-service-perfdata#performance資料存放區檔案host_perfdata_file=/usr/local/pnp4nagios/var/host-perfdataservice_perfdata_file=/usr/local/pnp4nagios/var/service-perfdata#performance資料存放區格式host_perfdata_file_template=DATATYPE::HOSTPERFDATA\tTIMET::$TIMET$\tHOSTNAME::$HOSTNAME$\tHOSTPERFDATA::$HOSTPERFDATA$\tHOSTCHECKCOMMAND::$HOSTCHECKCOMMAND$\tHOSTSTATE::$HOSTSTATE$\tHOSTSTATETYPE::$HOSTSTATETYPE$service_perfdata_file_template=DATATYPE::SERVICEPERFDATA\tTIMET::$TIMET$\tHOSTNAME::$HOSTNAME$\tSERVICEDESC::$SERVICEDESC$\tSERVICEPERFDATA::$SERVICEPERFDATA$\tSERVICECHECKCOMMAND::$SERVICECHECKCOMMAND$\tHOSTSTATE::$HOSTSTATE$\tHOSTSTATETYPE::$HOSTSTATETYPE$\tSERVICESTATE::$SERVICESTATE$\tSERVICESTATETYPE::$SERVICESTATETYPE$\tSERVICEOUTPUT::$SERVICEOUTPUT$#performance檔案儲存體方式host_perfdata_file_mode=aservice_perfdata_file_mode=a#performance檔案處理時間間隔host_perfdata_file_processing_interval=15service_perfdata_file_processing_interval=15<pre name="code" class="plain">#performance檔案處理命令
host_perfdata_file_processing_command=process-host-perfdata-fileservice_perfdata_file_processing_command=process-service-perfdata-file
6.2 修改/usr/local/nagios/etc/objects/commands.cfg,增加performance檔案處理命令
define command{ command_name process-service-perfdata-file command_line /bin/mv /usr/local/pnp4nagios/var/service-perfdata /usr/local/pnp4nagios/var/spool/service-perfdata.$TIMET$}define command{ command_name process-host-perfdata-file command_line /bin/mv /usr/local/pnp4nagios/var/host-perfdata /usr/local/pnp4nagios/var/spool/host-perfdata.$TIMET$}
6.3 修改nagios.cfg,設定在nagios web gui中顯示pnp4nagios表徵圖的方式
第一種方法在templates.cfg裡面加入如下,只能在新視窗開啟映像資料
define host { name host-pnp action_url /pnp4nagios/index.php/graph?host=$HOSTNAME$&srv=_HOST_ register 0 }define service { name srv-pnp action_url /pnp4nagios/index.php/graph?host=$HOSTNAME$&srv=$SERVICEDESC$ register 0 }
第二種方法可以在滑鼠移到pnp4nagios表徵圖的時候就可以開到即時表徵圖,不過效果不是很好,按照說明加入如下:
拷貝status-header.ssi到/usr/local/nagios/share/ssi/目錄下面,同時修改templates.cfg,加入如下內容:
define host { name host-pnp action_url /pnp4nagios/index.php/graph?host=$HOSTNAME$&srv=_HOST_' class='tips' rel='/pnp4nagios/index.php/popup?host=$HOSTNAME$&srv=_HOST_ register 0 }define service { name srv-pnp action_url /pnp4nagios/index.php/graph?host=$HOSTNAME$&srv=$SERVICEDESC$' class='tips' rel='/pnp4nagios/index.php/popup?host=$HOSTNAME$&srv=$SERVICEDESC$ register 0 }
Note: 自動出現的小視窗清晰度不好,我喜歡第一種方式
Note: 這裡沒有涉及email的配置,記得通知設計的時候小心訊息泛濫被投訴。。。
第一篇: Nagios 使用介紹
第三篇: Nagios monitored Client配置和指令碼實現
問怎正確使用nagios服務,實現對Linux伺服器監控,並且不需要在被控端做任何設定,該怎實現?
nagios是目前非常流行的系統,伺服器監控免費軟體,很多大的國內網站像搜狐,網易都在使用nagios進行伺服器監控。
nagios的有點在於他本身只是一個架構,對於nagios擴充監控模組,以及警示模組非常方便,能很方便的加入自己編寫的服務監控,以及手機簡訊,郵件,gtalk ,msn警示等等。
以下是nagios在linux REDHAT AS4U4 下的安裝和簡單的配置過程:
下載軟體:
wget
wget
wget
添加使用者:
useradd -m nagios
passwd nagios
groupadd nagcmd
usermod -G nagcmd nagios
usermod -G nagcmd daemon
編譯安裝nagios
tar -xvzf nagios-3.0.3.tar.gz
cd nagios-3.0.3
./configure --with-command-group=nagcmd
make all
make install
make install-init
make install-config
make install-commandmode
設定apache伺服器訪問密碼:
cd /usr/local/nagios/etc/
/usr/local/apache/bin/htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin
cd /usr/local/apache/conf/
vi httpd-vhosts.conf
配置apache的cgi ,具體配置如下:
ScriptAlias /nagios/cgi-bin /usr/local/nagios/sbin
<Directory "/usr/local/nagios/sbin">
Options ExecCGI
AllowOverride None
Order allow,deny
Allow from all
AuthName "Nagios Access"
AuthType Basic
AuthUserFile /usr/local/nagios/etc/htpasswd.users
Require valid-user
</Directory>
Alias /nagios /usr/local/nagios/share
<Directory "/usr/local/nagios/share">
Options None
AllowOverride None
Order allow,deny
Allow from all
AuthName "Nagios Access"
AuthType Basic
AuthUserFile /usr/local/nagios/etc/htpasswd.users
Require valid-us......餘下全文>>
怎用 nagios 監控 linux 系統 io 使用方式
如果預設指令碼沒有的話,就自己寫指令碼吧