黑客技术群

黑客入侵,黑客基地,黑客组织,网站黑客,黑客平台

nagios监控网络服务器和网络服务配置篇

nagios配置

1:配置web接口

假设你已经运行了apache,如无,请参考:

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

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

添加以下内容:

  • ScriptAlias/nagios/cgi-bin/usr/local/nagios/sbin
  • <Directory"/usr/local/nagios/sbin">    
  • OptionsExecCGI
  • AllowOverrideNone
  • Orderallow,deny
  • Allowfromall
  • AuthName"NagiosAccess"
  • AuthTypeBasic
  • AuthUserFile/usr/local/nagios/etc/htpasswd.users
  • Requirevalid-user
  • </Directory>    
  • Alias/nagios/usr/local/nagios/share
  • <Directory"/usr/local/nagios/share">    
  • OptionsNone
  • AllowOverrideNone
  • Orderallow,deny
  • Allowfromall
  • AuthName"NagiosAccess"
  • AuthTypeBasic
  • AuthUserFile/usr/local/nagios/etc/htpasswd.users
  • Requirevalid-user
  • </Directory>
  • 修改后,保存文件并重启apache:

    /usr/local/apahce2/bin/apachectlrestart

    2:配置apache的BASIC认证:

    生成认证密码:

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

    apache完成接口配置。

    开始配置nagios:

    cd/usr/local/nagios/etc/

    在/usr/local/nagios/etc下是nagios模板文件的配置-sample,把.cfg-sample所有文件都复制成.cfg

    例如:cpnagios.cfg-samplenagios.cfg

    完成所有副本.

    viminimal.cfg

    注释所有command:

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

    修改cgi.cfg

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

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

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

    若正确,将显示以下结果:

    TotalWarnings:0

    TotalErrors:0

    否则,配置文件需要根据提示进行修改。配置文件等待。现在开始nagios

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

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

    安装daemontool:

  • mkdir-p/package
  • chmod1755/package
  • cd/package
  • fetchhttp://cr.yp.to/daemontools/daemontools-0.76.tar.gz
  • cdadmin/daemontools-0.76/
  • package/install
  • 检查svscan进程是否启动:

  • psaux|grepsvscan
  • root3760.00.016360con-IW-0:00.00/bin/sh/command/svscanboot
  • root4110.00.01224208con-S8Jul060:42.50svscan/service
  • ok,正常启动。

  • cd/service
  • mkdirnagios
  • chmod1755nagios
  • touch./run
  • chmod755./run
  • virun
  • PATH=/usr/local/bin:/usr/bin:/bin
  • exportPATH
  • execenv-PATH=$PATH\
  • /usr/local/nagios/bin/nagios/usr/local/nagios/etc/nagios.cfg
  • mkdirlog
  • cdlog
  • touch./run
  • chmod755./run
  • vi./run
  • #!/bin/sh
  • execsetuidgidlogadminmultilogts1000000n100./main
  • mkdirmain
  • chmod777main
  • chownnagios.nagiosmain
  • touchstatus
  • chownnagios.nagiosstatus
  • svc-u/service/nagios/
  • svstat/service/nagios/
  • root@##psauxww|grepnagios
  • root232760.00.11176488??I5:00PM0:01.71supervisenagios
  • nagios342510.00.323161552??S6:06PM0:00.10/usr/local/nagios/bin/nagios/usr/local/nagios/etc/nagios.cfg
  • root@##
  • ok,现在把nagios服务自动启动。svc命令可以启动或停止服务。

  • ---------------------------------------------------------------------------------
  • svcoptsservices
  • optsisaseriesofgetopt-styleoptions.servicesconsistsofanynumberofarguments,eachargumentnamingadirectoryusedbysupervise.
  • -u:Up.Iftheserviceisnotrunning,startit.Iftheservicestops,restartit.
  • -d:Down.Iftheserviceisrunning,senditaTERMsignalandthenaCONTsignal.Afteritstops,donotrestartit.
  • -o:Once.Iftheserviceisnotrunning,startit.Donotrestartitifitstops.
  • -p:Pause.SendtheserviceaSTOPsignal.
  • -c:Continue.SendtheserviceaCONTsignal.
  • -h:Hangup.SendtheserviceaHUPsignal.
  • -a:Alarm.SendtheserviceanALRMsignal.
  • -i:Interrupt.SendtheserviceanINTsignal.
  • -t:Terminate.SendtheserviceaTERMsignal.
  • -k:Kill.SendtheserviceaKILLsignal.
  • -x:Exit.supervisewillexitassoonastheserviceisdown.Ifyouusethisoptiononastablesystem,you'redoingsomethingwrong;superviseisdesignedtorunforever.
  • ---------------------------------------------------------------------------------
  • 比如:

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

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

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

    当然也可以用inited方式:

    /usr/local/etc/rc.d/nagiosstart/stop

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

    #p#

    nagios庐山真面目

    1)为主机添加一个服务

    为localhost主机添加qmail监控服务的方法如下:

  • viminimal.cfg
  • defineservice{
  • usegeneric-service;Nameofservicetemplatetouse
  • host_namelocalhost
  • service_descriptionqmail_smtp
  • is_volatile0
  • check_period24x7
  • max_check_attempts1
  • normal_check_interval1
  • retry_check_interval1
  • contact_groupsadmins
  • notification_optionsw,u,c,r
  • notification_interval960
  • notification_period24x7
  • check_commandcheck_smtp!2010%!
  • }
  • 可以直接复制原件进行修改,我这是复制原件check_local_disk进行host_name,service_description,check_command等

  • defineservice{
  • usegeneric-service;Nameofservicetemplatetouse
  • host_namelocalhost
  • service_descriptionqmail_pop3
  • is_volatile0
  • check_period24x7
  • max_check_attempts1
  • normal_check_interval1
  • retry_check_interval1
  • contact_groupsadmins
  • notification_optionsw,u,c,r
  • notification_interval960
  • notification_period24x7
  • check_commandcheck_pop!2010%!
  • }
  • 修改猫画虎,然后修改:

  • vicheckcommands.cfg
  • #'check_qmail'commanddefinition
  • definecommand{
  • command_namecheck_qmail
  • command_line$USER1$/check_smtp-H127.0.0.1
  • }
  • definecommand{
  • command_namecheck_pop3
  • command_line$USER1$/check_pop-H127.0.0.1
  • }
  • 然后检查配置文件:

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

    假如没有错误会显示:

    TotalWarnings:0

    TotalErrors:0

    如有错误,请根据提示修正。

    重启nagios

    svc-d/service/nagios/&&svc-u/service/nagios/

    通过web页面检查nagios的结果:

    http://10.5.1.153/nagios/

    点击“ServiceDetail”

    #p#

    2)添加主机和服务

    我们将监控主机的负载、磁盘和其他未通过端口启动的服务器状态,如:apache、mysql、qmail和ntp等等。所以没有端口。nagios能直接监控吗?答案是否定的。因此,我们必须安装两台主机nrpe,nrpe可启动5666端口,不断向监控中心主机传输检测信息。

    ok,我们把apache、mysql、qmail和ntp此外,这次我们将新建监控主机和服务的文件:

  • cd/usr/local/nagios/etc/
  • touch10_5_1_156.cfg
  • vinagios.cfg
  • cfg_file=/usr/local/nagios/etc/10_5_1_156.cfg
  • vi10_5_1_156.cfg
  • 定义主机:

  • definehost{
  • usegeneric-host;Nameofhosttemplatetouse
  • host_nametest_nrpe
  • aliasclient
  • address10.5.1.156
  • check_commandcheck-host-alive
  • max_check_attempts1
  • check_period24x7
  • notification_interval120
  • notification_period24x7
  • notification_optionsd,r
  • contact_groupsadmins
  • }
  • 定义主机需要检查的服务:

  • defineservice{
  • usegeneric-service;Nameofservicetemplatetouse
  • host_nametest_nrpe
  • service_descriptionPING
  • is_volatile0
  • check_period24x7
  • max_check_attempts1
  • normal_check_interval1
  • retry_check_interval1
  • contact_groupsadmins
  • notification_optionsw,u,c,r
  • notification_interval960
  • notification_period24x7
  • check_commandcheck_ping!100.0,20%!500.0,60%
  • }
  • defineservice{
  • usegeneric-service;Nameofservicetemplatetouse
  • host_nametest_nrpe
  • service_descriptionapache
  • is_volatile0
  • check_period24x7
  • max_check_attempts1
  • normal_check_interval1
  • retry_check_interval1
  • contact_groupsadmins
  • notification_optionsw,u,c,r
  • notification_interval960
  • notification_period24x7
  • check_commandcheck_http!100.0,20%!500.0,60%
  • }
  • defineservice{
  • usegeneric-service;Nameofservicetemplatetouse
  • host_nametest_nrpe
  • service_descriptionmysql
  • is_volatile0
  • check_period24x7
  • max_check_attempts1
  • normal_check_interval1
  • retry_check_interval1
  • contact_groupsadmins
  • notification_optionsw,u,c,r
  • notification_interval960
  • notification_period24x7
  • check_commandcheck_mysql!100.0,20%!500.0,60%
  • }
  • defineservice{
  • usegeneric-service;Nameofservicetemplatetouse
  • host_nametest_nrpe
  • service_descriptionntp
  • is_volatile0
  • check_period24x7
  • max_check_attempts1
  • normal_check_interval1
  • retry_check_interval1
  • contact_groupsadmins
  • notification_optionsw,u,c,r
  • notification_interval960
  • notification_period24x7
  • check_commandcheck_ntp!100.0,20%!500.0,60%
  • }
  • defineservice{
  • usegeneric-service;Nameofservicetemplatetouse
  • host_nametest_nrpe
  • service_descriptionqmail_smtp
  • is_volatile0
  • check_period24x7
  • max_check_attempts1
  • normal_check_interval1
  • retry_check_interval1
  • contact_groupsadmins
  • notification_optionsw,u,c,r
  • notification_interval960
  • notification_period24x7
  • check_commandcheck_smtp!100.0,20%!500.0,60%
  • }
  • defineservice{
  • usegeneric-service;Nameofservicetemplatetouse
  • host_nametest_nrpe
  • service_descriptionqmail_pop3
  • is_volatile0
  • check_period24x7
  • max_check_attempts1
  • normal_check_interval1
  • retry_check_interval1
  • contact_groupsadmins
  • notification_optionsw,u,c,r
  • notification_interval960
  • notification_period24x7
  • check_commandcheck_pop!100.0,20%!500.0,60%
  • }
  • nagios在配置中,服务被定义。此时是否有更多的主机及其以下服务?这是肯定的。如何解决在此过程中添加主机和服务的可能问题?请阅读:概念、安装和故障解决方案

       
    • 评论列表:
    •  世味绿脊
       发布于 2022-06-03 21:33:50  回复该评论
    • ypeBasic AuthUserFile/usr/local/nagios/etc/htpasswd.users Requirevalid-user </Directory>修改后,保存文件并重启apache:/usr/local/apahce2/bin/apachectlres
    •  依疚轻禾
       发布于 2022-06-03 15:51:52  回复该评论
    • /nagios/bin/nagios-v/usr/local/nagios/etc/nagios.cfg若正确,将显示以下结果:TotalWarnings:0TotalErrors:0否则,配置文件需要根据提示进行修改。配置文件等待。现在开始nagios
    •  南殷歆笙
       发布于 2022-06-03 19:48:34  回复该评论
    • agios/bin/nagios-v/usr/local/nagios/etc/nagios.cfg假如没有错误会显示:TotalWarnings:0TotalErrors:0如有错误,请根据提示修正。重启nagi
    •  舔夺叹倦
       发布于 2022-06-03 14:15:53  回复该评论
    • d24x7 check_commandcheck_pop!100.0,20%!500.0,60% }nagios在配置中,服务被定义。此时是否有更多的主机及其以下服务?这是肯定的。如何解决在此过程中添加主机和服务的可能问题?请阅读:概念、安装和故障解决方案    

    发表评论:

    Powered By

    Copyright Your WebSite.Some Rights Reserved.