温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

一起搭建linux监控平台之nagios(四)监控端添加服务

发布时间:2020-06-02 11:32:16 来源:网络 阅读:459 作者:vbbb625 栏目:移动开发

 被监控端工作已经做好了,现在就只要在监控端进行操作了;

注意一下:被监控中mysql记得要设密码啊

添加服务类型也是2种:

1.web服务器

2.mysql服务器

下面是添加web服务的脚本:

 

  1. webservices () { 
  2.  read -p " Please input the web server IP: " webip 
  3.  read -p "please input the web alias name : "  host 
  4.  echo "define host{ 
  5.          host_name                       $host 
  6.          alias                           web-server 
  7.          address                         $webip 
  8.          check_command                   check-host-alive 
  9.          max_check_attempts              5 
  10.          check_period                    24x7 
  11.          contact_groups                  web-server 
  12.          notification_interval           10 
  13.          notification_period             24x7 
  14.          notification_options            d,u,r 
  15.          }" >> /usr/local/nagios/etc/objects/hosts.cfg 
  16.  sed -i "6,10{/members/s/$/,$host/}" /usr/local/nagios/etc/objects/hostgroups.cfg 
  17.   
  18.  echo " 
  19.  define hostescalation{  
  20.                  host_name               $host        
  21.                  first_notification      5                  
  22.                  last_notification       0                  
  23.                  notification_interval   10                
  24.                  contact_groups          web-server              
  25.                  }  
  26.  define serviceescalation{  
  27.                  host_name               $host  
  28.                  service_description     Nginx-Listener        
  29.                  first_notification      5  
  30.                  last_notification       0  
  31.                  notification_interval   10  
  32.                  contact_groups          web-server  
  33.                  }  
  34.  define serviceescalation{  
  35.                  host_name               $host  
  36.                  service_description     Linux-PHP-procs        
  37.                  first_notification      5  
  38.                  last_notification       0  
  39.                  notification_interval   10  
  40.                  contact_groups          web-server  
  41.                  }  
  42.  define serviceescalation{  
  43.                  host_name               $host  
  44.                  service_description     Linux-iftraffic        
  45.                  first_notification      5  
  46.                  last_notification       0  
  47.                  notification_interval   10  
  48.                  contact_groups          web-server  
  49.                  }  
  50.  define serviceescalation{  
  51.                  host_name               $host  
  52.                  service_description     check-ips        
  53.                  first_notification      5  
  54.                  last_notification       0  
  55.                  notification_interval   10  
  56.                  contact_groups          web-server  
  57.                  } " >> /usr/local/nagios/etc/objects/escalations.cfg  
  58.   
  59.  echo " 
  60.      define service{ 
  61.          host_name               $host 
  62.          service_description     check-host-alive 
  63.          check_command           check-host-alive 
  64.          max_check_attempts      4 
  65.          normal_check_interval   3 
  66.          retry_check_interval    2 
  67.          check_period            24x7 
  68.          notification_interval   10 
  69.          notification_period     24x7 
  70.          notification_options    w,u,c,r 
  71.          contact_groups          web-server 
  72.          } 
  73.       define service{ 
  74.          host_name               $host 
  75.          service_description     disk-/ 
  76.          check_command           check_local_disk!10%!5%!/ 
  77.          max_check_attempts      4 
  78.          normal_check_interval   3 
  79.          retry_check_interval    2 
  80.          check_period            24x7 
  81.          notification_interval   10 
  82.          notification_period     24x7 
  83.          notification_options    w,u,c,r 
  84.          contact_groups          web-server 
  85.          } 
  86.       define service{ 
  87.          host_name               $host 
  88.          service_description     SSH-Listener 
  89.          check_command           check_tcp!22 
  90.          max_check_attempts      4 
  91.          normal_check_interval   3 
  92.          retry_check_interval    2 
  93.          check_period            24x7 
  94.          notification_interval   10 
  95.          notification_period     24x7 
  96.          notification_options    w,u,c,r 
  97.          contact_groups          web-server 
  98.          } 
  99.       define service{ 
  100.          host_name               $host 
  101.          service_description     Nginx-Listener 
  102.          check_command           check_tcp!80 
  103.          max_check_attempts      4 
  104.          normal_check_interval   2 
  105.          retry_check_interval    1 
  106.          check_period            24x7 
  107.          notification_interval   2 
  108.          notification_period     24x7 
  109.          notification_options    w,u,c,r 
  110.          contact_groups          web-server 
  111.          } 
  112.       define service{ 
  113.          host_name               $host 
  114.          service_description     Linux-Memory 
  115.          check_command           check_nrpe!check_mem 
  116.          max_check_attempts      4 
  117.          normal_check_interval   3 
  118.          retry_check_interval    2 
  119.          check_period            24x7 
  120.          notification_interval   10 
  121.          notification_period     24x7 
  122.          notification_options    w,u,c,r 
  123.          contact_groups          web-server 
  124.          } 
  125.       define service{ 
  126.          host_name               $host 
  127.          service_description     Linux-load 
  128.          check_command           check_nrpe!check_load 
  129.          max_check_attempts      4 
  130.          normal_check_interval   3 
  131.          retry_check_interval    2 
  132.          check_period            24x7 
  133.          notification_interval   10 
  134.          notification_period     24x7 
  135.          notification_options    w,u,c,r 
  136.          contact_groups          web-server 
  137.          } 
  138.       define service{ 
  139.          host_name               $host 
  140.          service_description     Linux-total-procs 
  141.          check_command           check_nrpe!check_total_procs 
  142.          max_check_attempts      4 
  143.          normal_check_interval   3 
  144.          retry_check_interval    2 
  145.          check_period            24x7 
  146.          notification_interval   10 
  147.          notification_period     24x7 
  148.          notification_options    w,u,c,r 
  149.          contact_groups          web-server 
  150.          } 
  151.       define service{ 
  152.          host_name               $host 
  153.          service_description     Linux-PHP-procs 
  154.          check_command           check_nrpe!check_php_procs 
  155.          max_check_attempts      4 
  156.          normal_check_interval   3 
  157.          retry_check_interval    2 
  158.          check_period            24x7 
  159.          notification_interval   5 
  160.          notification_period     24x7 
  161.          notification_options    w,u,c,r 
  162.          contact_groups          web-server 
  163.          } 
  164.       define service{ 
  165.          host_name               $host 
  166.          service_description     Linux-CPU 
  167.          check_command           check_nrpe!check_cpu 
  168.          max_check_attempts      4 
  169.          normal_check_interval   3 
  170.          retry_check_interval    2 
  171.          check_period            24x7 
  172.          notification_interval   10 
  173.          notification_period     24x7 
  174.          notification_options    w,u,c,r 
  175.          contact_groups          web-server 
  176.          } 
  177.       define service{ 
  178.          host_name               $host 
  179.          service_description     Linux-user 
  180.          check_command           check_nrpe!check_users 
  181.          max_check_attempts      4 
  182.          normal_check_interval   3 
  183.          retry_check_interval    2 
  184.          check_period            24x7 
  185.          notification_interval   10 
  186.          notification_period     24x7 
  187.          notification_options    w,u,c,r 
  188.          contact_groups          web-server 
  189.          } 
  190.       define service{ 
  191.          host_name               $host 
  192.          service_description     check-ips 
  193.          check_command           check_nrpe!check_ips 
  194.          max_check_attempts      4 
  195.          normal_check_interval   2 
  196.          retry_check_interval    2 
  197.          check_period            24x7 
  198.          notification_interval   8 
  199.          notification_period     24x7 
  200.          notification_options    w,u,c,r 
  201.          contact_groups          web-server 
  202.          } 
  203.       define service{ 
  204.          host_name               $host 
  205.          service_description     Linux-iftraffic 
  206.          check_command           check_nrpe!check_iftraffic!"eth0"!50!100!50!m 
  207.          max_check_attempts      4 
  208.          normal_check_interval   4 
  209.          retry_check_interval    2 
  210.          check_period            24x7 
  211.          notification_interval   5 
  212.          notification_period     24x7 
  213.          notification_options    w,u,c,r 
  214.          contact_groups          web-server 
  215.          } 
  216.  " >> /usr/local/nagios/etc/objects/services.cfg 
  217.  echo "###############  Add web-server services completed ########"  
  218.   
  219.  } 
  220.   

下面是添加mysql服务的脚本:

 

  1. addmysqlservicemaster () { 
  2.  read -p " Please input the nagios server IP: " naigosip 
  3.  read -p " Please input the mysql server IP: " mysqlip 
  4.  read -p " please input the mysql alias name : "  host 
  5.  read -p " please input the mysql password :" mysqlpwd 
  6.  read -p " please input the nagios for mysql's password:" nagiospwd 
  7.   
  8.  echo "define host{ 
  9.          host_name                       $host 
  10.          alias                           web-server 
  11.          address                         $mysqlip 
  12.          check_command                   check-host-alive 
  13.          max_check_attempts              5 
  14.          check_period                    24x7 
  15.          contact_groups                  web-server 
  16.          notification_interval           10 
  17.          notification_period             24x7 
  18.          notification_options            d,u,r 
  19.          }" >> /usr/local/nagios/etc/objects/hosts.cfg 
  20.  sed -i "11,15{/members/s/$/,$host/}" /usr/local/nagios/etc/objects/hostgroups.cfg 
  21.  echo " 
  22.  define hostescalation{  
  23.                  host_name               $host        
  24.                  first_notification      5                  
  25.                  last_notification       0                  
  26.                  notification_interval   10                
  27.                  contact_groups          mysql-server              
  28.                  }  
  29.  define serviceescalation{  
  30.                  host_name               $host  
  31.                  service_description     Mysql-Listener        
  32.                  first_notification      5  
  33.                  last_notification       0  
  34.                  notification_interval   10  
  35.                  contact_groups          mysql-server  
  36.                  }  
  37.  define serviceescalation{  
  38.                  host_name               $host  
  39.                  service_description     Mysql-Status        
  40.                  first_notification      5  
  41.                  last_notification       0  
  42.                  notification_interval   10  
  43.                  contact_groups          mysql-server  
  44.                  } " >> /usr/local/nagios/etc/objects/escalations.cfg    
  45.   
  46.  echo "  
  47.     define service { 
  48.          host_name               $host 
  49.          service_description     check-host-alive 
  50.          check_command           check-host-alive 
  51.          max_check_attempts      4 
  52.          normal_check_interval   3 
  53.          retry_check_interval    2 
  54.          check_period            24x7 
  55.          notification_interval   10 
  56.          notification_period     24x7 
  57.          notification_options    w,u,c,r 
  58.          contact_groups          mysql-server 
  59.          } 
  60.  define service{ 
  61.          host_name               $host 
  62.          service_description     check_disk 
  63.          check_command           check_nrpe!check_disk 
  64.          max_check_attempts      4 
  65.          normal_check_interval   3 
  66.          retry_check_interval    2 
  67.          check_period            24x7 
  68.          notification_interval   10 
  69.          notification_period     24x7 
  70.          notification_options    w,u,c,r 
  71.          contact_groups          mysql-server 
  72.          } 
  73.    define service { 
  74.          host_name               $host 
  75.          service_description     SSH-Listener 
  76.          check_command           check_tcp!22 
  77.          max_check_attempts      4 
  78.          normal_check_interval   3 
  79.          retry_check_interval    2 
  80.          check_period            24x7 
  81.          notification_interval   10 
  82.          notification_period     24x7 
  83.          notification_options    w,u,c,r 
  84.          contact_groups          mysql-server 
  85.          } 
  86.  define service { 
  87.          host_name               $host 
  88.          service_description     Mysql-Listener 
  89.          check_command           check_tcp!3306 
  90.          max_check_attempts      4 
  91.          normal_check_interval   2 
  92.          retry_check_interval    1 
  93.          check_period            24x7 
  94.          notification_interval   2 
  95.          notification_period     24x7 
  96.          notification_options    w,u,c,r 
  97.          contact_groups          mysql-server 
  98.          } 
  99.  define service { 
  100.          host_name               $host 
  101.          service_description     Linux-Memory 
  102.          check_command           check_nrpe!check_mem 
  103.          max_check_attempts      4 
  104.          normal_check_interval   3 
  105.          retry_check_interval    2 
  106.          check_period            24x7 
  107.          notification_interval   10 
  108.          notification_period     24x7 
  109.          notification_options    w,u,c,r 
  110.          contact_groups          mysql-server 
  111.          } 
  112.  define service { 
  113.          host_name               $host 
  114.          service_description     Linux-load 
  115.          check_command           check_nrpe!check_load 
  116.          max_check_attempts      4 
  117.          normal_check_interval   3 
  118.          retry_check_interval    2 
  119.          check_period            24x7 
  120.          notification_interval   10 
  121.          notification_period     24x7 
  122.          notification_options    w,u,c,r 
  123.          contact_groups          mysql-server 
  124.          } 
  125.  define service { 
  126.          host_name               $host 
  127.          service_description     Linux-total-procs 
  128.          check_command           check_nrpe!check_total_procs 
  129.          max_check_attempts      4 
  130.          normal_check_interval   3 
  131.          retry_check_interval    2 
  132.          check_period            24x7 
  133.          notification_interval   10 
  134.          notification_period     24x7 
  135.          notification_options    w,u,c,r 
  136.          contact_groups          mysql-server 
  137.         } 
  138.  define service{ 
  139.          host_name               $host 
  140.          service_description     Linux-CPU 
  141.          check_command           check_nrpe!check_cpu 
  142.          max_check_attempts      4 
  143.          normal_check_interval   3 
  144.          retry_check_interval    2 
  145.          check_period            24x7 
  146.          notification_interval   10 
  147.          notification_period     24x7 
  148.          notification_options    w,u,c,r 
  149.          contact_groups          mysql-server 
  150.         } 
  151.  define service{ 
  152.          host_name               $host 
  153.          service_description     Linux-user 
  154.          check_command           check_nrpe!check_users 
  155.          max_check_attempts      4 
  156.          normal_check_interval   3 
  157.          retry_check_interval    2 
  158.          check_period            24x7 
  159.          notification_interval   10 
  160.          notification_period     24x7 
  161.          notification_options    w,u,c,r 
  162.          contact_groups          mysql-server 
  163.         } 
  164.       define service{ 
  165.          host_name               $host 
  166.          service_description     Linux-iftraffic 
  167.          check_command           check_nrpe!check_iftraffic!"eth0"!50!100!50!m 
  168.          max_check_attempts      4 
  169.          normal_check_interval   3 
  170.          retry_check_interval    2 
  171.          check_period            24x7 
  172.          notification_interval   10 
  173.          notification_period     24x7 
  174.          notification_options    w,u,c,r 
  175.          contact_groups          web-server 
  176.          } 
  177.  define service{ 
  178.          host_name               $host 
  179.          service_description     threads-connected 
  180.          check_command           check_mysql_health!nagios!$nagiospwd!threads-connected!$mysqlip!3306! 
  181.          max_check_attempts      4 
  182.          normal_check_interval   2 
  183.          retry_check_interval    1 
  184.          check_period            24x7 
  185.          notification_interval   10 
  186.          notification_period     24x7 
  187.          notification_options    w,u,c,r 
  188.          contact_groups          mysql-server 
  189.         } 
  190.  define service{ 
  191.          host_name               $host 
  192.          service_description     Mysql-Status 
  193.          check_command           check_mysql 
  194.          max_check_attempts      4 
  195.          normal_check_interval   2 
  196.          retry_check_interval    1 
  197.          check_period            24x7 
  198.          notification_interval   2 
  199.          notification_period     24x7 
  200.          notification_options    w,u,c,r 
  201.          contact_groups          mysql-server 
  202.         } " >> /usr/local/nagios/etc/objects/services.cfg 
  203.  echo "###############add mysql services ################" 

这样就行了

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI