资讯

精准传达 • 有效沟通

从品牌网站建设到网络营销策划,从策略到执行的一站式服务

nagios安装与配置-创新互联

nagios

创新互联专注于网站建设|成都网站改版|优化|托管以及网络推广,积累了大量的网站设计与制作经验,为许多企业提供了网站定制设计服务,案例作品覆盖成都高空作业车租赁等行业。能根据企业所处的行业与销售的产品,结合品牌形象的塑造,量身设计品质网站。

nagios配置文件设置分为俩种,一种如下设置,第二种为创建servers目录集中管理被监控主机和generic_cfg目录管理监控本机的配置文件。

# yum install -y httpd php glibc glibc-common gd gd-devel gcc

[root@teacher ~]# useradd nagios

[root@teacher ~]# groupadd nagcmd

[root@teacher ~]# usermod -a -G nagcmd apache

[root@teacher ~]# usermod -a -G nagcmd nagios

开始安装

# tar zxvf nagios-3.2.3.tar.gz -C /usr/local/src

# cd /usr/local/src/nagios-3.2.3/

# ./configure --prefix=/usr/local/nagios --with-command-group=nagcmd

# make all
# make install-init
# make install-commandmode
# make install-config
# make install-webconf

# cd /etc/httpd/conf.d
# vim nagios.conf
  //记住保存用户名和密码的文件

# htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin  //配置密码
-------------
安装插件

# tar zxvf nagios-plugins-1.4.15.tar.gz -C /usr/local/src

# cd /usr/local/src/nagios-plugins-1.4.15/

# ./configure --with-nagios-user=nagios --with-nagios-group=nagcmd

# make
# make install

# cd /usr/local/nagios/libexec/
# ls
# ./check_ssh --help  //查看帮助

启动服务
# service httpd restart

# service nagios restart
----------------------------

监控端 (服务器端) 192.168.3.2
# cd  /usr/local/nagios/etc/objects
# vim contacts.cfg

 39 define contact{
 40         contact_name                    matrix
 41 #       use                             generic-contact
 42         alias                           administrator
 43         service_notification_period     24x7
 44         host_notification_period        24x7
 45         service_notification_options    w,u,c,r
 46         host_notification_options       d,u,r
 47         service_notification_commands   notify-service-by-email
 48         host_notification_commands      notify-host-by-email
 49
 50         email                           matrix@localhost
 51         }

define contactgroup{
        contactgroup_name       admins
        alias                   Nagios Administrators
        members                 nagiosadmin,matrix      //添加matrix 逗号分隔
        }

# vim remotehost.cfg

define host{
host_name  apache
alias      apache
address    192.168.3.3
max_check_attempts   5
check_period    24x7
normal_check_interval 5
retry_check_interval 1
contact_groups admins
notification_period  24x7
notification_options d,u,r
}

# vim services.cfg

define service{
use  local-service
host_name  apache
service_description  apache_alive
check_command    check_ping!100.0,20%!500.0,60%
}

define service{
host_name   apache
service_description  check_tcp 80
max_check_attempts   5
check_period  24x7
normal_check_interval  5
retry_check_interval  2
contact_groups   admins
notification_period  24x7
notification_options   w,u,c,r
check_command   check_tcp!80
}

# pwd
/usr/local/nagios/etc
# vim nagios.cfg

  34 cfg_file=/usr/local/nagios/etc/objects/remotehost.cfg
  35 cfg_file=/usr/local/nagios/etc/objects/services.cfg

//检查配置文件错误
# /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg

Total Warnings: 0
Total Errors:   0

//服务重启
# /etc/init.d/nagios restart

firefox http://192.168.3.2/nagios &
   //监控端的ip
-------------------------------
需要监控被监控端的web服务
在被监控端  192.168.3.3
启动网页服务
# service httpd restart

--------------------------------------
通过NRPE 监控远程主机

远程主机(被监控端) 192.168.3.3

# useradd -s /sbin/nologin -M  nagios

# yum install gcc glibc glibc-common -y

# tar zxvf nagios-plugins-1.4.15.tar.gz -C /usr/local/src

