nagios是目前非常流行的系统,服务器监控免费软件,很多大的国内站点像搜狐,网易都在使用nagios进行服务器监控。
nagios的有点在于他本身只是一个框架,对于nagios扩展监控模块,以及报警模块非常方便,能很方便的加入自己编写的服务监控,以及手机短信,邮件,gtalk ,msn报警等等。以下是nagios在linux REDHAT AS4U4 下的安装和简单的配置过程:下载软件:添加用户:
useradd -m nagios
passwd nagiosgroupadd nagcmdusermod -G nagcmd nagiosusermod -G nagcmd daemon编译安装nagios
tar -xvzf nagios-cn-3.2.3.tar.bz2cd nagios-3.0.3
./configure –with-command-group=nagcmdmake allmake installmake install-initmake install-configmake install-commandmode设置apache服务器访问密码:cd /usr/local/nagios/etc//usr/local/apache/bin/htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmincd /usr/local/apache/conf/vi httpd-vhosts.conf配置apache的cgi ,具体配置如下:ScriptAlias /nagios/cgi-bin /usr/local/nagios/sbin<Directory “/usr/local/nagios/sbin”>Options ExecCGIAllowOverride NoneOrder allow,denyAllow from allAuthName “Nagios Access”AuthType BasicAuthUserFile /usr/local/nagios/etc/htpasswd.usersRequire valid-user</Directory>Alias /nagios /usr/local/nagios/share<Directory “/usr/local/nagios/share”>Options NoneAllowOverride NoneOrder allow,denyAllow from allAuthName “Nagios Access”AuthType BasicAuthUserFile /usr/local/nagios/etc/htpasswd.usersRequire valid-user</Directory>重启apache/usr/local/apache/bin/apachectl configtest/usr/local/apache/bin/apachectl stop/usr/local/apache/bin/apachectl start安装nagios插件tar -xvzf nagios-plugins-2.0.1.tar.gzcd nagios-plugins-1.4.12
./configure –with-nagios-user=nagios –with-nagios-group=nagiosmakemake installchkconfig –add nagioschkconfig nagios on/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfgservice nagios start现在你可以通过浏览器访问监控的界面了,现在你仅仅能看到对于本机的监控,接下来我们添加一个http服务的监控cd /usr/local/nagios/vi nagios.cfg添加一行:cfg_file=/usr/local/nagios/etc/objects/wwws.cfg编写配置wwws.cfgtouch objects/hosts.cfg objects/wwws.cfgvi objects/wwws.cfg具体内容如下:define host{ use generic-host host_name maycode alias address 10.11.24.42 hostgroups webhosts max_check_attempts 10 } define hostgroup{ hostgroup_name webhosts alias web service hosts members maycode } define service{ use generic-service host_name maycode service_description HTTP check_command check_http! -H }请根据具体情况修改为你要监控的主机以及域名,现在来看看你的配置文件是否正确:/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
如果争取,请重启nagios服务器service nagios start接下来请去浏览器看看吧,如果在host部分看到pending别奇怪啊,我们只设置了监控www服务器,如果你需要监控alive ,请参考localhost.cfg配置文件。在libexec目录下,所有的监控脚本和应用都在,你可以用 prog -h ,查看如何使用这些监控脚本和程序。如果你自己写的程序最好也放在这个目录下。