nagios监控网络服务器和网络服务配置篇(1)
2013-05-22 11:23:25 点击:

nagios配置1:配置web接口假设你已经运行了apache,如果没有,请参考:http://localhost/upload/blog.php?do-showone-tid-18.htmlvi/usr/lo...

nagios配置

1:配置web接口

假设你已经运行了apache,如果没有,请参考:

http://localhost/upload/blog.php?do-showone-tid-18.html

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

添加如下内容:

  1. ScriptAlias /nagios/cgi-bin /usr/local/nagios/sbin   
  2.  
  3. <Directory "/usr/local/nagios/sbin">   
  4.   Options ExecCGI   
  5.   AllowOverride None   
  6.   Order allow,deny   
  7.   Allow from all   
  8.   AuthName "Nagios Access"   
  9.   AuthType Basic   
  10.   AuthUserFile /usr/local/nagios/etc/htpasswd.users   
  11.   Require valid-user   
  12. </Directory>   
  13.  
  14. Alias /nagios /usr/local/nagios/share   
  15.  
  16. <Directory "/usr/local/nagios/share">   
  17.   Options None   
  18.   AllowOverride None   
  19.   Order allow,deny   
  20.   Allow from all   
  21.   AuthName "Nagios Access"   
  22.   AuthType Basic   
  23.   AuthUserFile /usr/local/nagios/etc/htpasswd.users   
  24.   Require valid-user   
  25. </Directory>  

修改完毕,保存文件,并重启apache:

/usr/local/apahce2/bin/apachectl restart

2:配置apache的BASIC认证:

生成认证密码:

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

apache接口配置完成。

开始配置nagios:

cd /usr/local/nagios/etc/

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

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

全部拷贝完成即可.

vi minimal.cfg

注释所有command:

注释的方法是在每一个定义语句前面添加”#“

修改cgi.cfg

修改use_authentication=1为use_authentication=0,即不用验证.不然有一些页面不会显示。

现在检查配置文件是否有语法错误:

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

如果正确,会显示以下结果:

Total Warnings: 0

Total Errors:   0

否则,需要根据提示进行修改配置文件。配置文件等会再弄。现在启动nagios

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

为了使nagios异常中断,我们使用daemontools启动:

安装daemontool:

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

检查svscan进程是否启动:

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

ok,启动正常了。

  1. cd /service   
  2. mkdir nagios   
  3. chmod 1755 nagios   
  4. touch ./run   
  5. chmod 755 ./run   
  6. vi run   
  7. PATH=/usr/local/bin:/usr/bin:/bin   
  8. export PATH   
  9.  
  10. exec env - PATH=$PATH    
  11. /usr/local/nagios/bin/nagios /usr/local/nagios/etc/nagios.cfg   
  12.  
  13. mkdir log   
  14. cd log   
  15. touch ./run   
  16. chmod 755 ./run   
  17. vi ./run   
  18. #!/bin/sh   
  19. exec setuidgid logadmin multilog t s1000000 n100 ./main   
  20.  
  21. mkdir main   
  22. chmod 777 main   
  23. chown nagios.nagios main   
  24. touch status   
  25. chown nagios.nagios status   
  26.  
  27. svc -u /service/nagios/   
  28. svstat /service/nagios/   
  29. root@## ps auxww | grep nagios   
  30. root     23276 0.0 0.1 1176   488 ?? I   5:00PM   0:01.71 supervise nagios   
  31. 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   
  32. root@##   

ok,现在把nagios服务做成自动启动的服务了。通过svc命令可以启动或者停止服务。

  1. ---------------------------------------------------------------------------------   
  2. svc opts services   
  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. -d: Down. If the service is running, send it a TERM signal and then a CONT signal. After it stops, do not restart it.    
  7. -o: Once. If the service is not running, start it. Do not restart it if it stops.    
  8. -p: Pause. Send the service a STOP signal.    
  9. -c: Continue. Send the service a CONT signal.    
  10. -h: Hangup. Send the service a HUP signal.    
  11. -a: Alarm. Send the service an ALRM signal.    
  12. -i: Interrupt. Send the service an INT signal.    
  13. -t: Terminate. Send the service a TERM signal.    
  14. -k: Kill. Send the service a KILL signal.    
  15. -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.   
  16. ---------------------------------------------------------------------------------  

比如:

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

重启nagios--svc -t /service/nagios/

启动nagios--svc -u /service/nagios/

当然,你也可以使用inited的方式进行:

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

好了,反正daemontools很强大,现在打开网页:http://localhost/nagios/,一定会让你大吃一惊,呵呵,我的服务器和服务状态都清楚的看到了。现在我们的nagios中只有一个,那就是它自己,localhost,呵呵,等会我们添加别的主机和主机服务。



相关热词搜索:

上一篇:Windows安全模式运用技巧
下一篇:nagios监控网络服务器和网络服务故障解决篇