監控利器nagios的詳細安裝文檔

1. 編譯nagios corephp

添加用戶和組: nagios
也可使用其餘用戶來運行nagios, 非nagios用戶須要在configure時設置參數
[root@localhost ~]# useradd nagios
[root@localhost ~]# passwd nagios
Changing password for user nagios.
New UNIX password:
BAD PASSWORD: it is too simplistic/systematic
Retype new UNIX password:
passwd: all authentication tokens updated successfully.
下載nagios源碼包
[root@localhost ~]# su - nagios
[nagios@localhost ~]$ mkdir downloads
[nagios@localhost ~]$ cd downloads/
[nagios@localhost downloads]$ wget 'http://prdownloads.sourceforge.net/sourceforge/nagios/nagios-3.4.1.tar.gz'
[nagios@localhost downloads]$ cd
[nagios@localhost ~]$ mkdir build
[nagios@localhost ~]$ cd build/
[nagios@localhost build]$ tar -zxvf ../downloads/nagios-3.4.1.tar.gz
configure以前,先安裝系統中的庫文件
將安裝盤放入光驅後,使用mount命令掛載,而後使用rpm命令安裝庫文件
[root@localhost ~]# mount /dev/cdrom /mnt/
mount: block device /dev/cdrom is write-protected, mounting read-only
[root@localhost ~]# cd /mnt/Server/
[root@localhost Server]# rpm -ivh gd-devel-2.0.33-9.4.el5_1.1.i386.rpm fontconfig-devel-2.4.1-7.el5.i386.rpm freetype-devel-2.2.1-21.el5_3.i386.rpm libX11-devel-1.0.3-11.el5.i386.rpm libXpm-devel-3.5.5-3.i386.rpm gd-2.0.33-9.4.el5_1.1.i386.rpm libjpeg-devel-6b-37.i386.rpm libpng-devel-1.2.10-7.1.el5_3.2.i386.rpm libXau-devel-1.0.1-3.1.i386.rpm libXdmcp-devel-1.0.1-2.1.i386.rpm xorg-x11-proto-devel-7.1-13.el5.i386.rpm mesa-libGL-devel-6.5.1-7.7.el5.i386.rpm
[root@localhost Server]# sudo rpm -ivh apr-devel-1.2.7-11.el5_3.1.i386.rpm
[root@localhost Server]# rpm -ivh apr-util-devel-1.2.7-7.el5_3.2.i386.rpm apr-1.2.7-11.el5_3.1.i386.rpm pcre-devel-6.6-2.el5_1.7.i386.rpm
完成後,開始configure nagios
咱們將nagios安裝在/home/nagios/nagios目錄下
[nagios@localhost build]$ cd nagios/
[nagios@localhost nagios]$ ./configure --prefix=/home/nagios/nagios
*** Configuration summary for nagios 3.4.1 05-11-2012 ***:
General Options:
-------------------------
       Nagios executable:  nagios
       Nagios user/group:  nagios,nagios
      Command user/group:  nagios,nagios
           Embedded Perl:  no
            Event Broker:  yes
       Install ${prefix}:  /home/nagios/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
Review the options above for accuracy.  If they look okay,
type 'make all' to compile the main program and CGIs.
編譯之後能夠看到以上信息,說明配置正確,咱們開始make 和 make install
[nagios@localhost nagios]$ make all
[nagios@localhost nagios]$ make install
[root@localhost nagios]# make install-init
   #經過make install-init 命令能夠再/etc/rc.d/init.d目錄下建立Nagios啓動腳本,須要root用戶
[nagios@localhost nagios]$ make install-commandmode
   #經過make install-commandmode命令來配置目錄權限
[nagios@localhost nagios]$ make install-config
   #make install-config命令用來安裝Nagios示例配置文件,這裏的安裝路徑是/home/nagios/nagios/etc
  #設置開機啓動,需root用戶
[root@localhost ~]# chkconfig --add nagios
[root@localhost ~]# chkconfig --level 35 nagios on
[root@localhost ~]# chkconfig --list nagios
nagios          0:off   1:off   2:off   3:on    4:on    5:on    6:off
2. 編譯nagios 插件
[nagios@localhost build]$ tar -zxvf ../downloads/nagios-plugins-1.4.16.tar.gz
[nagios@localhost nagios-plugins-1.4.16]$ ./configure --prefix=/home/nagios/nagios/
[nagios@localhost nagios-plugins-1.4.16]$ make
[nagios@localhost nagios-plugins-1.4.16]$ make install
3. 安裝和配置apache、PHP
安裝apr和apr-util、pcre

[nagios@localhost downloads]$ wget http://mirrors.tuna.tsinghua.edu.cn/apache//apr/apr-1.4.6.tar.gzhtml

[nagios@localhost build]$ tar -zxvf ../downloads/apr-1.4.6.tar.gz linux

[nagios@localhost build]$ cd apr-1.4.6/
[nagios@localhost apr-1.4.6]$ ./configure --prefix=/home/nagios/apr
[nagios@localhost apr-1.4.6]$ make
[nagios@localhost apr-1.4.6]$ make install
[nagios@localhost downloads]$ cd ../build/
[nagios@localhost build]$ tar -zxvf ../downloads/apr-util-1.5.1.tar.gz
[nagios@localhost apr-util-1.5.1]$ ./configure --prefix=/home/nagios/apr-util --with-apr=/home/nagios/apr/
[nagios@localhost apr-util-1.5.1]$ make
[nagios@localhost apr-util-1.5.1]$ make  install
[nagios@localhost downloads]$ cd ../build/
[nagios@localhost build]$ tar -zxvf ../downloads/pcre-8.31.tar.gz
[nagios@localhost pcre-8.31]$ ./configure --prefix=/home/nagios/pcre
[nagios@localhost pcre-8.31]$ make
[nagios@localhost pcre-8.31]$ make install
如今就已經安裝好apr和apr-util、pcre了,再來編譯下apache
[nagios@localhost build]$ tar -zxvf ../downloads/httpd-2.4.3.tar.gz
[nagios@localhost build]$ cd httpd-2.4.3/

[nagios@localhost httpd-2.4.3]$ ./configure --prefix=/home/nagios/apache2 --with-apr=/home/nagios/apr --with-apr-util=/home/nagios/apr-util/ --with-pcre=/home/nagios/pcre/ios

[nagios@localhost httpd-2.4.3]$ make
[nagios@localhost httpd-2.4.3]$ make install
如今安裝PHP
[nagios@localhost build]$ tar -zxvf ../downloads/php-5.4.7.tar.gz
[nagios@localhost build]$ cd php-5.4.7/
[nagios@localhost php-5.4.7]$ ./configure --prefix=/home/nagios/php --with-apxs2=/home/nagios/apache2/bin/apxs
[nagios@localhost php-5.4.7]$ make -j  10
[nagios@localhost php-5.4.7]$ make test  
[nagios@localhost php-5.4.7]$ make install
配置apache:
首先在Apache配置文件/home/nagios/apache2/conf/httpd.conf中修改Apache進程的啓動用戶爲nagios,即找到:
User daemon
Group daemon
修改成:
User nagios
Group nagios
而後找到:
   DirectoryIndex index.html
修改成:
   DirectoryIndex index.html index.php
再找到:
Listen 80
修改爲:
Listen 8080
接着增長:
   AddType application/x-httpd-php .php
安全起見,通常要求必須通過受權才能訪問Nagios的web監控界面,所以須要增長驗證配置,即在httpd.conf文件的最後添加以下信息:
#setting for nagios
ScriptAlias /nagios/cgi-bin "/home/nagios/nagios/sbin/"
<Directory "/home/nagios/nagios/sbin">
   AuthType Basic
   Options ExecCGI
   AllowOverride None
   Order allow,deny
   Allow from all
   AuthName "Nagios Access"
   AuthUserFile /home/nagios/nagios/etc/htpasswd
   Require valid-user
</Directory>
Alias /nagios "/home/nagios/nagios/share"
<Directory "/home/nagios/nagios/share">
   AuthType Basic
   Options None
   AllowOverride None
   Order allow,deny
   Allow from all
   AuthName "nagios Access"
   AuthUserFile /home/nagios/nagios/etc/htpasswd
   Require valid-user
</Directory>
建立Apache目錄驗證文件
在上面的配置中,制定了目錄驗證文件htpasswd,下面建立這樣一個文件:
[nagios@localhost ~]$ /home/nagios/apache2/bin/htpasswd -c /home/nagios/nagios/etc/htpasswd nagiosadmin
這樣就在/home/nagios/nagios/etc目錄下建立了一個htpasswd驗證文件,對於的用戶名爲nagiosadmin。當經過http://ip:8080/nagios訪問web監控界面是就須要輸入用戶名和密碼了。
啓動Apache服務:
[nagios@localhost ~]$ /home/nagios/apache2/bin/apachectl start
而後用netstat -nltp命令查看對應的程序端口起來了沒有。
注意:
若是在nagios頁面下沒法解析CGI文件,那就在/home/nagios/nagios/conf/httpd.conf文件中將LoadModule cgid_module modules/mod_cgid.so這行的#去掉。而後重啓一下apache就能夠看到主機的狀態了。
相關文章
相關標籤/搜索