1、實驗環(huán)境:

主機名: ip 需要的軟件環(huán)境
nagios-server 192.168.124.143 Apache、Php、Nagios、nagios-plugins、nrpe
nagios-linux 192.168.124.203 nagios-plugins、nrpe
監(jiān)控機 nagios-server上需要 安裝nagios軟件,對監(jiān)控的數(shù)據(jù)做處理,并且提供 web界面查看和管理。當然也對本機自身的信息進行監(jiān)控;
被監(jiān)控機 nagios-linux需安裝NRPE及nagios plugins,根據(jù)監(jiān)控機的請求執(zhí)行監(jiān) 控,然后將結(jié)果回傳給監(jiān)控機;
一、Nagios監(jiān)控機(192.168.124.143)上的環(huán)境準備
1、 安裝編譯環(huán)境
使用yum安裝
[root@localhost ~]# yum install -y gcc glibc glibc-common gd xinetd openssl-devel mysql-devel
2、 創(chuàng)建nagios用戶和用戶組
[root@localhost ~]#useradd -s /sbin/nologin nagios
[root@localhost ~]#mkdir /usr/local/nagios
[root@localhost ~]#chown -R nagios:nagios /usr/local/nagios
3、 yum安裝httpd和php,并配置httpd支持php
只要能實現(xiàn)瀏覽器能正常訪問 http://本機IP/index.php 既可
4、 編譯安裝nagios
上傳nagios源碼包至/root目錄下
[root@localhost ~]#tar zxvf nagios-4.0.3.tar.gz
[root@localhost ~]#cd nagios-4.0.3
[root@localhost ~]#./configure --prefix=/usr/local/nagios --with-nagiosuser=nagios --with-nagios-group=nagios
[root@localhost ~]#make all
[root@localhost ~]#make install
[root@localhost ~]#make install-init
[root@localhost ~]#make install-commandmode
[root@localhost ~]#make install-config
[root@localhost ~]#make install-webconf
[root@localhost ~]#chkconfig --add nagios # 將nagios加入系統(tǒng) 服務(wù)
[root@localhost ~]#chkconfig nagios on
5、 驗證nagios是否被正確安裝
切換目錄到安裝路徑(這里是/usr/local/nagios),看是否存在etc、bin、 libexec、sbin、share、var 這些目錄,如果存在則可以表明程序被正確的安裝到 系統(tǒng)了。
Nagios 各個目錄用途說明如下:
目錄名 用途
bin Nagios 可執(zhí)行程序所在目錄
etc Nagios 配置文件所在目錄
sbin Nagios CGI文件所在目錄,也就是執(zhí)行外部命令所需文件所在的目錄 share Nagios網(wǎng)頁文件所在的目錄
libexec Nagios 外部插件所在目錄
var Nagios 日志文件、lock 等文件所在的目錄
var/archives Nagios 日志自動歸檔目錄
var/rw 用來存放外部命令文件的目錄
6、 安裝nagios插件
上傳nagios-plugins-1.5.tar.gz至/root目錄下
[root@localhost ~]#tar zxvf nagios-plugins-1.5.tar.gz
[root@localhost ~]#cd nagios-plugins-1.5
[root@localhost ~]#./configure --prefix=/usr/local/nagios --with-mysql --with-nagios-user=nagios --with-nagiosgroup=nagios
[root@localhost ~]#make && make install
備注:
--with-mysql 使nagios插件支持監(jiān)控mysql(系統(tǒng)要先yum安裝好 mysql-devel軟件包),在libexec目錄下會有 check_mysql和check_mysql_query命令
7、 安裝check_nrpe插件
上傳nrpe-2.12.tar.gz至/root目錄下
[root@localhost ~]#tar zxvf nrpe-2.12.tar.gz
[root@localhost ~]#cd nrpe-2.12
[root@localhost ~]#./configure --with-nrpe-user=nagios --with-nrpe-group=nagios --with-nagiosuser=nagios --with-nagios-group=nagios --enable-command-args --enable-ssl
[root@localhost ~]#make all
[root@localhost ~]#make install-plugin
監(jiān)控機上只運行到這一步就行,因為只需要nrpe中的check_nrpe插件
8、 修改apache的配置文件/etc/httpd/conf/httpd.conf
[root@localhost ~]#vim /etc/httpd/conf/httpd.conf
User apache修改為User nagios
Group apache修改為Group nagios
DirectoryIndex index.html修改為DirectoryIndex index.php
保存
9、 為了安全起見,一般情況下要讓nagios 的web 監(jiān)控頁面必須經(jīng)過授權(quán)才能訪問 編譯安裝nagios 4.0.3版本完成后,已自動配置httpd并設(shè)定了默認的htpasswd驗證文件 /usr/local/nagios/etc/ htpasswd.users
[root@localhost ~]#htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin #指定用戶 nagiosadmin可以訪問
10、 啟動httpd服務(wù)
[root@localhost ~]#service httpd restart
[root@localhost ~]#service nagios start
11、 瀏覽器訪問nagios站點
http://192.168.124.143/nagios
二、被監(jiān)控機(192.168.124.203)安裝nrpe及nagios-plugins
1、 安裝編譯環(huán)境
使用yum安裝
[root@localhost ~]# yum install -y gcc glibc glibc-common gd xinetd openssl-devel mysql-devel
2、 編譯安裝nagios插件
上傳nagios-plugins-1.5.tar.gz至/root目錄下
[root@localhost ~]#tar -zxvf nagios-plugins-1.5.tar.gz
[root@localhost ~]#cd nagios-plugins-1.5
[root@localhost ~]#./configure --with-mysql --with-nagios-user=nagios --with-nagios-group=nagios
[root@localhost ~]#make && make install
這一步完成后會在/usr/local/nagios/下生成兩個目錄libexec和share,修改目錄權(quán)限 [root@localhost ~]#useradd -s /sbin/nologin nagios
[root@localhost ~]#chown -R nagios:nagios /usr/local/nagios
3、 編譯安裝nrpe
上傳nrpe-2.12.tar.gz至/root目錄下
[root@localhost ~]#tar -zxvf nrpe-2.12.tar.gz
[root@localhost ~]#cd nrpe-2.12
[root@localhost ~]#./configure --with-nrpe-user=nagios --with-nrpe-group=nagios --with-nagiosuser=nagios --with-nagios-group=nagios --enable-command-args --enable-ssl
[root@localhost ~]#make all
[root@localhost ~]#make install-plugin
[root@localhost ~]#make install-daemon
[root@localhost ~]#make install-daemon-config
#現(xiàn)在再查看/usr/local/nagios 目錄就會發(fā)現(xiàn)有4個子目錄
[root@localhost ~]#make install-xinetd
[root@localhost ~]#vim /etc/xinetd.d/nrpe
修改在末尾項 only_from = 192.168.124.0/24
這里設(shè)置允許監(jiān)控機所在的網(wǎng)段訪問
[root@localhost ~]#vim /etc/services
#編輯/etc/services 文件,末尾增加NRPE服務(wù)內(nèi)容
在最后添加 nrpe 5666/tcp #nrpe
[root@localhost ~]#service xinetd restart
[root@localhost ~]#netstat -ntulp|grep 5666
#查看nrpe是否已啟動并監(jiān)聽5666端口
4、 測試nrpe是否正常工作
在監(jiān)控機(192.168.124.143)執(zhí)行check_nrpe這個插件來測試與被監(jiān)控機(192.168.124.203)的通訊
[root@localhost ~]#/usr/local/nagios/libexec/check_nrpe -H 192.168.124.203 如顯示 NRPE V2.12 ,則nrpe通訊正常
三、監(jiān)控機(192.168.124.143)上的配置
1、 在commands.cfg文件末尾增加check_nrpe的定義
[root@localhost ~]#vim /usr/local/nagios/etc/objects/commands.cfg
#添加如下 代碼
define command{
command_name check_nrpe
command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$ }
2、 定義對Nagios-Linux 主機的監(jiān)控,創(chuàng)建nagios_linux.cfg文件并加入以下 代碼內(nèi)容
[root@localhost ~]#vim /usr/local/nagios/etc/objects/nagios_linux.cfg
define host{
use linux-server
host_name nagios-linux
alias nagios-linux
address 192.168.124.67 #此處設(shè)置被監(jiān)控機的IP地址 }
define service{ #添加監(jiān)控CPU負載的服務(wù)
use local-service
host_name nagios-linux
service_description CPU Load
check_command check_nrpe!check_load
}
define service{ #添加監(jiān)控總進程數(shù)的服務(wù)
use local-service
host_name nagios-linux
service_description Total Processes
check_command check_nrpe!check_total_procs
}
上述代碼分別定義了CPU Load(cpu負載)以及Total Processes(總進程數(shù))的監(jiān) 控服務(wù),還可以在此文件中增加其他的監(jiān)控服務(wù)
3、 在nagios的主配置文件nagios.cfg末尾增加如下代碼內(nèi)容
[root@localhost ~]#vim /usr/local/nagios/etc/nagios.cfg
cfg_file=/usr/local/nagios/etc/objects/nagios_linux.cfg
#在nagios的主配置文件中增 加被監(jiān)控機的配置文件
4、 重啟各項服務(wù)
[root@localhost ~]#service httpd restart
[root@localhost ~]#service nagios restart
5、 驗證nagios是否能監(jiān)控到本機(localhost)以及被監(jiān)控機nagios-linux
http://ip/nagios
6、[root@localhost ~]#service httpd restart
[root@localhost ~]#service nagios restart
#重啟驗證新增的監(jiān)控信息
ok!到此結(jié)束!希望對你有所幫助
另外有需要云服務(wù)器可以了解下創(chuàng)新互聯(lián)scvps.cn,海內(nèi)外云服務(wù)器15元起步,三天無理由+7*72小時售后在線,公司持有idc許可證,提供“云服務(wù)器、裸金屬服務(wù)器、高防服務(wù)器、香港服務(wù)器、美國服務(wù)器、虛擬主機、免備案服務(wù)器”等云主機租用服務(wù)以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡單易用、服務(wù)可用性高、性價比高”等特點與優(yōu)勢,專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應(yīng)用場景需求。
文章名稱:搭建nagios監(jiān)控步驟-創(chuàng)新互聯(lián)
路徑分享:http://chinadenli.net/article2/ccgeic.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站建設(shè)、電子商務(wù)、小程序開發(fā)、搜索引擎優(yōu)化、移動網(wǎng)站建設(shè)、網(wǎng)站設(shè)計公司
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容