Nagios服务器端安装部署详解

转自:http://blog.itpub.net/26230597/viewspace-1159459/

http://blog.itpub.net/26230597/viewspace-1159578/

 

下载地址如下: http://sourceforge.net/projects/nagios/files/

具体详细下载地址:http://prdownloads.sourceforge.net/sourceforge/nagios/nagios-4.0.6.tar.gz

1 开始下载:
wget http://sourceforge.net/projects/nagios/files/nagios-4.x/nagios-4.0.6/nagios-4.0.6.tar.gz/download?use_mirror=jaist
如下图所示,下载free版本的。

安装前准备工作,安装一些lib包:

[root@cache-2 root]# yum -y install httpd gcc glibc glibc-common

# yum install -y gcc glibc glibc-common gd gd-devel xinetd openssl-devel

 

2 进行selinux设置,或者关闭selinux

查看SELinux状态:

(1)/usr/sbin/sestatus -v      ##如果SELinux status参数为enabled即为开启状态

SELinux status:                 enabled

(2)getenforce                 ##也可以用这个命令检查

关闭SELinux:

(3)临时关闭(不用重启机器):

setenforce 0                  ##设置SELinux 成为permissive模式

##setenforce 1 设置SELinux 成为enforcing模式

(4)修改配置文件需要重启机器:

修改/etc/selinux/config 文件

将SELINUX=enforcing改为SELINUX=disabled

重启机器即可

 

3 开始准备nagios安装环境

(1) 添加nagios运行所需要的用户和组:

groupadd nagcmd

useradd -m nagios

usermod -a -G nagcmd nagios

 

把apache加入到nagcmd组,以便于在通过web Interface操作nagios时能够具有足够的权限:

# usermod -a -G nagcmd apache

 

4 编译安装准备

./configure –with-command-group=nagios –prefix=/opt/app/nagios –enable-embedded-perl –with-httpd-conf=/usr/local/apache2/conf

点击(此处)折叠或打开

  1. 2 tar -xvf nagios-4.0.6.tar.gz
  2. cd /root/nagios-4.0.6
  3. [root@cache-2 nagios-4.0.6]# ./configure –with-command-group=nagios –prefix=/opt/app/nagios –enable-embedded-perl –with-httpd-conf=/usr/local/apache2/conf
  4. checking for a BSD-compatible install… /usr/bin/install -c
  5. checking build system type… x86_64-unknown-linux-gnu
  6. checking host system type… x86_64-unknown-linux-gnu
  7. checking for gcc… gcc
  8. checking for C compiler default output file name… a.out
  9. checking whether the C compiler works… yes
  10. checking whether we are cross compiling… no
  11. checking for suffix of executables…
  12. checking for suffix of object files… o
  13. checking whether we are using the GNU C compiler… yes
  14. checking whether gcc accepts -g… yes
  15. checking for gcc option to accept ISO C89… none needed
  16. checking whether make sets $(MAKE)… yes
  17. checking for strip… /usr/bin/strip
  18. checking how to run the C preprocessor… gcc -E
  19. checking for grep that handles long lines and -e… /bin/grep
  20. checking for egrep… /bin/grep -E
  21. checking for ANSI C header files… yes
  22. checking whether time.h and sys/time.h may both be included… yes
  23. checking for sys/wait.h that is POSIX.1 compatible… yes
  24. checking for sys/types.h… yes
  25. checking for sys/stat.h… yes
  26. checking for stdlib.h… yes
  27. checking for string.h… yes
  28. checking for memory.h… yes
  29. checking for strings.h… yes
  30. checking for inttypes.h… yes
  31. checking for stdint.h… yes
  32. checking for unistd.h… yes
  33. checking arpa/inet.h usability… yes
  34. checking arpa/inet.h presence… yes
  35. checking for arpa/inet.h… yes
  36. checking ctype.h usability… yes
  37. checking ctype.h presence… yes
  38. checking for ctype.h… yes
  39. checking dirent.h usability… yes
  40. checking dirent.h presence… yes
  41. checking for dirent.h… yes
  42. checking errno.h usability… yes
  43. checking errno.h presence… yes
  44. checking for errno.h… yes
  45. checking fcntl.h usability… yes
  46. checking fcntl.h presence… yes
  47. checking for fcntl.h… yes
  48. checking getopt.h usability… yes
  49. checking getopt.h presence… yes
  50. checking for getopt.h… yes
  51. checking grp.h usability… yes
  52. checking grp.h presence… yes
  53. checking for grp.h… yes
  54. checking libgen.h usability… yes
  55. checking libgen.h presence… yes
  56. checking for libgen.h… yes
  57. checking limits.h usability… yes
  58. checking limits.h presence… yes
  59. checking for limits.h… yes
  60. checking math.h usability… yes
  61. checking math.h presence… yes
  62. checking for math.h… yes
  63. checking netdb.h usability… yes
  64. checking netdb.h presence… yes
  65. checking for netdb.h… yes
  66. checking netinet/in.h usability… yes
  67. checking netinet/in.h presence… yes
  68. checking for netinet/in.h… yes
  69. checking pwd.h usability… yes
  70. checking pwd.h presence… yes
  71. checking for pwd.h… yes
  72. checking regex.h usability… yes
  73. checking regex.h presence… yes
  74. checking for regex.h… yes
  75. checking signal.h usability… yes
  76. checking signal.h presence… yes
  77. checking for signal.h… yes
  78. checking socket.h usability… no
  79. checking socket.h presence… no
  80. checking for socket.h… no
  81. checking stdarg.h usability… yes
  82. checking stdarg.h presence… yes
  83. checking for stdarg.h… yes
  84. checking for string.h… (cached) yes
  85. checking for strings.h… (cached) yes
  86. checking sys/mman.h usability… yes
  87. checking sys/mman.h presence… yes
  88. checking for sys/mman.h… yes
  89. checking for sys/types.h… (cached) yes
  90. checking sys/time.h usability… yes
  91. checking sys/time.h presence… yes
  92. checking for sys/time.h… yes
  93. checking sys/resource.h usability… yes
  94. checking sys/resource.h presence… yes
  95. checking for sys/resource.h… yes
  96. checking for sys/wait.h… (cached) yes
  97. checking sys/socket.h usability… yes
  98. checking sys/socket.h presence… yes
  99. checking for sys/socket.h… yes
  100. checking for sys/stat.h… (cached) yes
  101. checking sys/timeb.h usability… yes
  102. checking sys/timeb.h presence… yes
  103. checking for sys/timeb.h… yes
  104. checking sys/un.h usability… yes
  105. checking sys/un.h presence… yes
  106. checking for sys/un.h… yes
  107. checking sys/ipc.h usability… yes
  108. checking sys/ipc.h presence… yes
  109. checking for sys/ipc.h… yes
  110. checking sys/msg.h usability… yes
  111. checking sys/msg.h presence… yes
  112. checking for sys/msg.h… yes
  113. checking sys/poll.h usability… yes
  114. checking sys/poll.h presence… yes
  115. checking for sys/poll.h… yes
  116. checking syslog.h usability… yes
  117. checking syslog.h presence… yes
  118. checking for syslog.h… yes
  119. checking uio.h usability… no
  120. checking uio.h presence… no
  121. checking for uio.h… no
  122. checking for unistd.h… (cached) yes
  123. checking locale.h usability… yes
  124. checking locale.h presence… yes
  125. checking for locale.h… yes
  126. checking wchar.h usability… yes
  127. checking wchar.h presence… yes
  128. checking for wchar.h… yes
  129. checking for an ANSI C-conforming const… yes
  130. checking whether struct tm is in sys/time.h or time.h… time.h
  131. checking for struct tm.tm_zone… yes
  132. checking for mode_t… yes
  133. checking for pid_t… yes
  134. checking for size_t… yes
  135. checking return type of signal handlers… void
  136. checking for uid_t in sys/types.h… yes
  137. checking type of array argument to getgroups… gid_t
  138. checking for va_copy… yes
  139. checking for vsnprintf… yes
  140. checking for snprintf… yes
  141. checking for asprintf… yes
  142. checking for vasprintf… yes
  143. checking for C99 vsnprintf… yes
  144. checking for library containing getservbyname… none required
  145. checking for library containing connect… none required
  146. checking for initgroups… yes
  147. checking for setenv… yes
  148. checking for strdup… yes
  149. checking for strstr… yes
  150. checking for strtoul… yes
  151. checking for unsetenv… yes
  152. checking for type of socket size… size_t
  153. checking for library containing nanosleep… none required
  154. checking for mail… /bin/mail
  155. checking for glibc at least version 2.4… yes
  156. checking sys/epoll.h usability… yes
  157. checking sys/epoll.h presence… yes
  158. checking for sys/epoll.h… yes
  159. checking sys/select.h usability… yes
  160. checking sys/select.h presence… yes
  161. checking for sys/select.h… yes
  162. checking for main in -liconv… no
  163. checking for gdImagePng in -lgd (order 1)… no
  164. checking for gdImagePng in -lgd (order 2)… no
  165. checking for gdImagePng in -lgd (order 3)… no
  166. checking for gdImagePng in -lgd (order 4)… no
  167. *** GD, PNG, and/or JPEG libraries could not be located… *********
  168. Boutell\

5 开始make安装
5.1 make all
[root@cache-2 nagios-4.0.6]#  make all

点击(此处)折叠或打开

  1. [root@cache-2 nagios-4.0.6]# make all
  2. cd ./base && make
  3. make[1]: Entering directory `/root/nagios-4.0.6/base\’
  4. gcc -Wall -I.. -g -O2 -DHAVE_CONFIG_H -DNSCORE -c -o nagios.o nagios.c
  5. gcc -Wall -I.. -g -O2 -DHAVE_CONFIG_H -DNSCORE -c -o broker.o broker.c
  6. gcc -Wall -I.. -g -O2 -DHAVE_CONFIG_H -DNSCORE -c -o nebmods.o nebmods.c
  7. gcc -Wall -I.. -g -O2 -DHAVE_CONFIG_H -DNSCORE -c -o ../common/shared.o ../common/shared.c
  8. gcc -Wall -I.. -g -O2 -DHAVE_CONFIG_H -DNSCORE -c -o nerd.o nerd.c
  9. gcc -Wall -I.. -g -O2 -DHAVE_CONFIG_H -DNSCORE -c -o query-handler.o query-handler.c
  10. gcc -Wall -I.. -g -O2 -DHAVE_CONFIG_H -DNSCORE -c -o workers.o workers.c
  11. gcc -Wall -I.. -g -O2 -DHAVE_CONFIG_H -DNSCORE -c -o checks.o checks.c
  12. gcc -Wall -I.. -g -O2 -DHAVE_CONFIG_H -DNSCORE -c -o config.o config.c
  13. gcc -Wall -I.. -g -O2 -DHAVE_CONFIG_H -DNSCORE -c -o commands.o commands.c
  14. commands.c: 在函数‘process_passive_service_check’中:
  15. commands.c:2247: 警告:赋值丢弃了指针目标类型的限定
  16. commands.c: 在函数‘process_passive_host_check’中:
  17. commands.c:2339: 警告:赋值丢弃了指针目标类型的限定
  18. gcc -Wall -I.. -g -O2 -DHAVE_CONFIG_H -DNSCORE -c -o events.o events.c
  19. gcc -Wall -I.. -g -O2 -DHAVE_CONFIG_H -DNSCORE -c -o flapping.o flapping.c
  20. gcc -Wall -I.. -g -O2 -DHAVE_CONFIG_H -DNSCORE -c -o logging.o logging.c
  21. gcc -Wall -I.. -g -O2 -DHAVE_CONFIG_H -DNSCORE -c -o macros-base.o ../common/macros.c
  22. gcc -Wall -I.. -g -O2 -DHAVE_CONFIG_H -DNSCORE -c -o netutils.o netutils.c
  23. gcc -Wall -I.. -g -O2 -DHAVE_CONFIG_H -DNSCORE -c -o notifications.o notifications.c
  24. gcc -Wall -I.. -g -O2 -DHAVE_CONFIG_H -DNSCORE -c -o sehandlers.o sehandlers.c
  25. gcc -Wall -I.. -g -O2 -DHAVE_CONFIG_H -DNSCORE -c -o utils.o utils.c
  26. gcc -Wall -I.. -g -O2 -DHAVE_CONFIG_H -DNSCORE -c -o retention-base.o sretention.c
  27. gcc -Wall -I.. -g -O2 -DHAVE_CONFIG_H -DNSCORE -c -o xretention-base.o ../xdata/xrddefault.c
  28. gcc -Wall -I.. -g -O2 -DHAVE_CONFIG_H -DNSCORE -c -o comments-base.o ../common/comments.c
  29. gcc -Wall -I.. -g -O2 -DHAVE_CONFIG_H -DNSCORE -c -o xcomments-base.o ../xdata/xcddefault.c
  30. gcc -Wall -I.. -g -O2 -DHAVE_CONFIG_H -DNSCORE -c -o objects-base.o ../common/objects.c
  31. gcc -Wall -I.. -g -O2 -DHAVE_CONFIG_H -DNSCORE -c -o xobjects-base.o ../xdata/xodtemplate.c
  32. gcc -Wall -I.. -g -O2 -DHAVE_CONFIG_H -DNSCORE -c -o statusdata-base.o ../common/statusdata.c
  33. gcc -Wall -I.. -g -O2 -DHAVE_CONFIG_H -DNSCORE -c -o xstatusdata-base.o ../xdata/xsddefault.c
  34. gcc -Wall -I.. -g -O2 -DHAVE_CONFIG_H -DNSCORE -c -o perfdata-base.o perfdata.c
  35. gcc -Wall -I.. -g -O2 -DHAVE_CONFIG_H -DNSCORE -c -o xperfdata-base.o ../xdata/xpddefault.c
  36. gcc -Wall -I.. -g -O2 -DHAVE_CONFIG_H -DNSCORE -c -o downtime-base.o ../common/downtime.c
  37. make -C ../lib
  38. make[2]: Entering directory `/root/nagios-4.0.6/lib\’
  39. gcc -g -O2 -DHAVE_CONFIG_H -c squeue.c -o squeue.o
  40. gcc -g -O2 -DHAVE_CONFIG_H -c kvvec.c -o kvvec.o
  41. gcc -g -O2 -DHAVE_CONFIG_H -c iocache.c -o iocache.o
  42. gcc -g -O2 -DHAVE_CONFIG_H -c iobroker.c -o iobroker.o
  43. gcc -g -O2 -DHAVE_CONFIG_H -c bitmap.c -o bitmap.o
  44. gcc -g -O2 -DHAVE_CONFIG_H -c dkhash.c -o dkhash.o
  45. gcc -g -O2 -DHAVE_CONFIG_H -c runcmd.c -o runcmd.o
  46. gcc -g -O2 -DHAVE_CONFIG_H -c nsutils.c -o nsutils.o
  47. gcc -g -O2 -DHAVE_CONFIG_H -c fanout.c -o fanout.o
  48. gcc -g -O2 -DHAVE_CONFIG_H -c pqueue.c -o pqueue.o
  49. gcc -g -O2 -DHAVE_CONFIG_H -c worker.c -o worker.o
  50. gcc -g -O2 -DHAVE_CONFIG_H -c skiplist.c -o skiplist.o
  51. gcc -g -O2 -DHAVE_CONFIG_H -c nsock.c -o nsock.o
  52. gcc -g -O2 -DHAVE_CONFIG_H -c nspath.c -o nspath.o
  53. ar cr libnagios.a squeue.o kvvec.o iocache.o iobroker.o bitmap.o dkhash.o runcmd.o nsutils.o fanout.o pqueue.o worker.o skiplist.o nsock.o nspath.o
  54. make[2]: Leaving directory `/root/nagios-4.0.6/lib\’
  55. gcc -Wall -I.. -g -O2 -DHAVE_CONFIG_H -DNSCORE -o nagios nagios.o broker.o nebmods.o ../common/shared.o nerd.o query-handler.o workers.o checks.o config.o commands.o events.o flapping.o logging.o macros-base.o netutils.o notifications.o sehandlers.o utils.o retention-base.o xretention-base.o comments-base.o xcomments-base.o objects-base.o xobjects-base.o statusdata-base.o xstatusdata-base.o perfdata-base.o xperfdata-base.o downtime-base.o -Wl,-export-dynamic -lm -ldl ../lib/libnagios.a
  56. gcc -Wall -I.. -g -O2 -DHAVE_CONFIG_H -DNSCORE -o nagiostats nagiostats.c -lm ../lib/libnagios.a
  57. make[1]: Leaving directory `/root/nagios-4.0.6/base\’
  58. cd ./cgi && make
  59. make[1]: Entering directory `/root/nagios-4.0.6/cgi\’
  60. gcc -Wall -I.. -g -O2 -DHAVE_CONFIG_H -DNSCGI -c -o getcgi.o getcgi.c
  61. gcc -Wall -I.. -g -O2 -DHAVE_CONFIG_H -DNSCGI -c -o cgiutils.o cgiutils.c
  62. gcc -Wall -I.. -g -O2 -DHAVE_CONFIG_H -DNSCGI -c -o cgiauth.o cgiauth.c
  63. gcc -Wall -I.. -g -O2 -DHAVE_CONFIG_H -DNSCGI -c -o macros-cgi.o ../common/macros.c
  64. gcc -Wall -I.. -g -O2 -DHAVE_CONFIG_H -DNSCGI -c -o objects-cgi.o ../common/objects.c
  65. gcc -Wall -I.. -g -O2 -DHAVE_CONFIG_H -DNSCGI -c -o xobjects-cgi.o ../xdata/xodtemplate.c
  66. gcc -Wall -I.. -g -O2 -DHAVE_CONFIG_H -DNSCGI -c -o statusdata-cgi.o ../common/statusdata.c
  67. gcc -Wall -I.. -g -O2 -DHAVE_CONFIG_H -DNSCGI -c -o xstatusdata-cgi.o ../xdata/xsddefault.c
  68. gcc -Wall -I.. -g -O2 -DHAVE_CONFIG_H -DNSCGI -c -o comments-cgi.o ../common/comments.c
  69. gcc -Wall -I.. -g -O2 -DHAVE_CONFIG_H -DNSCGI -c -o downtime-cgi.o ../common/downtime.c
  70. ../common/downtime.c:194: 警告:‘downtime_remove’定义后未使用
  71. gcc -Wall -I.. -g -O2 -DHAVE_CONFIG_H -DNSCGI -DJSON_NAGIOS_4X -c -o archiveutils.o archiveutils.c
  72. gcc -Wall -I.. -g -O2 -DHAVE_CONFIG_H -DNSCGI -DJSON_NAGIOS_4X -c -o jsonutils.o jsonutils.c
  73. gcc -Wall -I.. -g -O2 -DHAVE_CONFIG_H -DNSCGI -DJSON_NAGIOS_4X -o archivejson.cgi archivejson.c ../common/shared.o getcgi.o cgiutils.o cgiauth.o macros-cgi.o objects-cgi.o xobjects-cgi.o statusdata-cgi.o xstatusdata-cgi.o comments-cgi.o downtime-cgi.o ../lib/libnagios.a archiveutils.o jsonutils.o
  74. gcc -Wall -I.. -g -O2 -DHAVE_CONFIG_H -DNSCGI -o avail.cgi avail.c ../common/shared.o getcgi.o cgiutils.o cgiauth.o macros-cgi.o objects-cgi.o xobjects-cgi.o statusdata-cgi.o xstatusdata-cgi.o comments-cgi.o downtime-cgi.o ../lib/libnagios.a
  75. gcc -Wall -I.. -g -O2 -DHAVE_CONFIG_H -DNSCGI -c -o extcmd_list.o extcmd_list.c
  76. gcc -Wall -I.. -g -O2 -DHAVE_CONFIG_H -DNSCGI -o cmd.cgi cmd.c extcmd_list.o ../common/shared.o getcgi.o cgiutils.o cgiauth.o macros-cgi.o objects-cgi.o xobjects-cgi.o statusdata-cgi.o xstatusdata-cgi.o comments-cgi.o downtime-cgi.o ../lib/libnagios.a
  77. gcc -Wall -I.. -g -O2 -DHAVE_CONFIG_H -DNSCGI -o config.cgi config.c ../common/shared.o getcgi.o cgiutils.o cgiauth.o macros-cgi.o objects-cgi.o xobjects-cgi.o statusdata-cgi.o xstatusdata-cgi.o comments-cgi.o downtime-cgi.o ../lib/libnagios.a
  78. gcc -Wall -I.. -g -O2 -DHAVE_CONFIG_H -DNSCGI -o extinfo.cgi extinfo.c ../common/shared.o getcgi.o cgiutils.o cgiauth.o macros-cgi.o objects-cgi.o xobjects-cgi.o statusdata-cgi.o xstatusdata-cgi.o comments-cgi.o downtime-cgi.o ../lib/libnagios.a
  79. gcc -Wall -I.. -g -O2 -DHAVE_CONFIG_H -DNSCGI -o history.cgi history.c ../common/shared.o getcgi.o cgiutils.o cgiauth.o macros-cgi.o objects-cgi.o xobjects-cgi.o statusdata-cgi.o xstatusdata-cgi.o comments-cgi.o downtime-cgi.o ../lib/libnagios.a
  80. gcc -Wall -I.. -g -O2 -DHAVE_CONFIG_H -DNSCGI -o notifications.cgi notifications.c ../common/shared.o getcgi.o cgiutils.o cgiauth.o macros-cgi.o objects-cgi.o xobjects-cgi.o statusdata-cgi.o xstatusdata-cgi.o comments-cgi.o downtime-cgi.o ../lib/libnagios.a
  81. gcc -Wall -I.. -g -O2 -DHAVE_CONFIG_H -DNSCGI -DJSON_NAGIOS_4X -o objectjson.cgi objectjson.c ../common/shared.o getcgi.o cgiutils.o cgiauth.o macros-cgi.o objects-cgi.o xobjects-cgi.o statusdata-cgi.o xstatusdata-cgi.o comments-cgi.o downtime-cgi.o ../lib/libnagios.a jsonutils.o
  82. gcc -Wall -I.. -g -O2 -DHAVE_CONFIG_H -DNSCGI -o outages.cgi outages.c ../common/shared.o getcgi.o cgiutils.o cgiauth.o macros-cgi.o objects-cgi.o xobjects-cgi.o statusdata-cgi.o xstatusdata-cgi.o comments-cgi.o downtime-cgi.o ../lib/libnagios.a
  83. gcc -Wall -I.. -g -O2 -DHAVE_CONFIG_H -DNSCGI -o showlog.cgi showlog.c ../common/shared.o getcgi.o cgiutils.o cgiauth.o macros-cgi.o objects-cgi.o xobjects-cgi.o statusdata-cgi.o xstatusdata-cgi.o comments-cgi.o downtime-cgi.o ../lib/libnagios.a
  84. gcc -Wall -I.. -g -O2 -DHAVE_CONFIG_H -DNSCGI -o status.cgi status.c ../common/shared.o getcgi.o cgiutils.o cgiauth.o macros-cgi.o objects-cgi.o xobjects-cgi.o statusdata-cgi.o xstatusdata-cgi.o comments-cgi.o downtime-cgi.o ../lib/libnagios.a
  85. gcc -Wall -I.. -g -O2 -DHAVE_CONFIG_H -DNSCGI -DJSON_NAGIOS_4X -o statusjson.cgi statusjson.c ../common/shared.o getcgi.o cgiutils.o cgiauth.o macros-cgi.o objects-cgi.o xobjects-cgi.o statusdata-cgi.o xstatusdata-cgi.o comments-cgi.o downtime-cgi.o ../lib/libnagios.a jsonutils.o
  86. gcc -Wall -I.. -g -O2 -DHAVE_CONFIG_H -DNSCGI -o statuswml.cgi statuswml.c ../common/shared.o getcgi.o cgiutils.o cgiauth.o macros-cgi.o objects-cgi.o xobjects-cgi.o statusdata-cgi.o xstatusdata-cgi.o comments-cgi.o downtime-cgi.o ../lib/libnagios.a
  87. gcc -Wall -I.. -g -O2 -DHAVE_CONFIG_H -DNSCGI -o summary.cgi summary.c ../common/shared.o getcgi.o cgiutils.o cgiauth.o macros-cgi.o objects-cgi.o xobjects-cgi.o statusdata-cgi.o xstatusdata-cgi.o comments-cgi.o downtime-cgi.o ../lib/libnagios.a
  88. gcc -Wall -I.. -g -O2 -DHAVE_CONFIG_H -DNSCGI -o tac.cgi tac.c ../common/shared.o getcgi.o cgiutils.o cgiauth.o macros-cgi.o objects-cgi.o xobjects-cgi.o statusdata-cgi.o xstatusdata-cgi.o comments-cgi.o downtime-cgi.o ../lib/libnagios.a
  89. gcc -Wall -I.. -g -O2 -DHAVE_CONFIG_H -DNSCGI -o statuswrl.cgi statuswrl.c ../common/shared.o getcgi.o cgiutils.o cgiauth.o macros-cgi.o objects-cgi.o xobjects-cgi.o statusdata-cgi.o xstatusdata-cgi.o comments-cgi.o downtime-cgi.o ../lib/libnagios.a -lm
  90. gcc -Wall -I.. -g -O2 -DHAVE_CONFIG_H -DNSCGI -o statusmap.cgi statusmap.c ../common/shared.o getcgi.o cgiutils.o cgiauth.o macros-cgi.o objects-cgi.o xobjects-cgi.o statusdata-cgi.o xstatusdata-cgi.o comments-cgi.o downtime-cgi.o ../lib/libnagios.a -lgd -lpng -ljpeg -lz -lm
  91. gcc -Wall -I.. -g -O2 -DHAVE_CONFIG_H -DNSCGI -o trends.cgi trends.c ../common/shared.o getcgi.o cgiutils.o cgiauth.o macros-cgi.o objects-cgi.o xobjects-cgi.o statusdata-cgi.o xstatusdata-cgi.o comments-cgi.o downtime-cgi.o ../lib/libnagios.a -lgd -lpng -ljpeg -lz -lm
  92. gcc -Wall -I.. -g -O2 -DHAVE_CONFIG_H -DNSCGI -o histogram.cgi histogram.c ../common/shared.o getcgi.o cgiutils.o cgiauth.o macros-cgi.o objects-cgi.o xobjects-cgi.o statusdata-cgi.o xstatusdata-cgi.o comments-cgi.o downtime-cgi.o ../lib/libnagios.a -lgd -lpng -ljpeg -lz -lm
  93. make[1]: Leaving directory `/root/nagios-4.0.6/cgi\’
  94. cd ./html && make
  95. make[1]: Entering directory `/root/nagios-4.0.6/html\’
  96. make[1]: Nothing to be done for `all\’.
  97. make[1]: Leaving directory `/root/nagios-4.0.6/html\’
  98. if [ xyes = xyes ]; then \\
  99.         cd ./module && make; \\
  100.     fi
  101. make[1]: Entering directory `/root/nagios-4.0.6/module\’
  102. gcc -I.. -fPIC -g -O2 -DHAVE_CONFIG_H -o helloworld.o helloworld.c -shared
  103. make[1]: Leaving directory `/root/nagios-4.0.6/module\’
  104. cd ./worker && make all
  105. make[1]: Entering directory `/root/nagios-4.0.6/worker\’
  106. cd ./ping && make all
  107. make[2]: Entering directory `/root/nagios-4.0.6/worker/ping\’
  108. gcc -I.. -I ../../include -I ../.. -g -O2 -DHAVE_CONFIG_H -o worker-ping worker-ping.c -L ../../lib -l nagios
  109. make[2]: Leaving directory `/root/nagios-4.0.6/worker/ping\’
  110. make[1]: Leaving directory `/root/nagios-4.0.6/worker\’
  111. *** Compile finished ***
  112. If the main program and CGIs compiled without any errors, you
  113. can continue with installing Nagios as follows (type \’make\’
  114. without any arguments for a list of all possible options):
  115.   make install
  116.      – This installs the main program, CGIs, and HTML files
  117.   make install-init
  118.      – This installs the init script in /etc/rc.d/init.d
  119.   make install-commandmode
  120.      – This installs and configures permissions on the
  121.        directory for holding the external command file
  122.   make install-config
  123.      – This installs *SAMPLE* config files in /usr/local/nagios/etc
  124.        You\’ll have to modify these sample files before you can
  125.        use Nagios. Read the HTML documentation for more info
  126.        on doing this. Pay particular attention to the docs on
  127.        object configuration files, as they determine what/how
  128.        things get
  129.   make install-webconf
  130.      – This installs the Apache config file for the Nagios
  131.        web interface
  132.   make install-exfoliation
  133.      – This installs the Exfoliation theme for the Nagios
  134.        web interface
  135.   make install-classicui
  136.      – This installs the classic theme for the Nagios
  137.        web interface
  138. *** Support Notes *******************************************
  139. If you have questions about configuring or running Nagios,
  140. please make sure that you:
  141.      – Look at the sample config files
  142.      – Read the documentation on the Nagios Library at:
  143.            http://library.nagios.com
  144. before you post a question to one of the mailing lists.
  145. Also make sure to include pertinent information that could
  146. help others help you. This might include:
  147.      – What version of Nagios you are using
  148.      – What version of the plugins you are using
  149.      – Relevant snippets from your config files
  150.      – Relevant error messages from the Nagios log file
  151. For more information on obtaining support for Nagios, visit:
  152.        http://support.nagios.com
  153. *************************************************************
  154. Enjoy.


5.2 make install

[root@cache-2 nagios-4.0.6]# make install

点击(此处)折叠或打开

  1. [root@cache-2 nagios-4.0.6]# make install
  2. cd ./base && make install
  3. make[1]: Entering directory `/root/nagios-4.0.6/base\’
  4. make install-basic
  5. make[2]: Entering directory `/root/nagios-4.0.6/base\’
  6. /usr/bin/install -c -m 775 -o nagios -g nagios -d /usr/local/nagios/bin
  7. /usr/bin/install -c -m 774 -o nagios -g nagios nagios /usr/local/nagios/bin
  8. /usr/bin/install -c -m 774 -o nagios -g nagios nagiostats /usr/local/nagios/bin
  9. make[2]: Leaving directory `/root/nagios-4.0.6/base\’
  10. make strip-post-install
  11. make[2]: Entering directory `/root/nagios-4.0.6/base\’
  12. /usr/bin/strip /usr/local/nagios/bin/nagios
  13. /usr/bin/strip /usr/local/nagios/bin/nagiostats
  14. make[2]: Leaving directory `/root/nagios-4.0.6/base\’
  15. make[1]: Leaving directory `/root/nagios-4.0.6/base\’
  16. cd ./cgi && make install
  17. make[1]: Entering directory `/root/nagios-4.0.6/cgi\’
  18. make install-basic
  19. make[2]: Entering directory `/root/nagios-4.0.6/cgi\’
  20. /usr/bin/install -c -m 775 -o nagios -g nagios -d /usr/local/nagios/sbin
  21. for file in *.cgi; do \\
  22.         /usr/bin/install -c -m 775 -o nagios -g nagios $file /usr/local/nagios/sbin; \\
  23.     done
  24. make[2]: Leaving directory `/root/nagios-4.0.6/cgi\’
  25. make strip-post-install
  26. make[2]: Entering directory `/root/nagios-4.0.6/cgi\’
  27. for file in *.cgi; do \\
  28.         /usr/bin/strip /usr/local/nagios/sbin/$file; \\
  29.     done
  30. [root@cache-2 nagios-4.0.6]# make install-config
  31. /usr/bin/install -c -m 775 -o nagios -g nagios -d /usr/local/nagios/etc
  32. /usr/bin/install -c -m 775 -o nagios -g nagios -d /usr/local/nagios/etc/objects
  33. /usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/nagios.cfg /usr/local/nagios/etc/nagios.cfg
  34. /usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/cgi.cfg /usr/local/nagios/etc/cgi.cfg
  35. /usr/bin/install -c -b -m 660 -o nagios -g nagios sample-config/resource.cfg /usr/local/nagios/etc/resource.cfg
  36. /usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/template-object/templates.cfg /usr/local/nagios/etc/objects/templates.cfg
  37. /usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/template-object/commands.cfg /usr/local/nagios/etc/objects/commands.cfg
  38. /usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/template-object/contacts.cfg /usr/local/nagios/etc/objects/contacts.cfg
  39. /usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/template-object/timeperiods.cfg /usr/local/nagios/etc/objects/timeperiods.cfg
  40. /usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/template-object/localhost.cfg /usr/local/nagios/etc/objects/localhost.cfg
  41. /usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/template-object/windows.cfg /usr/local/nagios/etc/objects/windows.cfg
  42. /usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/template-object/printer.cfg /usr/local/nagios/etc/objects/printer.cfg
  43. /usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/template-object/switch.cfg /usr/local/nagios/etc/objects/switch.cfg
  44. *** Config files installed ***
  45. Remember, these are *SAMPLE* config files. You\

5.3 make install-config

点击(此处)折叠或打开

  1. [root@cache-2 nagios-4.0.6]# make install-config
  2. /usr/bin/install -c -m 775 -o nagios -g nagios -d /usr/local/nagios/etc
  3. /usr/bin/install -c -m 775 -o nagios -g nagios -d /usr/local/nagios/etc/objects
  4. /usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/nagios.cfg /usr/local/nagios/etc/nagios.cfg
  5. /usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/cgi.cfg /usr/local/nagios/etc/cgi.cfg
  6. /usr/bin/install -c -b -m 660 -o nagios -g nagios sample-config/resource.cfg /usr/local/nagios/etc/resource.cfg
  7. /usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/template-object/templates.cfg /usr/local/nagios/etc/objects/templates.cfg
  8. /usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/template-object/commands.cfg /usr/local/nagios/etc/objects/commands.cfg
  9. /usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/template-object/contacts.cfg /usr/local/nagios/etc/objects/contacts.cfg
  10. /usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/template-object/timeperiods.cfg /usr/local/nagios/etc/objects/timeperiods.cfg
  11. /usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/template-object/localhost.cfg /usr/local/nagios/etc/objects/localhost.cfg
  12. /usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/template-object/windows.cfg /usr/local/nagios/etc/objects/windows.cfg
  13. /usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/template-object/printer.cfg /usr/local/nagios/etc/objects/printer.cfg
  14. /usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/template-object/switch.cfg /usr/local/nagios/etc/objects/switch.cfg
  15. *** Config files installed ***

 

5.4 make install-commandmode

点击(此处)折叠或打开

  1. [root@cache-2 nagios-4.0.6]# make install-commandmode
  2. /usr/bin/install -c -m 775 -o nagios -g nagios -d /usr/local/nagios/var/rw
  3. chmod g+s /usr/local/nagios/var/rw
  4. *** External command directory configured ***
  5. Remember, these are *SAMPLE* config files. You\


5.5 make install-init

点击(此处)折叠或打开

  1. [root@cache-2 nagios-4.0.6]# make install-init
  2. /usr/bin/install -c -m 755 -d -o root -g root /etc/rc.d/init.d
  3. /usr/bin/install -c -m 755 -o root -g root daemon-init /etc/rc.d/init.d/nagios
  4. *** Init script installed ***

[root@cache-2 nagios-4.0.6]#

加到启动项里面去:

# chkconfig –add nagios

# chkconfig –level 35 nagios on

# chkconfig –list nagios

 

检查主机配置文件是否正确:

/var/www/nagios/bin/nagios -v /var/www/nagios/etc/nagios.cfg

5.6 Check安装是否正确:

5.6.1说明:

切换目录到安装路径(这里是/usr/local/nagios),看是否存在etc、bin、sbin、share、var 这五个目录,如果存在则可以表明程序被正确的安装到系统了。Nagios 各个目录用途说明如下:

bin    Nagios 可执行程序所在目录

etc   Nagios 配置文件所在目录

sbin  Nagios CGI 文件所在目录,也就是执行外部命令所需文件所在的目录

share        Nagios网页文件所在的目录

libexec      Nagios 外部插件所在目录

var   Nagios 日志文件、lock 等文件所在的目录

var/archives     Nagios 日志自动归档目录

var/rw      用来存放外部命令文件的目录

 

5.6.2 check
cd /usr/local/nagios
ll

点击(此处)折叠或打开

  1. [root@cache-2 nagios-4.0.6]# cd /usr/local/nagios
  2. [root@cache-2 nagios]# ll
  3. 总用量 24
  4. drwxrwxr-x. 2 nagios nagios 4096 5月 5 15:31 bin
  5. drwxrwxr-x. 3 nagios nagios 4096 5月 5 15:32 etc
  6. drwxrwxr-x. 2 nagios nagios 4096 5月 5 15:31 libexec
  7. drwxrwxr-x. 2 nagios nagios 4096 5月 5 15:31 sbin
  8. drwxrwxr-x. 10 nagios nagios 4096 5月 5 15:31 share
  9. drwxrwxr-x. 5 nagios nagios 4096 5月 5 15:32 var

 

5.7 安装nagios插件
wget http://nagios-plugins.org/download/nagios-plugins-2.0.tar.gz

点击(此处)折叠或打开

    1. [root@cache-2 ~]# wget http://nagios-plugins.org/download/nagios-plugins-2.0.tar.gz
    2. –2014-05-05 15:52:52– http://nagios-plugins.org/download/nagios-plugins-2.0.tar.gz
    3. 正在解析主机 nagios-plugins.org… 72.14.186.43
    4. 正在连接 nagios-plugins.org|72.14.186.43|:80… 已连接。
    5. 已发出 HTTP 请求,正在等待回应… 200 OK
    6. 长度:2501847 (2.4M) [application/x-gzip]
    7. 正在保存至: “nagios-plugins-2.0.tar.gz”
    8. 15% [======================> ] 390,650 116K/s eta(英国中部时19% [============================> ] 486,218 131K/s eta(英国中部时23% [==================================> ] 594,818 147K/s eta(英国中部时28% [=========================================> ] 715,002 163K/s eta(英国中部时34% [==================================================> ] 859,802 183K/s eta(英国中部时40% [============================================================> ] 1,020,530 203K/s eta(英国中部时48% [=======================================================================> ] 1,217,458 227K/s eta(英国中部时56% [====================================================================================> ] 1,421,626 250K/s eta(英国中部时66% [==================================================================================================> ] 1,666,338 277K/s eta(英国中部时77% [==================================================================================================================> ] 1,929,874 303K/s eta(英国中部时88% [====================================================================================================================================> ] 2,222,370 332K/s eta(英国中部时100%[=====================================================================================================================================================>] 2,501,847 373K/s in 6.5s
    9. 2014-05-05 15:53:00 (373 KB/s) – 已保存 “nagios-plugins-2.0.tar.gz” [2501847/2501847])

[root@cache-2 ~]# tar -xvf nagios-plugins-2.0.tar.gz

[root@cache-2 ~]# cd nagios-plugins-2.0

[root@cache-2 ~]#./configure –with-nagios-user=nagios –with-nagios-group=nagios  –prefix=/usr/local/nagios –with-mysql

[root@cache-2 ~]# make && make install

5.8 安装配置apache和php
(1)安装apache
下载 wget http://archive.apache.org/dist/httpd/httpd-2.4.7.tar.gz

点击(此处)折叠或打开

  1. [root@cache-2 ~]# wget http://archive.apache.org/dist/httpd/httpd-2.4.7.tar.gz
  2. –2014-05-05 16:15:48– http://archive.apache.org/dist/httpd/httpd-2.4.7.tar.gz
  3. 正在解析主机 archive.apache.org… 192.87.106.229, 140.211.11.131, 2001:610:1:80bc:192:87:106:229
  4. 正在连接 archive.apache.org|192.87.106.229|:80… 已连接。
  5. 已发出 HTTP 请求,正在等待回应… 200 OK
  6. 长度:6747087 (6.4M) [application/x-gzip]
  7. 正在保存至: “httpd-2.4.7.tar.gz”
  8.  1% [=> ] 117,271 33.5K/s eta(英国中部时 2% [==> ] 144,857 36.2K/s eta(英国中部时 2% [===> ] 194,163 43.0K/s eta(英国中部时 3% [====> ] 265,189 52.9K/s eta(英国中部时 5% [======> ] 343,455 62.3K/s eta(英国中部时 6% [========> ] 442,449 73.4K/s eta(英国中部时 8% [===========> ] 560,877 85.8K/s eta(英国中部时10% [===============> ] 730,441 104K/s eta(英国中部时14% [====================> ] 947,789 125K/s eta(英国中部时18% [==========================> ] 1,230,297 152K/s eta(英国中部时23% [==================================> ] 1,602,729 185K/s eta(英国中部时30% [=============================================> ] 2,083,761 228K/s eta(英国中部时40% [===========================================================> ] 2,706,697 280K/s eta(英国中部时52% [=============================================================================> ] 3,512,081 346K/s eta(英国中部时67% [===================================================================================================> ] 4,537,561 445K/s eta(英国中部时87% [=================================================================================================================================> ] 5,872,913 575K/s eta(英国中部时96% [===============================================================================================================================================> ] 6,514,833 633K/s eta(英国中部时100%[=====================================================================================================================================================>] 6,747,087 655K/s in 11s
  9. 2014-05-05 16:16:01 (574 KB/s) – 已保存 “httpd-2.4.7.tar.gz” [6747087/6747087])

开始安装:
tar -xvf httpd-2.4.7.tar.gz
cd httpd-2.4.7
./configure –prefix=/usr/local/apache2
make && make install

点击(此处)折叠或打开

  1. [root@cache-2 ~]# tar -xvf httpd-2.4.7.tar.gz
  2. [root@cache-2 ~]# cd httpd-2.4.7
  3. [root@cache-2 httpd-2.4.7]# ./configure –prefix=/usr/local/apache2
  4. checking for chosen layout… Apache
  5. checking for working mkdir -p… yes
  6. checking for grep that handles long lines and -e… /bin/grep
  7. checking for egrep… /bin/grep -E
  8. checking build system type… x86_64-unknown-linux-gnu
  9. checking host system type… x86_64-unknown-linux-gnu
  10. checking target system type… x86_64-unknown-linux-gnu
  11. configure:
  12. configure: Configuring Apache Portable Runtime library…
  13. configure:
  14. checking for APR… no
  15. configure: error: APR not found. Please read the documentation.
  16. Google之后,发现可能是gcc版本太低了,可能是apache版本太高,换低点的2.2.23版本吧。
  17. wget http://archive.apache.org/dist/httpd/httpd-2.2.23.tar.gz
  18. tar -xvf httpd-2.2.23.tar.gz
  19. cd httpd-2.2.23
  20. ./configure –prefix=/usr/local/apache2
  21. make && make install

 

(2) 安装php版本

wget http://cn2.php.net/distributions/php-5.4.26.tar.gz

tar -xvf php-5.4.26.tar.gz

cd php-5.4.26

./configure –prefix=/usr/local/php –with-apxs2=/usr/local/apache2/bin/apxs

有报错信息:

Configuring extensions

checking size of long… (cached) 8

checking size of int… (cached) 4

checking for int32_t… yes

checking for uint32_t… yes

checking for sys/types.h… (cached) yes

checking for inttypes.h… (cached) yes

checking for stdint.h… (cached) yes

checking for string.h… (cached) yes

checking for stdlib.h… (cached) yes

checking for strtoll… yes

checking for atoll… yes

checking for strftime… (cached) yes

checking which regex library to use… php

checking whether to enable LIBXML support… yes

checking libxml2 install dir… no

checking for xml2-config path…

configure: error: xml2-config not found. Please check your libxml2 installation.

 

需要重新安装lib

yum install libxml2 –y

yum install libxml2-devel –y

 

之后继续make,成功了:

Make && make install

[activating module `php5′ in /usr/local/apache2/conf/httpd.conf]

