溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

rhel6-nagios的安裝與配置

發(fā)布時間:2020-06-03 04:05:05 來源:網(wǎng)絡(luò) 閱讀:4724 作者:木魚梵心 欄目:移動開發(fā)

軟件下載地址:http://yunpan.cn/QbFvRDxugZZsT

這里有配置nagios所需的所有的各種版本的軟件資源,包括fetion資源


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

nagios主機:desk32.example.com 192.168.122.32\

mysql主機:desk3.example.com 192.168.122.3

2.nagios的安裝:

nagios是用一些命令在被監(jiān)控主機上運行后將采集的信息返回。

編譯需要的依賴包:

yum install httpd gcc make gd-devel perl-ExtUtils-Embed.x86_64 -y
yum  -y   localinstall  gd-devel-2.0.35-10.el6.x86_64
useradd nagios          #運行 nagios 服務(wù)的用戶
usermod -G nagios apache        #使 apache 用戶對 nagios 目錄具有寫權(quán)限,不然 web 頁面操作失敗
 tar jxf nagios-cn-3.2.3.tar.bz2
cd nagios-cn-3.2.3
useradd  nagios
usermod -G nagios apache
./configure --prefix=/usr/local/nagios --enable-embedded-perl
make all
make install
make install-init
make install-commandmode
make install-config
make install-webconf


bin Nagios 執(zhí)行程序所在目錄,這個目錄只有一個文件 nagios

etc Nagios 配置文件位置,初始安裝完后,只有幾個*.cfg-sample 文件

sbin Nagios Cgi 文件所在目錄,也就是執(zhí)行外部命令所需文件所在的目錄

share Nagios 網(wǎng)頁文件所在的目錄

var Nagios 日志文件、spid 等文件所在的目錄


3.安裝nagios-plugin插件:

安裝依賴包:

yum -y install mysql-devel openssl-devel
[root@desk32 nagios-plugins-1.4.16]# ./configure --with-nagios-user=nagios --with-nagios-group=nagios --enable-extra-opts  --enable-perl-modules
[root@desk32 nagios-plugins-1.4.16]#make && make install


再沒有安裝插件前在/usr/local/nagios/libexec下沒有東西,安裝后次目錄下安裝的是nagios用于檢查的命令。


[root@desk32 nagios-plugins-1.4.16]# cd /usr/local/nagios/
[root@desk32 nagios]# ls
bin  etc  include  libexec  perl  sbin  share  var
[root@desk32 nagios]# ls libexec/
…........check_apt check_file_age check_jabber check_nt        check_rpc       check_time   check_breeze    check_flexlm        check_load         check_ntp  …...........

主配置文件 nagios.cfg 定義和控制 nagios 行為 需要修改

Cgi 配置文件 cgi.cfg 瀏覽器執(zhí)行諸如重啟 nagios 服務(wù)等要修改

宏定義文件 Resource.cfg 定義插件路徑 不需修改

命令定義文件 Commands.cfg 定義怎么發(fā)送短信、郵件等 需要修改

其他文件 contactgroups.cfg,contacts.cfg 監(jiān)控對象配置文件,如主機 主配置文件,包含,手動聯(lián)系人配置文件

[root@desk32 etc]# vim nagios.cfg
#注釋或刪掉這行
#cfg_file=/usr/local/nagios/etc/localhost.cfg
#主機配置文件路徑
cfg_file=/usr/local/nagios/etc/objects/hosts.cfg
cfg_file=/usr/local/nagios/etc/objects/service.cfg
//將服務(wù)與主機分開    
#//主機組配置文件路徑
cfg_file=/usr/local/nagios/etc/hostgroups.cfg
#聯(lián)系人配置文件路徑
cfg_file=/usr/local/nagios/etc/contacts.cfg
#聯(lián)系組配置文件路徑
cfg_file=/usr/local/nagios/etc/contactgroups.cfg
#服務(wù)配置文件路徑
cfg_file=/usr/local/nagios/etc/services.cfg
#監(jiān)視時段配置文件路徑
cfg_file=/usr/local/nagios/etc/timeperiods.cfg
#在 web 界面下重啟 nagios、停止主機/服務(wù)檢查等操作,.默認值是 0.
check_external_commands=1
#根據(jù)自己的情況定這個命令檢查時間間隔.默認值是 1 秒.
command_check_interval=10s

注意:以上的有些文件的位置是不正確的。因為存在軟件的升級等原因,文件位置有一些的調(diào)整

