一、遠端主機添加nagios使用者
<code>[root@yo ~]</code><code># useradd -s /sbin/nologin nagios</code>
二、安裝nagios-plugins插件
<code>[root@yo nagios-plugins-2.1.1]</code><code># ./configure --prefix=/usr/local/nagios --with-nagios-user=nagios --with-nagios-group=nagios</code>
<code>[root@yo nagios-plugins-2.1.1]</code><code># make && make install</code>
三、檢視生成的目錄檔案
<code>[root@yo nagios-plugins-2.1.1]</code><code># ls /usr/local/nagios/</code>
<code>include libexec share</code>
四、安裝nrpe
<code>[root@yo nrpe-2.15]</code><code># ./configure </code>
<code>[root@yo nrpe-2.15]</code><code># make all</code>
<code>[root@yo nrpe-2.15]</code><code># make install-daemon</code>
<code>[root@yo nrpe-2.15]</code><code># make install-daemon-config</code>
<code>[root@yo nrpe-2.15]</code><code># make install-plugin</code>
五、安裝nrpe守護程序的服務xinetd
<code>[root@yo nrpe-2.15]</code><code># make install-xinetd</code>
<code>/usr/bin/install</code> <code>-c -m 644 sample-config</code><code>/nrpe</code><code>.xinetd </code><code>/etc/xinetd</code><code>.d</code><code>/nrpe</code>
六、打開/etc/xinetd.d/nrpe檔案,修改添加服務端IP
<code> </code><code>only_from = 127.0.0.1 localhost 192.168.1.21</code>
七、添加nrpe守護程序端口号
<code>[root@yo nrpe-2.15]</code><code># vim /etc/services</code>
<code>nrpe 5666</code><code>/tcp</code> <code>#nrpe</code>
八、安裝xinetd軟體包,并重新開機xinetd服務
<code>[root@yo nrpe-2.15]</code><code># yum -y install xinetd</code>
<code>[root@yo nrpe-2.15]</code><code># /etc/init.d/xinetd restart</code>
<code>Stopping xinetd: [FAILED]</code>
<code>Starting xinetd: [ OK ]</code>
九、檢視監聽端口和nrpe程序有沒有起來
<code>[root@yo nrpe-2.15]</code><code># netstat -ntlp |grep 5666</code>
<code>tcp 0 0 :::5666 :::* LISTEN 73351</code><code>/xinetd</code>
<code>[root@yo nrpe-2.15]</code><code># netstat -at | grep nrpe</code>
<code>tcp 0 0 *:nrpe *:* LISTEN</code>
十、在遠端主機運作check_nrpe測試有沒有安裝或配置成功
<code>[root@yo nrpe-2.15]</code><code># /usr/local/nagios/libexec/check_nrpe -H 127.0.0.1 </code>
<code>NRPE v2.15</code>
<code>[root@yo nrpe-2.15]</code><code># /usr/local/nagios/libexec/check_nrpe -H 127.0.0.1 -c check_users</code>
<code>USERS OK - 5 </code><code>users</code> <code>currently logged </code><code>in</code> <code>|</code><code>users</code><code>=5;5;10;0</code>
<code>[root@yo nrpe-2.15]</code><code># /usr/local/nagios/libexec/check_nrpe -H 127.0.0.1 -c check_load</code>
<code>OK - load average: 0.00, 0.00, 0.00|load1=0.000;15.000;30.000;0; load5=0.000;10.000;25.000;0; load15=0.000;5.000;20.000;0;</code>
<code>[root@yo nrpe-2.15]</code><code># /usr/local/nagios/libexec/check_nrpe -H localhost</code>
<code>[root@yo nrpe-2.15]</code><code># /usr/local/nagios/libexec/check_nrpe -H localhost -c check_users</code>
十一、以下是在服務端測試
<code>[root@www ~]</code><code># /usr/local/nagios/libexec/check_nrpe -H 192.168.1.250</code>
<code>[root@www ~]</code><code># /usr/local/nagios/libexec/check_nrpe -H 192.168.1.250 -c check_users</code>
十二、服務端添加hosts.cfg和services.cfg兩個檔案,作為遠端主機的監控配置檔案
<code>[root@www ~]</code><code># vim /etc/nagios/nagios.cfg </code>
<code>cfg_file=</code><code>/etc/nagios/objects/hosts</code><code>.cfg</code>
<code>cfg_file=</code><code>/etc/nagios/objects/services</code><code>.cfg</code>
<code>[root@www ~]</code><code># touch /etc/nagios/objects/hosts.cfg</code>
<code>[root@www ~]</code><code># touch /etc/nagios/objects/services.cfg</code>
十三、配置services.cfg檔案
<code>define service{</code>
<code> </code><code>use generic-service</code>
<code> </code><code>host_name tecmint</code>
<code> </code><code>service_description CPU Load</code>
<code> </code><code>check_command check_nrpe!check_load</code>
<code> </code><code>}</code>
<code> </code><code>service_description Total Processes</code>
<code> </code><code>check_command check_nrpe!check_total_procs</code>
<code> </code><code>service_description Current Users</code>
<code> </code><code>check_command check_nrpe!check_users</code>
<code> </code><code>service_description SSH Monitoring</code>
<code> </code><code>check_command check_nrpe!check_ssh</code>
<code> </code><code>service_description FTP Monitoring</code>
<code> </code><code>check_command check_nrpe!check_ftp</code>
十四、配置hosts.cfg檔案
<code>## Default Linux Host Template ##</code>
<code>define host{</code>
<code>name linux-box ; Name of this template</code>
<code>use generic-host ; Inherit default values</code>
<code>check_period 24x7</code>
<code>check_interval 5</code>
<code>retry_interval 1</code>
<code>max_check_attempts 10</code>
<code>check_command check-host-alive</code>
<code>notification_period 24x7</code>
<code>notification_interval 30</code>
<code>notification_options d,r</code>
<code>contact_groups admins</code>
<code>register 0 ; DONT REGISTER THIS - ITS A TEMPLATE</code>
<code>}</code>
<code>## Default</code>
<code>use linux-box ; Inherit default values from a template</code>
<code>host_name tecmint ; The name we're giving to this server</code>
<code>alias</code> <code>CentOS 6.5 ; A longer name </code><code>for</code> <code>the server</code>
<code>address 192.168.1.250 ; IP address of Remote Linux host</code>
十五、檢查配置并重新開機nagios
<code>[root@www ~]</code><code># /usr/local/nagios/bin/nagios -v /etc/nagios/nagios.cfg </code>
<code>Total Warnings: 0</code>
<code>Total Errors: 0</code>
<code>[root@www ~]</code><code># service nagios restart</code>
十六、在web頁面上檢視結果
<a href="http://s4.51cto.com/wyfs02/M00/79/9E/wKioL1aWTwrTYbBtAAKNLqV2vXA284.jpg" target="_blank"></a>
本文轉自 HMLinux 51CTO部落格,原文連結:http://blog.51cto.com/7424593/1734791