1.nagiso目录结构
[root@F-LVS ~]# ll /usr/local/nagios/ 总用量 32 drwxrwxr-x. 2 nagios nagios 4096 9月 6 23:49 bin //命令目录 drwxrwxr-x. 3 nagios nagios 4096 9月 6 23:50 etc //配置文件目录 drwxr-xr-x. 2 root root 4096 9月 6 23:43 include //包含目录 drwxrwxr-x. 2 nagios nagios 4096 9月 6 23:49 libexec //插件目录 drwxr-xr-x. 5 root root 4096 9月 6 23:43 perl // drwxrwxr-x. 2 nagios nagios 4096 9月 6 23:34 sbin //CGI程序 drwxrwxr-x. 11 nagios nagios 4096 9月 6 23:43 share //web界面展示程序,站点目录 drwxrwxr-x. 5 nagios nagios 4096 9月 7 01:26 var //日志目录
2.配置文件
[root@F-LVS ~]# ll /usr/local/nagios/etc 总用量 136 -rw-rw-r--. 1 nagios nagios 11669 9月 6 23:37 cgi.cfg //配置文件包含在主配置文件里 -rw-r--r--. 1 root root 20 9月 6 23:40 htpasswd.users //web密码认证文件 -rw-rw-r--. 1 nagios nagios 44710 9月 6 23:37 nagios.cfg //主配置文件 -rw-r--r--. 1 nagios nagios 7207 9月 6 23:50 nrpe.cfg //客户端配置文件 drwxrwxr-x. 2 nagios nagios 4096 9月 6 23:37 objects //配置文件包含在主配置文件里 -rw-rw----. 1 nagios nagios 1340 9月 6 23:37 resource.cfg //配置文件包含在主配置文件里
[root@F-LVS ~]# ll /usr/local/nagios/etc/objects/ 总用量 96 -rw-rw-r--. 1 nagios nagios 7716 9月 6 23:37 commands.cfg //nagios命令相关配置,关联插件 -rw-rw-r--. 1 nagios nagios 2166 9月 6 23:37 contacts.cfg //报警联系人相关配置文件 -rw-rw-r--. 1 nagios nagios 5403 9月 6 23:37 localhost.cfg //本机使用模板 -rw-rw-r--. 1 nagios nagios 3124 9月 6 23:37 printer.cfg //打印机 -rw-rw-r--. 1 nagios nagios 3293 9月 6 23:37 switch.cfg //交换机 -rw-rw-r--. 1 nagios nagios 10812 9月 6 23:37 templates.cfg //模板配置文件,类似shell里函数功能 -rw-rw-r--. 1 nagios nagios 3208 9月 6 23:37 timeperiods.cfg //报警周期时间相关配置 -rw-rw-r--. 1 nagios nagios 4019 9月 6 23:37 windows.cfg //windows
3.主配置文件
[root@F-LVS nagios]# tar zcvf etc.tar.gz ./etc/ [root@F-LVS nagios]# vim /usr/local/nagios/etc/nagios.cfg +34 添加: cfg_file=/usr/local/nagios/etc/objects/services.cfg cfg_file=/usr/local/nagios/etc/objects/hosts.cfg cfg_dir=/usr/local/nagios/etc/services 注释: #cfg_file=/usr/local/nagios/etc/objects/localhost.cfg
4.生成相关文件
mkdir -p /usr/local/nagios/etc/services chown -R nagios.nagios /usr/local/nagios/etc/services cd /usr/local/nagios/etc/objects/ head -51 localhost.cfg >hosts.cfg chown -R nagios.nagios /usr/local/nagios/etc/objects/hosts.cfg 生成services.cfg文件 touch services.cfg chown -R nagios.nagios services.cfg
5.配置hosts.cfg
vim /usr/local/nagios/etc/objects/hosts.cfg #被监控的主机: define host{ use linux-server host_name A-host alias A-host address 192.168.1.10 } define hostgroup{ hostgroup_name linux-servers alias Linux Servers members A-host }
6.配置services.cfg
#定义服务(需要监控的服务) vim /usr/local/nagios/etc/objects/services.cfg 添加: define service { use generic-service #服务模板 host_name A-host #监控的主机 service_description Disk Partition #监控磁盘分区 check_command check_nrpe!check_disk #监控的命令 }
7.配置commands.cfg
#定义命令 vim /usr/local/nagios/etc/objects/commands.cfg 添加: define command{ command_name check_nrpe command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$ }
8.检查语法
/etc/init.d/nagios checkconfig 或 /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg #检测原理 /usr/local/nagios/libexec/check_nrpe -H 192.168.1.10 -c check_disk
9.配置cgi.cfg
vim /usr/local/nagios/etc/cgi.cfg :g/nagiosadmin/s//qinzc/g //批量替换 ,配置WEB认证时生成的帐号 /etc/init.d/nagios restart //重启 修改原理位置: authorized_for_system_information=qinzc authorized_for_configuration_information=qinzc authorized_for_system_commands=qinzc authorized_for_all_services=qinzc authorized_for_all_hosts=qinzc authorized_for_all_service_commands=qinzc authorized_for_all_host_commands=qinzc
nagios-URL监控范例
define service { use generic-service host_name A-host,15-host service_description wangzhan_url check_command check_weburl!-I 192.168.1.10 max_check_attempts 3 normal_check_interval 2 retry_check_interval 1 check_period 24x7 notification_interval 30 notification_options w,u,c,r notification_period 24x7 contact_groups admins }
端口监控范例
define service { use generic-service host_name A-host,15-host service_description prot_jk check_command check_tcp!80 max_check_attempts 3 normal_check_interval 2 retry_check_interval 1 check_period 24x7 notification_interval 30 notification_options w,u,c,r notification_period 24x7 contact_groups admins }
停留在世界边缘,与之惜别