[root@desk32 objects]# cp localhost.cfg hosts.cfg #創(chuàng)建主機定義文件
[root@desk32 objects]# cp localhost.cfg service.cfg   #創(chuàng)建服務(wù)定義文件
[root@desk32 objects]#vim hosts.cfg  #只剩下對于主機及主機組的定義將服務(wù)的定義刪掉
#########################################
# HOST DEFINITION
#########################################
# Define a host for the local machine
define host{
        use                     linux-server         
        host_name               desk32.example.com
        alias                   ngios服務(wù)器
        address                 127.0.0.1
        icon_p_w_picpath              switch.gif
        statusmap_p_w_picpath         switch.gd2
        2d_coords               100,200
        3d_coords               100,200,100
        }
define host{
        use                     linux-server
        host_name               王茲銀家電機
        alias                   家庭上網(wǎng)用機
        parents                 desk32.example.com
        address                 127.0.0.1
        icon_p_w_picpath              web.gif
        statusmap_p_w_picpath         web.gd2
        2d_coords               100,300
        3d_coords               100,300,100
        }
#####################################################################
# HOST GROUP DEFINITION
#####################################################################
# Define an optional hostgroup for Linux machines
define hostgroup{
        hostgroup_name  linux-servers
        alias           Linux Servers
        members         *       #包含的主機“*”代表包含上定義的所有的主機
        }
define hostgroup{
        hostgroup_name 家用機器組
        alias   放在家里用的PC機
       members 王茲銀家電機   #只包含主機“王茲銀家電機”
#        members     *
       #包含所有主機
        }


以下就是主機組的區(qū)別:

rhel6-nagios的安裝與配置

以下關(guān)于服務(wù)的定義:

[root@desk32 objects]# vim /usr/local/nagios/etc/objects/service.cfg
#########################################
# SERVICE DEFINITIONS
#########################################
define service{
        use                             local-service      
        host_name                       *
      #表示此服務(wù)將監(jiān)控所有主機
        service_description             PING
        }
define service{
        use                             local-service       
        host_name                       *
        service_description             根分區(qū)
        }
define service{
        use                             local-service      
        host_name                       desk32.example.com
   #該服務(wù)只監(jiān)控desk32
        service_description             登錄用戶數(shù)
        }
define service{
        use                             local-service      
        host_name                       desk32.example.com
        service_description             進程總數(shù)
        }
define service{
        use                             local-service       
        host_name                       desk32.example.com
        service_description             系統(tǒng)負荷
        }
define service{
        use                             local-service     
        host_name                       desk32.example.com
        service_description             交換空間利用率
        }
define service{
        use                             local-service    
        host_name                       desk32.example.com
        service_description             SSH
        }
define service{
        use                             local-service     
        host_name                       desk32.example.com
        service_description             HTTP
        }
#########################################
#DEFINE SERVICEGROUP
#########################################
define servicegroup{
        servicegroup_name       系統(tǒng)檢查
        alias                   系統(tǒng)狀況
    embers desk32.example.com,PING,desk32.example.com,根分區(qū),desk32.example.com,登錄用戶數(shù),desk32.example.com,系統(tǒng)負荷,desk32.example.com,交換空間利用率,desk32.example.com,SSH,desk32.example.com,HTTP,desk32.example.com,進程總數(shù)
        }


rhel6-nagios的安裝與配置

ot@desk32 objects]# /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
Total Warnings: 0
Total Errors:   0
#保證配置文件的語法沒有問題
[root@desk32 etc]# /etc/init.d/nagios start


4.apache的安裝配置:

yum -y install httpd
配置apache的虛擬主機:
[root@desk32 conf]# vim /etc/httpd/conf/httpd.conf
NameVirtualHost *:80
<VirtualHost *:80>
    DocumentRoot /usr/local/nagios/share
    ServerName nagios.example.com
</VirtualHost>
[root@desk32 conf]# /etc/init.d/httpd restart
[root@desk32 conf]# htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin
#nagios 監(jiān)控頁面訪問用戶和密碼


以上的管理員的用戶信息實在:/usr/local/nagios/etc/cgi.cfg中定義的,當然是可以修改的;

#如有多個用戶,中間用逗號隔開

authorized_for_system_information=sery

authorized_for_configuration_information=sery

authorized_for_system_commands=sery

authorized_for_all_services=sery

authorized_for_all_hosts=nagiosadmin,sery

authorized_for_all_service_commands=sery

authorized_for_all_host_commands=sery

在這里指定的用戶”sery”可以通過瀏覽器操縱 nagios 服務(wù)的關(guān)閉、重啟等各種操作

