温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

Nagios安装配置和基于NRPE监控远程Linux主机

发布时间:2020-06-19 16:42:15 来源:网络 阅读:914 作者:zrh2010 栏目:移动开发

实验平台:LInux-5.8,yum源已配置好,SeLinux处于关闭状态

监控端:172.16.14.15
被监控端:172.16.14.14
 
一:安装配置Nagios
 
这个过程在监控端172.16.14.15实现:
 
1、解决安装Nagios的依赖关系:
Nagios基本组件的运行依赖于httpd、gcc和gd
 
  1. # yum -y install httpd gcc glibc glibc-common gd gd-devel \ 
  2. php php-mysql mysql mysql-devel mysql-server 
2、添加nagios运行所需要的用户和组:
 
  1. # groupadd  nagcmd 
  2. # useradd -G nagcmd nagios 
  3. # passwd nagios 
把apache加入到nagcmd组,以便于在通过web Interface操作nagios时能够具有足够的权限:

  1. # usermod -a -G nagcmd apache 
3、编译安装nagios:
 
  1. # tar zxf nagios-3.3.1.tar.gz 
  2. # cd nagios 
  3. # ./configure  --with-command-group=nagcmd --enable-event-broker 
  4. ##--sysconfdir=/etc/nagios   自己可以指定nagios的配置文件路径 
  5. ##--with-command-group=nagcmd  使用前面创建的组 
  6. ##--enable-event-broker 为使用NDOutils做准备的 
  7.  
  8. # make all 
  9. # make install    ##安装nagios 
  10. # make install-init  ##安装nagios的init脚本,即/etc/rc.d/init.d/nagios 
  11. # make install-commandmode  ##安装命令模式 
  12. # make install-config  ##安装生成配置文件 
  13.  
  14. # make install-webconf   ##安装web接口的,识别nagios程序位置/usr/local/nagios/share 
  15. ##然后进入/etc/httpd/conf.d,会发现多了nagios.conf文件,为访问 
  16. ##nagios的web页面定义了一个别名,当访问172.16.14.15/nagios时就可 
  17. ##以访问/usr/local/nagios/share的文件了 
我们的nagios web页面不能随便让人访问吧,所以需创建一个登录nagios
web程序的用户,只有通过认证的用户才能访问:
 
  1. # htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin 
重新启动httpd:
 
  1. # service httpd restart 
4、编译安装nagios-plugins
nagios的所有监控工作都是通过插件完成的,因此,在启动nagios之前
还需要为其安装官方提供的插件。
 
  1. # tar zxf nagios-plugins-1.4.15.tar.gz 
  2. # cd nagios-plugins-1.4.15 
  3. # ./configure --with-nagios-user=nagios --with-nagios-group=nagios 
  4. # make 
  5. # make install 
5、配置并启动Nagios
 
  1. (1)把nagios添加为系统服务并将之加入到自动启动服务队列: 
  2. # chkconfig --add nagios 
  3. # chkconfig nagios on 
  4.  
  5. (2)检查其主配置文件的语法是否正确: 
  6. # /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg 
  7.  
  8. (3)如果上面的语法检查没有问题,接下来就可以正式启动nagios服务了: 
  9. # service nagios start 
接下来就可以访问nagios了,提示输入用户名和密码:

Nagios安装配置和基于NRPE监控远程Linux主机

输入前面设定的用户和密码后,进入nagios的界面:

Nagios安装配置和基于NRPE监控远程Linux主机

查看hosts信息:

Nagios安装配置和基于NRPE监控远程Linux主机

各服务意思:
  1. current Load:CPU的负载情况,当前显示是Ok的 
  2. Current Users:用户数 
  3. HTTP:显示HTTP服务事物信息的,当前显示WARNING是因为没有提供web页面 
  4. PING:用来ping主机的 
  5. Root Partition:显示根分区信息的 
  6. SSH:显示SSH的状态的 
  7. Swap Usage:显示交换分区使用情况的 
  8. Total Processes:总进程数状态 
  9.  
  10. 在右上角还有一个各项状态汇总图 
 
 
二:基于NRPE监控远程Linux主机
 
NRPE(Nagios Remote Plugin Executor)是用于在远端服务器上运行检测命令的守护进程,
它用于让Nagios监控端基于安装的方式触发远端主机上的检测命令,并将检测结果输出至监控端

