nagios安裝配置
一 使用目的
作為系統運維人員,對系統的監控是不可或缺的一項重要任務,當系統出現故障時能在第一時間得到通知並解決故障是每個運維人員職責。時下監控軟體有很多比如:zabbix,cacti,nagios等,本文主要介紹nagios的一些基本功能。
二 Nagios工作原理
Nagios的功能是監控服務和主機,但是他自身並不包括這部分功能,所有的監控、檢測功能都是通過各種外掛來完成的。
啟動Nagios後,它會週期性的自動呼叫外掛去檢測伺服器狀態,同時Nagios會維持一個佇列,所有外掛返回來的狀態資訊都進入佇列,Nagios每次都從隊首開始讀取資訊,並進行處理後,把狀態結果通過web顯示出來。 Nagios提供了許多外掛,利用這些外掛可以方便的監控很多服務狀態。安裝完成後,在nagios主目錄下的/libexec裡放有 nagios自帶的可以使用的所有外掛,如,check_disk是檢查磁碟空間的外掛,check_load是檢查CPU負載的,等等。每一個外掛可以 通過執行./check_xxx –h 來檢視其使用方法和功能。
Nagios可以識別4種狀態返回資訊,即 0(OK)表示狀態正常/綠色、1(WARNING)表示出現警告/黃色、2(CRITICAL)表示出現非常嚴重的錯誤/紅色、3(UNKNOWN)表 示未知錯誤/深黃色。Nagios根據外掛返回來的值,來判斷監控物件的狀態,並通過web顯示出來,以供管理員及時發現故障
四種狀態
![2 2](https://i.iter01.com/images/c75dc647926357f625a59735219ab05e392f79c917d437ebcc13ad597032ef6e.jpg)
Nagios 系統提供了一個外掛NRPE。Nagios 通過週期性的執行它來獲得遠端伺服器的各種狀態資訊。它們之間的關係如下圖所示:
![1 1](https://i.iter01.com/images/62b76ad3521b0afcb578660fcd95dc6a59162fa935f8c95a1a59b969d3f5a33d.jpg)
nagios-server | 192.168.151.90 | Red Hat Enterprise Linux Server release 5.7 |apache,php,nagios,nagios-plugin,nrpe
nagios-client | 192.168.151.69 | Red Hat Enterprise Linux Server release 5.7 |nagios-plugin,nrpe
四 服務端安裝軟體
在nagios-server上裝如下軟體
httpd-2.4.6.tar.gz
php-5.4.10.tar.gz
nagios-3.4.3.tar.gz
nagios-plugins-1.5.tar.gz
nrpe-2.13.tar.gz
1 nagios安裝
tar zxf nagios-3.4.3.tar.gz
cd nagios-3.4.3
./configure --prefix=/usr/local/nagios
make all
make install
make install-init
make install-commandmode
make install-config
2 nagios-plugins安裝
tar zxf nagios-plugins-1.5.tar.gz
cd nagios-plugins-1.5
./configure --prefix=/usr/local/nagios
make
make install
3 nrpe安裝,只需要安裝check_nrpe,不需要配置檔案
tar zxf nrpe-2.13.tar.gz
cd nrpe-2.13
./configure
make all
make install-plugin
4 apache,php安裝
tar zxf httpd-2.4.6.tar.gz
cd httpd-2.4.6
./configure --prefix=/usr/local/apache
make
make install
tar zxf php-5.4.10.tar.gz
cd php-5.4.10
./configure --prefix=/usr/local/php --with-apxs2=/usr/local/apache/bin/apxs
make && make install
a apache整合php,紅色字型為新增的部分
DirectoryIndex index.html index.php
AddType application/x-httpd-php .php
b nagios web頁面授權
ScriptAlias /nagios/cgi-bin /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
Alias /nagios /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
c 建立驗證檔案
/usr/local/apache/bin/htpasswd -c /usr/local/nagios/etc/htpasswd nagios
根據提示輸入密碼
在/usr/local/nagios/etc下面就生成了一個密碼檔案
啟動apache和nagios
/usr/local/apache/bin/apachectl start
/etc/init.d/nagios start
現在可以在瀏覽器中訪問nagios頁面http://192.168.151.90/nagios
五 客戶端軟體安裝
在客戶端要裝如下軟體
nagios-plugins-1.5.tar.gz
nrpe-2.13.tar.gz
建立nagios使用者
useradd nagios
軟體安裝
cd /usr/local/src
wget https://www.nagios-plugins.org/download/nagios-plugins-1.5.tar.gz
tar zxf nagios-plugins-1.5.tar.gz
cd nagios-plugins-1.5
./configure --prefix=/usr/local/nagios
make
make install
cd /usr/local/src
wget http://prdownloads.sourceforge.net/sourceforge/nagios/nrpe-2.13.tar.gz
tar zxf nrpe-2.13.tar.gz
cd nrpe-2.13
./configure
make all
cd ./src && make install-plugin
cd ./src && make install-daemon
make install-daemon-config
如果安裝成功,在/usr/local/nagios下會有下面幾個目錄
[root@localhost ~]# ll /usr/local/nagios/
total 24
drwxrwxr-x 2 nagios nagios 4096 Nov 13 23:42 bin
drwxrwxr-x 2 nagios nagios 4096 Nov 13 23:42 etc
drwxrwxr-x 2 nagios nagios 4096 Nov 13 23:41 libexec
drwxr-xr-x 2 root root 4096 Nov 13 23:28 share
在libexec下會有一個check_nrpe檔案
六 nagios配置
客戶端配置
以xinetd方式啟動nrpe,配置如下
cat /etc/xinetd.d/nrpe
service nrpe
{
flags = REUSE
socket_type = stream
port = 5666
wait = no
user = nagios
group = nagios
server = /usr/local/nagios/bin/nrpe
server_args = -c /usr/local/nagios/etc/nrpe.cfg --inetd
log_on_failure += USERID
disable = no
only_from = 192.168.151.90
}
/etc/services中新增如下行
nrpe 5666/tcp
nrpe.cfg是nrpe的配置檔案,對使用者,磁碟,負載,程式及swap資源的監控配置如下:
cat /usr/local/nagios/etc/nrpe.cfg |grep -v \#|sed '/^$/d'
log_facility=daemon
pid_file=/var/run/nrpe.pid
server_port=5666
server_address=127.0.0.1
nrpe_user=nagios
nrpe_group=nagios
allowed_hosts=127.0.0.1
dont_blame_nrpe=0
debug=0
command_timeout=60
connection_timeout=300
command[check_users]=/usr/local/nagios/libexec/check_users -w 5 -c 10
command[check_load]=/usr/local/nagios/libexec/check_load -w 15,10,5 -c 30,25,20
command[check_hda1]=/usr/local/nagios/libexec/check_disk -w 20% -c 10% -p /dev/hda1
command[check_zombie_procs]=/usr/local/nagios/libexec/check_procs -w 5 -c 10 -s Z
command[check_total_procs]=/usr/local/nagios/libexec/check_procs -w 150 -c 200
command[check_swap]=/usr/local/nagios/libexec/check_swap -w 20% -c 10%
-w=warnning -c=critical
服務端配置
檔案目錄含義如下:
本文配置示例如下:
nagios.cfg檔案
cat nagios.cfg |grep cfg|grep -v \#
cfg_file=/usr/local/nagios/etc/objects/commands.cfg
cfg_file=/usr/local/nagios/etc/objects/contacts.cfg
cfg_file=/usr/local/nagios/etc/objects/timeperiods.cfg
cfg_file=/usr/local/nagios/etc/objects/templates.cfg
resource_file=/usr/local/nagios/etc/resource.cfg
objects下的檔案
[root@master objects]# ll /usr/local/nagios/etc/objects/
total 68
-rw-rw-r-- 1 nagios nagios 8214 Oct 25 10:54 commands.cfg
-rw-rw-r-- 1 nagios nagios 388 Oct 25 10:14 contacts.cfg
-rw-r--r-- 1 root root 2166 Oct 25 10:12 contacts.cfg.original
-rw-rw-r-- 1 nagios nagios 5403 Oct 24 11:43 localhost.cfg
-rw-rw-r-- 1 nagios nagios 3124 Oct 24 11:43 printer.cfg
-rw-rw-r-- 1 nagios nagios 3293 Oct 24 11:43 switch.cfg
-rw-rw-r-- 1 nagios nagios 11986 Oct 24 16:05 templates.cfg
-rw-rw-r-- 1 nagios nagios 3208 Oct 24 11:43 timeperiods.cfg
-rw-rw-r-- 1 nagios nagios 4019 Oct 24 11:43 windows.cfg
templates.cfg檔案
[root@master objects]# tail -28 templates.cfg
define service {
name linux-services
use generic-service
max_check_attempts 3
normal_check_interval 3
retry_check_interval 2
check_period 24x7
notification_period 24x7
notification_interval 0
notification_options w,u,c,r,f
contact_groups admins
register 0
}
define host {
name linux-host
use generic-host
max_check_attempts 3
normal_check_interval 3
retry_check_interval 2
check_period 24x7
notification_period 24x7
notification_interval 0
notification_options d,u,r,f
check_command check-host-alive
contact_groups admins
register 0
}
[root@master objects]#
到此,nagios安裝結束,本文會繼續更新
遇到的問題:
cgi頁面不能解析,ie顯示為亂碼,firefox顯示為下載cgi頁面
解決:
apache 開啟LoadModule cgid_module modules/mod_cgid.so
頁面提示It appears as though you do not have permission to view information for any of the services you requested...
解決:
開啟cgi.cfg配置檔案,裡面有個引數,設定為1:
use_authentication=1
/usr/local/nagios/libexec/check_nrpe -H 192.168.151.69出現錯誤提示
CHECK_NRPE: Error - Could not complete SSL handshake
客戶端,服務端版本是否一致
nrpe是否有daemon方式啟動的程式,關閉,以xinetd方式啟動
二 Nagios工作原理
Nagios的功能是監控服務和主機,但是他自身並不包括這部分功能,所有的監控、檢測功能都是通過各種外掛來完成的。
啟動Nagios後,它會週期性的自動呼叫外掛去檢測伺服器狀態,同時Nagios會維持一個佇列,所有外掛返回來的狀態資訊都進入佇列,Nagios每次都從隊首開始讀取資訊,並進行處理後,把狀態結果通過web顯示出來。 Nagios提供了許多外掛,利用這些外掛可以方便的監控很多服務狀態。安裝完成後,在nagios主目錄下的/libexec裡放有 nagios自帶的可以使用的所有外掛,如,check_disk是檢查磁碟空間的外掛,check_load是檢查CPU負載的,等等。每一個外掛可以 通過執行./check_xxx –h 來檢視其使用方法和功能。
Nagios可以識別4種狀態返回資訊,即 0(OK)表示狀態正常/綠色、1(WARNING)表示出現警告/黃色、2(CRITICAL)表示出現非常嚴重的錯誤/紅色、3(UNKNOWN)表 示未知錯誤/深黃色。Nagios根據外掛返回來的值,來判斷監控物件的狀態,並通過web顯示出來,以供管理員及時發現故障
四種狀態
![2 2](https://i.iter01.com/images/c75dc647926357f625a59735219ab05e392f79c917d437ebcc13ad597032ef6e.jpg)
Nagios 系統提供了一個外掛NRPE。Nagios 通過週期性的執行它來獲得遠端伺服器的各種狀態資訊。它們之間的關係如下圖所示:
![1 1](https://i.iter01.com/images/62b76ad3521b0afcb578660fcd95dc6a59162fa935f8c95a1a59b969d3f5a33d.jpg)
Nagios 通過NRPE 來遠端管理服務
1. Nagios 執行安裝在它裡面的check_nrpe 外掛,並告訴check_nrpe 去檢測哪些服務。
2. 通過SSL,check_nrpe 連線遠端機器上的NRPE daemon
3. NRPE 執行本地的各種外掛去檢測本地的服務和狀態(check_disk,..etc)
4. 最後,NRPE 把檢測的結果傳給主機端的check_nrpe,check_nrpe 再把結果送到Nagios狀態佇列中。
5. Nagios 依次讀取佇列中的資訊,再把結果顯示出來。
三 實驗環境nagios-server | 192.168.151.90 | Red Hat Enterprise Linux Server release 5.7 |apache,php,nagios,nagios-plugin,nrpe
nagios-client | 192.168.151.69 | Red Hat Enterprise Linux Server release 5.7 |nagios-plugin,nrpe
四 服務端安裝軟體
在nagios-server上裝如下軟體
httpd-2.4.6.tar.gz
php-5.4.10.tar.gz
nagios-3.4.3.tar.gz
nagios-plugins-1.5.tar.gz
nrpe-2.13.tar.gz
1 nagios安裝
tar zxf nagios-3.4.3.tar.gz
cd nagios-3.4.3
./configure --prefix=/usr/local/nagios
make all
make install
make install-init
make install-commandmode
make install-config
2 nagios-plugins安裝
tar zxf nagios-plugins-1.5.tar.gz
cd nagios-plugins-1.5
./configure --prefix=/usr/local/nagios
make
make install
3 nrpe安裝,只需要安裝check_nrpe,不需要配置檔案
tar zxf nrpe-2.13.tar.gz
cd nrpe-2.13
./configure
make all
make install-plugin
4 apache,php安裝
tar zxf httpd-2.4.6.tar.gz
cd httpd-2.4.6
./configure --prefix=/usr/local/apache
make
make install
tar zxf php-5.4.10.tar.gz
cd php-5.4.10
./configure --prefix=/usr/local/php --with-apxs2=/usr/local/apache/bin/apxs
make && make install
a apache整合php,紅色字型為新增的部分
DirectoryIndex index.html index.php
AddType application/x-httpd-php .php
b nagios web頁面授權
ScriptAlias /nagios/cgi-bin /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
Alias /nagios /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
c 建立驗證檔案
/usr/local/apache/bin/htpasswd -c /usr/local/nagios/etc/htpasswd nagios
根據提示輸入密碼
在/usr/local/nagios/etc下面就生成了一個密碼檔案
啟動apache和nagios
/usr/local/apache/bin/apachectl start
/etc/init.d/nagios start
現在可以在瀏覽器中訪問nagios頁面http://192.168.151.90/nagios
五 客戶端軟體安裝
在客戶端要裝如下軟體
nagios-plugins-1.5.tar.gz
nrpe-2.13.tar.gz
建立nagios使用者
useradd nagios
軟體安裝
cd /usr/local/src
wget https://www.nagios-plugins.org/download/nagios-plugins-1.5.tar.gz
tar zxf nagios-plugins-1.5.tar.gz
cd nagios-plugins-1.5
./configure --prefix=/usr/local/nagios
make
make install
cd /usr/local/src
wget http://prdownloads.sourceforge.net/sourceforge/nagios/nrpe-2.13.tar.gz
tar zxf nrpe-2.13.tar.gz
cd nrpe-2.13
./configure
make all
cd ./src && make install-plugin
cd ./src && make install-daemon
make install-daemon-config
如果安裝成功,在/usr/local/nagios下會有下面幾個目錄
[root@localhost ~]# ll /usr/local/nagios/
total 24
drwxrwxr-x 2 nagios nagios 4096 Nov 13 23:42 bin
drwxrwxr-x 2 nagios nagios 4096 Nov 13 23:42 etc
drwxrwxr-x 2 nagios nagios 4096 Nov 13 23:41 libexec
drwxr-xr-x 2 root root 4096 Nov 13 23:28 share
在libexec下會有一個check_nrpe檔案
六 nagios配置
客戶端配置
以xinetd方式啟動nrpe,配置如下
cat /etc/xinetd.d/nrpe
service nrpe
{
flags = REUSE
socket_type = stream
port = 5666
wait = no
user = nagios
group = nagios
server = /usr/local/nagios/bin/nrpe
server_args = -c /usr/local/nagios/etc/nrpe.cfg --inetd
log_on_failure += USERID
disable = no
only_from = 192.168.151.90
}
/etc/services中新增如下行
nrpe 5666/tcp
nrpe.cfg是nrpe的配置檔案,對使用者,磁碟,負載,程式及swap資源的監控配置如下:
cat /usr/local/nagios/etc/nrpe.cfg |grep -v \#|sed '/^$/d'
log_facility=daemon
pid_file=/var/run/nrpe.pid
server_port=5666
server_address=127.0.0.1
nrpe_user=nagios
nrpe_group=nagios
allowed_hosts=127.0.0.1
dont_blame_nrpe=0
debug=0
command_timeout=60
connection_timeout=300
command[check_users]=/usr/local/nagios/libexec/check_users -w 5 -c 10
command[check_load]=/usr/local/nagios/libexec/check_load -w 15,10,5 -c 30,25,20
command[check_hda1]=/usr/local/nagios/libexec/check_disk -w 20% -c 10% -p /dev/hda1
command[check_zombie_procs]=/usr/local/nagios/libexec/check_procs -w 5 -c 10 -s Z
command[check_total_procs]=/usr/local/nagios/libexec/check_procs -w 150 -c 200
command[check_swap]=/usr/local/nagios/libexec/check_swap -w 20% -c 10%
-w=warnning -c=critical
服務端配置
檔案目錄含義如下:
檔名或目錄名 | 用途 |
cgi.cfg | 控制CGI訪問的配置檔案 |
nagios.cfg | Nagios 主配置檔案 |
resource.cfg | 變數定義檔案,又稱為資原始檔,在些檔案中定義變數,以便由其他配置檔案引用,如$USER1$ |
objects | objects 是一個目錄,在此目錄下有很多配置檔案模板,用於定義Nagios 物件 |
objects/commands.cfg | 命令定義配置檔案,其中定義的命令可以被其他配置檔案引用 |
objects/contacts.cfg | 定義聯絡人和聯絡人組的配置檔案 |
objects/localhost.cfg | 定義監控本地主機的配置檔案 |
objects/printer.cfg | 定義監控印表機的一個配置檔案模板,預設沒有啟用此檔案 |
objects/switch.cfg | 定義監控路由器的一個配置檔案模板,預設沒有啟用此檔案 |
objects/templates.cfg | 定義主機和服務的一個模板配置檔案,可以在其他配置檔案中引用 |
objects/timeperiods.cfg | 定義Nagios 監控時間段的配置檔案 |
objects/windows.cfg | 監控Windows 主機的一個配置檔案模板,預設沒有啟用此檔案 |
nagios.cfg檔案
cat nagios.cfg |grep cfg|grep -v \#
cfg_file=/usr/local/nagios/etc/objects/commands.cfg
cfg_file=/usr/local/nagios/etc/objects/contacts.cfg
cfg_file=/usr/local/nagios/etc/objects/timeperiods.cfg
cfg_file=/usr/local/nagios/etc/objects/templates.cfg
resource_file=/usr/local/nagios/etc/resource.cfg
objects下的檔案
[root@master objects]# ll /usr/local/nagios/etc/objects/
total 68
-rw-rw-r-- 1 nagios nagios 8214 Oct 25 10:54 commands.cfg
-rw-rw-r-- 1 nagios nagios 388 Oct 25 10:14 contacts.cfg
-rw-r--r-- 1 root root 2166 Oct 25 10:12 contacts.cfg.original
-rw-rw-r-- 1 nagios nagios 5403 Oct 24 11:43 localhost.cfg
-rw-rw-r-- 1 nagios nagios 3124 Oct 24 11:43 printer.cfg
-rw-rw-r-- 1 nagios nagios 3293 Oct 24 11:43 switch.cfg
-rw-rw-r-- 1 nagios nagios 11986 Oct 24 16:05 templates.cfg
-rw-rw-r-- 1 nagios nagios 3208 Oct 24 11:43 timeperiods.cfg
-rw-rw-r-- 1 nagios nagios 4019 Oct 24 11:43 windows.cfg
templates.cfg檔案
[root@master objects]# tail -28 templates.cfg
define service {
name linux-services
use generic-service
max_check_attempts 3
normal_check_interval 3
retry_check_interval 2
check_period 24x7
notification_period 24x7
notification_interval 0
notification_options w,u,c,r,f
contact_groups admins
register 0
}
define host {
name linux-host
use generic-host
max_check_attempts 3
normal_check_interval 3
retry_check_interval 2
check_period 24x7
notification_period 24x7
notification_interval 0
notification_options d,u,r,f
check_command check-host-alive
contact_groups admins
register 0
}
[root@master objects]#
到此,nagios安裝結束,本文會繼續更新
遇到的問題:
cgi頁面不能解析,ie顯示為亂碼,firefox顯示為下載cgi頁面
解決:
apache 開啟LoadModule cgid_module modules/mod_cgid.so
頁面提示It appears as though you do not have permission to view information for any of the services you requested...
解決:
開啟cgi.cfg配置檔案,裡面有個引數,設定為1:
use_authentication=1
/usr/local/nagios/libexec/check_nrpe -H 192.168.151.69出現錯誤提示
CHECK_NRPE: Error - Could not complete SSL handshake
客戶端,服務端版本是否一致
nrpe是否有daemon方式啟動的程式,關閉,以xinetd方式啟動
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/27181165/viewspace-775807/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- CentOS原始碼安裝、配置Nagios(core)+PluginsCentOS原始碼iOSPlugin
- Nagios安裝步驟iOS
- Nagios+PNP安裝部署iOS
- 如何在 CentOS 8/RHEL 8 上安裝和配置 Nagios CoreCentOSiOS
- 本地windows搭建spark環境,安裝與詳細配置(jdk安裝與配置,scala安裝與配置,hadoop安裝與配置,spark安裝與配置)WindowsSparkJDKHadoop
- centos7 (阿里雲、linux) 單機spark的安裝與配置詳解(jdk安裝與配置,scala安裝與配置,hadoop安裝與配置,spark安裝與配置)CentOS阿里LinuxSparkJDKHadoop
- leanote安裝配置
- JENKINS安裝配置Jenkins
- oracle安裝配置Oracle
- ceph安裝配置
- 【mongodb安裝配置】MongoDB
- ELK 安裝配置
- 安裝配置ETCD
- SwitchOmega 安裝配置
- MySQL安裝配置MySql
- JWT安裝配置JWT
- Prometheus安裝配置Prometheus
- MariaDB 安裝配置
- ccache安裝配置
- alertmanager安裝配置
- VNC安裝配置VNC
- Hive安裝配置Hive
- Zookeeper 安裝配置
- PotPlayer 配置安裝
- SSH免密登入+JDK安裝配置+Hadoop安裝配置JDKHadoop
- CentOS 7 安裝、配置、使用 PostgreSQL 10 安裝及基礎配置CentOSSQL
- Linux下安裝java及配置(yum安裝)LinuxJava
- Mysql for Linux安裝配置之—— rpm(bundle)安裝MySqlLinux
- Mysql for Linux安裝配置之—— 原始碼安裝MySqlLinux原始碼
- MySQL安裝之二_安裝配置泥潭版MySql
- CentOS安裝配置yumCentOS
- CentOS redis安裝配置CentOSRedis
- Jenkins安裝及配置Jenkins
- Supervisor安裝與配置
- Nginx安裝與配置Nginx
- pip安裝源配置
- zabbix的安裝配置
- hbase 2.0.2安裝配置
- MongoDB安裝配置教程MongoDB