自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

用Nagios來(lái)監(jiān)控網(wǎng)絡(luò)服務(wù)器-nagios配置

運(yùn)維 系統(tǒng)運(yùn)維
什么是nagios?如何用Nagios來(lái)監(jiān)控網(wǎng)絡(luò)服務(wù)器?nagios怎樣安裝?nagios怎樣配置?Nagios是一個(gè)用來(lái)監(jiān)控主機(jī)、服務(wù)和網(wǎng)絡(luò)的開(kāi)放源碼軟件,很多大的公司或組織都在使用它。本文講述的是用Nagios來(lái)監(jiān)控網(wǎng)絡(luò)服務(wù)器,nagios配置

  現(xiàn)在開(kāi)始配置:

  1:配置web接口

  假設(shè)你已經(jīng)運(yùn)行了apache,如果沒(méi)有,請(qǐng)參考:apache的安裝

  1.   vi /usr/local/apache2/conf/httpd.conf  
  2.  

  添加如下內(nèi)容:

  1.   ScriptAlias /nagios/cgi-bin /usr/local/nagios/sbin  
  2.  
  3.     
  4.  
  5.   Options Execcgi  
  6.  
  7.   AllowOverride None  
  8.  
  9.   Order allow,deny  
  10.  
  11.   Allow from all  
  12.  
  13.   AuthName "Nagios Access"  
  14.  
  15.   AuthType Basic  
  16.  
  17.   AuthUserFile /usr/local/nagios/etc/htpasswd.users  
  18.  
  19.   Require valid-user  
  20.  
  21.     
  22.  
  23.   Alias /nagios /usr/local/nagios/share  
  24.  
  25.     
  26.  
  27.   Options None  
  28.  
  29.   AllowOverride None  
  30.  
  31.   Order allow,deny  
  32.  
  33.   Allow from all  
  34.  
  35.   AuthName "Nagios Access"  
  36.  
  37.   AuthType Basic  
  38.  
  39.   AuthUserFile /usr/local/nagios/etc/htpasswd.users  
  40.  
  41.   Require valid-user  
  42.  

  

  修改完畢,保存文件,并重啟apache:

  1.   /usr/local/apahce2/bin/apachectl restart  
  2.  

  2:配置apache的BASIC認(rèn)證:

  生成認(rèn)證密碼:

  1.   /usr/local/apache2/bin/htpasswd –c /usr/local/nagios/etc/htpasswd.users nagios nagios  
  2.  

  apache接口配置完成。

#p#

  開(kāi)始配置nagios:

  1.   cd /usr/local/nagios/etc/  
  2.  

  在/usr/local/nagios/etc下是nagios的配置模板文件-sample,把.cfg-sample文件全部拷貝成.cfg

  例如:cp nagios.cfg-sample nagios.cfg

  全部拷貝完成即可.

  1.   vi minimal.cfg  
  2.  

  注釋所有command:

  注釋的方法是在每一個(gè)定義語(yǔ)句前面添加”#“

  修改cgi.cfg

  修改use_authentication=1為use_authentication=0,即不用驗(yàn)證.不然有一些頁(yè)面不會(huì)顯示。

  現(xiàn)在檢查配置文件是否有語(yǔ)法錯(cuò)誤:

  1.   /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg  
  2.  

  如果正確,會(huì)顯示以下結(jié)果:

  1.   Total Warnings: 0  
  2.  
  3.   Total Errors: 0  
  4.  

  否則,需要根據(jù)提示進(jìn)行修改配置文件。

  配置文件等會(huì)再弄。現(xiàn)在啟動(dòng)nagios

  1.   /usr/local/nagios/bin/nagios -d /usr/local/nagios/etc/nagios.cfg  
  2.  

  為了使nagios異常中斷,我們使用daemontools啟動(dòng):

#p#

  安裝daemontool:

  1.   mkdir -p /package  
  2.  
  3.   chmod 1755 /package  
  4.  
  5.   cd /package  
  6.  
  7.   fetch http://cr.yp.to/daemontools/daemontools-0.76.tar.gz  
  8.  
  9.   cd admin/daemontools-0.76/  
  10.  
  11.   package/install  
  12.  

  檢查svscan進(jìn)程是否啟動(dòng):

  1.   ps aux | grep svscan  
  2.  
  3.   root 376 0.0 0.0 1636 0 con- IW - 0:00.00 /bin/sh /command/svscanboot  
  4.  
  5.   root 411 0.0 0.0 1224 208 con- S 8Jul06 0:42.50 svscan /service  
  6.  

  ok,啟動(dòng)正常了。

  1.   cd /service  
  2.  
  3.   mkdir nagios  
  4.  
  5.   chmod 1755 nagios  
  6.  
  7.   touch ./run  
  8.  
  9.   chmod 755 ./run  
  10.  
  11.   vi run  
  12.  
  13.   PATH=/usr/local/bin:/usr/bin:/bin  
  14.  
  15.   export PATH  
  16.  
  17.   exec env - PATH=$PATH \  
  18.  
  19.   /usr/local/nagios/bin/nagios /usr/local/nagios/etc/nagios.cfg  
  20.  
  21.   mkdir log  
  22.  
  23.   cd log  
  24.  
  25.   touch ./run  
  26.  
  27.   chmod 755 ./run  
  28.  
  29.   vi ./run  
  30.  
  31.   #!/bin/sh  
  32.  
  33.   exec setuidgid logadmin multilog t s1000000 n100 ./main  
  34.  
  35.   mkdir main  
  36.  
  37.   chmod 777 main  
  38.  
  39.   chown nagios.nagios main  
  40.  
  41.   touch status  
  42.  
  43.   chown nagios.nagios status  
  44.  
  45.   svc -u /service/nagios/  
  46.  
  47.   svstat /service/nagios/  
  48.  
  49.   root@## ps auxww | grep nagios  
  50.  
  51.   root 23276 0.0 0.1 1176 488 ?? I 5:00PM 0:01.71 supervise nagios  
  52.  
  53.   nagios 34251 0.0 0.3 2316 1552 ?? S 6:06PM 0:00.10 /usr/local/nagios/bin/nagios /usr/local/nagios/etc/nagios.cfg  
  54.  
  55.   root@##  
  56.  

  ok,現(xiàn)在把nagios服務(wù)做成自動(dòng)啟動(dòng)的服務(wù)了。

  通過(guò)svc命令可以啟動(dòng)或者停止服務(wù)。

  ---------------------------------------------------------------------------------

  1.   svc opts services  
  2.  
  3.   opts is a series of getopt-style options. services consists of any number of arguments, each argument naming a directory used by supervise.  
  4.  
  5.   -u: Up. If the service is not running, start it. If the service stops, restart it.  
  6.  
  7.   -d: Down. If the service is running, send it a TERM signal and then a CONT signal. After it stops, do not restart it.  
  8.  
  9.   -o: Once. If the service is not running, start it. Do not restart it if it stops.  
  10.  
  11.   -p: Pause. Send the service a STOP signal.  
  12.  
  13.   -c: Continue. Send the service a CONT signal.  
  14.  
  15.   -h: Hangup. Send the service a HUP signal.  
  16.  
  17.   -a: Alarm. Send the service an ALRM signal.  
  18.  
  19.   -i: Interrupt. Send the service an INT signal.  
  20.  
  21.   -t: Terminate. Send the service a TERM signal.  
  22.  
  23.   -k: Kill. Send the service a KILL signal.  
  24.  
  25.   -x: Exit. supervise will exit as soon as the service is down. If you use this option on a stable system, you're doing something wrong; supervise is designed to run forever.  
  26.  

  ---------------------------------------------------------------------------------

  比如:

  停止nagios--svc -d /service/nagios/

  重啟nagios--svc -t /service/nagios/

  啟動(dòng)nagios--svc -u /service/nagios/

  當(dāng)然,你也可以使用inited的方式進(jìn)行:

  /usr/local/etc/rc.d/nagios start/stop

  好了,反正daemontools很強(qiáng)大,以后慢慢熟悉,轉(zhuǎn)入正題。

  現(xiàn)在打開(kāi)網(wǎng)頁(yè):http://localhost/nagios/

  一定會(huì)讓你大吃一驚,呵呵,我的服務(wù)器和服務(wù)狀態(tài)都清楚的看到了。

  現(xiàn)在我們的nagios中只有一個(gè),那就是它自己,localhost,呵呵,等會(huì)我們添加別的主機(jī)和主機(jī)服務(wù),ok,我們認(rèn)識(shí)一下nagios的廬山真面目:

#p#

  配置nagios:

  1)為主機(jī)添加服務(wù)

  2)添加主機(jī)并添加服務(wù)

  3)停止一個(gè)服務(wù)

  4)刪除一臺(tái)主機(jī)和服務(wù)

  5)查看所有主機(jī)的故障

  6)查看一臺(tái)特定的主機(jī)狀態(tài)

  7)改變報(bào)警的時(shí)間間隔

  8)改變發(fā)現(xiàn)故障的重試次數(shù)

  9)如何在nagios中使用外部命令

  1)為主機(jī)添加一個(gè)服務(wù)

  為localhost主機(jī)添加qmail服務(wù)的監(jiān)控,方法如下:

  1.   vi minimal.cfg  
  2.  
  3.   define service{  
  4.  
  5.   use generic-service ; Name of service template to use  
  6.  
  7.   host_name localhost  
  8.  
  9.   service_description qmail_smtp  
  10.  
  11.   is_volatile 0  
  12.  
  13.   check_period 24x7  
  14.  
  15.   max_check_attempts 1  
  16.  
  17.   normal_check_interval 1  
  18.  
  19.   retry_check_interval 1  
  20.  
  21.   contact_groups admins  
  22.  
  23.   notification_options w,u,c,r  
  24.  
  25.   notification_interval 960  
  26.  
  27.   notification_period 24x7  
  28.  
  29.   check_command check_smtp!20%!10%!/  
  30.  
  31.   }  
  32.  

  可以直接拷貝原有的進(jìn)行修改,我這個(gè)就是拷貝的原有的check_local_disk進(jìn)行的。

  修改host_name,service_description,check_command等

  1.   define service{  
  2.  
  3.   use generic-service ; Name of service template to use  
  4.  
  5.   host_name localhost  
  6.  
  7.   service_description qmail_pop3  
  8.  
  9.   is_volatile 0  
  10.  
  11.   check_period 24x7  
  12.  
  13.   max_check_attempts 1  
  14.  
  15.   normal_check_interval 1  
  16.  
  17.   retry_check_interval 1  
  18.  
  19.   contact_groups admins  
  20.  
  21.   notification_options w,u,c,r  
  22.  
  23.   notification_interval 960  
  24.  
  25.   notification_period 24x7  
  26.  
  27.   check_command check_pop!20%!10%!/  
  28.  
  29.   }  
  30.  

  照貓畫(huà)虎的進(jìn)行修改,然后去修改:

  1.   vi checkcommands.cfg  
  2.  
  3.   #'check_qmail' command definition  
  4.  
  5.   define command{  
  6.  
  7.   command_name check_qmail  
  8.  
  9.   command_line $USER1$/check_smtp -H 127.0.0.1  
  10.  
  11.   }  
  12.  
  13.   define command{  
  14.  
  15.   command_name check_pop3  
  16.  
  17.   command_line $USER1$/check_pop -H 127.0.0.1  
  18.  
  19.   }  
  20.  

  保存,然后檢查配置文件:

  1.   /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg  
  2.  

  如果沒(méi)有錯(cuò)誤會(huì)顯示:

  1.   Total Warnings: 0  
  2.  
  3.   Total Errors: 0  
  4.  

  如果有錯(cuò)誤,請(qǐng)根據(jù)提示進(jìn)行錯(cuò)誤的修正。

  重啟nagios

  1.   svc -d /service/nagios/ && svc -u /service/nagios/  
  2.  

  通過(guò)web頁(yè)面檢查nagios的結(jié)果:

  http://10.5.1.153/nagios/

  點(diǎn)擊“Service Detail”

  會(huì)出現(xiàn):

  2)添加主機(jī)并添加服務(wù)

  我們會(huì)監(jiān)控這臺(tái)主機(jī)的負(fù)載、磁盤(pán)等一些沒(méi)有通過(guò)端口方式啟動(dòng)的服務(wù)器狀態(tài),以及它的服務(wù),比如:apache、mysql、qmail和ntp等等吧。那么沒(méi)有端口的nagios直接能監(jiān)控到嗎?答案是不行。所以我們必須在兩臺(tái)主機(jī)上安裝nrpe,nrpe可以啟動(dòng)5666端口,把檢測(cè)的信息源源不斷的傳給監(jiān)控中心的主機(jī)。

  ok,我們把a(bǔ)pache、mysql、qmail和ntp先加上,這回我們把監(jiān)控的主機(jī)和服務(wù)新建一個(gè)文件:

  1.   cd /usr/local/nagios/etc/  
  2.  
  3.   touch 10_5_1_156.cfg  
  4.  
  5.   vi nagios.cfg  
  6.  
  7.   cfg_file=/usr/local/nagios/etc/10_5_1_156.cfg  
  8.  
  9.   vi 10_5_1_156.cfg  
  10.  

  定義一個(gè)主機(jī):

  1.   define host{  
  2.  
  3.   use generic-host ; Name of host template to use  
  4.  
  5.   host_name test_nrpe  
  6.  
  7.   alias client  
  8.  
  9.   address 10.5.1.156  
  10.  
  11.   check_command check-host-alive  
  12.  
  13.   max_check_attempts 1  
  14.  
  15.   check_period 24x7  
  16.  
  17.   notification_interval 120  
  18.  
  19.   notification_period 24x7  
  20.  
  21.   notification_options d,r  
  22.  
  23.   contact_groups admins  
  24.  
  25.   }  
  26.  

  定義主機(jī)需要檢查的服務(wù):

  1.   define service{  
  2.  
  3.   use generic-service ; Name of service template to use  
  4.  
  5.   host_name test_nrpe  
  6.  
  7.   service_description PING  
  8.  
  9.   is_volatile 0  
  10.  
  11.   check_period 24x7  
  12.  
  13.   max_check_attempts 1  
  14.  
  15.   normal_check_interval 1  
  16.  
  17.   retry_check_interval 1  
  18.  
  19.   contact_groups admins  
  20.  
  21.   notification_options w,u,c,r  
  22.  
  23.   notification_interval 960  
  24.  
  25.   notification_period 24x7  
  26.  
  27.   check_command check_ping!100.0,20%!500.0,60%  
  28.  
  29.   }  
  30.  
  31.   define service{  
  32.  
  33.   use generic-service ; Name of service template to use  
  34.  
  35.   host_name test_nrpe  
  36.  
  37.   service_description apache  
  38.  
  39.   is_volatile 0  
  40.  
  41.   check_period 24x7  
  42.  
  43.   max_check_attempts 1  
  44.  
  45.   normal_check_interval 1  
  46.  
  47.   retry_check_interval 1  
  48.  
  49.   contact_groups admins  
  50.  
  51.   notification_options w,u,c,r  
  52.  
  53.   notification_interval 960  
  54.  
  55.   notification_period 24x7  
  56.  
  57.   check_command check_http!100.0,20%!500.0,60%  
  58.  
  59.   }  
  60.  
  61.   define service{  
  62.  
  63.   use generic-service ; Name of service template to use  
  64.  
  65.   host_name test_nrpe  
  66.  
  67.   service_description mysql  
  68.  
  69.   is_volatile 0  
  70.  
  71.   check_period 24x7  
  72.  
  73.   max_check_attempts 1  
  74.  
  75.   normal_check_interval 1  
  76.  
  77.   retry_check_interval 1  
  78.  
  79.   contact_groups admins  
  80.  
  81.   notification_options w,u,c,r  
  82.  
  83.   notification_interval 960  
  84.  
  85.   notification_period 24x7  
  86.  
  87.   check_command check_mysql!100.0,20%!500.0,60%  
  88.  
  89.   }  
  90.  
  91.   define service{  
  92.  
  93.   use generic-service ; Name of service template to use  
  94.  
  95.   host_name test_nrpe  
  96.  
  97.   service_description ntp  
  98.  
  99.   is_volatile 0  
  100.  
  101.   check_period 24x7  
  102.  
  103.   max_check_attempts 1  
  104.  
  105.   normal_check_interval 1  
  106.  
  107.   retry_check_interval 1  
  108.  
  109.   contact_groups admins  
  110.  
  111.   notification_options w,u,c,r  
  112.  
  113.   notification_interval 960  
  114.  
  115.   notification_period 24x7  
  116.  
  117.   check_command check_ntp!100.0,20%!500.0,60%  
  118.  
  119.   }  
  120.  
  121.   define service{  
  122.  
  123.   use generic-service ; Name of service template to use  
  124.  
  125.   host_name test_nrpe  
  126.  
  127.   service_description qmail_smtp  
  128.  
  129.   is_volatile 0  
  130.  
  131.   check_period 24x7  
  132.  
  133.   max_check_attempts 1  
  134.  
  135.   normal_check_interval 1  
  136.  
  137.   retry_check_interval 1  
  138.  
  139.   contact_groups admins  
  140.  
  141.   notification_options w,u,c,r  
  142.  
  143.   notification_interval 960  
  144.  
  145.   notification_period 24x7  
  146.  
  147.   check_command check_smtp!100.0,20%!500.0,60%  
  148.  
  149.   }  
  150.  
  151.   define service{  
  152.  
  153.   use generic-service ; Name of service template to use  
  154.  
  155.   host_name test_nrpe  
  156.  
  157.   service_description qmail_pop3  
  158.  
  159.   is_volatile 0  
  160.  
  161.   check_period 24x7  
  162.  
  163.   max_check_attempts 1  
  164.  
  165.   normal_check_interval 1  
  166.  
  167.   retry_check_interval 1  
  168.  
  169.   contact_groups admins  
  170.  
  171.   notification_options w,u,c,r  
  172.  
  173.   notification_interval 960  
  174.  
  175.   notification_period 24x7  
  176.  
  177.   check_command check_pop!100.0,20%!500.0,60%  
  178.  
  179.   }  
  180.  

  現(xiàn)在我們象上次一樣把服務(wù)也定義完了。

【編輯推薦】

使用Nagios的建議技巧

使用Nagios實(shí)現(xiàn)網(wǎng)絡(luò)監(jiān)控

Cents下Nagios的安裝-Apache服務(wù)的安裝

責(zé)任編輯:zhaolei 來(lái)源: hackervip
相關(guān)推薦

2011-03-22 15:17:14

Nagios安裝

2011-03-22 15:17:13

Nagios監(jiān)控

2011-08-22 11:00:17

nagios

2011-08-22 11:00:10

nagios

2011-08-22 11:00:14

nagios

2011-08-22 10:30:29

nagios

2011-03-21 11:21:04

LinuxNagios

2011-03-22 09:03:47

Nagios配置

2011-03-23 15:13:08

Nagios監(jiān)控Oracle

2011-03-25 14:40:33

Nagios監(jiān)控

2011-03-21 14:53:27

Nagios監(jiān)控Linux

2011-04-06 14:24:21

Nagios監(jiān)控Linux

2011-07-14 14:17:33

網(wǎng)絡(luò)服務(wù)器配置DNS服務(wù)器

2011-07-14 14:45:01

網(wǎng)絡(luò)服務(wù)器配置DHCP服務(wù)器

2011-07-14 15:28:11

服務(wù)器

2014-06-26 14:10:44

2011-03-23 10:17:26

2010-03-24 11:39:01

2011-07-14 14:58:19

網(wǎng)絡(luò)服務(wù)器配置服務(wù)器

2011-03-22 09:07:13

Nagios監(jiān)控Linux
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號(hào)