监控端:172.16.14.15
被监控端:172.16.14.14
 
  1. 安装开发包组: 
  2. yum  -y groupinstall "Development Libraries" "Development Tools"  
1、安装配置被监控端
1)先添加nagios用户
 
  1. # useradd -s /sbin/nologin nagios 
2)NRPE依赖于nagios-plugins,因此,需要先安装之
 
  1. # tar zxf nagios-plugins-1.4.15.tar.gz 
  2. # cd nagios-plugins-1.4.15 
  3. # ./configure --with-nagios-user=nagios --with-nagios- 
  4.  
  5. group=nagios 
  6. # make all 
  7. # make install 
3)安装NRPE
 
  1. # tar -zxvf nrpe-2.13.tar.gz 
  2. # cd nrpe-2.13.tar.gz 
  3. # ./configure --with-nrpe-user=nagios \   ##添加nrpe用户 
  4.      --with-nrpe-group=nagios \          ##nrpe组 
  5.      --with-nagios-user=nagios \    ##nagios用户名 
  6.      --with-nagios-group=nagios \    ##nagios组名 
  7.      --enable-command-args \   ##向命令传递参数的 
  8.      --enable-ssl    ##默认选项,监控端和被监控端传递信息需要ssl加密 
  9.  
  10. # make all 
  11. # make install-plugin   ##安装插件 
  12. # make install-daemon   ##将nrpe安装成守护进程 
  13. # make install-daemon-config   ##安装守护进程的配置文件 
4)配置NRPE:
 
  1. # vim /usr/local/nagios/etc/nrpe.conf 
  2.  
  3. log_facility=daemon   ##日志文件的设施 
  4. pid_file=/var/run/nrpe.pid   ##pid文件路径,自己可以定义 
  5. server_address=172.16.14.14  ##监听的地址 
  6. server_port=5666   ##端口号 
  7. nrpe_user=nagios   ##nrpe用户 
  8. nrpe_group=nagios  ##nrpe组名 
  9. allowed_hosts=172.16.14.15  ##定义本机所允许的监控端的IP地址。 
  10.  
  11. command_timeout=60   ##定义命令的超时时间 
  12. connection_timeout=300   ##链接的超时时间 
  13. debug=0  ##调试功能没打开 
5)启动NRPE:
 
  1. # /usr/local/nagios/bin/nrpe -c 
  2.  
  3. /usr/local/nagios/etc/nrpe.cfg –d 
为了便于NRPE服务的启动,可以将如下内容定义为/etc/init.d/nrped脚本:
 
  1. #!/bin/bash 
  2. # chkconfig: 2345 88 12 
  3. # description: NRPE DAEMON 
  4.  
  5. NRPE=/usr/local/nagios/bin/nrpe 
  6. NRPECONF=/usr/local/nagios/etc/nrpe.cfg 
  7.  
  8. case "$1" in 
  9.      start) 
  10.           echo -n "Starting NRPE daemon..." 
  11.           $NRPE -c $NRPECONF -d 
  12.           echo " done." 
  13.           ;; 
  14.      stop) 
  15.           echo -n "Stopping NRPE daemon..." 
  16.           pkill -u nagios nrpe 
  17.           echo " done." 
  18.      ;; 
  19.      restart) 
  20.           $0 stop 
  21.           sleep 2 
  22.           $0 start 
  23.           ;; 
  24.      *) 
  25.           echo "Usage: $0 start|stop|restart" 
  26.           ;; 
  27.      esac 
  28. exit 0 
赋予执行权限:
 
  1. # chmod +x /etc/init.d/nrped 
添加至服务列表:
 
  1. # chkconfig --add nrped 
  2. # chkconfig --list nrped 
6)启动nrped服务和查看端口:
 
  1. # service nrped start 
  2.  
  3. # netstat -tnlp | grep 5666 
  4. tcp        0      0 172.16.14.14:5666           0.0.0.0:*   LISTEN     \
  5.  24909/nrpe 
7)配置允许远程主机监控的对象:
在/usr/local/nagios/etc/nrpe.cfg中添加:
 
  1. command[check_users]=/usr/local/nagios/libexec/check_users -w 5 -c 10 
  2. command[check_load]=/usr/local/nagios/libexec/check_load -w 15,10,5 -c 30,25,20 
  3. command[check_sda1]=/usr/local/nagios/libexec/check_disk -w 20% -c 10% -p /dev/sda1 
  4. command[check_sda2]=/usr/local/nagios/libexec/check_disk -w 20% -c 10% -p /dev/sda2 
  5. command[check_sda3]=/usr/local/nagios/libexec/check_disk -w 20% -c 10% -p /dev/sda3 
  6. command[check_zombie_procs]=/usr/local/nagios/libexec/check_procs -w 5 -c 10 -s Z 
  7. command[check_total_procs]=/usr/local/nagios/libexec/check_procs -w 150 -c 200  
 
2、配置监控端:

1)安装NRPE
 
  1. # tar -zxvf nrpe-2.13.tar.gz 
  2. # cd nrpe-2.13.tar.gz 
  3. # ./configure --with-nrpe-user=nagios \ 
  4.      --with-nrpe-group=nagios \ 
  5.      --with-nagios-user=nagios \ 
  6.      --with-nagios-group=nagios \ 
  7.      --enable-command-args \ 
  8.      --enable-ssl 
  9. # make all 
  10. # make install-plugin 
安装完成后在/usr/local/nagios/libexec/下会生成一个check_nrpe插
 
  1. # cd /usr/local/nagios/libexec/ 
  2. # ./check_nrpe -H 172.16.14.14 
  3. NRPE v2.13   ##说明监控端与被监控端可以通信了 
2)定义如何监控远程主机及服务:
  1. 在commands.cfg 定义check_nrpe命令: 
  2.      define command 
  3.      { 
  4.           command_name check_nrpe 
  5.           command_line $USER1$/check_nrpe –H $HOSTADDRESS$ -c $ARG1$ 
  6.  
3)在/usr/local/nagios/etc/objects下定义Linux主机linhost.cfg
 
定义的对象要与被监控端nrpe.conf文件中允许被监控的对象对应:
 
  1. # vim linhost.cfg   
  2.  
  3. define host{ 
  4.         use             linux-server     
  5.         host_name       linhost 
  6.         alias           My Linux Host      
  7.         address         172.16.14.14  
  8.  
  9. define service{ 
  10.         use                     generic-service 
  11.         host_name               linhost 
  12.         service_description      CHECK USERS 
  13.         check_command           check_nrpe!check_users 
  14.         } 
  15.  
  16. define service{ 
  17.         use                     generic-service 
  18.         host_name               linhost 
  19.         service_description     Load 
  20.         check_command           check_nrpe!check_load 
  21.         } 
  22.  
  23. define service{ 
  24.         use                     generic-service 
  25.         host_name               linhost 
  26.         service_description     SDA1 
  27.         check_command           check_nrpe!check_sda1 
  28.         } 
  29.  
  30. define service{ 
  31.         use                     generic-service 
  32.         host_name               linhost 
  33.         service_description     SDA2 
  34.         check_command           check_nrpe!check_sda2 
  35.         } 
  36.  
  37. define service{ 
  38.         use                     generic-service 
  39.         host_name               linhost 
  40.         service_description     SDA3 
  41.         check_command           check_nrpe!check_sda3 
  42.         } 
  43.  
  44. define service{ 
  45.         use                     generic-service 
  46.         host_name               linhost 
  47.         service_description     Zombie 
  48.         check_command           check_nrpe!check_zombie_procs 
  49.         } 
  50.  
  51. define service{ 
  52.         use                     generic-service 
  53.         host_name               linhost 
  54.         service_description     Total procs 
  55.         check_command           check_nrpe!check_total_procs 
4)将linuxhost.cfg包含进主配置文件中:
 
  1. # vim /usr/local/nagios/etc/nagios.cfg 
  2. cfg_file=/usr/local/nagios/etc/objects/linhost.cfg 
5)检查语法正确性:
 
  1. # /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg  
  2. Total Warnings: 0 
  3. Total Errors:   0 
  4. Things look okay - No serious problems were detected during the pre-flight check 
一定要记得重启服务啊,我在做时忘了重启服务了,排错好长时间,也为前面步骤错了呢,惭愧!
# service nagios restart

3、查看web nagios页面,显示自己定义的linhost信息:

 

Nagios安装配置和基于NRPE监控远程Linux主机

这样就实现了对Linux主机进行远程监控了
 
 
 
向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI