1. 程式人生 > >【運維管理】Nagios監控搭建與配置詳細步驟

【運維管理】Nagios監控搭建與配置詳細步驟

1.基礎支援套件:gcc glibc glibc-common gd gd-devel xinetd openssl-devel httpd php   注:php和httpd均用原始碼包安裝,安裝配置方法此處不在詳述

# yum install -y gcc glibc glibc-common gd gd-devel xinetd openssl-devel

2.建立Nagios賬戶和組

#useradd -m nagios
#groupadd nagcmd
#usermod -a -G nagcmd nagios
#usermod -a -G nagcmd apache

3.編譯安裝

#tar xvf nagios-3.5.1.tar.gz
#cd nagios-3.5.1
#./configure prefix=/usr/local/nagios --with-command-group=nagcmd --with-nagios-user=nagios --with-nagios-group=nagios
#make all
#make install
#make install-init        (生成init啟動指令碼)
#make install-config      (生成一些模板配置檔案)
#make install-commandmode (設定相應的許可權)
#make install-webconf     (生成Apache配置檔案nagios.conf)

4.為Nagios設定Web驗證的密碼

#/usr/local/apache/bin/htpasswd -c /usr/local/nagios/etc/htpasswd.user nagiosadmin

5.設定Nagios的開機啟動

chkconfig --add nagios
chkconfig nagios on

6.安裝Nagios的外掛nagios-plugin

#tar zxvf nagios-plugins-1.4.16.tar.gz
#cd nagios-plugins-1.4.16
#./configure --prefix=/usr/local/nagios --with-nagios-user=nagios --with-nagios-group=nagios
 --with-apt-get-command --with-ping6-command --with-ping-command --with-mysql
 --with-gnutls --enable-extra-opts
#make 
#make install


7.此時完成初步安裝,可以監控檢視本機的一些服務,檢測配置檔案並啟動nagios

#/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg

Nagios Core 3.5.1
Copyright (c) 2009-2011 Nagios Core Development Team and Community Contributors
Copyright (c) 1999-2009 Ethan Galstad
Last Modified: 08-30-2013
License: GPL

Website: http://www.nagios.org
Reading configuration data...
   Read main config file okay...
Processing object config file '/usr/local/nagios/etc/objects/commands.cfg'...
Processing object config file '/usr/local/nagios/etc/objects/contacts.cfg'...
Processing object config file '/usr/local/nagios/etc/objects/timeperiods.cfg'...
Processing object config file '/usr/local/nagios/etc/objects/templates.cfg'...
Processing object config directory '/usr/local/nagios/etc/servers'...
Processing object config file '/usr/local/nagios/etc/servers/localhost.cfg'...
   Read object config files okay...

Running pre-flight check on configuration data...

Checking services...
 Checked 6 services.
Checking hosts...
 Checked 1 hosts.
Checking host groups...
 Checked 0 host groups.
Checking service groups...
 Checked 0 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

出現此處,表明,配置檔案沒有錯誤,可以啟動nagios和apache

#service nagios start
#/usr/local/apache/sbin/apchectl

此時提示頁面無法訪問,原因在於由於Apache是原始碼包安裝,預設路徑和rpm包不一樣,需要在Apache的httpd.conf配置檔案中新增指定訪問路徑


8. 配置apache並載入nagios登入頁面  
找到apache 的配置檔案/usr/local/apache/conf/httpd.conf

找到:

User daemon 
Group daemon 修改為

User nagios 
Group nagios

為了安全起見,一般情況下要讓nagios 的web 監控頁面必須經過授權才能訪問,這需要增加驗證配置,即在httpd.conf 檔案最後新增如下資訊:

下面資訊在編譯nagios(make install-webconf )時就已經生成,配置資訊在:/etc/httpd/confd.d/nagios.conf 檔案中

#######################################################################
#setting for nagios
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.user
     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.user
     Require valid-user

###########################################################################

9.重啟nagios、apache並訪問nagios

#service nagios restart
#/usr/local/apache/bin/apachectl restart
http://192.168.6.6/nagions

