一:Nagios的安装1.安装编译所需的软件包;[root@nagios~]#yum–yinstallhttpdphp-*gd-*mysql-devel[root@nagios~]#setenforce0#关闭selinux[root@nagios~]#sed's/=enforcing/=permissive/'/etc/sysconfig/selinux2.创建运行nagios服务的用户;[root@nagios~]#useraddnagios#创建运行nagios服务的用户[root@nagios~]#usermod–Gnagiosapache#使apache用户对nagios目录具有写权限,不然web页面操作失败3.Nagios软件安装;[root@nagios~]#tarzxfnagios-cn-3.2.3.tar.gz#释放nagios源码包[root@nagios~]#cdnagios-cn-3.2.3Ps:若在RHEL6X32位系统中安装nagios-cn-3.2.3.tar.bz2要先执行makeclean操作,然后再执行./configure和makeall等操作,否则执行makeall时会报错![root@nagiosnagios-cn-3.2.3]#./configure--enable-embedded-perl#编译nagios[root@nagiosnagios-cn-3.2.3]#makeall[root@nagiosnagios-cn-3.2.3]#makeinstall#安装主程序,CGI和HTML文件[root@nagiosnagios-cn-3.2.3]#makeinstall-init#在/etc/rc.d/init.d安装启动脚本[root@nagiosnagios-cn-3.2.3]#makeinstall-commandmode#配置目录权限[root@nagiosnagios-cn-3.2.3]#makeinstall-config#安装示例配置文件[root@nagiosnagios-cn-3.2.3]#makeinstall-webconf#安装nagios的web接口,会在/etc/httpd/conf.d目录中创建nagios.conf文件4.安装Nagios-plugins插件;[root@nagios~]#tarzxfnagios-plugins-1.4.15.tar.gz[root@nagios~]#cdnagios-plugins-1.4.15[root@nagiosnagios-plugins-1.4.15]#./configure–with-nagios-user=nagios\--with-nagios-group=nagios–enable-extra-opts\--enable-libtap--enable-perl-modules[root@nagiosnagios-plugins-1.4.15]#make&&makeinstall(Ps:会在”/usr/local/nagios/libexec”目录下多出一些文件,这里存放nagios所有插件)5.修改nagios的主配置文件nagios.cfg;[root@nagios~]#vim/usr/local/nagios/etc/nagios.cfg新建cfg_file=/usr/local/nagios/etc/objects/hosts.cfg#存放主机与主机组定义cfg_file=/usr/local/nagios/etc/objects/services.cfg#存放服务与服务组定义修改#cfg_file=/usr/local/nagios/etc/objects/localhost.cfg#加”#”注释,在36行6.创建hosts.cfg文件;[root@nagios~]#vim/usr/local/nagios/etc/objects/hosts.cfgdefinehost{uselinux-server#定义使用的模版host_namenagios#被监控主机名称aliasnagios#别名address127.0.0.1#被监控主机的IP地址icon_imageweb.gifstatusmap_imageweb.gd22d_coords100,3003d_coords100,300,100check_commandcheck-host-alive#监控命令,来自commands.cfg文件max_check_attempts5#检查失败后重试的次数check_period24x7#查看的时间段,来自timeperiods.cfg定义contact_groupsadmins#联系人组,在contactgroups.cfg中定义的notification_interval10#提醒的间隔,每隔10分钟提醒一次notification_period24x7#提醒的周期,24x7,来自timeperiods.cfg定义notification_optionsd,u,r#指定什么情况下提醒}definehostgroup{hostgroup_namelinux-serversaliaslinuxservermembers*}7.创建services.cfg文件;[root@nagios~]#vim/usr/local/nagios/etc/objects/services.cfgdefineservice{uselocal-servicehost_namenagiosservice_groupssystemcheckservice_description主机存活check_commandcheck-host-alive}defineservice{uselocal-servicehost_namenagiosservice_groupssystemcheckservice_description登录用户数check_commandcheck_local_users!20!50#监测远程主机当前的登录用户数量,如果大于20用户则报warning,如果大于50则报critical}defineservice{uselocal-servicehost_namenagiosservice_groupssystemcheckservice_description根分区使用率check_commandcheck_local_disk!20%!10%!/#如果可用空间低于20%会报Warning,如果可用空间低于10%则报Critical}defineservice{uselocal-servicehost_namenagiosservice_groupssystemcheckservice_description进程总数check_commandcheck_local_procs!250!400!RSZDT#监测远程主机当前的进程总数,如果大于250进程则报warning,如果大于400进程则报critical,S(休眠)、R(运行)、Z(僵死)、D(不可中断)、T(停止)}defineservice{uselocal-servicehost_namenagiosservice_groupssystemcheckservice_descriptionCPU负载check_commandcheck_local_load!5.0,4.0,3.0!10.0,6.0,4.0#当1分钟多于5个进程等待,5分钟多于4个,15分钟多于3个则为warning状态#当1分钟多于10个进程等待,5分钟多于6个,15分钟多于4个则为critical状态}defineservice{uselocal-servicehost_namenagiosservice_groupssystemcheckservice_description交换空间利用率check_commandcheck_local_swap!20%!10%#如果交换空间低于20%会报Warning,如果可用空间低于10%则报Critical}defineservicegroup{servicegroup_namesystemcheckaliassystemcheck}[root@nagios~]#/usr/local/nagios/bin/nagios–v/usr/local/nagios/etc/nagios.cfg#校验nagios配置文件的正确性[root@nagios~]#htpasswd–c/usr/local/nagios/etc/htpasswd.usersnagiosadmin#添加一个访问nagios页面的授权用户,默认用户是nagiosadmin,创建其他用户修改/usr/local/nagios/etc/cgi.cfg文件:方法一:修改use_authentication=0值为0(在78行)方法二:authorized_for_system_information=nagiosadminauthorized_for_configuration_information=nagiosadminauthorized_for_system_commands=nagiosadminauthorized_for_all_services=nagiosadminauthorized_for_all_hosts=nagiosadminauthorized_for_all_service_commands=nagiosadminauthorized_for_all_host_commands=nagiosadmin(用:%s/nagiosadmin/新用户名命令替换所有nagiosadmin字符)8.启动httpd和nagios服务并设置开机自动启动[root@nagios~]#serviceiptablesstop[root@nagios~]#servicenagiosstart[root@nagios~]#servicehttpdstart[root@nagios~]#chkconfighttpdon[root@nagios~]#chkconfignagioson[root@nagios~]#chkconfigiptablesoff(Ps:如果开启了selinux需要配置如下两步:chcon-R–thttpd_sys_content_t/usr/local/nagios/sbin/chcon-R–thttpd_sys-content_t/usr/local/nagios/share/)二:被监控端安装(以mysql为例,监控mysql服务的运行情况)1.安装并启动mysql的服务[root@mysql~]#yum–yinstallmysql-server[root@mysql~]#servicemysqldstart[root@mysql~]#serviceiptablesstop[root@mysql~]#chkconfigmysqldon[root@mysql~]#chkconfigiptablesoff2.在mysql服务器上创建监控检测帐户[root@mysql~]#mysqlmysqlcreatedatabasenagdb;mysqlgrantselectonnagdb.*tonagdb@’监控主机IP’;mysqlflushprivileges;mysqlexit3.在nagis主机上检测是否可以链接mysql主机上的mysql服务[root@nagios~]#/usr/local/nagios/libexec/check_mysql–H被监控端IP–unagdb–dnagdb4.在nagios主机上添加对msyql服务监控的定义[root@nagios~]#vim/usr/local/nagios/etc/objects/h