中文字幕av专区_日韩电影在线播放_精品国产精品久久一区免费式_av在线免费观看网站

溫馨提示×

溫馨提示×

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

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

監控之nagios的安裝部署(監控本機及其他主機的配置+警報機制的配置)

發布時間:2020-06-22 23:05:54 來源:網絡 閱讀:2845 作者:firelowrie 欄目:移動開發

主機環境   redhat6.5 64位

實驗環境   服務端1 ip 172.25.25.1

           服務端2 ip 172.25.25.2

安裝包     nagios-plugins-2.1.1.tar.gz  

nagios-cn-3.2.3.tar.bz2

gd-devel-2.0.35-11.el6.x86_64.rpm

nrpe-2.15.tar.gz

防火墻狀態:關閉

Selinux狀態:Disabled


1.安裝nagios、監控本地及測試

A)配置安裝nagios及插件

[root@sever1 mnt]# ls

nagios-plugins-2.1.1.tar.gz     nagios-cn-3.2.3.tar.bz2

gd-devel-2.0.35-11.el6.x86_64.rpm

[root@sever1 mnt]# yum installgd-devel-2.0.35-11.el6.x86_64.rpm -y

[root@sever1 mnt]# useradd Nagios                  #創建系統用戶ngios

[root@sever1 mnt]# usermod -a -G nagcmd Nagios      #將nagios添加到nagcmd附加組

[root@sever1 mnt]# usermod -a -G nagcmd apache      #將apache也添加到nagcnd附加組

[root@sever1 mnt]# id Nagios                       #查看

uid=1001(nagios) gid=1001(nagios)groups=1001(nagios),1002(nagcmd)

[root@sever1 mnt]# id apache

uid=48(apache) gid=48(apache) groups=48(apache),1002(nagcmd)

[root@sever1 mnt]# tar jxf nagios-cn-3.2.3.tar.bz2  #解壓

[root@sever1 mnt]# cd nagios-cn-3.2.3

[root@sever1 nagios-cn-3.2.3]# ./configure--with-command-group=nagcmd  #配置

[root@sever1 nagios-cn-3.2.3]# make all

[root@sever1 nagios-cn-3.2.3]# make install         #安裝

[root@sever1 nagios-cn-3.2.3]# make install-init    #安裝腳本文件

[root@sever1 nagios-cn-3.2.3]# make install-config  #安裝配置文件

[root@sever1 nagios-cn-3.2.3]# make install-webconf

[root@sever1 nagios-cn-3.2.3]# cat /usr/local/nagios/etc/htpasswd.users #查看密碼

nagiosadmin:gCWSDnqEHR45c

[root@sever1 nagios-cn-3.2.3]# htpasswd -c/usr/local/nagios/etc/htpasswd.users nagiosadmin                                #修改密碼

New password:

Re-type new password:

Adding password for user nagiosadmin

[root@sever1 nagios-cn-3.2.3]# cat/usr/local/nagios/etc/htpasswd.usersnagiosadmin:QNeDXoEuaEVuI

[root@sever1 nagios-cn-3.2.3]# /etc/init.d/httpd start      #開啟httpd

Stopping httpd:                                           [ OK  ]

[root@sever1 nagios-cn-3.2.3]# /usr/local/nagios/bin/nagios -v/usr/local/nagios/etc/nagios.cfg                           #校驗nagios的語法

[root@sever1 nagios-cn-3.2.3]# /etc/init.d/nagios start     #開啟nagios

Starting nagios: done.

#安裝nagios插件

[root@sever1 mnt]# tar zxf nagios-plugins-2.1.1.tar.gz      #解壓

[root@sever1 mnt]# cd nagios-plugins-2.1.1

[root@sever1 nagios-plugins-2.1.1]# ./config--with-nagios-user=nagios --with-nagios-group=nagios                                                #配置

[root@sever1 nagios-plugins-2.1.1]# make                    #編譯

[root@sever1 nagios-plugins-2.1.1]# make install            #安裝

B)添加本地服務

 [root@server1 etc]# vimnagios.cfg

  cfg_file=/usr/local/nagios/etc/objects/hosts.cfg        #添加文件
  cfg_file=/usr/local/nagios/etc/objects/services.cfg   
  # Definitions formonitoring the local (Linux) host
  #cfg_file=/usr/local/nagios/etc/objects/localhost.cfg   #標記localhost文件

[root@server1 etc]# cd objects/

[root@server1 objects]# cp -p localhost.cfg hosts.cfg

