最近由於,科研須要,接觸上了Nagios,這裏,我將安裝筆記作個詳解。爲本身後續須要和博友們學習!php
前期博客,你們自行去看,能進入搜索來安裝Nagios的博友們,相信已經有必定基礎了。html
我這裏是,先在虛擬機裏安裝了兩臺CentOS6.5,而後,配置了靜態ip和連網。這裏很簡單,很少贅述。linux
我這裏,本身新建過nagios的用戶和用戶組。ios
好比拿nagios2這臺機器而言。web
[root@nagios2 ~]# groupadd nagios [root@nagios2 ~]# useradd -m -g nagios nagios [root@nagios2 ~]# passwd nagios Changing password for user nagios. New password: (個人密碼是nagios) BAD PASSWORD: it is based on a dictionary word Retype new password: (個人密碼是nagios) passwd: all authentication tokens updated successfully.
1.進行環境安裝apache
#yuminstall -y gcc glibcglibc-common gd gd-devel xinetd openssl-devel httpd php
2.進行selinux設置vim
SELINUX=disabled
3.創建用戶和用戶組瀏覽器
新建用戶nagios和用戶組nagios,並修改/usr/local/nagios是所屬組和所屬用戶。
[root@nagios1 nagios]# pwd /home/nagios [root@nagios1 nagios]# useradd -s /sbin/nologin nagios
[root@nagios1 nagios]# mkdir /usr/local/nagios
[root@nagios1 nagios]# chown -R nagios:nagios /usr/local/nagios
並將nagios以及apache用戶加入到nagcmd組中,確保nagios和apache有權限。
[root@nagios1 nagios]# groupadd nagcmd
[root@nagios1 nagios]# usermod -G nagcmd nagios
[root@nagios1 nagios]# usermod -G nagcmd apache
4.下載nagios壓縮包(可在線,也能夠離線)ide
我這裏,在/home/nagios家目錄下,下載。post
[root@nagios1 nagios]# wget http://prdownloads.sourceforge.net/sourceforge/nagios/nagios-4.0.8.tar.gz
獲得
解壓縮和進入目錄
[root@nagios1 nagios]# tar –zxvf nagios-4.0.8.tar.gz
[root@nagios1 nagios]# cd nagios-4.0.8
進行初始化和創建編譯的環境
[root@nagios1 nagios-4.0.8]# pwd
/home/nagios/nagios-4.0.8
[root@nagios1 nagios-4.0.8]# ./configure –prefix=/usr/local/nagios –with-command-group=nagcmd
[root@nagios1 nagios-4.0.8]# make all (這是在,安裝二進制文件)
[root@nagios1 nagios-4.0.8]# make install (這是在,初始化腳本)
[root@nagios1 nagios-4.0.8]# make install-init (這是在,示例配置文件)
[root@nagios1 nagios-4.0.8]# make install-commandmode (這是在,設置目錄權限)
而後,完成上述以後,執行
[root@nagios1 nagios-4.0.8]# ls /usr/local/nagios
bin etc include libexec sbin share var
[root@nagios1 nagios-4.0.8]#
可以在/usr/local/nagios的目錄下面看到這些目錄(bin etc sbin share var)就說明nagios安裝成功了。
注意:安裝完成以後,先不要急着去啓動nagios,由於還有一些操做須要執行。
五、安裝nagios的web配置文件
[root@nagios1 nagios-4.0.8]# pwd /home/nagios/nagios-4.0.8 [root@nagios1 nagios-4.0.8]# make install-webconf
安裝完成之後是默認安裝到Apache的conf.d的目錄下的。
(Apache的服務就是httpd,這個服務咱們在一開始的時候就已經經過yum安裝過了。在這個版本里面httpd是集成在系統內的,因此能夠直接安裝。)
6.使用apache來建立基本的web頁認證方式
在apache中使用基本認證的方式建立一個admin的用戶用於nagios的web界面的登陸。
注意記住你所設置的登陸口令,而該用戶會的賬號和密碼會被存儲。
[root@nagios1 nagios-4.0.8]# pwd /home/nagios/nagios-4.0.8 [root@nagios1 nagios-4.0.8]# htpasswd -c /usr/local/nagios/etc/htpasswd.users admin New password: (由於,用戶名是admin,因此選擇密碼也是admin,爲了方便記憶) Re-type new password: Adding password for user admin [root@nagios1 nagios-4.0.8]#
設置完成以後,在nagios主程序安裝完成以後,會自動將相關apache的配置文件放到/etc/httpd/conf.d/下面,而文件名是nagios.conf文件內容以下:
[root@nagios1 nagios-4.0.8]# pwd /home/nagios/nagios-4.0.8 [root@nagios1 nagios-4.0.8]# vim /etc/httpd/conf.d/nagios.conf
# SAMPLE CONFIG SNIPPETS FOR APACHE WEB SERVER # # This file contains examples of entries that need # to be incorporated into your Apache web server # configuration file. Customize the paths, etc. as # needed to fit your system. ScriptAlias /nagios/cgi-bin "/usr/local/nagios/sbin" <Directory "/usr/local/nagios/sbin"> # SSLRequireSSL Options ExecCGI AllowOverride None Order allow,deny Allow from all # Order deny,allow # Deny from all # Allow from 127.0.0.1 AuthName "Nagios Access" AuthType Basic AuthUserFile /usr/local/nagios/etc/htpasswd.users Require valid-user </Directory> Alias /nagios "/usr/local/nagios/share" <Directory "/usr/local/nagios/share"> # SSLRequireSSL Options None AllowOverride None Order allow,deny Allow from all
# Order deny,allow
# Deny from all
# Allow from 127.0.0.1
AuthName "Nagios Access"
AuthType Basic
AuthUserFile /usr/local/nagios/etc/htpasswd.users
Require valid-user
</Directory>
以上,這就意味着只有經過認證用戶才能夠經過http訪問/usr/local/nagios/share以及/usr/local/nagios/sbin目錄下的內容。
而這個可以經過認證的用戶也就是admin,以後能夠重啓apache來應用配置:
[root@nagios1 nagios-4.0.8]# pwd /home/nagios/nagios-4.0.8 [root@nagios1 nagios-4.0.8]# service httpd restart
[root@nagios1 nagios-4.0.8]# chkconfig –-level 235 httpd on
7.nagios插件nagios-plugins-2.0.3.tar.gz的安裝
爲何須要安裝這個插件呢?
剛纔已經提到Nagios主程序只是一個控制中心,而可以起到服務監測和系統監測等功能的是衆多Nagios的插件,沒有插件的Nagios系統其實只是一個空殼。所以在安裝了Nagios平臺以後咱們還須要安裝插件。
[root@nagios1 nagios-4.0.8]# pwd /home/nagios/nagios-4.0.8 [root@nagios1 nagios-4.0.8]# wget http://nagios-plugins.org/download/nagios-plugins-2.0.3.tar.gz
解壓縮和進入目錄
[root@nagios1 nagios]# pwd /home/nagios [root@nagios1 nagios]# tar -zxvf nagios-plugins-2.0.3.tar.gz
[root@nagios1 nagios]# cd nagios-plugins-2.0.3
[root@nagios1 nagios-plugins-2.0.3]# pwd
/home/nagios/nagios-plugins-2.0.3
[root@nagios1 nagios-plugins-2.0.3]# ./configure –prefix=/usr/local/nagios –with-nagios-user=nagios–with-nagios-group=nagios
[root@nagios1 nagios-plugins-2.0.3]# make
[root@nagios1 nagios-plugins-2.0.3]# make install
而後把nagios加入到服務列表中以便在系統啓動的時候自動啓動:
[root@nagios1 nagios-plugins-2.0.3]# chkconfig –add nagios
[root@nagios1 nagios-plugins-2.0.3]# chkconfig nagios on
8.檢查配置文件的正確性並打開web訪問
[root@nagios1 nagios-plugins-2.0.3]# pwd /home/nagios/nagios-plugins-2.0.3 [root@nagios1 nagios-plugins-2.0.3]# /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg Nagios Core 4.0.8 Copyright (c) 2009-present Nagios Core Development Team and Community Contributors Copyright (c) 1999-2009 Ethan Galstad Last Modified: 08-12-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 8 services. Checked 1 hosts. Checked 1 host groups. Checked 0 service groups. Checked 1 contacts. Checked 1 contact groups. Checked 24 commands. Checked 5 time periods. Checked 0 host escalations. Checked 0 service escalations. Checking for circular paths... Checked 1 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@nagios1 nagios-plugins-2.0.3]#
若是你們最後的結果和我上面的同樣沒有報錯,就能夠啓動nagios服務了。
注意:
另外建議在較大量修改配置文件後,也能夠用這條命令來檢測是否配置徹底正確,而後再啓動nagios的服務。
九、開啓nagios和關閉nagios
以後能夠在瀏覽器上訪問連接http://192.168.80.160/nagios/,若是可以正常看到頁面,證實nagios主程序和插件都安裝和配置成功!點擊「Hosts」的連接來查看你本機的監視詳情。
[root@nagios1 nagios]# service iptables status
[root@nagios1 nagios]# service iptables stop
[root@nagios1 nagios]# service nagios start
若是在開啓nagios時,出現上述的狀況。則
解決方法:關閉selinux
修改/etc/sysconfig/selinux ,將SELINUX=disabled 保存後,reboot。(別忘記了重啓它)
查看selinux狀態sestatus -v
[root@nagios1 nagios]# pwd /home/nagios [root@nagios1 nagios]# ll total 4372 drwxrwxr-x. 18 nagios nagios 4096 Mar 26 00:38 nagios-4.0.8 -rw-rw-r--. 1 nagios nagios 1805059 Aug 12 2014 nagios-4.0.8.tar.gz drwxr-xr-x. 15 nagios nagios 4096 Mar 26 00:50 nagios-plugins-2.0.3 -rw-rw-r--. 1 nagios nagios 2659772 Mar 26 00:00 nagios-plugins-2.0.3.tar.gz [root@nagios1 nagios]# service nagios stop Stopping nagios:. done. [root@nagios1 nagios]#
若是監控的頁面出現下面的錯誤提示,那麼就須要修改nagios的配置文件來進行修復了。
即:vi /usr/local/nagios/etc/cgi.cfg
找到use_authentication=1 #把1修改成0,而後保存
而後從新啓動服務:# service nagios restart
# service httpd restart
而後再試着訪問就沒有問題了。
還有,若是沒有在你的本地電腦上打開不了這個web界面,那麼可能須要關閉linux裏面的防火牆,命令以下:
# service iptables status 查看防火牆狀態
# service iptables stop 關閉防火牆