Installing PHP CLI binary:        /usr/local/php/bin/

Installing PHP CLI man page:      /usr/local/php/php/man/man1/

Installing PHP CGI binary:        /usr/local/php/bin/

Installing PHP CGI man page:      /usr/local/php/php/man/man1/

Installing build environment:     /usr/local/php/lib/php/build/

Installing header files:          /usr/local/php/include/php/

Installing helper programs:       /usr/local/php/bin/

program: phpize

program: php-config

Installing man pages:             /usr/local/php/php/man/man1/

page: phpize.1

page: php-config.1

Installing PEAR environment:      /usr/local/php/lib/php/

[PEAR] Archive_Tar    – installed: 1.3.11

[PEAR] Console_Getopt – installed: 1.3.1

warning: pear/PEAR requires package “pear/Structures_Graph” (recommended version 1.0.4)

warning: pear/PEAR requires package “pear/XML_Util” (recommended version 1.2.1)

[PEAR] PEAR           – installed: 1.9.4

Wrote PEAR system config file at: /usr/local/php/etc/pear.conf

You may want to add: /usr/local/php/lib/php to your php.ini include_path

[PEAR] Structures_Graph- installed: 1.0.4

[PEAR] XML_Util       – installed: 1.2.1

/root/php/php-5.4.26/build/shtool install -c ext/phar/phar.phar /usr/local/php/bin

ln -s -f /usr/local/php/bin/phar.phar /usr/local/php/bin/phar

Installing PDO headers:          /usr/local/php/include/php/ext/pdo/

 

(3) 配置apache

Apache的配置文件在 /usr/local/apache2/conf/httpd.conf ,vim打开

User daemon

Group daemon

修改成:

User nagios

Group nagios

 

<IfModule dir_module>

DirectoryIndex index.html

</IfModule>

修改成:

<IfModule dir_module>

DirectoryIndex index.html index.php

AddType application/x-httpd-php .php

</IfModule>

 

为了安全起见:nagios的web监控页面需要经过授权才能访问,这需要增加验证配置,即在httpd.conf 文件最后添加如下信息:

#setting for nagios

ScriptAlias /nagios/cgi-bin “/usr/local/nagios/sbin”

<Directory “/usr/local/nagios/sbin”>

AuthType Basic

Options ExecCGI

AllowOverride None

Order allow,deny

Allow from all

AuthName “Nagios Access”

AuthUserFile /usr/local/nagios/etc/htpasswd  //用于此目录访问身份验证的文件

Require valid-user

</Directory>

Alias /nagios “/usr/local/nagios/share”

<Directory “/usr/local/nagios/share”>

AuthType Basic

Options None

AllowOverride None