# cd /usr/local/src/nagios-plugins-1.4.15/

# ./configure --prefix=/usr/local/nagios
# make
# make install

安装NRPE
# yum install openssl openssl-devel -y

# tar zxvf nrpe-2.12.tar.gz -C /usr/local/src

# cd /usr/local/src/nrpe-2.12/

# ./configure --prefix=/usr/local/nagios

# make all

# make install-plugin
# make install-daemon
# make install-daemon-config
# make install-xinetd

# vim /etc/services

 418 nrpe            5666/tcp                        # nrpe

# vim /etc/xinetd.d/nrpe

disable         = no
        only_from       = 192.168.3.2  127.0.0.1             //添加监控端的ip地址

# /etc/init.d/xinetd  restart

# netstat -altunp | grep :5666
tcp        0      0 0.0.0.0:5666                0.0.0.0:*                   LISTEN      21318/xinetd

若开启防火墙需开放端口

iptables -A INPUT -p tcp -m tcp --dport 5666 -j ACCEPT

编辑配置文件
# vim /usr/local/nagios/etc/nrpe.cfg

199 command[check_users]=/usr/local/nagios/libexec/check_users -w 5 -c 10
200 command[check_load]=/usr/local/nagios/libexec/check_load -w 15,10,5 -c 30,25,20
201 command[check_sda1]=/usr/local/nagios/libexec/check_disk -w 20% -c 10% -p /dev/sda1
202 command[check_sda2]=/usr/local/nagios/libexec/check_disk -w 20% -c 10% -p /dev/sda2
203 command[check_zombie_procs]=/usr/local/nagios/libexec/check_procs -w 5 -c 10 -s Z
204 command[check_total_procs]=/usr/local/nagios/libexec/check_procs -w 150 -c 200

在本机测试
# /usr/local/nagios/libexec/check_nrpe -H localhost -c check_sda2
DISK OK - free space: / 21788 MB (77% inode=98%);| /=6431MB;23804;26780;0;29756
[root@teacher xinetd.d]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/sda2              30G  6.3G   22G  23% /
/dev/sda1              99M   12M   83M  12% /boot
tmpfs                 252M     0  252M   0% /dev/shm
/rhel55.iso           2.9G  2.9G     0 100% /mnt/cdrom

[root@teacher xinetd.d]# df -i
Filesystem            Inodes   IUsed   IFree IUse% Mounted on
/dev/sda2            7864320  156918 7707402    2% /
/dev/sda1              26104      34   26070    1% /boot
tmpfs                  64413       1   64412    1% /dev/shm
/rhel55.iso                0       0       0    -  /mnt/cdrom
-------------------------

监控端  192.168.3.2

# yum install openssl openssl-devel -y

# tar zxvf nrpe-2.12.tar.gz -C /usr/local/src

# cd /usr/local/src/nrpe-2.12/

# ./configure --prefix=/usr/local/nagios
# make all
# make install-plugin

手动测试  写上被监控端的ip地址

# /usr/local/nagios/libexec/check_nrpe -H 192.168.3.3 -c check_sda2

DISK OK - free space: / 21788 MB (77% inode=98%);| /=6431MB;23804;26780;0;29756

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

# vim commands.cfg

添加
define command{
        command_name    check_nrpe
        command_line    $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$
        }

# vim services.cfg

#define 192.168.3.3 "/boot"
define service{
use  local-service
host_name  apache
service_description  boot partition
check_command    check_nrpe!check_sda1
}

#define 192.168.3.3 "/"
define service{
use  local-service
host_name  apache
service_description  / partition
check_command    check_nrpe!check_sda2
}

检查配置文件
# /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg

服务重启
# service nagios restart

另外有需要云服务器可以了解下创新互联scvps.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。


网站栏目:nagios安装与配置-创新互联
标题路径:http://cdkjz.cn/article/eepsd.html
多年建站经验

多一份参考,总有益处

联系快上网,免费获得专属《策划方案》及报价

咨询相关问题或预约面谈,可以通过以下方式与我们联系

业务热线:400-028-6601 / 大客户专线   成都:13518219792   座机:028-86922220