[root@server1 objects]# cp -p localhost.cfg services.cfg

[root@server1 objects]# vim hosts.cfg                       #主機配置文件

define host{                                               #主機
        use                     linux-server                #使用的模板
        host_name               server1.example.com         #主機名
        alias                   Manager                     #別名
        address                 172.25.29.1                 #ip
        icon_p_w_picpath              server.gif                  #下面幾行是在拓撲圖中的位置
       statusmap_p_w_picpath         server.gd2
        2d_coords               500,200
        3d_coords               500,200,100
        }
define hostgroup{
       hostgroup_name  linux-servers ;The name of the hostgroup
        alias           Linux Servers ; Long name of the group
        members         *    ; Comma separated list of hosts that belong to this group
        }

[root@server1 objects]# vim service.cfg                         #服務配置文件

define servicegroup{                                        #服務組
        servicegroup_name系統負荷檢查                
        alias 負荷檢查                                
        membersserver1.example.com,進程總數,server1.example.com,登錄用戶數,server1.example.com,根分區,server1.example.com,交換空間利用率
        }
 
define service{                                            #服務
        use                             local-service      #使用的模板  
        host_name                       *
       service_description            PING
       check_command                  check_ping!100.0,20%!500.0,60% #要傳的參數
        }
 
define service{
        use                             local-service         ; Name of service template to use
        host_name                       server1.example.com
       service_description             根分區
       check_command                  check_local_disk!20%!10%!/
        }
define service{
        use                             local-service         ; Name of service template to use
        host_name                       server1.example.com
       service_description             登錄用戶數
       check_command                  check_local_users!20!50
        }
 
define service{
        use                             local-service         ; Name of service template to use
        host_name                       server1.example.com
       service_description             進程總數
       check_command                   check_local_procs!250!400!RSZDT
        }
 
define service{
        use                             local-service         ; Name of service template to use
        host_name                       server1.example.com
 
       service_description             系統負荷
       check_command                  check_local_load!5.0,4.0,3.0!10.0,6.0,4.0
        }
 
define service{
        use                             local-service         ; Name of service template to use
        host_name                       server1.example.com
       service_description             交換空間利用率
       check_command                  check_local_swap!20!10
        }
 
define service{
        use                             local-service         ; Name of service template to use
        host_name                       server1.example.com
       service_description            SSH
       check_command                  check_tcp!22!1.0!10.0
       notifications_enabled           0
        }
define service{
        use                             local-service         ; Name of service template to use
        host_name                       server1.example.com
       service_description            HTTP
       check_command                  check_http
       notifications_enabled           0
        }

[root@server1 objects]# /etc/init.d/nagios reload       #刷新

Running configuration check...done.

Reloading nagios configuration...done

C)測試172.25.25.1/Nagios

監控之nagios的安裝部署(監控本機及其他主機的配置+警報機制的配置)


2.遠程監控服務端2mysql及測試

  A)     安裝mysql及添加授權

服務端2

[root@server2 ~]# yum install mysql-server -y       #安裝mysql

[root@server2 ~]# /etc/init.d/mysqld start          #開啟mysql

[root@server2 ~]# mysql_secure_installation         #初始化,添加密碼redhat

[root@server2 ~]# mysql -predhat                    #進入mysql

mysql> create database nagdb;                       #添加nagdb庫

Query OK, 1 row affected (0.00 sec)               

mysql> grant select on nagdb.* to nagios@'172.25.25.1'identified by 'redhat';

Query OK, 0 rows affected (0.00 sec)                #給nagios用戶授予nagdb庫的查看權限

mysql> Bye                                          #退出

 

#服務端1,測試

[root@server1 objects]# ./check_mysql -H 172.25.25.2 -u nagios-p redhat -d nagdb

  B)     將mysql服務(服務端2)添加到nagios(服務端1)

服務端1

[root@server1 objects]# vim hosts.cfg                #定義主機

define host{
        use                     linux-server        #調用的模版
        host_name              server2.example.com  #主機名(command.cfg中要調用的參數)
        alias                    MYSQL              #別名
        address                 172.25.25.2         #ip
        icon_p_w_picpath              server.gif
       statusmap_p_w_picpath         server.gd2           #坐標的定義
        2d_coords               400,200
        3d_coords               400,200,100
        }
[root@server1 objects]# vim services.cfg            #定義服務
####################check_mysql#######################
define service{
        use                             local-service       
        host_name                       server2.example.com(調用hosts.cfg中的host_name)
       service_description            MYSQL
       check_command                  check_mysql!nagios!redhat!nagdb    #command.cfg中要調用的參數(命令名字!主機名!密碼!數據庫的名稱)
        }

[root@server1 objects]# vim commands.cfg            #定義命令

# 'check_mysql' command definition
define command{
        command_name    check_mysql                #命令的名字
        command_line    $USER1$/check_mysql -H $HOSTADDRESS$ -u$ARG1$ -p $ARG2$ -d  $ARG3$       #調用的腳本絕對路徑 -H 主機名(調用hosts.cfg中的host_name) -u mysql的用戶名 -p 用戶密碼 -d 數據庫的名稱
        }

[root@server1 objects]# /usr/local/nagios/bin/nagios -v/usr/local/nagios/etc/nagios.cfg                                                      #檢查是否有語法錯誤

Total Warnings: 0

Total Errors:   0                                    #無語法錯誤

Things look okay - No serious problems were detected during thepre-flight check

[root@server1 objects]# /etc/init.d/nagios reload    #刷新

Running configuration check...done.

Reloading nagios configuration...done

C)測試

點擊拓撲圖,添加server2.example.com成功

監控之nagios的安裝部署(監控本機及其他主機的配置+警報機制的配置)

點擊主機,查看兩臺主機

監控之nagios的安裝部署(監控本機及其他主機的配置+警報機制的配置)

點擊服務,如圖

監控之nagios的安裝部署(監控本機及其他主機的配置+警報機制的配置)


3.遠程監控服務端2的根分區和用戶數

A)安裝nagios插件及nrpe

服務端2

[root@server2 mnt]# ls

nagios-plugins-2.1.1.tar.gz nrpe-2.15.tar.gz

[root@server2 mnt]# tar zxf nagios-plugins-2.1.1.tar.gz #解壓plugins插件

[root@server2 mnt]# cd nagios-plugins-2.1.1

[root@server2 nagios-plugins-2.1.1]# ./configure           

[root@server2 nagios-plugins-2.1.1]# make                 

[root@server2 nagios-plugins-2.1.1]# make install         

[root@server2 mnt]# cd /usr/local/nagios/                 

[root@server2 nagios]# ls

include  libexec  share

[root@server2 nagios]# useradd -u 1001 nagios           #創建nagios用戶

[root@server2 nagios]# chown nagios.nagios * -R         #修改文件權限

[root@server2 nagios]# ll                              #查看

total 12

drwxr-xr-x 2 nagios nagios 4096 Oct 23 10:50 include

drwxr-xr-x 2 nagios nagios 4096 Oct 23 10:50 libexec

drwxr-xr-x 3 nagios nagios 4096 Oct 23 10:50 share

[root@server2 libexec]# cd /mnt/

[root@server2 mnt]# tar zxf nrpe-2.15.tar.gz            #解壓nrpe

[root@server2 mnt]# cd nrpe-2.15

[root@server2 nrpe-2.15]# ./configure                  #配置

[root@server2 nrpe-2.15]# make all

[root@server2 nrpe-2.15]# make install-plugin

[root@server2 nrpe-2.15]# make install-daemon

[root@server2 nrpe-2.15]# make install-daemon-config

[root@server2 nrpe-2.15]# yum install -y xinetd

[root@server2 nrpe-2.15]# make install-xinetd

[root@server2 nrpe-2.15]# vim /etc/services             #添加nrpe的端口

nrpe            5666/tcp

[root@server2 nrpe-2.15]# cd /etc/xinetd.d/

[root@server2 xinetd.d]# vim nrpe                  #進入配置文件

 15         only_from       = 172.25.25.1          #允許172.25.25.1監聽

[root@server2 etc]# cd /usr/local/nagios/etc/

[root@server2 etc]# ls

nrpe.cfg

[root@server2 etc]# vim nrpe.cfg                   #修改命令

221 command[check_disk]=/usr/local/nagios/libexec/check_disk -w20% -c 10% -p /

[root@server2 etc]# cd ..

[root@server2 nagios]# ls

bin  etc  include libexec  share

[root@server2 nagios]# cd libexec/

[root@server2 libexec]# ./check_disk -w 20% -c 10% -p /     #測試

DISK OK - free space: / 6222 MB (85% inode=93%);|/=1057MB;6135;6902;0;7669

[root@server2 libexec]# /etc/init.d/xinetd start            #開啟xinetd

Starting xinetd:                                          [  OK  ]

[root@server2 libexec]# netstat -antple |grep 5666          #查看端口,開啟

tcp        0     0 :::5666                    :::*                        LISTEN      0         23552      23120/xinetd       

[root@server2 libexec]# scp check_nrpe172.25.25.1:/usr/local/nagios/libexec/

root@172.25.25.1's password:                               #將nrpe傳給服務端1

check_nrpe                                   100%   75KB 75.0KB/s   00:00 

B) 將根分區和用戶數(服務端2)添加到nagios(服務端1) 

服務端1

[root@server1 libexec]# pwd

/usr/local/nagios/libexec

[root@server1 libexec]# chown nagios.nagios check_nrpe      #修改權限

[root@server1 libexec]# ./check_nrpe -H 172.25.25.2        #測試

NRPE v2.15

[root@server1 libexec]# cd ..

[root@server1 nagios]# cd etc/objects/

[root@server1 objects]# vim services.cfg                   #添加服務

####################check_nrpe#######################
define service{
        use                             local-service       
        host_name                       server2.example.com
       service_description             根分區
       check_command                  check_nrpe!check_disk
        }
 
define service{
        use                             local-service        
        host_name                       server2.example.com
       service_description             登錄用戶數
       check_command                  check_nrpe!check_users
        }

[root@server1 objects]# vim commands.cfg                   #添加命令

# 'check_nrpe' command definition
define command{
        command_name    check_nrpe
        command_line    $USER1$/check_nrpe -H $HOSTADDRESS$ -c$ARG1$
        }

[root@server1 objects]# /usr/local/nagios/bin/nagios -v/usr/local/nagios/etc/nagios.cfg

Total Warnings: 0

Total Errors:   0

Things look okay - No serious problems were detected during thepre-flight check

[root@server1 objects]# /etc/init.d/nagios reload           #刷新

C)測試

監控之nagios的安裝部署(監控本機及其他主機的配置+警報機制的配置)

 

4.nagios警報的配置及測試(郵件聯系人)

[root@server1 objects]# vim contacts.cfg                           #修改郵件地址

35         email                           xxxxxxxxxx@qq.com

[root@server1 objects]# /etc/init.d/nagios reload                  #刷新

[root@server1 ~]$ cd /mnt/

[root@server1 mnt]$ ls

alert-agent-4.1.3.1-linux-x64.tar.gz

[root@server1 mnt]$ tar zxfalert-agent-4.1.3.1-linux-x64.tar.gz -C /usr/local/nagios/libexec/

[root@server1 mnt]$ cd /usr/local/nagios/libexec/

[root@server1 libexec]$ cpalert-agent/plugin/nagios-plugin/nagios .

[root@server1 libexec]$ cpalert-agent/plugin/nagios-plugin/110monitor.cfg ../etc/objects/

[root@server1 libexec]$ chmod +x nagios

[root@server1 libexec]$ chmod nagios.nagios * -R

[root@server1 libexec]$ cd ..

[root@server1 nagios]# cd etc/

[root@server1 etc]# vim nagios.cfg

cfg_file=/usr/local/nagios/etc/objects/110monitor.cfg      #添加

[root@server1 etc]# cd objects/

[root@server1 objects]# vim 110monitor.cfg

18         pager                           379cd8ca-5700-e2ef-10a2-c72a9158b55a                            #改成自己生成的key

[root@server1 objects]# /usr/local/nagios/bin/nagios -v/usr/local/nagios/etc/nagios.cfg

Total Warnings: 0

Total Errors:   0

Things look okay - No serious problems were detected during thepre-flight check

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

 

  B)測試  當把服務端2的mysql停掉之后,如圖:

監控之nagios的安裝部署(監控本機及其他主機的配置+警報機制的配置)

郵件也發過來了,如圖

監控之nagios的安裝部署(監控本機及其他主機的配置+警報機制的配置)

 

向AI問一下細節

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

AI

宝应县| 顺义区| 丰台区| 深圳市| 新龙县| 平和县| 灵石县| 丹棱县| 定陶县| 依兰县| 鹿邑县| 乐亭县| 屯昌县| 金门县| 射洪县| 阜城县| 巴东县| 临沧市| 靖边县| 阿尔山市| 监利县| 都江堰市| 宝鸡市| 金昌市| 吴忠市| 麻阳| 吉林省| 兴安盟| 舞阳县| 武宁县| 资兴市| 太湖县| 阿瓦提县| 庆城县| 万载县| 高邑县| 固原市| 吴川市| 藁城市| 修文县| 页游|