如下: 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
[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/confchecking for a BSD-compatible install... /usr/bin/install -cchecking build system type... x86_64-unknown-linux-gnuchecking host system type... x86_64-unknown-linux-gnuchecking for gcc... gccchecking for C compiler default output file name... a.outchecking whether the C compiler works... yeschecking whether we are cross compiling... no............................. HTML URL: http://localhost/nagios/ CGI URL: http://localhost/nagios/cgi-bin/ Traceroute (used by WAP): /bin/tracerouteReview the options above for accuracy. If they look okay,type 'make all' to compile the main program and CGIs.
5 開始make安裝
5.1 make all
[root@cache-2 nagios-4.0.6]# make all
cd ./base && makemake[1]: Entering directory `/root/nagios-4.0.6/base'gcc -Wall -I.. -g -O2 -DHAVE_CONFIG_H -DNSCORE -c -o nagios.o nagios.cgcc -Wall -I.. -g -O2 -DHAVE_CONFIG_H -DNSCORE -c -o broker.o broker.cgcc -Wall -I.. -g -O2 -DHAVE_CONFIG_H -DNSCORE -c -o nebmods.o nebmods.........................For more information on obtaining support for Nagios, visit: http://support.nagios.com*************************************************************Enjoy.
5.2 make install
[root@cache-2 nagios-4.0.6]# make install
cd ./base && make installmake[1]: Entering directory `/root/nagios-4.0.6/base'make install-basicmake[2]: Entering directory `/root/nagios-4.0.6/base'.....................................................make[2]: Entering directory `/root/nagios-4.0.6/cgi'for file in *.cgi; do \/usr/bin/strip /usr/local/nagios/sbin/$file; \done
5.3 make install-config
[root@cache-2 nagios-4.0.6]# make install-config/usr/bin/install -c -m 775 -o nagios -g nagios -d /usr/local/nagios/etc/usr/bin/install -c -m 775 -o nagios -g nagios -d /usr/local/nagios/etc/objects/usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/nagios.cfg /usr/local/nagios/etc/nagios.cfg..................................................../usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/template-object/printer.cfg /usr/local/nagios/etc/objects/printer.cfg/usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/template-object/switch.cfg /usr/local/nagios/etc/objects/switch.cfg*** Config files installed ***
5.4 make install-commandmode
[root@cache-2 nagios-4.0.6]# make install-commandmode/usr/bin/install -c -m 775 -o nagios -g nagios -d /usr/local/nagios/var/rwchmod g+s /usr/local/nagios/var/rw*** External command directory configured ***Remember, these are *SAMPLE* config files. You'll need to readthe documentation for more information on how to actually defineservices, hosts, etc. to fit your particular needs.
5.5 make install-init
[root@cache-2 nagios-4.0.6]# make install-init/usr/bin/install -c -m 755 -d -o root -g root /etc/rc.d/init.d/usr/bin/install -c -m 755 -o root -g root daemon-init /etc/rc.d/init.d/nagios*** 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
[root@cache-2 nagios-4.0.6]# cd /usr/local/nagios[root@cache-2 nagios]# ll總用量 24drwxrwxr-x. 2 nagios nagios 4096 5月 5 15:31 bindrwxrwxr-x. 3 nagios nagios 4096 5月 5 15:32 etcdrwxrwxr-x. 2 nagios nagios 4096 5月 5 15:31 libexecdrwxrwxr-x. 2 nagios nagios 4096 5月 5 15:31 sbindrwxrwxr-x. 10 nagios nagios 4096 5月 5 15:31 sharedrwxrwxr-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
[root@cache-2 ~]# wget http://nagios-plugins.org/download/nagios-plugins-2.0.tar.gz--2014-05-05 15:52:52-- http://nagios-plugins.org/download/nagios-plugins-2.0.tar.gz正在解析主機 nagios-plugins.org... 72.14.186.43正在串連 nagios-plugins.org|72.14.186.43|:80... 已串連。已發出 HTTP 要求,正在等待回應... 200 OK............................................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
[root@cache-2 ~]# wget http://archive.apache.org/dist/httpd/httpd-2.4.7.tar.gz--2014-05-05 16:15:48-- http://archive.apache.org/dist/httpd/httpd-2.4.7.tar.gz正在解析主機 archive.apache.org... 192.87.106.229, 140.211.11.131, 2001:610:1:80bc:192:87:106:229正在串連 archive.apache.org|192.87.106.229|:80... 已串連。已發出 HTTP 要求,正在等待回應... 200 OK長度:6747087 (6.4M) [application/x-gzip]正在儲存至: “httpd-2.4.7.tar.gz” 1% [=> ..............................................................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
[root@cache-2 ~]# tar -xvf httpd-2.4.7.tar.gz[root@cache-2 ~]# cd httpd-2.4.7[root@cache-2 httpd-2.4.7]# ./configure --prefix=/usr/local/apache2checking for chosen layout... Apachechecking for working mkdir -p... yeschecking for grep that handles long lines and -e... /bin/grepchecking for egrep... /bin/grep -Echecking build system type... x86_64-unknown-linux-gnuchecking host system type... x86_64-unknown-linux-gnuchecking target system type... x86_64-unknown-linux-gnuconfigure: configure: Configuring Apache Portable Runtime library...configure: checking for APR... noconfigure: error: APR not found. Please read the documentation.Google之後,發現可能是gcc版本太低了,可能是apache版本太高,換低點的2.2.23版本吧。wget http://archive.apache.org/dist/httpd/httpd-2.2.23.tar.gztar -xvf httpd-2.2.23.tar.gzcd httpd-2.2.23./configure --prefix=/usr/local/apache2make && 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/,可以開啟了,如下所示: