手机版
你好,游客 登录 注册
背景:
阅读新闻

详解搭建Linux监控平台之Nagios

监控端添加服务

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

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

这样就行了。

linux
【内容导航】
第1页:LAMP环境 第2页:监控端环境部署
第3页:被监控端的环境部署 第4页:监控端添加服务
第5页:使用以及相关说明
相关资讯       Nagios 
本文评论   查看全部评论 (0)
表情: 表情 姓名: 字数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款