Build Nagios Monitoring Server

Source: Internet
Author: User

案例1:常用系统监控命令案例2:搭建nagios监控服务器案例3:配置文件及插件使用

1 Case 1: Common system monitoring commands
1.1 Questions

This case requires practicing common system monitoring commands to complete the following tasks:

使用vmstat命令监控内存及磁盘I/O信息使用iostat命令监控CPU处理器及磁盘的I/O信息使用sar命令监控系统最近的CPU/内存等活动

1.2 Steps

The implementation of this case needs to follow the steps below.

Step one: Use the Vmstat command to monitor memory and disk I/O information

1) Report memory, swap partition, CPU and other activity information, update data every 2 seconds

[[email protected] ~]# vmstat 2procs -----------memory---------- ---swap-- -----io---- -system-- ------cpu----- r  b   swpd   free   buff  cache   si   so    bi    bo   in   cs us sy id wa st 2  0      0 1447960   1204 331260    0    0   422     9   59  153  1  1 98  0  0 0  0      0 1447944   1204 331260    0    0     0     0    9   12  0  0 100  0  0 0  0      0 1447944   1204 331260    0    0     0     0    9   12  0.. ..

2) Report I/O information of the disk once

[[email protected] ~]# vmstat -ddisk- ------------reads------------ ------------writes----------- -----IO------       total merged sectors      ms  total merged sectors      ms    cur    secvda     7863     12  576137    2560   1427     25   12085    6142      0      3sr0       11      0      88       3      0      0       0       0      0      0dm-0    6529      0  562281    2503    356      0    7989    6480      0      3dm-1     141      0    2536       7      0      0       0       0      0      0

3) Report I/O information for a specified partition

[[email protected] ~]# vmstat -p /dev/vda1vda1          reads   read sectors  writes    requested writes                1010       8792       1025       4096

Step Two: Monitor CPU processor and disk I/O information using the Iostat command

1) Report CPU and disk I/O information once

[[email protected] ~]# iostatLinux 3.10.0-327.el7.x86_64 (svr7.tedu.cn)     2017年05月03日     _x86_64_    (1 CPU)avg-cpu:  %user   %nice %system %iowait  %steal   %idle           0.77    0.00    0.71    0.05    0.00   98.47Device:            tps    kB_read/s    kB_wrtn/s    kB_read    kB_wrtnvda               9.85       304.60         6.45     288160       6103scd0              0.01         0.05         0.00         44          0dm-0              7.30       297.28         4.29     281232       4055dm-1              0.15         1.34         0.00       1268          0

2) Report CPU and disk I/O information, sampled every 2 seconds

[[email protected] ~]# iostat 2Linux 3.10.0-327.el7.x86_64 (svr7.tedu.cn) May 03, 2017 _x86_64_ (1 CPU) avg-            CPU:%user%nice%system%iowait%steal%idle 0.66 0.00 0.61 0.05 0.00 98.68Device: TPS kb_read/s kb_wrtn/s kb_read Kb_wrtnvda 8.42 259.61 5.62 288168 62     35scd0 0.01 0.04 0.00 0dm-0 6.25 253.37 3.77 281240 4187dm-1 0.13 1.14 0.00 1268 0AVG-CPU:%user%nice%system %iowait%steal%idle 0.00 0.00 0.00 0.00 0.00 100.00device:tps KB_READ/S KB_WR         TN/S Kb_read Kb_wrtnvda 0.00 0.00 0.00 0 0SCD0 0.00              0.00 0.00 0 0dm-0 0.00 0.00 0.00 0 0dm-1 0.00 0.00 0.00 0 0.. ..

Step three: Monitor the system's recent cpu/memory activities using the SAR command

1) View the most recent system activity complete (-a) report

