您好,登錄后才能下訂單哦!
我的環境如下:
Centos-6.2
Nagios 4.0.1
Nagios Plugin 1.5
Nagios是一個非常棒的免費的開源的監控工具,它提供給你一個很全面的監控環境,始終密切監視你的機器或者網絡,不管是在數據中心還是在你自己的一個小實驗室。
步驟1:安裝需要的依賴包
需要安裝Apache、PHP和一些庫像:gcc、glibc、glibc-common、gd、gd-devel、make、net-snmp
[root@taoteng ~]# yum install -y httpd php gcc glibc glibc-common gd gd-devel make net-snmp
創建一個新的nagios用戶和nagcmd組賬戶并設置密碼。
[root@taoteng ~]# useradd nagios [root@taoteng ~]# groupadd nagcmd
接下來,添加nagios和Apache用戶到nagcmd組。
[root@tecmint]# usermod -G nagcmd nagios
[root@tecmint]# usermod -G nagcmd apache
步驟3:下載Nagios-4.0.1和Nagios-plugin-1.5
在/root目錄下創建一個安裝包以及后續需要下載的安裝包的目錄。
[root@taoteng ~]# mkdir /root/nagios
[root@taoteng ~]# cd /root/nagios
現在來下載最新版本的Nagio-4.0.1和Nagios-plugin-1.5通過wget命令
[root@taoteng nagios]# wget http://prdownloads.sourceforge.net/sourceforge/nagios/nagios-4.0.1.tar.gz
[root@taoteng nagios]# wget https://www.nagios-plugins.org/download/nagios-plugins-1.5.tar.gz
步驟4:提取Nagios和nagios-plugins壓縮包
我們需要通過tar命令來提取下載的壓縮包里面的文件:
[root@taoteng nagios]# tar -zxvf nagios-4.0.1.tar.gz
[root@taoteng nagios]# tar -zxvf nagios-plugins-1.5.tar.gz
緊接著nagios文件夾里面將會出現解壓之后的文件夾
[root@taoteng nagios]# ll
總用量 30668
drwxrwxr-x 18 root root 4096 2月 20 21:22 nagios-4.0.1
-r-xr-xr-x 1 root root 1696847 2月 20 20:58 nagios-4.0.1.tar.gz
drwxr-xr-x 15 nagios nagios 4096 2月 24 00:58 nagios-cn-3.2.3
-r-xr-xr-x 1 root root 9638175 2月 20 20:58 nagios-cn-3.2.3.tar.bz2
drwxr-xr-x 15 200 300 4096 2月 20 22:04 nagios-plugins-1.5
-r-xr-xr-x 1 root root 2428258 2月 20 20:58 nagios-plugins-1.5.tar.gz
配置nagios的核心
現在,首先我們將配置nagios核心,將進入到nagios文件夾里面運行configure命令,如果一切運行順利將會出現下面的界面:
[root@taoteng nagios]# cd nagios-4.0.1
[root@taoteng nagios-4.0.1]# ./configure --with-command-group=nagcmd
輸出示例:
Nagios executable: nagios Nagios user/group: nagios,nagios Command user/group: nagios,nagcmd Event Broker: yes Install ${prefix}: /usr/local/nagios Install ${includedir}: /usr/local/nagios/include/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/tracerouteReview the options above for accuracy. If they look okay,type 'make all' to compile the main program and CGIs.
隨后配置和編譯所有的的二進制文件,make和make install將會在你的機器上安裝所需的二進制文件然后才能繼續安裝,
[root@taoteng nagios-4.0.1]# make
[root@taoteng nagios-4.0.1]# make install
輸出樣例:
*** Main program, CGIs and HTML files installed ***You can continue with installing Nagios as follows (type 'make'without any arguments for a list of all possible options): make install-init - This installs the init script in /etc/rc.d/init.d make install-commandmode - This installs and configures permissions on the directory for holding the external command file make install-config - This installs sample config files in /usr/local/nagios/etc
其實從上面的樣例上可以看出下步我們需要的操作步驟,接著執行make install-init去安裝初始化腳本。
[root@taoteng nagios-4.0.1]# make install-init
從輸出的命令行上可以看出我們需要安裝外部命令文件(libxce)
[root@taoteng nagios-4.0.1]# make install-commandmode
接下來安裝nagios示例文件,運行下面的命令:
[root@taoteng nagios-4.0.1]# 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/cgi.cfg /usr/local/nagios/etc/cgi.cfg/usr/bin/install -c -b -m 660 -o nagios -g nagios sample-config/resource.cfg /usr/local/nagios/etc/resource.cfg/usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/template-object/templates.cfg /usr/local/nagios/etc/objects/templates.cfg/usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/template-object/commands.cfg /usr/local/nagios/etc/objects/commands.cfg/usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/template-object/contacts.cfg /usr/local/nagios/etc/objects/contacts.cfg/usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/template-object/timeperiods.cfg /usr/local/nagios/etc/objects/timeperiods.cfg/usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/template-object/localhost.cfg /usr/local/nagios/etc/objects/localhost.cfg/usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/template-object/windows.cfg /usr/local/nagios/etc/objects/windows.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 ***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:自定義nagios配置文件
打開“contacts.cfg”文件編輯當出現報警狀態時候的nagios管理員的電子郵箱
[root@taoteng nagios-4.0.1]# vi /usr/local/nagios/etc/objects/contacts.cfg
輸出樣例:
###############################################################################
#
# CONTACTS
#
###############################################################################
###############################################################################
# Just one contact defined by default - the Nagios admin (that's you)
# This contact definition inherits a lot of default values from the 'generic-contact'
# template which is defined elsewhere.
define contact{
contact_name nagiosadmin ; Short name of user
use generic-contact ; Inherit default values from generic-contact template (defined above)
alias Nagios Admin ; Full name of user
email xiantao412@sina.com ; <<***** CHANGE THIS TO YOUR EMAIL ADDRESS ******
}
步驟6:安裝和配置Nagios的web接口
到目前為止,我們已經完成了所有的配置,接下來將用下面的命令來配置Nagios的web接口。
下面的命令將配置web接口并同時創建一個“nagiosadmin”管理用戶。
[root@taoteng nagios-4.0.1]# make install-webconf
接下來的這步將會創建一個密碼為“nagiosadmin”記住這個密碼,因為待會兒在瀏覽器中登錄的時候將會用到這個密碼。
[root@taoteng nagios-4.0.1]# htpasswd -s -c /usr/local/nagios/etc/htpasswd.users nagiosadmin
New password:
Re-type new password:
Adding password for user nagiosadmin
重啟Apache服務使新的配置生效。
[root@taoteng nagios-4.0.1]# service httpd restart (On RedHat/CentOS)
[root@taoteng nagios-4.0.1]# systemctl start httpd.service (On Fedora)
步驟7:編譯和安裝nagios插件。
這兒已經下載了nagios插件在/root/nagios目錄下面,直接進去編譯和安裝即可:
[root@taoteng nagios]# tar -zxvf nagios-plugins-1.5
[root@taoteng nagios]# ./configure --with-nagios-user=nagios --with-nagios-group=nagios
[root@taoteng nagios]# make
[root@taoteng nagios]# make install
步驟8:驗證nagios配置文件的是否有錯誤(這就是nagios其中的一個很不錯的地方,可以很清晰的告訴你是否有錯誤)如果沒有什么錯誤就輸出下面的語句:
[root@taoteng nagios]# /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfgs
輸出示例:
Running pre-flight check on configuration data...
Checking services...
Checked 34 services.
Checking hosts...
Checked 14 hosts.
Checking host groups...
Checked 4 host groups.
Checking service groups...
Checked 2 service groups.
Checking contacts...
Checked 1 contacts.
Checking contact groups...
Checked 1 contact groups.
Checking service escalations...
Checked 0 service escalations.
Checking service dependencies...
Checked 0 service dependencies.
Checking host escalations...
Checked 0 host escalations.
Checking host dependencies...
Checked 0 host dependencies.
Checking commands...
Checked 25 commands.
Checking time periods...
Checked 5 time periods.
Checking for circular paths between hosts...
Checking for circular host and service dependencies...
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
步驟9:讓Nagios服務隨計算機開機啟動
為了是Nagios和httpd在重啟之后工作,我們需要把這兩個服務chkconfig一下:
[root@taoteng ~]# chkconfig --add nagios
[root@taoteng ~]#chkconfig --level 35 nagios on
[root@taoteng ~]#chkconfig --add httpd
[root@taoteng ~]#chkconfig --level 35 httpd on
重啟Nagios使更改生效!
[root@taoten ~]#service nagios restart
步驟10:通過瀏覽器來登錄到Nagios
我們的Nagios已經可以開始工作了,瀏覽器中輸入http://192.168.162.153/nagios;輸入“nagiosadmin”然后輸入密碼就okay了!
Nagios Login
主機概述:
Nagios Overview
Congratulations! You’ve successfully installed and configured Nagios and its Plugins. You’ve just begin your journey into monitoring.
如果你已經安裝了一個老版本的nagios,那么你可以直接下載最新版本的nagios,按照下面的命令直接編譯安裝即可
[root@taoteng ~]# service nagios stop
[root@taoteng ~]# tar –zxvf nagios-4.0.1.tar.gz
[root@taoteng ~]# cd nagios-4.0.1
[root@taoteng ~]# ./configure
[root@taoteng ~]# make all
[root@taoteng ~]# make install
[root@taoteng ~]# service nagios start
到這里,nagios的基本配置已經完成,當然安裝過程中n難免會出現錯誤的~會在后續的過程中更新出來當然也非常歡迎友友聯系我一起來交流解決您碰見的問題。
后續的博客也會跟進nagios如何添加Linux主機、windows主機、交換機、打印機等等一些設備到Nagios監視服務器中。
-------------第一次 發博文,錯誤之處,歡迎指出,敬請原諒-------------
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。