營運監控利器Nagios之:安裝nagios

來源:互聯網
上載者:User

標籤:nagios 營運監控   安裝nagios   

一、安裝前準備

(1)建立nagios使用者和使用者組
[[email protected] ~]#useradd -s /sbin/nologin nagios
[[email protected] ~]#mkdir /usr/local/nagios
[[email protected] ~]#chown –R  nagios.nagios /usr/local/nagios
(2)開啟系統sendmail服務
 在nagios監控伺服器上開啟sendmail服務的主要作用是讓nagios在檢測到故障時可以發送警示郵件,目前幾乎所有的linux發行版本都預設內建了sendmail服務,所以,在安裝系統時只需開啟sendmail服務即可,並且不需要在sendmail上做任何配置。

二、 編譯安裝Nagios
[[email protected] ~]# tar -zxvf nagios-3.2.0.tar.gz
[[email protected] ~]# cd nagios-3.2.0
[[email protected] nagios-3.2.0]#./configure --prefix=/usr/local/nagios  
#指定nagios的安裝目錄,這裡指定nagios安裝到/usr/local/nagios目錄
[[email protected] nagios-3.2.0]#make all  
[[email protected] nagios-3.2.0]#make install       
# make install用來安裝nagios的主程式,CGI和HTML檔案
[[email protected] nagios-3.2.0]# make install-init   
#通過make install-init命令可以在/etc/rc.d/init.d目錄下建立nagios啟動指令碼
[[email protected] nagios-3.2.0]# make install-commandmode  
#通過make install-commandmode命令來配置目錄許可權
[[email protected] nagios-3.2.0]# make install-config   
#make install-cofig命令用來安裝nagios樣本設定檔,這裡安裝的路徑是/usr/local/nagios/etc

3、Nagios目錄介紹

Nagios安裝完成後,各個目錄結構以及功能說明如下表所示:營運監控利器Nagios之:安裝nagios


4、  安裝Nagios外掛程式

 這裡下載的版本是nagios-plugins-1.4.14。
 注意:外掛程式版本與nagios版本的關聯並不大。
[[email protected] nagios]#tar –zxvf  nagios-plugins-1.4.14.tar.gz
[[email protected] nagios]#cd  nagios-plugins-1.4.14
[[email protected] nagios-plugins-1.4.14]#./configure --prefix=/usr/local/nagios
[[email protected] nagios-plugins-1.4.14]# make 
[[email protected] nagios-plugins-1.4.14]# make install
 安裝完成,在/usr/local/nagios下的libexec目錄下,產生很多可執行檔,這些正是nagios所需要的外掛程式。

5、安裝Nagios中文化外掛程式
 中文外掛程式:
   http://sourceforge.net/projects/nagios-cn/files/
下載對應nagios版本的中文外掛程式,然後開始安裝:
[[email protected] ~]#tar xvfz nagios-cn-3.2.0.tar.bz2
[[email protected] nagios-cn-3.2.0]#cd nagios-cn-3.2.0
[[email protected] nagios-cn-3.2.0]#./configure
[[email protected] nagios-cn-3.2.0]#make all
[[email protected] nagios-cn-3.2.0]#make install


6、安裝與配置apache和php
 apache和php不是安裝nagios所必須的,但是nagios提供了web監控介面,通過web監控介面可以清晰的看到被監控主機、資源的運行狀態,因此,安裝一個web服務是很必要的。
 需要注意的是,nagios在nagios3.1.x版本以後,配置web監控介面時需要php的支援。這裡我們下載的nagios版本為nagios-3.2.0,因此在編譯安裝完成apache後,還需要編譯php模組,這裡選取的php版本為php5.3.2。
(1)安裝apache與php
首先安裝apache,步驟如下:
[[email protected] ~]# tar zxvf httpd-2.0.63.tar.gz
[[email protected] ~]#cd httpd-2.0.63
[[email protected] ~]#./configure  --prefix=/usr/local/apache2
[[email protected] ~]#make
[[email protected] ~]#make install
接著安裝php,步驟如下:
[[email protected] ~]# tar zxvf php-5.3.2.tar.gz
[[email protected] ~]#cd php-5.3.2
[[email protected] ~]#./configure  --prefix=/usr/local/php \
>--with-apxs2=/usr/local/apache2/bin/apxs
[[email protected] ~]#make
[[email protected] ~]#make install
從安裝步驟可知,apache安裝路徑為/usr/local/apache2,而php安裝路徑為/usr/local/php。

(2)配置apache
找到apache設定檔/usr/local/apache2/conf/httpd.conf 
找到:
User nobody
Group #-1
修改為
User nagios
Group nagios
然後找到
DirectoryIndex index.html index.html.var
修改為
DirectoryIndex index.html index.php
接著增加如下內容:
AddType application/x-httpd-php .php

為了安全其間,一般情況下要讓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>

(3)建立apache目錄驗證檔案
  在上面的配置中,指定了目錄驗證檔案htpasswd,下面要建立這個檔案:
 [[email protected] nagios]#/usr/local/apache2/bin/htpasswd \
>-c /usr/local/nagios/etc/htpasswd ixdba     
 New password: (輸入密碼)     
 Re-type new password: (再輸入一次密碼)     
 Adding password for user ixdba
 這樣就在/usr/local/nagios/etc目錄下建立了一個htpasswd驗證檔案,當通過http://ip/nagios/訪問時就需要輸入使用者名稱和密碼了。
 最後,啟動服務: 
 [[email protected] nagiosserver ~]#/usr/local/apache2/bin/apachectl  start

營運監控利器Nagios之:安裝nagios

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.