提示輸入使用者名稱密碼,訪問成功

但是登陸進去後,nagios頁面右側全部亂碼
解決方法:

主要是apache沒有開啟cgi指令碼的緣故

進入apache的主配置檔案httpd.conf
#vim /usr/local/apache/conf/httpd.conf
 
#LoadModule cgid_module modules/mod_cgid.so
#LoadModule actions_module modules/mod_actions.so

將上面2行的#去掉,重啟apache就OK

再次訪問 ,亂碼消失OK!

(二)配置Nagios

1.nagios配置目錄資訊

# cd /usr/local/nagios/etc/
# ls
cgi.cfg  htpasswd.user  nagios.cfg  objects  resource.cfg
[[email protected] etc]# ll
total 68
-rw-rw-r-- 1 nagios nagios 11669 Nov 29 14:18 cgi.cfg (CGI配置檔案)
-rw-r--r-- 1 root   root      50 Nov 29 14:20 htpasswd.user (Apache的驗證密碼檔案)
-rw-rw-r-- 1 nagios nagios 44710 Nov 29 14:18 nagios.cfg (主配置檔案)
drwxrwxr-x 2 nagios nagios  4096 Nov 29 14:18 objects (物件定義檔案目錄)
-rw-rw---- 1 nagios nagios  1340 Nov 29 14:18 resource.cfg (資源配置檔案)

2.修改nagios.cfg主配置檔案

#vim nagios.cfg

註釋掉:cfg_file=/usr/local/nagios/etc/objects/localhost.cfg  ———— #cfg_file=/usr/local/nagios/etc/objects/localhost.cfg
將 #cfg_dir=/usr/local/nagios/etc/servers  的 #(註釋)去掉 -----  cfg_dir=/usr/local/nagios/etc/servers

在/usr/local/nagios/etc/目錄中新建 servers子目錄,在裡面可以直接新增主機配置檔案
#mkdir servers

3.配置object目錄中的配置檔案

#cd objects/
#ll
total 48
-rw-rw-r-- 1 nagios nagios  7716 Nov 29 14:18 commands.cfg (命令定義檔案)
-rw-rw-r-- 1 nagios nagios  2166 Nov 29 14:18 contacts.cfg (聯絡人資訊定義檔案)
-rw-rw-r-- 1 nagios nagios  5403 Nov 29 14:18 localhost.cfg
-rw-rw-r-- 1 nagios nagios  3124 Nov 29 14:18 printer.cfg
-rw-rw-r-- 1 nagios nagios  3293 Nov 29 14:18 switch.cfg
-rw-rw-r-- 1 nagios nagios 10812 Nov 29 14:18 templates.cfg
-rw-rw-r-- 1 nagios nagios  3208 Nov 29 14:18 timeperiods.cfg (時間週期定義檔案)
-rw-rw-r-- 1 nagios nagios  4019 Nov 29 14:18 windows.cfg

配置聯絡人資訊(郵件接收者郵箱地址)

儲存,退出。

(三)nrpe安裝配置

1.安裝nrpe

#tar zxvf nrpe-2.12.tar.gz
#cd nrpe-1.12
# ./configure && make all
#make install-plugin
#make install-daemon
#make install-daemon-config
#make install-xinetd

2.配置nrpe

#vim /etc/xinetd.d/nrpe
在only_from=127.0.0.1 後新增 192.168.6.6 以空格隔開

3.新增埠

#vim /etc/services       在最後新增   nrpe  5666/tcp   #nrpe


修改配置檔案/usr/local/nagios/etc/objects/commands.cfg加入對nrpe的支援

#vim /usr/local/nagios/etc/objects/commands.cfg     在末尾新增如下內容

##############################################################################
#nrpe set 
define command{ 
command_name check_nrpe 
command_line /usr/local/nagios/libexec/check_nrpe -H $HOSTADDRESS$ -c $ARG1$ 

##############################################################################


4.配置/usr/local/nagios/etc/nrpe.cfg 檔案

#cd /usr/local/nagios/etc/nrpe.cfg
#vim nrpe.cfg
將command[check_hda1]=/usr/local/nagios/libexec/check_disk -w 20% -c 10% -p /dev/hda1 中的hda1改為: sda  如下:
command[check_sda]=/usr/local/nagios/libexec/check_disk -w 20% -c 10% -p /dev/sda

將command[check_total_procs]=/usr/local/nagios/libexec/check_procs -w 150 -c 200  改為:
  command[check_total_procs]=/usr/local/nagios/libexec/check_procs -w 400 -c 450

新增 command[check_swap]=/usr/local/nagios/libexec/check_swap -w 90% -c 80%

儲存,退出。

重啟xinetd服務

OK,Nagios服務端安裝成功!!!

(四)Nagios客戶端安裝配置


#yum install -y openssl openssl-devel

#useradd -s /sbin/nlogin nagios


2.安裝nagios-plugin

# cd /opt/software/
#tar zxvf nagios-plugins-1.4.16.tar.gz
#cd nagios-plugin-1.4.16
#./configure --prefix=/usr/local/nagios --with-nagios-user=nagios --with-nagios-group=nagios --enable-libtap
--enable-redhat-pthread-workaround --with-apt-get-command --with-ping6-command --with-ping-command 
--with-mysql --with-gnutls --enable-extra-opts --with-openssl --with-trusted-path
#make
#make install

3.安裝配置nrpe

#yum install xinetd -y

#tar zxvf nrpe-2.12.tar.gz
#cd nrpe-2.12
#./configure && make all
#make install-plugin
#make install-daemon 
#make install-daemon-config 
#make install-xinetd

#vim /etc/xinetd.d/nrpe  
在only_from    = 127.0.0.1 後新增 nagios伺服器端IP地址 192.168.6.6 如下:
  only_from    = 127.0.0.1 192.168.6.6

#vim /etc/services
在檔案末尾新增 nrpe   5666/tcp      #nrpe

修改/usr/local/nagios/etc/nrpe.cfg

#cp -p  /usr/local/nagios/etc/nrpe.cfg    /usr/local/nagios/etc/nrpe.cfg.default   -修改前先備份一下該配置檔案

#vim /usr/local/nagios/etc/nrpe.cfg
將nrpe.cfg檔案中的 hda1 字元全部修改為 sda  
或者使用sed命令批量修改,如下:
sed  -i 's/hda1/sda/g'  /usr/local/nagios/etc/nrpe.cfg

新增swep分割槽監控:  command[check_swap]=/usr/local/nagios/libexec/check_swap -w 90% -c 80%

儲存,退出。

重啟xinetd服務 :
#service xinetd restart
 

(五) 在服務端/usr/local/nagios/etc/servers/目錄中新增編輯被監控主機配置檔案

1.本地主機配置檔案模版

#cd /usr/local/nagios/etc/servers
#touch localhost.cfg   注:localhost.cfg 為本地主機配置檔案
#vim localhost.cfg   新增如下模版內容
##########################################################################################
#define  host

define host{ 
host_name 192.168.6.6-nagios server     #主機名稱,可隨便定義
alias nagios Server                     #伺服器別名,監控端為Server 被監控端為 Client
address 192.168.6.6                     #伺服器端IP地址 或者被監控端IP地址
check_command check-host-alive          #檢查的命令
check_interval 1 
#retry_interval 1 
max_check_attempts 1 
check_period 24x7                       #檢查的時間範圍
process_perf_data 0 
retain_nonstatus_information 0 
contact_groups admins                   #聯絡人組
notification_interval 10                #檢查時間間隔,單位為分鐘 
notification_period 24x7 
notification_options d,u,r              #通知選項,d-宕機(down)  w-報警(warning)  u-未知(unkown) c-嚴重(critical) r-從異常情況恢復
}

#define services

#define check-host-alive
define service { 
host_name 192.168.6.6-nagios server 
service_description check-host-alive 
check_period 24x7 
max_check_attempts 1 
normal_check_interval 1 
#retry_check_interval 1 
contact_groups admins 
notification_interval 10 
notification_period 24x7 
notification_options w,u,c,r 
check_command check-host-alive 
}

define service { 
host_name 192.168.6.6-nagios server 
service_description check-users 
check_period 24x7 
max_check_attempts 4 
normal_check_interval 1 
retry_check_interval 1 
contact_groups admins 
notification_interval 10 
notification_period 24x7 
notification_options w,u,c,r 
check_command check_nrpe!check_users 
}

define service { 
host_name 192.168.6.6-nagios server 
service_description check-load 
check_period 24x7 
max_check_attempts 4 
normal_check_interval 1 
retry_check_interval 1 
contact_groups admins 
notification_interval 10 
notification_period 24x7 
notification_options w,u,c,r 
check_command check_nrpe!check_load 
}

define service { 
host_name 192.168.6.6-nagios server 
service_description check-total-procs 
check_period 24x7 
max_check_attempts 4 
normal_check_interval 1 
retry_check_interval 1 
contact_groups admins 
notification_interval 10 
notification_period 24x7 
notification_options w,u,c,r 
check_command check_nrpe!check_total_procs 
}

define service {
host_name 192.168.6.6-nagios server
service_description check_sda
check_period 24x7
max_check_attempts 4
normal_check_interval 1
retry_check_interval 1
contact_groups admins
notification_interval 10
notification_period 24x7
notification_options w,u,c,r
check_command check_nrpe!check_sda
}

define service {
host_name 192.168.6.6-nagios server
service_description check_swap
check_period 24x7
max_check_attempts 4
normal_check_interval 1
retry_check_interval 1
contact_groups admins
notification_interval 10
notification_period 24x7
notification_options w,u,c,r
check_command check_nrpe!check_swap
}
########################################################################################

2.其它主機配置檔案模版

#cd /usr/local/nagios/etc/servers/
#touch 192.168.2.33.cfg
#vim 192.168.2.33.cfg   新增如下內容

##################################################################################
#define  host

define host{ 
host_name 192.168.2.33-Test 
alias nagios Client 
address 192.168.2.33 
check_command check-host-alive 
check_interval 1 
#retry_interval 1 
max_check_attempts 1 
check_period 24x7 
process_perf_data 0 
retain_nonstatus_information 0 
contact_groups admins 
notification_interval 10 
notification_period 24x7 
notification_options d,u,r 
}

#define check-host-alive
define service { 
host_name 192.168.2.33-Test 
service_description check-host-alive 
check_period 24x7 
max_check_attempts 1 
normal_check_interval 1 
#retry_check_interval 1 
contact_groups admins 
notification_interval 10 
notification_period 24x7 
notification_options w,u,c,r 
check_command check-host-alive 
}

define service { 
host_name 192.168.2.33-Test 
service_description check-users 
check_period 24x7 
max_check_attempts 4 
normal_check_interval 1 
retry_check_interval 1 
contact_groups admins 
notification_interval 10 
notification_period 24x7 
notification_options w,u,c,r 
check_command check_nrpe!check_users 
}

define service { 
host_name 192.168.2.33-Test 
service_description check-load 
check_period 24x7 
max_check_attempts 4 
normal_check_interval 1 
retry_check_interval 1 
contact_groups admins 
notification_interval 10 
notification_period 24x7 
notification_options w,u,c,r 
check_command check_nrpe!check_load 
}

define service { 
host_name 192.168.2.33-Test
service_description check-total-procs 
check_period 24x7 
max_check_attempts 4 
normal_check_interval 1 
retry_check_interval 1 
contact_groups admins 
notification_interval 10 
notification_period 24x7 
notification_options w,u,c,r 
check_command check_nrpe!check_total_procs 
}

define service {
host_name 192.168.2.33-Test
service_description check_sda
check_period 24x7
max_check_attempts 4
normal_check_interval 1
retry_check_interval 1
contact_groups admins
notification_interval 10
notification_period 24x7
notification_options w,u,c,r
check_command check_nrpe!check_sda
}

define service {
host_name 192.168.2.33-Test
service_description check_swap
check_period 24x7
max_check_attempts 4
normal_check_interval 1
retry_check_interval 1
contact_groups admins
notification_interval 10
notification_period 24x7
notification_options w,u,c,r
check_command check_nrpe!check_swap
}
##############################################################################################

3.監控伺服器監控執行的埠

(1)Nagios客戶端配置

#vim /usr/local/nagios/etc/nrpe.cfg  檔案末尾新增定義埠資訊,如下:

command[check_TemplateUpload:8080]=/usr/local/nagios/libexec/check_tcp -H localhost -p 8080  -w 120 -c 180

儲存,退出

重啟xinetd服務

#service xinetd restart


(2)Nagios服務端配置

#vim /usr/local/nagios/etc/services/192.168.2.33.cfg 檔案末尾新增如下內容

define service {
host_name 192.168.2.33-Test
service_description check_TemplateUpload:8080  
check_period 24x7
max_check_attempts 4
normal_check_interval 1
retry_check_interval 1
contact_groups admins
notification_interval 10
notification_period 24x7
notification_options w,u,c,r
check_command check_nrpe!check_TemplateUpload:8080
}

儲存,退出

重啟nagios服務

#service nagios restart

訪問Nagios服務

大功告成!!!!!

相關推薦

管理Nagios監控搭建配置詳細步驟

1.基礎支援套件:gcc glibc glibc-common gd gd-devel xinetd openssl-devel httpd php   注:php和httpd均用原始碼包安裝,安裝配置方法此處不在詳述 # yum install -y gcc glibc glibc-common gd

管理人員必須熟悉的工具彙總

運維人員必須熟悉的運維工具彙總 某日受邀請參加了一個BBS活動,於是有了下面的內容。 下面是在linux網站運維方向老男孩最近幾年常用的免費的開源軟體,臨時即興想起來的,在這裡和大家分享,希望給初學者指引一點路。 linux的世界真的很精彩,還沒入門的朋友趕緊進來吧!

心得查得到資料頁面卻不顯示的解決方案

今天工作中碰到一個詭異的問題,如下圖,明明查出來是有31條資料,但是頁面上缺沒有顯示? 一開始認為是js的問題,前臺介面程式碼過濾了一遍,結果發現很簡單,沒有發現什麼問題,如下: sortOrder: 'desc', pagination: true, pageNum

理論RAID級別簡介

獨立硬碟冗餘陣列(RAID, Redundant Array of Independent Disks),舊稱廉價磁碟冗餘陣列(RAID, Redundant Array of Inexpensive Disks),簡稱硬碟陣列。由伯克利大學一位教授提出,其基本思想就是把多個相對便宜的硬碟組合起來,成為一個硬

心得如何應對停電

運維工作中,經常會碰到停電的事情,有臨時檢修的,有消防演習的(當然最好只是演習),有故障巡檢的。。。 碰到這種情況,如何應對,才能保證辦公網路和通訊,在恢復供電以後保證正常呢? 根據個人的經驗,總結如下,供大家參考,如果有更好的辦法,請直接回復即可。 首先,停電前的準備。弄清楚停電的

筆記Git

Git分散式版本控制系統 ## 依賴安裝 yum install curl-devel expat-devel openssl-devel zlib-devel gcc perl-ExtUtils-MakeMaker ## 配置使用git倉庫的人員姓名 git config --g

筆記nginx反向代理

http{ }模組 http負載 stream{ }模組 ssh轉發 stream { upstream sshtest1 { server 192.168.1.100:22; server 192.168.1.200:22; } server {

筆記Eclipse中git外掛的使用

我這個是比較新的版本,已經集成了EGit外掛,其他版本的可以自己安裝一下: 使用Eclipse Marketplace安裝: 用Install New Software安裝 安裝源 http://mirrors.ustc.edu.cn/eclipse/e

筆記Git程式碼回滾

先用Eclipse演示一下git回滾的操作, 想知道Eclipse中git外掛的安裝和使用的,可以看一下我的另一篇文章 https://blog.csdn.net/wuguifa/article/details/86134534 從git遠端倉拉取一個專案,演

實戰一次linux日誌分割之路——將日誌按照每小時進行分割,並按照“日期-小時”格式保存

linu 一次 圖片 威脅 rontab acc 記錄 進一步 bash 是這樣的,現在需要對nginx的access.log進行按照每小時進行分割,並且最好還要能夠以 “日期+時間”的形式,命名保存。 兩點,一個是按照每小時進行分割,一個是將日誌以“日期+時間”的形式進行

安全-安全術語

訪問 分享圖片 子集 聯網 匿名 美國 交換 殺毒軟件 別人 什麽是抓雞? 指通過掃描弱口令、爆破、漏洞自動化種馬達到控制機器。 被種了馬的機器,會被用來對別人實行DDos GJ,或者用來刷流量,刷廣告,或者當跳板,用來做違法的事情。 1433抓雞(Sql

安全-***流程

特定 com 9.png 想要 進行 分享圖片 inf 分享 數據 常規***; 1.簽訂保密協議 2.針對性目標進行測試 3.指定範圍去測試 非常規:1.APT***,沒有指定範圍,沒有特定目標,不擇手段的去獲取我想要的數據。***測試流程:***

安全-HTTP協議

src 推薦 詳情 ima 如果 image des baidu www. 如果想深入了解,推薦《圖解HTTP》,網上有PDF版。 兩個命令: curl curl www.baidu.com 可以看到網頁信息 curl www.baidu.com -I

安全-BurpSuite安裝

過去 ava 學習 地方 運維 結果 配置環境變量 本地 image 軟件所需環境:jdk1.8,因為是java開發的下圖為界面圖片,學習是為了獲取HTTP的數據包,進行攔截,修改數據庫包的測試。1.安裝JDK,並配置環境變量。2.找到burpsuite.jar文件,單擊右

安全-Fiddler-抓包工具

技術 ofo 發送 com href 官網 bubuko 運維安全 抓包工具 https://www.telerik.com/fiddler 官網地址會攔截電腦發送的一些http請求。【運維安全】-Fiddler-抓包工具

安全- 什麽是SQL註入

不同的 原理 bubuko 數據 最終 語句 技術 技術分享 上傳 為什麽要學Web漏洞? 1.需要看懂日誌,別人是怎麽***的? 2.需要看懂別人提交的***語句。 3.需要看懂別人怎麽操作的 SQL註入原理: 把sql語句插入web的表中,提交的查詢sql,上傳給數據庫

安全-註入分類

大量 mage sql apps png p地址 提交 技術 .com 如何去發現SQL註入? 1.通過Web漏洞掃描工具:APPScan、AWVS、 2.在參數後面添加特殊字符,比如單引號,各種各樣的字符,通過提交字符,是否有報錯的行為,來判斷是否有註入漏洞。 3.通

Flutter 系列——1Flutter環境搭建配置這一篇就夠了(Windows)

最近正式入坑Flutter,首先從環境搭建開始,看了網上好多關於Windows環境搭建的資料,基本都是按官方文件寫的,看完的感受是,還不如直接去看官方文件。 本文主要總結我實際搭建的過程,最後發現不一定按網上那些部落格或者官方文件寫的來也可以搭建成功。 總的來說需要的

老鳥中秋新作以太坊聯盟鏈-多節點私鏈搭建手冊

成功 main 情況下 tex exp 配置環境 bmi 手冊 aliyun 修訂日期 姓名 郵箱 2018-09-23 brucefeng [email protected] 一. 前言 這半個月都在處理其他的事情,沒來得及更新博客,今天看

NagiosLinux下Nagios的安裝配置

一、Nagios簡介   Nagios是一款開源的電腦系統和網路監視工具,能有效監控Windows、Linux和Unix的主機狀態,交換機路由器等網路設定,印表機等。在系統或服務狀態異常時發出郵件或簡訊報警第一時間通知網站運維人員,在狀態恢復後發出正常的郵件或簡訊通知。