完成以上的所有操作后我們在裝有瀏覽器的主機上添加虛擬主機中的域名解析:

192.168.122.32nagios.example.com

網(wǎng)頁訪問:http://nagios.example.com

rhel6-nagios的安裝與配置

rhel6-nagios的安裝與配置


2ngios監(jiān)控其他的主機

1)監(jiān)控mysql主機的mysql服務(wù):

mysql 主機上運行有 mysql 服務(wù),在其上創(chuàng)建監(jiān)控檢測帳戶

mysql> create database nagdb;
mysql> grant select on nagdb.* to nagdb@'192.168.122.32';
mysql> flush privileges;
[root@desk32 libexec]# cd /usr/local/nagios/libexec/
[root@desk32 libexec]# ./check_mysql -H 192.168.122.3 -u nagdb -d nagdb
Uptime: 363  Threads: 1  Questions: 6  Slow queries: 0  Opens: 15  Flush tables: 1  Open tables: 8  Queries per second avg: 0.16
## -H 指定檢測的主機,-u 制定select mysql的用戶,-d  指定登錄select的數(shù)據(jù)庫


添加監(jiān)控主機信息:

vim /usr/local/nagios/etc/objects/hosts.cfg   添加:
define host{
        use                     linux-server
        host_name              desk3.example.com
        alias                   mysql服務(wù)器
        address                 192.168.122.3 ;desk3.example.com
        icon_p_w_picpath              server.gif
        statusmap_p_w_picpath         server.gd2
        2d_coords               500,200
        3d_coords               500,200,100
        }
[root@desk32 objects]# vim /usr/local/nagios/etc/objects/service.cfg
添加:
###################check_mysql#############################
define service{
        use                     local-service
        host_name               desk3.example.com
        service_groups          mysql服務(wù)組
        service_description     mysql服務(wù)
        check_command           check_mysql
        }
##########################check_mysql_groups#########################
define servicegroup{
        servicegroup_name       mysql服務(wù)組
        alias                   mysql服務(wù)器
        members desk3.example.com,mysql服務(wù)
        }
對于位置在libexec下的命令還必須在commands.cfg中定義才可以使用;
#####################check_mysql###########################
define command{
        command_name    check_mysql
        command_line    $USER1$/check_mysql -H $HOSTADDRESS$ -u nagdb -d nagdb
        }
#$USER1$ 這的就是libexec目錄
[root@desk32objects]# /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
[root@desk32 objects]# /etc/init.d/nagios reload

rhel6-nagios的安裝與配置


刷新網(wǎng)頁后發(fā)現(xiàn)主機數(shù)多了一個:在該主機下的服務(wù):

rhel6-nagios的安裝與配置


以上的mysql服務(wù)之所以可以直接就可以監(jiān)控遠程的主機,是因為chek_mysql的命令本身就帶有-H指定主機訪問主機的能力;其他的監(jiān)控命令

并沒有這樣的功能,所以監(jiān)控遠程的其他的服務(wù)必須借助nrpe插件:

rhel6-nagios的安裝與配置


The NRPE addon consists of two pieces:

The check_nrpe plugin, which resides on the local monitoring machine

The NRPE daemon, which runs on the remote Linux/Unix machine

When Nagios needs to monitor a resource of service from a remote Linux/Unix machine:

Nagios will execute the check_nrpe plugin and tell it what service needs to be checked

The check_nrpe plugin contacts the NRPE daemon on the remote host over an (optionally) SSL-protected connection

The NRPE daemon runs the appropriate Nagios plugin to check the service or resource

The results from the service check are passed from the NRPE daemon back to the check_nrpe plugin, which then returns the check results to the Nagios process.

Note: The NRPE daemon requires that Nagios plugins be installed on the remote Linux/Unix host. Without these,the daemon wouldn't be able to monitor anything.


nagios主機上使用check_nrpe通過ssl鏈接遠程的主機的nrpe使用遠程主機上的命令檢查主機信息然后又將檢查的信息返回;

所以在遠程主機上要按裝nrpenagios-plugins


在遠程主機desk3:


tar zxf nagios-plugins-1.4.16.tar.gz
cd nagios-plugins-1.4.16
./configure --with-nagios-user=nagios --with-nagios-group=nagios --enable-extra-opts --enable-perl-modules  --enable-libtap –with-openssl
make && make install
[root@desk3 nrpe-2.14]# cd /usr/local/nagios/
[root@desk3 nagios]# chown  nagios.nagios . -R
[root@desk3 nrpe-2.14]# yum -y install xinetd #用于管理nrpe的啟動端口信息
tar zxf nrpe-2.14.tar.gz
cd nrpe-2.14
[root@desk3 nrpe-2.14]./configure
[root@desk3 nrpe-2.14]# make all
[root@desk3 nrpe-2.14]# make install
[root@desk3 nrpe-2.14]# make install-daemon-config
[root@desk3 nrpe-2.14]# make install-xinetd
[root@desk3 nagios]# vim /etc/xinetd.d/nrpe
        only_from       = 192.168.122.32
[root@desk3 nagios]# vim /etc/services
nrpe            5666/tcp #TCP port service nrpe
[root@desk3 etc]# vim /usr/local/nagios/etc/nrpe.cfg
command[check_disk]=/usr/local/nagios/libexec/check_disk -w 20% -c 10% -p /
因為系統(tǒng)上的分區(qū)可能會是lvm所以這樣修改
[root@desk3 etc]# /etc/init.d/xinetd restart
[root@desk3 etc]# netstat -anplt
tcp        0      0 :::5666                     :::*                LISTEN      3984/xinetd
因為在nagios主機上是通命令check_nrpe實現(xiàn)的所以在ngios主機上同樣安裝nrpe
[root@desk32 libexec]# ./check_nrpe -H 192.168.122.3
NRPE v2.14
    #看見如此信息則表明nrpe征程鏈接



Configuring Things On The Nagios Host


command definition for the check_nrpe plugin would look like this:

[root@desk32 libexec]# vim /usr/local/nagios/etc/objects/commands.cfg
###################chek_nrpe##############################
define command{
        command_name    check_nrpe
        command_line    /usr/local/nagios/libexec/check_nrpe -H $HOSTADDRESS$ -c $ARG1$
        }
###################check_nrpe#########################################
define service{
        use                     generic-service
        host_name               desk3.example.com
        service_description     CPU-LOAD
        check_command           check_nrpe!check_load
        }
define service{
        use                     generic-service
        host_name               desk3.example.com
        service_description     USERS
        check_command           check_nrpe!check_users
        }
define service{
        use                     generic-service
        host_name               desk3.example.com
        service_description     GEN-Free-Space
        check_command           check_nrpe!check_disk
        }
define service{
        use                     generic-service
        host_name               desk3.example.com
        service_description     Zombie-Process
        check_command           check_nrpe!check_zombie_procs
        }
define service{
        use                     generic-service
        host_name               desk3.example.com
        service_description     Total-Process
        check_command           check_nrpe!check_total_procs
        }
##########################check_nrpe+mysql_groups#####################
define servicegroup{
        servicegroup_name       遠程服務(wù)組
        alias                  mysql+nrpe服務(wù)
 members desk3.example.com,CPU-LOAD,desk3.example.com,USERS,    \
desk3.example.com,GEN-Free-Space,desk3.example.com,Zombie-          \
Process,desk3.example.com,Total-Process,desk3.example.com,mysql服務(wù)       
        }
為了方便查看將host.cfg中的主機的定義中的desk3.example.com的alias改為了“遠程主機”
[root@desk32 libexec]# /usr/local/nagios/bin/nagios -v               \
/usr/local/nagios/etc/nagios.cfg
[root@desk32 libexec]# /etc/init.d/nagios reload

rhel6-nagios的安裝與配置


可以看見遠程的主機desk3nrpe的那幾個服務(wù)已經(jīng)添加進來了;


測試:

mysql測試:

遠程mysql主機上:


[root@desk3 etc]# /etc/init.d/mysqld stop

rhel6-nagios的安裝與配置

[root@desk3 etc]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/vol0-root
    3.9G  1.1G  2.6G  31% /
[root@desk3 etc]# dd if=/dev/zero of=/bigfile bs=510M count=5
[root@desk3 etc]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/vol0-root
    .9G  3.6G   66M  99% /

rhel6-nagios的安裝與配置


naios采集到的所有的圖形信息,均存儲與rrdtool的環(huán)形數(shù)據(jù)庫中,其數(shù)據(jù)在/usr/local/nagios/var/rrd下存儲的;


5.圖形日志顯示:

rhel6-nagios的安裝與配置

后“圖書”標志為圖形日志,當前無法顯示:

[root@desk32 ~]# yum localinstall rrdtool-perl-1.3.8-6.el6.x86_64.rpm
[root@desk32 logs]# yum -y install perl-CGI

刷新后即可出現(xiàn)圖形化的日志信息



6.ngios整合飛信報警


linux: http://www.it-adv.net/fetion/downng/fetion20090406003-linux.tar.gz

linux 下需要的四個文件:http://www.it-adv.net/fetion/downng/library_linux.tar.gz

libACE.so.5.6.8

libACE_SSL.so.5.6.8

libcrypto.so.0.9.8

libssl.so.0.9.8

>> 使用說明 <<

以下參數(shù)提供登錄用的賬號密碼(三種方式,手機號-密碼 飛信號-密碼 文件--索引)

--mobile=[手機號]登錄手機號

--sid=[飛信號]登錄飛信號

--pwd=[密碼]登錄密碼

--config=[文件名]存儲手機號、密碼的文件。

--index=[索引號]索引

--msg-utf8=[信息]發(fā)送的消息,UTF8 編碼

--msg-gb=[信息]發(fā)送的消息,GB 編碼

--file-utf8=[文件 utf8 格式]發(fā)送文件內(nèi)容

--file-gb=[文件 gb 格式]發(fā)送文件內(nèi)容

--msg-type=[0/1/2]發(fā)送消息類型:普通消息 長消息 智能短信


[root@desk32 ~]# mv fetion /usr/local/nagios/libexec/

[root@desk32 ~]# chmod a+x /usr/local/nagios/libexec/fetion

[root@desk32 ~]# tar zxf linuxso_20101113.tar.gz -C /usr/local/lib

[root@desk32 ~]# ldconfig /usr/local/lib

[root@desk32 ~]# chown nagios.nagios /usr/local/nagios/libexec/fetion

[root@desk32 libexec]#cd /usr/local/nagios/libexec

[root@desk32 libexec]# ./fetion #安裝所有的依賴關(guān)系

當出現(xiàn)以下內(nèi)容后則表示fetion已經(jīng)準備妥當:

*************** IMPORTANT STATEMENT **************************

** PLEASEDON'TUSE THIS SOFTWARE TO S JUNK SHORT MESSAGES.**

**OTHERWISE PLEASE BEAR YOUR OWN CONSEQUENCES.**

**Version:[20101205002-linux]**

*******************************************************************

測試:

切換至nagios用戶:

[nagios@desk32./fetion--mobile=15829476129 --pwd=password --to=15829476129 --msg-utf8="good luck"

第一次要輸入驗證碼:

圖形驗證碼已經(jīng)生成,文件名為:15829476129.jpg請識別后輸入圖形驗證碼:

CG5Y

您輸入的識別碼是:CG5Y

SIP-C/4.0 280 Send SMS OK

T: sip:423345302@fetion.com.cn;p=7195

I: 2

Q: 1 M

L: 112

D: Wed, 28 Aug 2013 13:18:34 GMT

XI: C4134FD7BC7ED4B93982B2334E44124C

則表示短信發(fā)送成功;



7nagiosfetion的整合


[root@desk32 libexec]# su - nagios

[nagios@desk32 ~]$ cd /usr/local/nagios/libexec/

[nagios@desk32 libexec]$ vim fetion.sh

/usr/local/nagios/libexec/fetion --mobile=15829476129 --pwd=password --to="$1" --msg-utf8="$2" > /dev/null

[nagios@desk32 libexec]$ chmod a+x fetion.sh

[root@desk32 objects]# vim commands.cfg #定義監(jiān)控的飛信命令

# 'notify-host-by-fetion' command definition

define command{

command_namenotify-host-by-fetion

command_line$USER1$/fetion.sh $CONTACTPAGER$ "$NOTIFICATIONTYPE$ Host Alert: $HOSTNAME$ is $HOSTSTATE$"

}

# 'notify-service-by-fetion' command definition

define command{

command_namenotify-service-by-fetion

command_line$USER1$/fetion.sh $CONTACTPAGER$ "$NOTIFICATIONTYPE$ Service Alert: $HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$"

}


[root@desk32 objects]# vim templates.cfg #fetion 報警選項

service_notification_commandsnotify-service-by-email,notify-service-by-fetion

host_notification_commandsnotify-host-by-email,notify-host-by-fetion

[root@desk32 objects]# vim contacts.cfg#連接文件用于鏈接mail及發(fā)送短信的對象

emailnagios@localhost

pager182205090xx

[root@desk32 objects]# /etc/init.d/nagios reload

測試:

關(guān)閉desk32.example.comssh服務(wù),觀察看有沒有mailfetion的通知。






西安石油大學計算機學院

王茲銀

904483782

mailofwzy@163.com




附件:http://down.51cto.com/data/2363581
向AI問一下細節(jié)

免責聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI