centos7.4安裝監視軟體系列2:nagios

來源:互聯網
上載者:User

標籤:nagios   監控   

與系列1的Cacti類似,nagios也是一種監視軟體,涉及外掛程式較多,可靈活監控伺服器資源,使用更廣泛;
nagios自身是沒有監控功能的,它所有的功能都是通過調用外掛程式來完成的,它的工作模式有兩種:主動式監控、被動監控。
【被動監控】nagios通過nsca進行被動監控。就是由被檢測端伺服器主動上傳資料到nagios監控系統中,然後nagios讀取資料。這種監控方式提高了資料的即時性,降低監控延遲,監控的資料量也大大增加。目前已知的只有nsca外掛程式可以支援被動監控。
【主動式監控】nagios通過nrpe外掛程式和snmp協議進行主動式監控。Nagios會周期性地調用外掛程式去擷取遠程主機的資料,這樣一來即時性就差了一些。對於監控主機數量少的情況可以採用主動模式。

這裡介紹主動式監控的配置:

nagios調用它的外掛程式庫,外掛程式將監控結果返回給nagios,nagios分析這些結果並以web的方式展現給我們看,同時也會調用外掛程式提供警示功能。
而對於遠程監控則需要check_nrpe外掛程式,nagios執行該外掛程式,並告訴check_nrpe去檢測哪些服務。check_nrpe通過SSL串連遠端機器上的NRPE daemon,然後NRPE 可以運行本地的各種外掛程式去檢測本地的服務和狀態,最後NRPE把檢測的結果傳給nagios端的check_nrpe,nagios端的check_nrpe再把結果送到狀態隊列中讓nagios讀取資訊,最終呈現給管理員的web頁面結果。
Nagios的四種監控狀態:
0(OK)正常,綠色
1(warning)警告,×××
2(Critical)嚴重錯誤,紅色
3(unknown)位置錯誤,深×××

本例:監控用戶端的mysql

nagios服務端(監控端):192.168.80.80 需安裝如下軟體:
LAMP架構 提供網頁監控查看
nagios-4.3.4.tar.gz 服務端nagios主程式
nagios-plugins-2.2.1.tar.gz nagios外掛程式
nrpe-3.2.1.tar.gz 外掛程式,負責遠端連線
pnp4nagios-0.6.26.tar.gz 圖表工具

ngios用戶端(被監控):192.168.80.81 需安裝如下軟體:
nagios-plugins-2.2.1.tar.gz nagios外掛程式
nrpe-3.2.1.tar.gz 外掛程式,負責遠端連線
mysql 編譯安裝,僅供測試

案例實施:一.服務端(監控端)配置1.安裝lamp,可yum安裝,節省時間,調試可提供網站服務即可;2.安裝nagios:

groupadd nagcmd
useradd -G nagcmd nagios
usermod -a -G nagcmd apache
id -n -G apache

tar xf nagios-4.3.4.tar.gz
cd nagios-4.3.4
./configure --with-command-group=nagcmd

make all

make install
make install-init //產生管理指令碼
make install-commandmode //自動為nagios使用者佈建相關目錄的許可權
make install-config //安裝設定檔

cp -R contrib/eventhandlers/ /usr/local/nagios/libexec/
chown -R nagios:nagios /usr/local/nagios/libexec/eventhandlers
/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg //檢查設定檔
/etc/init.d/nagios checkconfig //檢查配置問題
make install-webconf //產生nagios/apache設定檔

htpasswd -c /usr/local/nagios/etc/htpasswd.users nagios

service nagios start
service httpd restart

win10訪問http://192.168.80.80/nagios/ //會進入nagios的主控制台,且會有登陸提示

3.安裝nagios-plugins

tar xf nagios-plugins-2.2.1.tar.gz
cd nagios-plugins-2.2.1
./configure \
--with-nagios-user=nagios \
--with-nagios-group=nagcmd \
--enable-perl-modules

make && make install

4.安裝nrpe

tar xf nrpe-3.2.1.tar.gz
cd nrpe-3.2.1
./configure
make all
make install-plugin
make install-daemon

cp sample-config/nrpe.cfg /usr/local/nagios/etc/nrpe.cfg

ls /usr/local/nagios/libexec/ //檢查外掛程式安裝情況

/usr/local/nagios/bin/nrpe -d -c /usr/local/nagios/etc/nrpe.cfg //啟動nrpe

echo "/usr/local/nagios/bin/nrpe -d -c /usr/local/nagios/etc/nrpe.cfg" >> /etc/rc.local //可設定開機啟動

chmod +x /etc/rc.d/rc.local
netstat -lnput|grep 5666

/usr/local/nagios/libexec/check_nrpe -H localhost //測試本地串連
NRPE v3.2.1

二:用戶端(被監控)設定1.手動編譯安裝mysql,測試可提供mysql服務2.安裝nagios-plugins

yum install -y perl-devel perl-CPAN openssl-devel

tar xf nagios-plugins-2.2.1.tar.gz

useradd -M nagios

cd nagios-plugins-2.2.1
./configure \
--with-nagios-user=nagios \
--with-nagios-group=nagios \
--enable-perl-modules

make && make install

3.安裝nrpe

tar xf nrpe-3.2.1.tar.gz
cd nrpe-3.2.1

./configure

make all
make install-plugin
make install-daemon

mkdir /usr/local/nagios/etc/
cp sample-config/nrpe.cfg /usr/local/nagios/etc/nrpe.cfg //複製模板,下面需要配置使用

ls /usr/local/nagios/libexec/ //查看nrpe外掛程式

/usr/local/nagios/bin/nrpe -d -c /usr/local/nagios/etc/nrpe.cfg //啟動nrpe

echo "/usr/local/nagios/bin/nrpe -d -c /usr/local/nagios/etc/nrpe.cfg" >> /etc/rc.local //可添加到開機啟動

chmod +x /etc/rc.d/rc.local
netstat -lnput|grep 5666

/usr/local/nagios/libexec/check_nrpe -H localhost //測試本地串連
NRPE v3.2.1

4.配置nrpe.cfg

cd /usr/local/nagios/etc/

vi nrpe.cfg

allowed_hosts=127.0.0.1,::1,192.168.80.80 //後面添加監控端80地址,允許服務端地址串連
command[check_users]=/usr/local/nagios/libexec/check_users -w 5 -c 10
//定義檢查使用者的命令,超過5個使用者w-warning。超過10個使用者c-critical 下同
command[check_load]=/usr/local/nagios/libexec/check_load -r -w .15,.10,.05 -c .30,.25,.20
command[check_sda1]=/usr/local/nagios/libexec/check_disk -w 20% -c 10% -p /dev/sda1
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
//以上都是用戶端定義的nrpe命令,可以被監控端nrpe調用,從而實現監控

/usr/local/nagios/libexec/check_nrpe -H localhost -c check_total_procs
//可先測試本地命令執行情況,確保沒有問題

三:服務端(監控端)配置測試1.測試兩台機nrpe是否能遠端連線

pkill nrpe
/usr/local/nagios/bin/nrpe -d -c /usr/local/nagios/etc/nrpe.cfg //重啟nrpe

/usr/local/nagios/libexec/check_nrpe -H 192.168.80.81 //測試連接情況
/usr/local/nagios/libexec/check_nrpe -H 192.168.80.81 -c check_sda1 //測試命令是否可執行

2.配置

vi /etc/usr/local/nagios/etc/nagios.cfg //配置主設定檔
cfg_dir=/usr/local/nagios/etc/conf //最後或合適位置新增子目錄,便於配置
mkdir /usr/local/nagios/etc/conf

vi /etc/usr/local/nagios/etc/objects/commands.cfg //配置命令設定檔,其中定義的命令可被其他設定檔調用
define command{
command_name check_nrpe
command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$
} //最後插入 增加對check_nrpe的定義

vi /etc/usr/local/nagios/etc/objects/contacts.cfg //配置連絡人或組,用於出現問題時通知
emial [email protected] //管理員郵箱地址

cd /usr/local/nagios/etc/conf //開始定義主機和主機群組、服務
vi host81.cfg //定義主機和主機群組
define host{
use linux-server //監控使用的模板
host_name mysql //監控平台上顯示的名稱
alias www.bb.com //監控平台上顯示的名稱
address 192.168.80.81 //被控端地址
}
define hostgroup{ //定義主機群組
hostgroup_name testgroup
alias mysql
members mysql
}

vi server81.cfg //定義服務 使用的check_command要在commands.cfg中定義過

define service{
host_name mysql //監控服務名
service_description check-host-alive //監控描述
check_command check-host-alive //監控命令名(主機是否存活)
max_check_attempts 3 //檢查失敗後重試次數
check_interval 2 //檢查間隔時間
retry_interval 2 //稍候再試時間
check_period 24x7 //監控時間段 timeperiods.cfg中定義的時間
notification_interval 300 //提醒的間隔時間,每300秒提醒一次
notification_period 24x7 //提醒的周期,是在timeperiods.cfg中定義的
notification_options w,u,c,r //當主機出現w-warning, u-unknown,c-critical,r-從異常狀態恢複時提醒管理員(d-down)
#contact_groups admins
process_perf_data 1
}
define service{
host_name mysql
service_description check-procs
check_command check_nrpe!check_total_procs
max_check_attempts 3
check_interval 2
retry_interval 2
check_period 24x7
notification_interval 300
notification_period 24x7
notification_options w,u,c,r
#contact_groups admins
process_perf_data 1
}
define service{
host_name mysql
service_description check-load
check_command check_nrpe!check_load
max_check_attempts 3
check_interval 2
retry_interval 2
check_period 24x7
notification_interval 300
notification_period 24x7
notification_options w,u,c,r
#contact_groups admins
process_perf_data 1
}
define service{
host_name mysql
service_description check-ssh
check_command check_ssh
max_check_attempts 3
check_interval 2
retry_interval 2
check_period 24x7
notification_interval 300
notification_period 24x7
notification_options w,u,c,r
#contact_groups admins
process_perf_data 1
}

cd /usr/local/nagios/etc //增加nagios組授權
grep nagiosadmin cgi.cfg //檢查設定檔中相關授權的使用者組預設只有nagiosadmin
sed -i ‘s/nagiosadmin/nagiosadmin,nagios/g‘ cgi.cfg //增加nagios組授權

service nagios restart

3.測試:

win10訪問http://192.168.80.80/nagios 就可以看到監控主機80.81

至此,nagios監控基本配置完畢,如何圖形化更直觀的在web上查看呢?就要添加使用圖形化模組,未完待續。。。

centos7.4安裝監視軟體系列2:nagios

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.