[[email protected] ~]# sar-alinux 3.10.0-327.el7.x86_64 (svr7.tedu.cn) May 03, 2017 _x86_64_ (1 CPU) 11:20 01 seconds CPU%usr%nice%sys%iowait%steal%irq%soft%guest%gnice%idle11 30 minutes 01 seconds al      L 0.17 0.00 0.11 0.01 0.00 0.00 0.00 0.00 0.00 99.7111 Hours 30 minutes 01 seconds 0      0.17 0.00 0.11 0.01 0.00 0.00 0.00 0.00 0.00 99.71 Average Time: all 0.17      0.00 0.11 0.01 0.00 0.00 0.00 0.00 0.00 99.71 Average Time: 0 0.17 0.00      0.11 0.01 0.00 0.00 0.00 0.00 0.00 99.7111 Hours 20 minutes 01 seconds proc/s Cswch/s11 30 minutes 01 seconds 0.39 23.27 Average time: 0.39 23.2711 hours 20 minutes 01 seconds pswpin/s Pswpout/s11 30 minutes 01 seconds 0.00 0.00 Average Time: 0.00 0.00      11:20 01 sec pgpgin/s pgpgout/s fault/s majflt/s pgfree/s pgscank/s pgscand/s pgsteal/s%vmeff11 30 minutes 01 seconds 6.30 0.35 165.40 0.03 133.94 0.00 0.00 0.00 0.00 Average Time: 6.30 0.35 165.40 0.03 133.94 0.00 0.00 0.00 0.0011 20 minute 01 seconds TPs Rtps Wtps bread/s bwrtn/s11 30 min 01 sec 0.38 0.27 0.1 1 12.59 0.70 Average time: 0.38 0.27 0.11 12.59 0.7011 hours 20 minutes 01 seconds frmpg/s bufpg/s campg/s11 30 min 0 1 sec-4.90 0.00 1.37 Average Time: 4.90 0.00 1.3711 Time 20 minutes 01 seconds kbmemfree kbmemused%memused kbbuffers KBCA Ched Kbcommit%commit kbactive kbinact kbdirty11 30 min 01 s 1444844 604264 29.49 1204 277020 154788 4 37.33 249044 241260 0 avg Time: 1444844 604264 29.49 1204 277020 1547884 37.33 24          9044 241260 011 20 minutes 01 seconds kbswpfree kbswpused%swpused Kbswpcad%swpcad11 30 minutes 01 seconds 2097148 0 0.00 0 0.00 Average Time: 2097148 0 0.00 0 0.00.. ..

2) Report The CPU activity information in 5 second intervals and then use 3 times

[[email protected] ~]# sar -u 5 3Linux 3.10.0-327.el7.x86_64 (svr7.tedu.cn)     2017年05月03日     _x86_64_    (1 CPU)11时44分20秒     CPU     %user     %nice   %system   %iowait    %steal     %idle11时44分25秒     all      0.00      0.00      0.00      0.00      0.00    100.0011时44分30秒     all      0.00      0.00      0.00      0.00      0.00    100.0011时44分35秒     all      0.00      0.00      0.00      0.00      0.00    100.00平均时间:     all      0.00      0.00      0.00      0.00      0.00    100.00

3) Report The most recent disk I/O information

[[email protected] ~]# sar -b Linux 3.10.0-327.el7.x86_64 (svr7.tedu.cn)     2017年05月03日     _x86_64_    (1 CPU).. ..11时20分01秒       tps      rtps      wtps   bread/s   bwrtn/s11时30分01秒      0.38      0.27      0.11     12.59      0.7011时40分01秒      0.25      0.13      0.12     15.62      0.93平均时间:      0.31      0.20      0.11     14.11      0.81

2 Case 2: Build Nagios Monitoring Server
2.1 Questions

This case requires a Nagios monitoring server to confirm that the Web interface is available:

安装nagios、nagios-plugins软件包配置及访问web界面,将管理用户/密码均设为 nagiosadmin

2.2 Steps

The implementation of this case needs to follow the steps below.

Step One: Pre-installation preparations

1) Install Site platform environment, compile tools

[[email protected] ~]# yum  -y  install  httpd  php  gd[[email protected] ~]# yum  -y  install  gcc  glibc  glibc-common

2) Create a running account

[[email protected] ~]# groupadd  nagcmd[[email protected] ~]# useradd  -G  nagcmd  nagios[[email protected] ~]# gpasswd  -a  apache  nagcmd

Step two: Compile and install Nagios and Nagios-plugins

1) Install Nagios

[[email protected] ~]# tar  xf  ~/nagios-4.3.1.tar.gz  -C  /usr/src/[[email protected] ~]# cd  /usr/src/nagios-4.3.1/[[email protected] nagios-4.3.1]# ./configure  --with-command-group=nagcmd[[email protected] nagios-4.3.1]# make  all                      //编译[[email protected] nagios-4.3.1]# make  install                 //安装程序[[email protected] nagios-4.3.1]# make  install-init             //安装控制脚本[[email protected] nagios-4.3.1]# make  install-config             //安装配置[[email protected] nagios-4.3.1]# make  install-commandmode      //调权限[[email protected] nagios-4.3.1]# make install-webconf             //部署网站配置[[email protected] nagios-4.3.1]# chkconfig  --add  nagios          //加载服务配置

2) Install Nagios-plugins

[[email protected] ~]# tar  xf  ~/nagios-plugins-2.1.4.tar.gz  -C  /usr/src/[[email protected] ~]# cd  /usr/src/nagios-plugins-2.1.4/[[email protected] nagios-plugins-2.1.4]# ./configure  --with-nagios-user=nagios  --with-nagios-group=nagcmd[[email protected] nagios-plugins-2.1.4]# make[[email protected] nagios-plugins-2.1.4]# make install

Step three: Enable and access the Nagios platform

1) Add Web Admin users to the Nagios platform

[[email protected] ~]# htpasswd  -c  /usr/local/nagios/etc/htpasswd.users nagiosadmin                                                  //建Web管理用户

2) Enable Nagios, httpd services

[[email protected] ~]# systemctl  restart  nagios      //启用nagios[[email protected] ~]# systemctl  restart  httpd          //启用Web

3) access to the Nagios Web interface

Firefox/HTTP/server address/nagios/,-1 is shown.

Figure-1
3 Case 3: Configuration file and plugin usage
3.1 Questions

This case requires familiarity with Nagios's frequently used plug-ins to accomplish the following tasks:

使用插件 check_http 检测本机的Web端口使用插件 check_tcp 检测本机的FTP服务端口使用插件 check_disk 检测本机根分区使用率:可用空间低于80%报 WARNING,可用空间低于60%报 CRITICAL

3.2 Steps

The implementation of this case needs to follow the steps below.

Step one: Use the plugin check_http to detect the native Web port

1) Turn off the httpd service of the machine, perform check_http check

[[email protected] ~]# /usr/local/nagios/libexec/check_http -H localhost -p 80connect to address localhost and port 80: 拒绝连接HTTP CRITICAL - Unable to open TCP socket

2) Start the HTTPD service and set the default home page index.html

[[email protected] ~]# vim  /var/www/html/index.htmlDefault site.[[email protected] ~]# systemctl  restart  httpd

3) perform check_http check again

[[email protected] ~]# /usr/local/nagios/libexec/check_http  -H  localhost  -p  80HTTP OK: HTTP/1.1 200 OK - 302 bytes in 0.006 second response time |time=0.006236s;;;0.000000 size=302B;;;0

Step two: Use the plugin check_tcp to detect the FTP service port of the machine

1) Perform check_ftp check when FTP service is not started

[[email protected] ~]# /usr/local/nagios/libexec/check_ftp -H localhost -p 21connect to address localhost and port 21: 拒绝连接

2) After installing and starting VSFTPD service, perform check_ftp check again

[[email protected] ~]# yum  -y  install  vsftpd[[email protected] ~]# systemctl  restart  vsftpd[[email protected] ~]# /usr/local/nagios/libexec/check_ftp -H localhost -p 21FTP OK - 0.002 second response time on localhost port 21 [220 (vsFTPd 3.0.2)]|time=0.002164s;;;0.000000;10.000000

Step three: Use plug-in Check_disk to detect native/boot partition usage

1) View the usage rate of the partition where the/boot directory resides

[[email protected] ~]# df  -hT  /boot文件系统       类型  容量  已用  可用 已用% 挂载点/dev/vda1      xfs   497M  140M  358M   29% /boot

2) Use Check_disk check

Free space less than 80% WARNING, free space less than 60% reported CRITICAL

[[email protected] ~]# /usr/local/nagios/libexec/check_disk  -w  80%  -c  60%  -p  /bootDISK WARNING - free space: /boot 357 MB (71% inode=99%);| /boot=139MB;99;198;0;496

3) Check the actual usage situation, lower the threshold value again Check_disk test

[[email protected] ~]# /usr/local/nagios/libexec/check_disk  -w  60%  -c  40%  -p  /bootDISK OK - free space: /boot 357 MB (71% inode=99%);| /boot=139MB;297;198;0;496

Build Nagios Monitoring Server

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.