Order allow,deny

Allow from all

AuthName “nagios Access”

AuthUserFile /usr/local/nagios/etc/htpasswd

Require valid-user

</Directory>

 

(4) 创建apache目录验证文件

在上面的配置中,指定了目录验证文件htpasswd,下面要创建这个文件:

/usr/local/apache2/bin/htpasswd -c /usr/local/nagios/etc/htpasswd david

[root@cache-2 php-5.4.26]#  /usr/local/apache2/bin/htpasswd -c /usr/local/nagios/etc/htpasswd david

New password:

Re-type new password:

Adding password for user david

查看认证文件的内容:

[root@cache-2 php-5.4.26]#  cat /usr/local/nagios/etc/htpasswd

david:$apr1$Pf9XIJjd$m5hR2vw70MlqwrChgN7zc/

[root@cache-2 php-5.4.26]#

 

启动apache服务:

/usr/local/apache2/bin/apachectl start

[root@cache-2 php-5.4.26]# /usr/local/apache2/bin/apachectl start

httpd: Could not reliably determine the server’s fully qualified domain name, using 10.254.3.41 for ServerName

(98)Address already in use: make_sock: could not bind to address [::]:80

(98)Address already in use: make_sock: could not bind to address 0.0.0.0:80

no listening sockets available, shutting down

Unable to open logs

修改ServerName以及Port

vi /usr/local/apache2/conf/httpd.conf

ServerName 改成 10.xx.3.x1

Listen 80 改成 Listen 81

http://10.xx.3.x1:81/nagios/,可以打开了,如下所示:

上一步骤: http://blog.csdn.net/mchdba/article/details/25654889

6 配置nagios

 

Nagios 主要用于监控一台或者多台本地主机及远程的各种信息,包括本机资源及对外的服务等。默认的Nagios 配置没有任何监控内容,仅是一些模板文件。若要让Nagios 提供服务,就必须修改配置文件,增加要监控的主机和服务,下面将详细介绍。

 

6.1 默认配置文件介绍

Nagios 安装完毕后,默认的配置文件在/usr/local/nagios/etc目录下。

[root@cache-2 etc]# cd /usr/local/nagios/etc

[root@cache-2 etc]# ls

cgi.cfg  htpasswd  nagios.cfg objects  resource.cfg

[root@cache-2 etc]#

[root@cache-2 etc]# cd objects

[root@cache-2 objects]# ls

commands.cfg contacts.cfg  localhost.cfg  printer.cfg switch.cfg  templates.cfg  timeperiods.cfg  windows.cfg

[root@cache-2 objects]#

 

每个文件或目录含义如下表所示:

文件名或目录名     用途

cgi.cfg      控制CGI访问的配置文件

nagios.cfg         Nagios 主配置文件

resource.cfg    变量定义文件,又称为资源文件,在些文件中定义变量,以便由其他配置文件引用,如$USER1$

objects     objects 是一个目录,在此目录下有很多配置文件模板,用于定义Nagios 对象

objects/commands.cfg    命令定义配置文件,其中定义的命令可以被其他配置文件引用

objects/contacts.cfg        定义联系人和联系人组的配置文件

objects/localhost.cfg       定义监控本地主机的配置文件

objects/printer.cfg  定义监控打印机的一个配置文件模板,默认没有启用此文件

objects/switch.cfg   定义监控路由器的一个配置文件模板,默认没有启用此文件

objects/templates.cfg     定义主机和服务的一个模板配置文件,可以在其他配置文件中引用

objects/timeperiods.cfg  定义Nagios 监控时间段的配置文件

objects/windows.cfg        监控Windows 主机的一个配置文件模板,默认没有启用此文件

 

 

6.2 配置文件之间的关系

 

在nagios的配置过程中涉及到的几个定义有:主机、主机组,服务、服务组,联系人、联系人组,监控时间,监控命令等,从这些定义可以看出,nagios各个配置文件之间是互为关联,彼此引用的。

 

成功配置出一台nagios监控系统,必须要弄清楚每个配置文件之间依赖与被依赖的关系,最重要的有四点:

 

第一:定义监控哪些主机、主机组、服务和服务组;

第二:定义这个监控要用什么命令实现;

第三:定义监控的时间段;

第四:定义主机或服务出现问题时要通知的联系人和联系人组。

 

6.3 配置Nagios

 为了能更清楚的说明问题,同时也为了维护方便,建议将nagios各个定义对象创建独立的配置文件:

·         创建hosts.cfg文件来定义主机和主机组

·         创建services.cfg文件来定义服务

·         用默认的contacts.cfg文件来定义联系人和联系人组

·         用默认的commands.cfg文件来定义命令

·         用默认的timeperiods.cfg来定义监控时间段

·         用默认的templates.cfg文件作为资源引用文件

 

 

a. timeperiods.cfg文件

define contact{
        name                            generic-contact    ; 联系人名称
        service_notification_period     24x7               ; 当服务出现异常时,发送通知的时间段,这个时间段"24x7"在timeperiods.cfg文件中定义
        host_notification_period        24x7               ; 当主机出现异常时,发送通知的时间段,这个时间段"24x7"在timeperiods.cfg文件中定义
        service_notification_options    w,u,c,r            ; 这个定义的是“通知可以被发出的情况”。w即warn,表示警告状态,u即unknown,表示不明状态;
                                                           ; c即criticle,表示紧急状态,r即recover,表示恢复状态;
                                                           ; 也就是在服务出现警告状态、未知状态、紧急状态和重新恢复状态时都发送通知给使用者。
        host_notification_options       d,u,r                   ; 定义主机在什么状态下需要发送通知给使用者,d即down,表示宕机状态;
                                                                ; u即unreachable,表示不可到达状态,r即recovery,表示重新恢复状态。
        service_notification_commands   notify-service-by-email ; 服务故障时,发送通知的方式,可以是邮件和短信,这里发送的方式是邮件;
                                                                ; 其中“notify-service-by-email”在commands.cfg文件中定义。
        host_notification_commands      notify-host-by-email    ; 主机故障时,发送通知的方式,可以是邮件和短信,这里发送的方式是邮件;
                                                                ; 其中“notify-host-by-email”在commands.cfg文件中定义。 
        register                        0                    ; DONT REGISTER THIS DEFINITION - ITS NOT A REAL CONTACT, JUST A TEMPLATE!
        }
