怎么在RedHat6.5上部署Nagios

发布时间:2021-09-16 18:09:43 作者:chen
来源:亿速云 阅读:116

这篇文章主要介绍“怎么在RedHat6.5上部署Nagios”,在日常操作中,相信很多人在怎么在RedHat6.5上部署Nagios问题上存在疑惑,小编查阅了各式资料,整理出简单好用的操作方法,希望对大家解答”怎么在RedHat6.5上部署Nagios”的疑惑有所帮助!接下来,请跟着小编一起来学习吧!

部署环境:系统,RedHat 6.5;组件,Nagios;

部署前准备:关闭Selinux,和防火墙(/etc/init.d/iptables stop);获取相关软件包。

(包括gd-devel mysql-server openssl-devel xinetd;等)

具体步骤:

1.在Nagios运行的主机上创建Nagios用户和nagcmd组;

groupadd nagcmd;

useradd -M -d /usr/local/nagios -G nagcmd nagios;

usermod -G nagcmd  apache

2.解压相应的源码包和插件包;并指定编译环境和参数;

cd /guo

tar jxf nagios-cn-3.2.3.tar.bz2;

cd nagios-cn-3.2.3

###指定编译环境组为"ngcmd";

./configure --with-command-group=nagcmd;

###开始编译并安装

make all && make install

###安装启动脚本

make install-init;

###安装WEB配置文件

make install-webconf;

###安装配置文件

make install-config;

###设定Nagios的登陆用户名和密码;

htpasswd/usr/local/nagios/etc/htpasswd.users nagiosadmin

###检查配置正确性

/usr/local/nagios/bin/nagios-v /usr/local/nagios/etc/nagios.cfg

确保无Error 或者warning。

3.启动相关服务并测试;

/etc/init.d/nagios start

/etc/init.d/httpd start

怎么在RedHat6.5上部署Nagios

怎么在RedHat6.5上部署Nagios

4.安装相关插件。

cd /guo

 tar zxf nagios-plugins-2.1.1.tar.gz 

cd nagios-plugins-2.1.1

./configure

###执行完毕应确保自身所需的功能后面的状态显示“yes”;比如后面要用到Mysql和ssl协议加密;那结果至少包含"--with-mysql:yes,--with-openssl:yes"

###插件会被自动安装至/usr/local/nagios/libexec;

cd /usr/local/nagios/libexec;

###调整并递归此目录下所有文件

chown nagios.nagios . -R ;

###再次检查配置

/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg 
###重载Nagios配置
/etc/init.d/nagios reload         

怎么在RedHat6.5上部署Nagios

  5.编辑相关配置文件。

cd /usr/local/nagios/etc/objects/

cp  -p localhost.cfg hosts.cfg

cp -p localhost.cfg services.cfg

vim /usr/local/nagios/etc/objects/hosts.cfg

###添加如下内容:

###通过hosts.cfg文件来指定被监控主机及其相关信息;

cfg_file=/usr/local/nagios/etc/objects/hosts.cfg

###通过services.cfg文件定义监控哪些服务和资源。

cfg_file=/usr/local/nagios/etc/objects/services.cfg


###vi hosts.cfg

                definehost{
                    use                     linux-server
                    host_name               pu_tao.example.com
                    alias                   Manager
                    address                 172.25.254.18
                    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
            alias           Linux Servers
            members         *
              }
本次取一台被监控主机做实验,仅写一个服务组

                define servicegroup{
               servicegroup_name 系统负荷检查
                alias 负荷检查
                members server2.example.com,进程总数,server2.example.com用户登录 数,server2.example.com,根分区,server2.example.com,交换空间利用率
               }

    监控ping的情况

            defineservice{    
                    use                             local-service        
                    host_name                       *
                    service_description             PING
                    check_command                   check_ping!100.0,20%!500.0,60%
                    }

     监控硬盘情况

              defineservice{
                   use                             local-service        
                    host_name                       xi_gua.example.com
                    service_description             根分区
                    check_command                   check_local_disk!20%!10%!/
                   }

     监控登录用户数

            defineservice{
                use                             local-service        
               host_name                      xi_gua.example.com
                service_description             登录用户数
                check_command                   check_local_users!20!50
               }
      监控系统负荷

          define service{
                use                             local-service        
                host_name                       xi_gua.example.com
               service_description             系统负荷
                check_command                   check_local_load!5.0,4.0,3.0!10.0,6.0,4.0
                }

        监控进程总数

            defineservice{
                use                             local-service        
                host_name                       xi_gua.example.com
                service_description             进程总数
               check_command                  check_local_procs!250!400!RSZDT
                }
        监控交换空间利用率

                define service{
                use                             local-service        
                host_name                       xi_gua.example.com
                service_description             交换空间利用率
                check_command                   check_local_swap!20!10
               }

        监控ssh情况

                define service{
                    use                             local-service        
                   host_name                      xi_gua.example.com
                   service_description             SSH
                   check_command                  check_tcp!22!1.0!10.0
                    notifications_enabled           0
                    }
          监控apache

                    defineservice{
                   use                             local-service        
                   host_name                      xi_gua.example.com
                   service_description            HTTP
                   check_command                  check_http
                  notifications_enabled           0
                    }

/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg 
/etc/init.d/nagios reload                         
如图显示本机的监控成功

怎么在RedHat6.5上部署Nagios

6.再开启一台主机。本次实验主机名为xi_gua.example.com.ip:172.25.254.17;同样关闭Selinux和防火墙。

在本机上安装Mysql;并创建用户Nagios和赋予一定权限。
create database nagdb;

grant select on nagdb.* tonagios@172.25.254.18 identified by  'nagios';

返回Nagios所在主机pu_tao.example.com;

cd    /usr/local/nagios/libexec
./check_mysql -H 172.25.254.3 -unagios -pnagios

执行完毕应有类似日志信息显示;如有且无报错说明本机成功监控对端mysql
cd /usr/local/nagios/etc/objects
在 commands.cfg 中添加监控mysql的命令

        # 'check_mysql' command definition    
            definecommand{
               command_name   check_mysql
                command_line   $USER1$/check_mysql -H $HOSTADDRESS$ -u $ARG1$ -p $ARG2$
                }
在services.cfg中添加监控mysql

     ##########################check_mysql
                   define service{
                      use                             local-service         
                        host_name                       xi_gua.example.com
                       service_description             MYSQL
                        check_command                   check_mysql!nagios!nagios
                        notifications_enabled           0
                        }

在hosts.cfg中添加

         define host{
               use                    linux-server
                host_name               xi_gua.example.com
                alias                   Manager
                parents                 xi_gua.example.com
                address                 172.25.254.17
               icon_p_w_picpath              server.gif
                statusmap_p_w_picpath         server.gd2
                2d_coords               400,100
                3d_coords               400,100,100
            }

/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
/etc/init.d/nagios reload                                        

如图表示成功检测server3主机上的mysql
怎么在RedHat6.5上部署Nagios

8.安装Nrpe使nagios监控多台主机;在172.25.254.17(xi_gua.example.com)上操作。

###解压相关组件并创建nagios用户;
tar zxfnrpe-2.15.tar.gz                                                                   
tar zxf  nagios-plugins-2.1.1.tar.gz                    
yum install mysql-devel openssl-devel -y 
useradd  -M -d /usr/local/nagios  nagios            
cd nagios-plugins-2.1.1
./configure
make all && make install
cd /usr/local/nagios/libexec/       
chown nagios.nagios . -R          
yum install xinetd
cd /root/nrpe-2.15                          
./configure
make all && make install

make install-plugin
make install-daemon

make install-daemon-config

make install-xinetd

vim /etc/xinetd.d/nrpe    

 #设定监控主机为172.25.254.18
only_from       = 172.25.254.18
vim /etc/services
 nrpe   5666/tcp                        
/etc/init.d/xinetd start                    
cd /usr/local/nagios/etc/


vim nrpe.cfg           

将command[check_hda1]=/usr/local/nagios/libexec/check_disk-w 20% -c 10% -p /dev/hda1改为

command[check_disk]=/usr/local/nagios/libexec/check_disk -w 20% -c 10% -p/  #监控根分区

/etc/init.d/xinetdrestart                 
cd /usr/local/nagios/libexec/     

 scp  check_nrpe root@172.25.254.18:/usr/local/nagios/libexec/ 将check_nrpe远程复制到pu_tao.exampl.com相应的目录中。
返回172.25.254.18;做如下操作
cd /usr/local/nagios/libexec/
chown nagios.nagios  check_nrpe   

 ###检测nrpe是否可用成功显示nrpe版本号
./chek_nrpe  -H  172.25.254.17           
cd /usr/local/nagios/etc/objcts/
在 commands.cfg 中添加check_nrpe的命令

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

在services.cfg中添加

        define service{
        use                             local-service         
        host_name                       xi_gua.example.com
        service_description             根分区
        check_command                   check_nrpe!check_disk
        }
define service{
        use                             local-service         
        host_name                       xi_gua.example.com
        service_description             登录用户数
        check_command                   check_nrpe!check_users
        }
监控根分区和登录人数

/usr/local/nagios/bin/nagios -v/usr/local/nagios/etc/nagios.cfg 
/etc/init.d/nagios reload                                                                  
如图可见监控成功

怎么在RedHat6.5上部署Nagios

怎么在RedHat6.5上部署Nagios


         

9.nagios的110云报警
到onealter官网下载所用的软件包这里用的是
alert-agent-4.1.3.1-linux-x64.tar.gz
在onealter网页添加nagios应用

怎么在RedHat6.5上部署Nagios
获取应用key
怎么在RedHat6.5上部署Nagios

怎么在RedHat6.5上部署Nagios
在xi_gua.example.com主机中:
tar zxf alert-agent-4.1.3.1-linux-x64.tar.gz  
cp -R alert-agent /usr/local/nagios/libexec/  #将解压好的包放入nagios插件目录中
cp alert-agent/plugin/nagios-plugin/nagios /usr/local/nagios/libexec/
chmod +x /usr/local/nagios/libexec/nagios
cp alert-agent/plugin/nagios-plugin/110monitor.cfg/usr/local/nagios/etc/objects/   #将110配置文件放入nagios配置文件目录
在110monitor.cfg文件中添加Key:
怎么在RedHat6.5上部署Nagios


修改/usr/local/nagios/etc/objects/contacts.cfg,新增110monitor到默认联系组
    define contactgroup{
    contactgroup_name       admins
    alias                   Nagios Administrators
    members                 nagiosadmin,110monitor
    }   
修改/usr/local/nagios/etc/nagios.cfg,将110monitor.cfg新增到nagios.cfg中
cfg_file=/usr/local/nagios/etc/objects/110monitor.cfg
/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg

/etc/init.d/nagios   reload    

到此,关于“怎么在RedHat6.5上部署Nagios”的学习就结束了,希望能够解决大家的疑惑。理论与实践的搭配能更好的帮助大家学习,快去试试吧!若想继续学习更多相关知识,请继续关注亿速云网站,小编会继续努力为大家带来更多实用的文章!

推荐阅读:
  1. 在Centos上Rpm模式部署Mysql
  2. nagios安装部署

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

redhat6.5 nagios

上一篇:IntelliJ IDEA的常用设置讲解

下一篇:java中命名管道跨进程通讯的示例分析

相关阅读

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

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