设为首页 收藏本站
查看: 875|回复: 0

搭建nagios监控步骤

[复制链接]

尚未签到

发表于 2019-1-12 14:39:16 | 显示全部楼层 |阅读模式
  1、实验环境:
  主机名:            ip              需要的软件环境
  nagios-server     192.168.124.143    Apache、Php、Nagios、nagios-plugins、nrpe
  nagios-linux      192.168.124.203    nagios-plugins、nrpe
  监控机 nagios-server上需要 安装nagios软件,对监控的数据做处理,并且提供 web界面查看和管理。当然也对本机自身的信息进行监控;
  被监控机 nagios-linux需安装NRPE及nagios plugins,根据监控机的请求执行监 控,然后将结果回传给监控机;
  一、Nagios监控机(192.168.124.143)上的环境准备
  1、 安装编译环境
  使用yum安装
  [root@localhost ~]# yum install -y gcc glibc glibc-common gd xinetd openssl-devel mysql-devel
  2、 创建nagios用户和用户组
  [root@localhost ~]#useradd -s /sbin/nologin nagios
  [root@localhost ~]#mkdir /usr/local/nagios
  [root@localhost ~]#chown -R nagios:nagios /usr/local/nagios
  3、 yum安装httpd和php,并配置httpd支持php
  只要能实现浏览器能正常访问 http://本机IP/index.php 既可
  4、 编译安装nagios
  上传nagios源码包至/root目录下
  [root@localhost ~]#tar zxvf nagios-4.0.3.tar.gz
  [root@localhost ~]#cd nagios-4.0.3
  [root@localhost ~]#./configure --prefix=/usr/local/nagios --with-nagiosuser=nagios --with-nagios-group=nagios
  [root@localhost ~]#make all
  [root@localhost ~]#make install
  [root@localhost ~]#make install-init
  [root@localhost ~]#make install-commandmode
  [root@localhost ~]#make install-config
  [root@localhost ~]#make install-webconf
  [root@localhost ~]#chkconfig --add nagios                           #       将nagios加入系统 服务
  [root@localhost ~]#chkconfig nagios on
  5、 验证nagios是否被正确安装
  切换目录到安装路径(这里是/usr/local/nagios),看是否存在etc、bin、 libexec、sbin、share、var  这些目录,如果存在则可以表明程序被正确的安装到 系统了。
  Nagios 各个目录用途说明如下:
  目录名             用途
  bin Nagios       可执行程序所在目录
  etc Nagios       配置文件所在目录
  sbin           Nagios CGI文件所在目录,也就是执行外部命令所需文件所在的目录       share          Nagios网页文件所在的目录
  libexec         Nagios 外部插件所在目录
  var Nagios     日志文件、lock 等文件所在的目录
  var/archives    Nagios 日志自动归档目录
  var/rw        用来存放外部命令文件的目录
  6、 安装nagios插件
  上传nagios-plugins-1.5.tar.gz至/root目录下
  [root@localhost ~]#tar zxvf nagios-plugins-1.5.tar.gz
  [root@localhost ~]#cd nagios-plugins-1.5
  [root@localhost ~]#./configure --prefix=/usr/local/nagios --with-mysql --with-nagios-user=nagios --with-nagiosgroup=nagios
  [root@localhost ~]#make && make install
  备注:
  --with-mysql 使nagios插件支持监控mysql(系统要先yum安装好 mysql-devel软件包),在libexec目录下会有 check_mysql和check_mysql_query命令
  7、 安装check_nrpe插件
  上传nrpe-2.12.tar.gz至/root目录下
  [root@localhost ~]#tar zxvf nrpe-2.12.tar.gz
  [root@localhost ~]#cd nrpe-2.12
  [root@localhost ~]#./configure --with-nrpe-user=nagios      --with-nrpe-group=nagios      --with-nagiosuser=nagios      --with-nagios-group=nagios      --enable-command-args      --enable-ssl
  [root@localhost ~]#make all
  [root@localhost ~]#make  install-plugin
  监控机上只运行到这一步就行,因为只需要nrpe中的check_nrpe插件
  8、 修改apache的配置文件/etc/httpd/conf/httpd.conf
  [root@localhost ~]#vim /etc/httpd/conf/httpd.conf
  User apache修改为User nagios
  Group apache修改为Group nagios
  DirectoryIndex index.html修改为DirectoryIndex index.php
  保存
  9、 为了安全起见,一般情况下要让nagios 的web 监控页面必须经过授权才能访问              编译安装nagios 4.0.3版本完成后,已自动配置httpd并设定了默认的htpasswd验证文件                  /usr/local/nagios/etc/ htpasswd.users
  [root@localhost ~]#htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin                       #指定用户 nagiosadmin可以访问
  10、 启动httpd服务
  [root@localhost ~]#service httpd restart
  [root@localhost ~]#service nagios start
  11、 浏览器访问nagios站点
  http://192.168.124.143/nagios
  二、被监控机(192.168.124.203)安装nrpe及nagios-plugins
  1、 安装编译环境
  使用yum安装
  [root@localhost ~]# yum install -y gcc glibc glibc-common gd xinetd openssl-devel mysql-devel
  2、 编译安装nagios插件
  上传nagios-plugins-1.5.tar.gz至/root目录下
  [root@localhost ~]#tar -zxvf nagios-plugins-1.5.tar.gz
  [root@localhost ~]#cd nagios-plugins-1.5
  [root@localhost ~]#./configure  --with-mysql --with-nagios-user=nagios --with-nagios-group=nagios
  [root@localhost ~]#make && make install
  这一步完成后会在/usr/local/nagios/下生成两个目录libexec和share,修改目录权限            [root@localhost ~]#useradd -s /sbin/nologin nagios
  [root@localhost ~]#chown  -R nagios:nagios /usr/local/nagios
  3、 编译安装nrpe
  上传nrpe-2.12.tar.gz至/root目录下
  [root@localhost ~]#tar -zxvf nrpe-2.12.tar.gz
  [root@localhost ~]#cd nrpe-2.12
  [root@localhost ~]#./configure --with-nrpe-user=nagios      --with-nrpe-group=nagios      --with-nagiosuser=nagios      --with-nagios-group=nagios      --enable-command-args      --enable-ssl
  [root@localhost ~]#make all
  [root@localhost ~]#make install-plugin
  [root@localhost ~]#make install-daemon
  [root@localhost ~]#make install-daemon-config
  #现在再查看/usr/local/nagios 目录就会发现有4个子目录
  [root@localhost ~]#make install-xinetd
  [root@localhost ~]#vim /etc/xinetd.d/nrpe
  修改在末尾项 only_from    = 192.168.124.0/24
  这里设置允许监控机所在的网段访问
  [root@localhost ~]#vim /etc/services
  #编辑/etc/services 文件,末尾增加NRPE服务内容
  在最后添加   nrpe    5666/tcp   #nrpe
  [root@localhost ~]#service xinetd restart
  [root@localhost ~]#netstat -ntulp|grep 5666
  #查看nrpe是否已启动并监听5666端口   

  4、 测试nrpe是否正常工作
  在监控机(192.168.124.143)执行check_nrpe这个插件来测试与被监控机(192.168.124.203)的通讯
  [root@localhost ~]#/usr/local/nagios/libexec/check_nrpe -H 192.168.124.203              如显示     NRPE V2.12   ,则nrpe通讯正常
  三、监控机(192.168.124.143)上的配置
  1、 在commands.cfg文件末尾增加check_nrpe的定义
  [root@localhost ~]#vim /usr/local/nagios/etc/objects/commands.cfg
  #添加如下 代码
  define command{
  command_name    check_nrpe
  command_line    $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$            }
  2、 定义对Nagios-Linux 主机的监控,创建nagios_linux.cfg文件并加入以下 代码内容
  

  [root@localhost ~]#vim /usr/local/nagios/etc/objects/nagios_linux.cfg
  define host{
  use             linux-server
  host_name         nagios-linux
  alias           nagios-linux
  address          192.168.124.67                 #此处设置被监控机的IP地址            }
  define service{          #添加监控CPU负载的服务
  use            local-service
  host_name        nagios-linux
  service_description   CPU Load
  check_command        check_nrpe!check_load
  }
  define service{            #添加监控总进程数的服务
  use             local-service
  host_name         nagios-linux
  service_description  Total Processes
  check_command      check_nrpe!check_total_procs
  }
  上述代码分别定义了CPU Load(cpu负载)以及Total Processes(总进程数)的监 控服务,还可以在此文件中增加其他的监控服务
  3、 在nagios的主配置文件nagios.cfg末尾增加如下代码内容
  [root@localhost ~]#vim /usr/local/nagios/etc/nagios.cfg
  cfg_file=/usr/local/nagios/etc/objects/nagios_linux.cfg
  #在nagios的主配置文件中增 加被监控机的配置文件
  4、 重启各项服务
  [root@localhost ~]#service httpd restart
  [root@localhost ~]#service nagios restart
  5、 验证nagios是否能监控到本机(localhost)以及被监控机nagios-linux
  http://ip/nagios
  6、[root@localhost ~]#service httpd restart
  [root@localhost ~]#service nagios restart
  #重启验证新增的监控信息
  ok!到此结束!希望对你有所帮助
  





运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-662455-1-1.html 上篇帖子: Nagios-IT老司机 下篇帖子: nagios告警发不出问题解决
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表