歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux基礎 >> Linux教程 >> RHEL/CentOS/Fedora安裝Nagios 4.0.1

RHEL/CentOS/Fedora安裝Nagios 4.0.1

日期:2017/2/28 14:34:25   编辑:Linux教程

Nagios 4.0.1版本安裝,適用於RHEL/CentOS 5.x/6.x 或者Fedora 17/18/19。

我的環境如下:

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

步驟2:創建一個nagios用戶和組

創建一個新的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 [email protected] ; <<***** 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)

Nagios 的詳細介紹:請點這裡
Nagios 的下載地址:請點這裡

Copyright © Linux教程網 All Rights Reserved