define host{
        name                            generic-host    ; 主机名称,这里的主机名,并不是直接对应到真正机器的主机名;
                                                        ; 乃是对应到在主机配置文件里所设定的主机名。
        notifications_enabled           1               ; Host notifications are enabled
        event_handler_enabled           1               ; Host event handler is enabled
        flap_detection_enabled          1               ; Flap detection is enabled
        failure_prediction_enabled      1               ; Failure prediction is enabled
        process_perf_data               1               ; 其值可以为0或1,其作用为是否启用Nagios的数据输出功能;
                                                        ; 如果将此项赋值为1,那么Nagios就会将收集的数据写入某个文件中,以备提取。
        retain_status_information       1               ; Retain status information across program restarts
        retain_nonstatus_information    1               ; Retain non-status information across program restarts
        notification_period             24x7            ; 指定“发送通知”的时间段,也就是可以在什么时候发送通知给使用者。
        register                        0               ; DONT REGISTER THIS DEFINITION - ITS NOT A REAL HOST, JUST A TEMPLATE!
        }
define service{
        name                            generic-service         ; 定义一个服务名称
        active_checks_enabled           1                       ; Active service checks are enabled
        passive_checks_enabled          1                       ; Passive service checks are enabled/accepted
        parallelize_check               1                       ; Active service checks should be parallelized;
                                                                ; (disabling this can lead to major performance problems)
        obsess_over_service             1                       ; We should obsess over this service (if necessary)
        check_freshness                 0                       ; Default is to NOT check service 'freshness'
        notifications_enabled           1                       ; Service notifications are enabled
        event_handler_enabled           1                       ; Service event handler is enabled
        flap_detection_enabled          1                       ; Flap detection is enabled
        failure_prediction_enabled      1                       ; Failure prediction is enabled
        process_perf_data               1                       ; Process performance data
        retain_status_information       1                       ; Retain status information across program restarts
        retain_nonstatus_information    1                       ; Retain non-status information across program restarts
        is_volatile                     0                       ; The service is not volatile
        check_period                    24x7             ; 这里的check_period告诉nagios检查服务的时间段。
        max_check_attempts              3                ; nagios对服务的最大检查次数。
        normal_check_interval           5                ; 此选项是用来设置服务检查时间间隔,也就是说,nagios这一次检查和下一次检查之间所隔的时间;
                                                         ; 这里是5分钟。
        retry_check_interval            2                ; 重试检查时间间隔,单位是分钟。
        contact_groups                  ts           ; 指定联系人组
        notification_options            w,u,c,r          ; 这个定义的是“通知可以被发出的情况”。w即warn,表示警告状态;
                                                         ; u即unknown,表示不明状态;
                                                         ; c即criticle,表示紧急状态,r即recover,表示恢复状态;
                                                         ; 也就是在服务出现警告状态、未知状态、紧急状态和重新恢复后都发送通知给使用者。
        notification_interval           10               ; Re-notify about service problems every hour
        notification_period             24x7             ; 指定“发送通知”的时间段,也就是可以在什么时候发送通知给使用者。
        register                        0                ; DONT REGISTER THIS DEFINITION - ITS NOT A REAL SERVICE, JUST A TEMPLATE!
        }
define service{
        name                            local-service           ; The name of this service template
        use                             generic-service         ; Inherit default values from the generic-service definition
        max_check_attempts              4             ; Re-check the service up to 4 times in order to determine its final (hard) state
        normal_check_interval           5             ; Check the service every 5 minutes under normal conditions
        retry_check_interval            1             ; Re-check the service every minute until a hard state can be determined
        register                        0             ; DONT REGISTER THIS DEFINITION - ITS NOT A REAL SERVICE, JUST A TEMPLATE!
        }

 


b. resource.cfg文件

resource.cfg是nagios的变量定义文件,文件内容只有一行:

$USER1$=/usr/local/nagios/libexec

其中,变量$USER1$指定了安装nagios插件的路径,如果把插件安装在了其它路径,只需在这里进行修改即可。需要注意的是,变量必须先定义,然后才能在其它配置文件中进行引用。

c. commands.cfg文件

此文件默认是存在的,无需修改即可使用,当然如果有新的命令需要加入时,在此文件进行添加即可。

 

#notify-host-by-email命令的定义 
define command{
        command_name    notify-host-by-email             #命令名称,即定义了一个主机异常时发送邮件的命令。
        command_line    /usr/bin/printf "%b" "***** Nagios *****\n\nNotification Type: $NOTIFICATIONTYPE$\nHost: $HOSTNAME$\nState: $HOSTSTATE$\nAddress: $HOSTADDRESS$\nInfo: $HOSTOUTPUT$\n\nDate/Time: $LONGDATETIME$\n" | /bin/mail -s "** $NOTIFICATIONTYPE$ Host Alert: $HOSTNAME$ is $HOSTSTATE$ **" $CONTACTEMAIL$                                     #命令具体的执行方式。
        }
#notify-service-by-email命令的定义 
define command{
        command_name    notify-service-by-email          #命令名称,即定义了一个服务异常时发送邮件的命令
        command_line    /usr/bin/printf "%b" "***** Nagios *****\n\nNotification Type: $NOTIFICATIONTYPE$\n\nService: $SERVICEDESC$\nHost: $HOSTALIAS$\nAddress: $HOSTADDRESS$\nState: $SERVICESTATE$\n\nDate/Time: $LONGDATETIME$\n\nAdditional Info:\n\n$SERVICEOUTPUT$\n" | /bin/mail -s "** $NOTIFICATIONTYPE$ Service Alert: $HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$ **" $CONTACTEMAIL$
        }
define command{
        command_name    check_local_disk
        command_line    $USER1$/check_disk -w $ARG1$ -c $ARG2$ -p $ARG3$            #$ARG1$是指在调用这个命令的时候,命令后面的第一个参数。
        }
define command{
        command_name    check_local_load
        command_line    $USER1$/check_load -w $ARG1$ -c $ARG2$
        }
define command{
        command_name    check_local_procs
        command_line    $USER1$/check_procs -w $ARG1$ -c $ARG2$ -s $ARG3$
        }
define command{
        command_name    check_local_users
        command_line    $USER1$/check_users -w $ARG1$ -c $ARG2$
        }

 

d. hosts.cfg文件

此文件默认不存在,需要手动创建,hosts.cfg主要用来指定被监控的主机地址以及相关属性信息,根据实验目标配置如下:

define host{   
        use                     linux-server          #引用主机linux-server的属性信息,linux-server主机在templates.cfg文件中进行了定义。
        host_name               Nagios-Linux          #主机名
        alias                   Nagios-Linux          #主机别名
        address                 192.168.1.111         #被监控的主机地址,这个地址可以是ip,也可以是域名。
        }   
#定义一个主机组   
define hostgroup{      
        hostgroup_name          bsmart-servers        #主机组名称,可以随意指定。
        alias                   bsmart servers        #主机组别名
        members                 Nagios-Linux          #主机组成员,其中“Nagios-Linux”就是上面定义的主机。     
        }

注意:在/usr/local/nagios/etc/objects 下默认有localhost.cfg和windows.cfg 这两个配置文件,localhost.cfg 文件是定义监控主机本身的,windows.cfg文件是定义windows 主机的,其中包括了对host 和相关services 的定义。所以在本次实验中,将直接在localhost.cfg 中定义监控主机(Nagios-Server),在windows.cfg中定义windows 主机(Nagios-Windows)。根据自己的需要修改其中的相关配置,详细如下:

localhost.cfg

define host{
        use                     linux-server            ; Name of host template to use
                                                        ; This host definition will inherit all variables that are defined
                                                        ; in (or inherited by) the linux-server host template definition.
        host_name               Nagios-Server
        alias                   Nagios-Server
        address                 127.0.0.1
        }
define hostgroup{
        hostgroup_name  linux-servers ; The name of the hostgroup
        alias           Linux Servers ; Long name of the group
        members         Nagios-Server ; Comma separated list of hosts that belong to this group
        }
define service{
        use                             local-service         ; Name of service template to use
        host_name                       Nagios-Server
        service_description             PING
        check_command                   check_ping!100.0,20%!500.0,60%
        }
define service{
        use                             local-service         ; Name of service template to use
        host_name                       Nagios-Server
        service_description             Root Partition
        check_command                   check_local_disk!20%!10%!/
        }
define service{
        use                             local-service         ; Name of service template to use
        host_name                       Nagios-Server
        service_description             Current Users
        check_command                   check_local_users!20!50
        }
define service{
        use                             local-service         ; Name of service template to use
        host_name                       Nagios-Server
        service_description             Total Processes
        check_command                   check_local_procs!250!400!RSZDT
        }
define service{
        use                             local-service         ; Name of service template to use
        host_name                       Nagios-Server
        service_description             Current Load
        check_command                   check_local_load!5.0,4.0,3.0!10.0,6.0,4.0
        }
define service{
        use                             local-service         ; Name of service template to use
        host_name                       Nagios-Server
        service_description             Swap Usage
        check_command                   check_local_swap!20!10
        }
define service{
        use                             local-service         ; Name of service template to use
        host_name                       Nagios-Server
        service_description             SSH
        check_command                   check_ssh
        notifications_enabled           0
        }
define service{
        use                             local-service         ; Name of service template to use
        host_name                       Nagios-Server
        service_description             HTTP
        check_command                   check_http
        notifications_enabled           0
        }

 

e. services.cfg文件

此文件默认也不存在,需要手动创建,services.cfg文件主要用于定义监控的服务和主机资源,例如监控http服务、ftp服务、主机磁盘空间、主机系统负载等等。Nagios-Server和Nagios-Windows相关服务已在相应的配置文件中定义,所以这里只需要定义Nagios-Linux相关服务即可,这里只定义一个检测是否存活的服务来验证配置文件的正确性,其他服务的定义将在后面讲到。

define service{  
        use                     local-service          #引用local-service服务的属性值,local-service在templates.cfg文件中进行了定义。
        host_name               Nagios-Linux           #指定要监控哪个主机上的服务,“Nagios-Server”在hosts.cfg文件中进行了定义。
        service_description     check-host-alive       #对监控服务内容的描述,以供维护人员参考。
        check_command           check-host-alive       #指定检查的命令。
        }  

 

f. contacts.cfg文件

contacts.cfg是一个定义联系人和联系人组的配置文件,当监控的主机或者服务出现故障,nagios会通过指定的通知方式(邮件或者短信)将信息发给这里指定的联系人或者使用者。

define contact{
        contact_name                    David             #联系人的名称,这个地方不要有空格
        use                             generic-contact   #引用generic-contact的属性信息,其中“generic-contact”在templates.cfg文件中进行定义
        alias                           Nagios Admin
        email                           david.tang@bsmart.cn
        }
define contactgroup{
        contactgroup_name       ts                              #联系人组的名称,同样不能空格
        alias                   Technical Support               #联系人组描述
        members                 David                           #联系人组成员,其中“david”就是上面定义的联系人,如果有多个联系人则以逗号相隔
        }

 

g. timeperiods.cfg文件

此文件只要用于定义监控的时间段,下面是一个配置好的实例:

#下面是定义一个名为24x7的时间段,即监控所有时间段  
define timeperiod{  
        timeperiod_name 24x7       #时间段的名称,这个地方不要有空格
        alias           24 Hours A Day, 7 Days A Week  
        sunday          00:00-24:00  
        monday          00:00-24:00  
        tuesday         00:00-24:00  
        wednesday       00:00-24:00  
        thursday        00:00-24:00  
        friday          00:00-24:00  
        saturday        00:00-24:00  
        }  
#下面是定义一个名为workhours的时间段,即工作时间段。  
define timeperiod{  
        timeperiod_name workhours   
        alias           Normal Work Hours  
        monday          09:00-17:00  
        tuesday         09:00-17:00  
        wednesday       09:00-17:00  
        thursday        09:00-17:00  
        friday          09:00-17:00  
        }  

 

h. cgi.cfg文件

此文件用来控制相关cgi脚本,如果想在nagios的web监控界面执行cgi脚本,例如重启nagios进程、关闭nagios通知、停止nagios主机检测等,这时就需要配置cgi.cfg文件了。
由于nagios的web监控界面验证用户为david,所以只需在cgi.cfg文件中添加此用户的执行权限就可以了,需要修改的配置信息如下:

default_user_name=david
authorized_for_system_information=nagiosadmin,david  
authorized_for_configuration_information=nagiosadmin,david  
authorized_for_system_commands=david
authorized_for_all_services=nagiosadmin,david  
authorized_for_all_hosts=nagiosadmin,david
authorized_for_all_service_commands=nagiosadmin,david  
authorized_for_all_host_commands=nagiosadmin,david 

 

i. nagios.cfg文件

nagios.cfg默认的路径为/usr/local/nagios/etc/nagios.cfg,是nagios的核心配置文件,所有的对象配置文件都必须在这个文件中进行定义才能发挥其作用,这里只需将对象配置文件在Nagios.cfg文件中进行引用即可。

log_file=/usr/local/nagios/var/nagios.log                  # 定义nagios日志文件的路径
cfg_file=/usr/local/nagios/etc/objects/commands.cfg        # “cfg_file”变量用来引用对象配置文件,如果有更多的对象配置文件,在这里依次添加即可。
cfg_file=/usr/local/nagios/etc/objects/contacts.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/timeperiods.cfg
cfg_file=/usr/local/nagios/etc/objects/templates.cfg
cfg_file=/usr/local/nagios/etc/objects/localhost.cfg       # 本机配置文件
cfg_file=/usr/local/nagios/etc/objects/windows.cfg         # windows 主机配置文件
object_cache_file=/usr/local/nagios/var/objects.cache      # 该变量用于指定一个“所有对象配置文件”的副本文件,或者叫对象缓冲文件
precached_object_file=/usr/local/nagios/var/objects.precache
resource_file=/usr/local/nagios/etc/resource.cfg           # 该变量用于指定nagios资源文件的路径,可以在nagios.cfg中定义多个资源文件。
status_file=/usr/local/nagios/var/status.dat               # 该变量用于定义一个状态文件,此文件用于保存nagios的当前状态、注释和宕机信息等。
status_update_interval=10                                  # 该变量用于定义状态文件(即status.dat)的更新时间间隔,单位是秒,最小更新间隔是1秒。
nagios_user=nagios                                         # 该变量指定了Nagios进程使用哪个用户运行。
nagios_group=nagios                                        # 该变量用于指定Nagios使用哪个用户组运行。
check_external_commands=1                                  # 该变量用于设置是否允许nagios在web监控界面运行cgi命令;
                                                           # 也就是是否允许nagios在web界面下执行重启nagios、停止主机/服务检查等操作;
                                                           # “1”为运行,“0”为不允许。
command_check_interval=10s                                 # 该变量用于设置nagios对外部命令检测的时间间隔,如果指定了一个数字加一个"s"(如10s);
                                                           # 那么外部检测命令的间隔是这个数值以秒为单位的时间间隔;
                                                           # 如果没有用"s",那么外部检测命令的间隔是以这个数值的“时间单位”的时间间隔。
interval_length=60                                         # 该变量指定了nagios的时间单位,默认值是60秒,也就是1分钟;
                                                           # 即在nagios配置中所有的时间单位都是分钟。

 

6.4 验证Nagios配置文件的正确性

Nagios 在验证配置文件方面做的非常到位,只需通过一个命令即可完成:

# /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg

 

[root@cache-2 etc]# /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg

Nagios Core 4.0.6
Copyright (c) 2009-present Nagios Core Development Team and Community Contributors
Copyright (c) 1999-2009 Ethan Galstad
Last Modified: 04-29-2014
License: GPL

Website: http://www.nagios.org
Reading configuration data...
   Read main config file okay...
   Read object config files okay...

Running pre-flight check on configuration data...

Checking objects...
	Checked 29 services.
	Checked 4 hosts.
	Checked 2 host groups.
	Checked 0 service groups.
	Checked 4 contacts.
	Checked 2 contact groups.
	Checked 26 commands.
	Checked 5 time periods.
	Checked 0 host escalations.
	Checked 0 service escalations.
Checking for circular paths...
	Checked 4 hosts
	Checked 0 service dependencies
	Checked 0 host dependencies
	Checked 5 timeperiods
Checking global event handlers...
Checking obsessive compulsive processor commands...
Checking misc settings...

Total Warnings: 0
Total Errors:   0

Things look okay - No serious problems were detected during the pre-flight check
[root@cache-2 etc]#

 

Nagios提供的这个验证功能非常有用,在错误信息中通常会打印出错误的配置文件以及文件中的哪一行,这使得nagios的配置变得非常容易,报警信息通常是可以忽略的,因为一般那些只是建议性的。

看到上面这些信息就说明没问题了,然后启动Nagios 服务。

 

发表评论

电子邮件地址不会被公开。