1. 1.安装所需环境
  2. LAMP或者LNMP 
  3. nagios-3.3.1.tar.gz-------------主程序
  4. nagios-plugins-1.4.15.tar.gz----插件
  5. 2.安装nagios-3.3.1.tar.gz
  6. 添加、修改用户以及组
  7. [root@localhost nagios]# useradd nagios
  8. [root@localhost nagios]# useradd apache
  9. [root@localhost nagios]# passwd nagios
  10. [root@localhost nagios]# groupadd nagcmd //创建用户组用于Web接口执行外部命令
  11. [root@localhost nagios]# usermod -g nagcmd nagios
  12. [root@localhost nagios]# usermod -g nagcmd apache
  13. [root@localhost monitor]# tar zxvf nagios-3.3.1.tar.gz -C /usr/local/src/
  14. [root@localhost monitor]# tar zxvf nagios-plugins-1.4.15.tar.gz -C /usr/local/src/
  15. [root@localhost monitor]# cd /usr/local/src/nagios
  16. [root@localhost nagios]# ./configure --prefix=/usr/local/nagios --with-nagios-user=nagios
  17. --with-nagios-group=nagios --with-command-group=nagcmd --with-gd-lib=/usr/lib/ --with-gd-inc=/usr/include/
  18. 配置成功后会有如下提示:
  19. *** Configuration summary for nagios 3.3.1 07-25-2011 ***:
  20.  
  21. General Options:
    ------------------------- Nagios executable: nagios
    Nagios user/group: nagios,nagios
    Command user/group: nagios,nagcmd
    Embedded Perl: no
    Event Broker: yes
    Install ${prefix}: /usr/local/nagios
    Lock file: ${prefix}/var/nagios.lock
    Check result directory: ${prefix}/var/spool/checkresults
    Init directory: /etc/rc.d/init.d
    Apache conf.d directory: /etc/httpd/conf.d
    Mail program: /bin/mail
    Host OS: linux-gnu
    Web Interface Options:
    ------------------------
    HTML URL: http://localhost/nagios/
    CGI URL: http://localhost/nagios/cgi-bin/
    Traceroute (used by WAP): /bin/traceroute
  22. [root@localhost nagios]# make all
  23. [root@localhost nagios]# make install
  24. [root@localhost nagios]# make install-init
  25. [root@localhost nagios]# make install-config
  26. [root@localhost nagios]# make install-commandmode
  27. [root@localhost nagios]# vi /usr/local/nagios/etc/objects/contacts.cfg
    修改email地址以接收报警内容
  28. [root@localhost nagios]# make install-webconf
  29. /usr/bin/install -c -m 644 sample-config/httpd.conf /etc/httpd/conf.d/nagios.conf
  30. /usr/bin/install: 无法创建普通文件"/etc/httpd/conf.d/nagios.conf": 没有那个文件或目录
  31. make: *** [install-webconf] 错误 1
  32. [root@localhost nagios]# mkdir -p /etc/httpd/conf.d/
  33. [root@localhost nagios]# /usr/local/webserver/apache/bin/htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin
  34. 3.安装nagios插件
  35. [root@localhost nagios]# cd ../nagios-plugins-1.4.15/
  36. [root@localhost nagios-plugins-1.4.15]# ./configure --with-nagios-user=nagios --with-nagios-group=nagios
  37. 配置成功后有如下提示:
  38. --with-apt-get-command:
  39. --with-ping6-command: /bin/ping6 -n -U -w %d -c %d %s
  40. --with-ping-command: /bin/ping -n -U -w %d -c %d %s
  41. --with-ipv6: yes
  42. --with-mysql: /usr/bin/mysql_config
  43. --with-openssl: yes
  44. --with-gnutls: no
  45. --enable-extra-opts: no
  46. --with-perl: /usr/bin/perl
  47. --enable-perl-modules: no
  48. --with-cgiurl: /nagios/cgi-bin
  49. --with-trusted-path: /bin:/sbin:/usr/bin:/usr/sbin
  50. --enable-libtap: no
  51. [root@bogon nagios-plugins-1.4.15]# make
    [root@bogon nagios-plugins-1.4.15]# make install
  52. 验证Nagios配置文件
  53. [root@bogon nagios]# /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
    启动Nagios服务
    [root@bogon nagios]# service nagios start
    4.编辑apache的httpd.conf
  54. 在最后添加:
    ScriptAlias /nagios/cgi-bin "/usr/local/nagios/sbin"
  55. <Directory "/usr/local/nagios/sbin">
  56. # SSLRequireSSL
  57. Options ExecCGI
  58. AllowOverride None
  59. Order allow,deny
  60. Allow from all
  61. # Order deny,allow
  62. # Deny from all
  63. # Allow from 127.0.0.1
  64. AuthName "Nagios Access"
  65. AuthType Basic
  66. AuthUserFile /usr/local/nagios/etc/htpasswd.users
  67. Require valid-user
  68. </Directory>
  69. Alias /nagios "/usr/local/nagios/share"
  70. <Directory "/usr/local/nagios/share">
  71. # SSLRequireSSL
  72. Options None
  73. AllowOverride None
  74. Order allow,deny
  75. Allow from all
  76. # Order deny,allow
  77. # Deny from all
  78. # Allow from 127.0.0.1
  79. AuthName "Nagios Access"
  80. AuthType Basic
  81. AuthUserFile /usr/local/nagios/etc/htpasswd.users
  82. Require valid-user
  83. </Directory>
  84. 5.再验证下
  85. [root@bogon nagios]# /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
    没有出错的话,重新启动nagios和apache
  86. 6.登录web页面
  87. http://localehost/nagios
  88. 输入刚才设置的用户名密码。
  89.