Nagios简介及部署

一 Nagios简介

   Nagios本身不包括监控主机和服务,所有功能由插件构成,重点关注于运行在服务器的服务是否正常,不生成图像,提供强大的监控预警机制和服务异常报警

   Nagios基本构成:

       Nagios 监控平台主程序

       Nagios-plugins 必选插件程序

       NRPE 监控远程Linux服务器的主机资源

       NSClient++ 用于监控Windows主机

       NDOUtils 将数据写入数据库   

   Nagios插件在主目录下的/libxex存放,其中自带插件:check_disk是检查磁盘空间的插件,check_load是检查cpu负载的插件。

   Nagios四种监控状态:

   Nagios可以识别四种状态返回信息。0(OK)表示状态正常(绿色显示),1(WARNING)表示出现警告(黄色),2(CRITICAL)表示出现非常严重错误(红色),3(UNKNOWN)表示未知错误(深黄色),nagios根据插件返回来的值来判断监控对象的状态,并通过web显示出来,以供管理员即时发现故障。



二 Nagios部署

   1.Nagios服务端部署   
   1.安装nagios依赖软件
  1. yum -y install gd gd-devel openssl openssl-devel httpd php gcc glibc glibc-common net-snmp wget
   2.创建nagios用户
  1. #创建nagios用户(不可登录)
  2. useradd nagios -M -s /bin/false
   3.源码包下载编译
  1. #下载Nagios Nagios-plugin Nrpe
  2. wget http://superb-sea2.dl.sourceforge.net/project/nagios/nagios-4.x/nagios-4.2.1/nagios-4.2.1.tar.gz
  3. wget https://nagios-plugins.org/download/nagios-plugins-2.1.2.tar.gz
  4. wget http://pilotfiber.dl.sourceforge.net/project/nagios/nrpe-3.x/nrpe-3.0.1.tar.gz
  5. #编译安装Nagios
  6. tar -zxf nagios-4.2.1.tar.gz -C /usr/src/
  7. cd /usr/src/nagios-4.2.1/
  8. ./configure --with-nagios-user=nagios --with-nagios-group=nagios
  9. make all
  10. make install #安装主程序,CGI以及HTML文件
  11. make install-init #安装启动脚本/etc/init.d/nagios
  12. make install-commandmode #安装与配置目录权限
  13. make install-config #安装配置文件模板
  14. make install-webconf # 由于nagios最终将以web的形式进行管理与监控,安装过程中使用make install-webconf命令将生成Apache附加配置文件/etc/httpd/conf.d/nagios.conf
  15. #安装Nagios-plugins插件
  16. tar -zxf /root/nagios-plugins-2.1.2.tar.gz -C /usr/src
  17. cd /usr/src/nagios-plugins-2.1.2/
  18. ./configure --prefix=/usr/local/nagios/
  19. make && make install
  20. #安装nrpe插件
  21. tar -zxf /root/nrpe-3.0.1.tar.gz -C /usr/src/
  22. cd /usr/src/nrpe-3.0.1/
  23. ./configure --prefix=/usr/local/nagios/
  24. make all 
  25. make install-plugin
  26. make install-daemon 
  27. make install-config
  28. chown -R nagios:nagios /usr/local/nagios
    4.防火墙和selinux设置
  1. firewall-cmd --permanent --add-port=80/tcp
  2. firewall-cmd --reload
  3. setenforce 0
  4. sed -i 's#=enforcing#=permissive#g' /etc/sysconfig/selinux
   5.创建web访问账户
  1. htpasswd -c /usr/local/nagios/etc/htpasswd.users tomcat
   6.启动nagios服务
  1. systemctl restart httpd
  2. systemctl enable httpd
  3. service nagios restart
  4. chkconfig nagios on
   7.Nagios配置文件配置
       1.主配置文件配置 
  1. vim /usr/local/nagios/etc/nagios.cfg
  2. #追加以下信息(使用cfg_file加载其他配置文件)
  3. #创建监控web服务器配置
  4. cfg_file=/usr/local/nagios/etc/objects/web.cfg
       2.cgi配置文件配置
  1. vim /usr/local/nagios/etc/cgi.cfg
  2. #要求验证的用户才可以使用cgi程序,追加tomcat账户允许使用cgi
  3. use_authentication=1
  4. #允许通过cgi查看nagios进程信息帐号
  5. authorized_for_system_information=nagiosadmin,tomcat
  6. #允许查看所有配置信息帐号
  7. authorized_for_configuration_information=nagiosadmin,tomcat
  8. #可以关闭开启nagios账户
  9. authorized_for_system_commands=nagiosadmin,tomcat
  10. #可以查看所有服务信息帐号
  11. authorized_for_all_services=nagiosadmin,tomcat
  12. #可以查看所有主机信息帐号
  13. authorized_for_all_hosts=nagiosadmin,tomcat
  14. #允许执行服务相关命令帐号
  15. authorized_for_all_service_commands=nagiosadmin,tomcat
  16. #允许执行主机相关命令帐号
  17. authorized_for_all_host_commands=nagiosadmin,tomcat
       3.命令配置文件(commands.cfg)(定义具体命令实现方式,如邮件发送工具和邮件格式)
  1. vim /usr/local/nagios/etc/objects/commands.cfg
  2. #追加以下内容,用于进行远程主机监控,需要安装nrpe软件包
  3. define command{
  4. command_name check_nrpe
  5. command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$
  6. }
       4.联系人配置文件(contact.cfg)(定义当监控发现设备或服务出现所需联系的人和方式)
  1. vim /usr/local/nagios/etc/objects/contacts.cfg
       5.时间定义配置文件(timeperiods.cfg)(定义报警时间周期)
  1. vim /usr/local/nagios/etc/objects/timeperiods.cfg
       6.监控本机配置文件(localhost.cfg)(设置如何监控本机资源)
  1. vim /usr/local/nagios/etc/objects/localhost.cfg
       7.模板配置文件(template.cfg)(定义其他配置文件需调用的定义,根据自己时间需修改报警通知时间、报警方式、报警选项)
  1. vim /usr/local/nagios/etc/objects/templates.cfg
       8.nrpe配置文件配置(nrpe.cfg),创建用于监控远程主机的命令
  1. vim /usr/local/nagios/etc/nrpe.cfg
  2. command[check_users]=/usr/local/nagios/libexec/check_users -w 5 -c 10
  3. command[check_load]=/usr/local/nagios/libexec/check_load -w 15,10,5 -c 30,25,20
  4. command[check_hda1]=/usr/local/nagios/libexec/check_disk -w 20% -c 10% -p /dev/hda1
  5. command[check_zombie_procs]=/usr/local/nagios/libexec/check_procs -w 5 -c 10 -s Z
  6. command[check_total_procs]=/usr/local/nagios/libexec/check_procs -w 150 -c 200
  7. #追加以下命令
  8. command[check_disk]=/usr/local/nagios/libexec/check_disk -w 20% -c 10%
        9.创建web.cfg远程web监控配置文件
  1. vim /usr/local/nagios/etc/objects/web.cfg
  2. define host{
  3. use linux-server ; Name of host template to use
  4. ; This host definition will inherit all variables that are defined
  5. ; in (or inherited by) the linux-server host template definition.
  6. host_name web
  7. alias test.com
  8. address 192.168.1.168
  9. }
  10. define hostgroup{
  11. hostgroup_name webs ;The name of the hostgroup
  12. alias Linux Servers ;Long name of the group
  13. members web ;Comma separated list of hosts that belong to this group
  14. }
  15. define service{
  16. use generic-service ; Name of service template to use
  17. host_name web
  18. service_description PING
  19. check_command check_ping!100.0,20%!500.0,60%
  20. notifications_enabled 1
  21. }
  22. define service{
  23. use generic-service ; Name of service template to use
  24. host_name web
  25. service_description Sys_Load
  26. check_command check_nrpe!check_load
  27. notifications_enabled 1
  28. }
  29. define service{
  30. use generic-service ; Name of service template to use
  31. host_name web
  32. service_description Current Users
  33. check_command check_nrpe!check_users
  34. notifications_enabled 1
  35. }
  36. define service{
  37. use generic-service ; Name of service template to use
  38. host_name web
  39. service_description Total Processes
  40. check_command check_nrpe!check_total_procs
  41. notifications_enabled 1
  42. }
  43. define service{
  44. use generic-service ; Name of service template to use
  45. host_name web
  46. service_description SSH
  47. check_command check_ssh
  48. notifications_enabled 1
  49. }
  50. define service{
  51. use generic-service ; Name of service template to use
  52. host_name web
  53. service_description HTTP
  54. check_command check_http
  55. notifications_enabled 1
  56. }
    8.重启nagios
  1. service nagios restart
   2.Nagios监控端布置
   1.安装nagios依赖
  1. yum -y install openssl openssl-devel gcc
   2.创建nagios用户
  1. useradd nagios -M -s /bin/false
   3.安装
  1. #下载Nagios-plugin Nrpe
  2. wget https://nagios-plugins.org/download/nagios-plugins-2.1.2.tar.gz
  3. wget http://pilotfiber.dl.sourceforge.net/project/nagios/nrpe-3.x/nrpe-3.0.1.tar.gz
  4. #安装Nagios-plugins插件
  5. tar -zxf /root/nagios-plugins-2.1.2.tar.gz -C /usr/src
  6. cd /usr/src/nagios-plugins-2.1.2/
  7. ./configure --prefix=/usr/local/nagios/
  8. make && make install
  9. #安装nrpe插件
  10. tar -zxf /root/nrpe-3.0.1.tar.gz -C /usr/src/
  11. cd /usr/src/nrpe-3.0.1/
  12. ./configure --prefix=/usr/local/nagios/
  13. make all
  14. make install-plugin
  15. make install-daemon
  16. make install-config
  17. chown -R nagios:nagios /usr/local/nagios
    4.修改nrpe配置文件
  1. vim /usr/local/nagios/etc/nrpe.cfg
  2. ...
  3. #设置允许那台主机可监控本机,其中192.168.1.166是远程监控主机
  4. allowed_hosts=127.0.0.1,192.168.1.166
  5. ...
  6. command[check_users]=/usr/local/nagios/libexec/check_users -w 5 -c 10
  7. command[check_load]=/usr/local/nagios/libexec/check_load -w 15,10,5 -c 30,25,20
  8. command[check_hda1]=/usr/local/nagios/libexec/check_disk -w 20% -c 10% -p /dev/hda1
  9. command[check_zombie_procs]=/usr/local/nagios/libexec/check_procs -w 5 -c 10 -s Z
  10. command[check_total_procs]=/usr/local/nagios/libexec/check_procs -w 150 -c 200
  11. #追加以下命令
  12. command[check_disk]=/usr/local/nagios/libexec/check_disk -w 20% -c 10%
   5.防火墙和selinux设置
  1. firewall-cmd --permanent --add-port=5666/tcp
  2. firewall-cmd --reload
  3. setenforce 0
  4. sed -i 's#=enforcing#=permissive#g' /etc/sysconfig/selinux
   6.启动nrpe
  1. /usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d
  2. echo "/usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d" >>/etc/rc.local
   3.nagios服务端测试
  1. /usr/local/nagios/libexec/check_nrpe -H 192.168.1.168

(错误是压根我就就没在客户端安装web)
  1. 注:最后错误PROCS CRITICAL: 376 processes修改localhost.cfg文件监控进程基数
  2. vim /usr/local/nagios/etc/objects/localhost.cfg
  3. define service{
  4. use local-service ; Name of service template to use
  5. host_name localhost
  6. service_description Total Processes
  7. check_command check_local_procs!544!744!RSZDT
  8. }



©️2020 CSDN 皮肤主题: 大白 设计师: CSDN官方博客 返回首页
实付0元
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、C币套餐、付费专栏及课程。

余额充值