centOS7下安装配置nagios
谨参照https://blog.csdn.net/ronmy/article/details/65662302,记录一下centOS7下nagios配置步骤,完整的步骤以及原理请参照原文,原文非常详细!
想要实现的效果是,把一台linux配置为监控主机,这台监控主机监控本机的一些服务,另外还监控一台linux机器和一台windows机器的服务。
nagios的安装:
安装基础支持套件:
[root@nagios-a ~]# yum install gcc glibc glibc-common gd gd-devel xinetd openssl-devel -y
创建nagios和nagios用户组,创建nagios目录并授权
[root@nagios-a ~]# useradd -s /sbin/nologin nagios
[root@nagios-a ~]# mkdir /usr/local/nagios
[root@nagios-a ~]# chown -R nagios.nagios /usr/local/nagios
查看授权是否成功
[root@nagios-a ~]# ll -d /usr/local/nagios/
drwxr-xr-x. 2 nagios nagios 6 Mar 13 16:35 /usr/local/nagios/
进入nagios网站下载nagios的压缩包,注意,www.nagios.org是开源的nagios core,而www.nagios.com是需要付费的功能更强大的nagios XI,这里讲的nagios是开源的nagios core。
wget https://assets.nagios.com/downloads/nagioscore/releases/nagios-4.4.3.tar.gz#_ga=2.261504205.1512090010.1552467729-531967639.1552467729tar -zxvf nagios-4.4.3.tar.gz cd nagios-4.4.3/./configure --prefix=/usr/local/nagios/make allmake installmake install -initmake install-commandmodemake install-config
进入nagios目录检查安装文件是否完整,检查nagios是否安装成功:
cd /usr/local/nagios/
ls
[root@nagios-a nagios]# ls
bin etc libexec sbin share var
/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfgNagios Core 4.4.3
Copyright (c) 2009-present Nagios Core Development Team and Community Contributors
Copyright (c) 1999-2009 Ethan Galstad
Last Modified: 2019-01-15
License: GPLWebsite: https://www.nagios.org
Reading configuration data...Read main config file okay...Read object config files okay...Running pre-flight check on configuration data...Checking objects...Checked 8 services.Checked 1 hosts.Checked 1 host groups.Checked 0 service groups.Checked 1 contacts.Checked 1 contact groups.Checked 24 commands.Checked 5 time periods.Checked 0 host escalations.Checked 0 service escalations.
Checking for circular paths...Checked 1 hostsChecked 0 service dependenciesChecked 0 host dependenciesChecked 5 timeperiods
Checking global event handlers...
Checking obsessive compulsive processor commands...
Checking misc settings...Total Warnings: 0
Total Errors: 0Things look okay - No serious problems were detected during the pre-flight check
安装配置php
yum install php
vim /etc/httpd/conf/httpd.confUser daemon
Group daemon
改为
User nagios
Group nagios <IfModule dir_module> DirectoryIndex index.html
</IfModule>
改为
<IfModule dir_module> DirectoryIndex index.html index.php
</IfModule> ServerName 192.200.1.121:80Listen 80
在这个文件最后增加以下代码,使nagios的web页面必须经过授权才能访问
#setting for nagios
ScriptAlias /nagios/cgi-bin "/usr/local/nagios/sbin"
<Directory "/usr/local/nagios/sbin"> AuthType Basic Options ExecCGI AllowOverride None Order allow,deny Allow from all AuthName "Nagios Access" #用于此目录访问身份验证的文件AuthUserFile /usr/local/nagios/etc/htpasswd Require valid-user
</Directory>
Alias /nagios "/usr/local/nagios/share"
<Directory "/usr/local/nagios/share"> AuthType Basic Options None AllowOverride None Order allow,deny Allow from all AuthName "nagios Access" AuthUserFile /usr/local/nagios/etc/htpasswd Require valid-user
</Directory>
在上面的配置中,指定了目录验证文件htpasswd,下面要创建这个文件:
/usr/bin/htpasswd -c /usr/local/nagios/etc/htpasswd nagios
修改 vim /usr/local/nagios/etc/cgi.cfg
default_user_name=nagios
authorized_for_system_information=nagiosadmin,nagios
authorized_for_configuration_information=nagiosadmin,nagios
authorized_for_system_commands=nagios
authorized_for_all_services=nagiosadmin,nagios
authorized_for_all_hosts=nagiosadmin,nagios
authorized_for_all_service_commands=nagiosadmin,nagios
authorized_for_all_host_commands=nagiosadmin,nagios
之后启动服务:
systemctl httpd.service start
/usr/local/nagios/bin/nagios -d /usr/local/nagios/etc/nagios.cfg
到此,nagios安装完成了,已经可以通过网页来访问了。
需要注意的是,nagios只是一个空壳,真正起到监控功能的是nagios的各种插件,现在安装nagios的插件,依然是那个网址,nagios.org:
下载后,解压,安装:
tar -zxvf nagios-plugins-2.2.1.tar.gz
cd nagios-plugins-2.2.1/
./configure --with-nagios-user=nagios --with-nagios-group=nagios
make
make all
make installls /usr/local/nagios/libexec/|wc -l
#查看插件的个数
插件装好了,下面修改一下配置文件,设置监控的主机,首先设置监控本机:
在/usr/local/nagios/etc/object/下,有一个localhost.cfg文件,这个文件本来就是存在的,是不需要修改的。
define host {use linux-server ; Name of host template to use; This host definition will inherit all variables that are defined; in (or inherited by) the linux-server host template definition.host_name localhostalias 1.121address 127.0.0.1
}
这样,本机就修改完了,接下来,进行监控windows的配置:
在/usr/local/nagios/etc/object/下,有一个windows.cfg文件,这个文件也是本来就存在的,修改这个文件,使nagios可以监控windows主机,修改这个文件也非常简单,只需要把windows主机的ip地址放在address对应位置就可以了:
define host {use windows-server ; Inherit default values from a templatehost_name winserver ; The name we're giving to this hostalias My Windows Server ; A longer name associated with the hostaddress 192.200.10.202 ; IP address of the host
}
当然,alias可以改成任意的名字。
重启nagios,可以发现localhost的服务被正常监控,windows主机也可以被ping通,但是windows的服务是监控不到的,这是怎么回事呢,是因为windows没有装nagios插件呀,这样nagios就无法监控到windows的服务了,下面为windows安装nagios插件:
windows下的nagios监控插件名叫NSClient++,访问官网http://www.nsclient.org,下载安装包,这里我下载的是NSCP-0.5.2.35-x64 .msi,下载完成以后,双击进行安装,
这里我选的是comlete:
安装完成后,记得在服务中把NSClient++服务启动起来:
然后看到有些服务已经起来了,但是有些服务看起来并不能正常监控,下面修改一下windows插件的配置文件,默认安装的位置是在C:\Program Files\NSClient++下,nsclient.ini这个文件就是配置文件了
# If you want to fill this file with all available options run the following command:
# nscp settings --generate --add-defaults --load-all
# If you want to activate a module and bring in all its options use:
# nscp settings --activate-module <MODULE NAME> --add-defaults
# For details run: nscp settings --help; in flight - TODO
[/settings/default]; Undocumented key
allowed hosts = 192.200.1.121; in flight - TODO
[/settings/NRPE/server]; Undocumented key
verify mode = none; Undocumented key
insecure = true; in flight - TODO
[/modules]; Undocumented key
CheckExternalScripts = enabled; Undocumented key
CheckHelpers = enabled; Undocumented key
CheckNSCP = enabled; Undocumented key
CheckDisk = enabled; Undocumented key
WEBServer = enabled; Undocumented key
CheckSystem = enabled; Undocumented key
NSClientServer = enabled; Undocumented key
CheckEventLog = enabled; Undocumented key
NSCAClient = enabled; Undocumented key
NRPEServer = enabled
把 diable改为enabled,这样服务就能被监控了,改完之后记得去把服务里把NSClient++服务重启一下,然后就能看到监控正常了呢
当然,如果有些服务你不想让他监控,那就去配置文件修改一下监控的内容,比如不想监控一些windows服务,那么就在:windows.cfg文件里把相应的服务注释掉:
#define service {
#
# use generic-service
# host_name winserver
# service_description W3SVC
# check_command check_nt!SERVICESTATE!-d SHOWALL -l W3SVC
#}# Create a service for monitoring the Explorer.exe process
# Change the host_name to match the name of the host you defined above#define service {# use generic-service
# host_name winserver
# service_description Explorer
# check_command check_nt!PROCSTATE!-d SHOWALL -l Explorer.exe
#}
同理,linux的本机localhost.cfg文件,注释掉相应的服务:
#define service {
#
# use local-service ; Name of service template to use
# host_name localhost
# service_description HTTP
# check_command check_http
# notifications_enabled 0
#}
之后重启nagios服务,可以看到注释掉的服务都不见了:
至此,已经配置好了nagios对本机和windows主机的监控,下面进行配置nagios监控其他linux机器:
监控其他linux机器,一般来说需要手动添加两个文件,在安装nagios目录下的 /nagios/etc/object/下,分别是hosts.cfg文件和services.cfg文件,其中hosts.cfg文件主要指定被监控主机的相关情况,包括ip地址以及主机名等;而services.cfg则是定义需要监控的服务等,下面给出简单的配置示例:
hosts.cfg
define host{use linux-serverhost_name 1.131address 192.200.1.131}define host{use linux-serverhost_name 2.76address 192.200.2.76}
#####################################################################
define hostgroup{hostgroup_name test-serversalias test serversmembers 1.131,2.76}
在hosts.cfg文件中简单定义了两台需要监控的linux主机以及一个主机组,use项是引用了local-service服务的属性值,这个local-service在template.cfg文件中有定义,定义如下:
define host {name linux-server ; The name of this host templateuse generic-host ; This template inherits other values from the generic-host templatecheck_period 24x7 ; By default, Linux hosts are checked round the clockcheck_interval 5 ; Actively check the host every 5 minutesretry_interval 1 ; Schedule host check retries at 1 minute intervalsmax_check_attempts 10 ; Check each Linux host 10 times (max)check_command check-host-alive ; Default command to check Linux hostsnotification_period workhours ; Linux admins hate to be woken up, so we only notify during the day; Note that the notification_period variable is being overridden from; the value that is inherited from the generic-host template!notification_interval 120 ; Resend notifications every 2 hoursnotification_options d,u,r ; Only send notifications for specific host statescontact_groups admins ; Notifications get sent to the admins by defaultregister 0 ; DON'T REGISTER THIS DEFINITION - ITS NOT A REAL HOST, JUST A TEMPLATE!
}
在services.cfg文件中简单定义了一个服务,用于测试监控主机是否能够正常被监控到:
define service{use local-servicehost_name 1.131,2.76service_description check-host-alivecheck_command check-host-alive}
现在两个配置文件写好了,然后需要在nagios.cfg(nagios.cfg文件在nagios目录下的etc下)文件中添加对这两个文件的引用,只需要添加以下两行:
cfg_file=/usr/local/nagios/etc/objects/hosts.cfgcfg_file=/usr/local/nagios/etc/objects/services.cfg
至此,对远端linux主机的简单监控就完成了,重启nagios以后可以看到两台linux主机已经up:
如果想要监控远端主机的多个服务,当然还是要装linux插件的,以远端主机1.131为例,安装nagios插件和nrpe,依然是去nagios官网下载,先增加nagios用户,之后获取nagios插件包和nrpe包,解压后安装:
useradd nagioswget https://nagios-plugins.org/download/nagios-plugins-2.2.1.tar.gz
wget https://github.com/NagiosEnterprises/nrpe/releases/download/nrpe-3.2.1/nrpe-3.2.1.tar.gz
tar -zxvf nagios-plugins-2.2.1.tar.gz
tar -zxvf nrpe-3.2.1.tar.gz
cd nagios-plugins-2.2.1/
./configure --prefix=/usr/local/nagios
make
make all
make installchown nagios.nagios /usr/local/nagios
chown -R nagios.nagios /usr/local/nagios/libexeccd nrpe-3.2.1/
./configure --prefix=/user/local/nagios
make all
make install
然后,修改一下配置文件,允许监控主机的监控,需要修改的是/usr/local/nagios/etc目录下的nrpe.cfg文件:
allowed_hosts=127.0.0.1,192.200.1.121
这里,只需要在allowed_hosts后加上监控主机的ip就可以了,然后开启nrpe服务,确认端口开启以后去监控主机上测试一下:
/usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d
[root@nagios-b etc]# netstat -tunlp | grep nrpe
tcp 0 0 0.0.0.0:5666 0.0.0.0:* LISTEN 12545/nrpe
tcp6 0 0 :::5666 :::* LISTEN 12545/nrpe 可以看到,端口已经在被监听了,下面去监控主机上测试一下:[root@nagios-a ~]# /usr/local/nagios/libexec/check_nrpe -H 192.200.1.131
NRPE v3.2.1正常显示了NRPE的版本
之后可以配置被监控主机的其他服务了,修改监控主机的/usr/local/nagios/etc/objects下的services.cfg,比如修改成这样:
define service{use local-servicehost_name 1.131service_description check-host-alivecheck_command check-host-alive}define service {use local-servicehost_name 1.131service_description PINGcheck_command check_ping!100.0,20%!500.0,60%
}# Define a service to check the disk space of the root partition
# on the local machine. Warning if < 20% free, critical if
# < 10% free space on partition.define service {use local-servicehost_name 1.131service_description Root Partitioncheck_command check_local_disk!20%!10%!/
}# Define a service to check the number of currently logged in
# users on the local machine. Warning if > 20 users, critical
# if > 50 users.define service {use local-servicehost_name 1.131service_description Current Userscheck_command check_local_users!20!50
}# Define a service to check the number of currently running procs
# on the local machine. Warning if > 250 processes, critical if
# > 400 processes.define service {use local-servicehost_name 1.131service_description Total Processescheck_command check_local_procs!250!400!RSZDT
}# Define a service to check the load on the local machine.define service {use local-servicehost_name 1.131service_description Current Loadcheck_command check_local_load!5.0,4.0,3.0!10.0,6.0,4.0
}# Define a service to check the swap usage the local machine.
# Critical if less than 10% of swap is free, warning if less than 20% is freedefine service {use local-servicehost_name 1.131service_description Swap Usagecheck_command check_local_swap!20%!10%
}# Define a service to check SSH on the local machine.
# Disable notifications for this service by default, as not all users may have SSH enabled.define service {use local-servicehost_name 1.131service_description SSHcheck_command check_sshnotifications_enabled 0
}
之后检查一下配置文件有没有错误:
/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
Nagios Core 4.4.3
Copyright (c) 2009-present Nagios Core Development Team and Community Contributors
Copyright (c) 1999-2009 Ethan Galstad
Last Modified: 2019-01-15
License: GPLWebsite: https://www.nagios.org
Reading configuration data...Read main config file okay...Read object config files okay...Running pre-flight check on configuration data...Checking objects...Checked 20 services.Checked 4 hosts.Checked 3 host groups.Checked 0 service groups.Checked 1 contacts.Checked 1 contact groups.Checked 24 commands.Checked 5 time periods.Checked 0 host escalations.Checked 0 service escalations.
Checking for circular paths...Checked 4 hostsChecked 0 service dependenciesChecked 0 host dependenciesChecked 5 timeperiods
Checking global event handlers...
Checking obsessive compulsive processor commands...
Checking misc settings...Total Warnings: 0
Total Errors: 0Things look okay - No serious problems were detected during the pre-flight check
如图输出证明没有问题,之后放心的重启nagios就好了
可以看到这些服务都可以正常监控了呢!
到这里配置已经完成了,还可以设置一个邮件报警的功能,这个功能的配置是在contacts.cfg这个配置文件中配置的,内容如下:
define contact {contact_name xiaobai ; Short name of useruse generic-contact ; Inherit default values from generic-contact template (defined above)alias Nagios Admin ; Full name of useremail *****@***.com ;<<***** CHANGE THIS TO YOUR EMAIL ADDRESS ******
}###############################################################################
#
# CONTACT GROUPS
#
################################################################################ We only have one contact in this simple configuration file, so there is
# no need to create more than one contact group.define contactgroup {contactgroup_name adminsalias Nagios Administratorsmembers xiaobai
}
在email出配置上你的地址,就可以收到邮箱报警啦!
至此,对我来说nagios的配置已经全部完成啦!
以上。
centOS7下安装配置nagios相关推荐
- Centos7下安装配置开源存储虚拟化QuadStor(4)----Vdisk Clone
操作环境 同< Centos7下安装配置开源存储虚拟化QuadStor(1)------初始化QuadStor> QuadStor Server:10.10.200.227 iSCSi I ...
- Centos7 下安装配置tomcat7
首先下载压缩包 wget http://mirrors.tuna.tsinghua.edu.cn/apache/tomcat/tomcat-7/v7.0.78/bin/apache-tomcat-7. ...
- linux7下安装git,centos7下安装配置git仓库
1.安装git yum -y install git 2.添加git用户和git用户组 useradd git 设置密码 passwd git 3.创建git仓库目录 我放在/var/gitdata/ ...
- 3.5.CentOS7下安装配置Zookeeper集群与一键启动小脚本
python编程快速上手(持续更新中-) 推荐系统基础 文章目录 python编程快速上手(持续更新中-) 推荐系统基础 一.事前准备 1.VMware下CentOS7虚拟机(三台) 2.Zookee ...
- CentOS7下安装配置zookeeper集群及设置开机自启
1.在做zookeeper集群之前需要有至少三台centos机器或虚拟机 一.Zookeeper原理简介 ZooKeeper是一个开放源码的分布式应用程序协调服务,它包含一个简单的原语集,分布式应用程 ...
- centos7下安装配置FMS5.0
最近需要使用rtmp服务器,在red5和AMS之间选择了AMS来搭建,说先说明一下AMS全称是adobe media server,在5.0版本之前名称是FMS(flash media server) ...
- Linux下安装配置Jenkins
前面简单介绍了下CentOS7下安装配置nuxus和CentOS7下防火墙的配置,今天继续介绍CentOS7下jenkins的安装配置. 下载 我在安装配置时,用的是jenkins的rpm包,下载地址 ...
- Centos7虚拟机下安装配置Tomcat
Centos7虚拟机下安装配置Tomcat 以下所有操作都是CentOS7的root身份.已经安装配置了Java环境.配置了nat虚拟网络.并且虚拟机已经连接互联网 打开终端.如果命令结尾是 # 则表 ...
- tomcat7.0.81 linux,Linux/CentOS7.0下安装配置Tomcat8.0
Linux/CentOS7.0下安装配置Tomcat8.0 一.配置Tomcat安装环境 1.下载对应的jdk 我用的是64位的下载地址: 下载将jdk加压后放到/usr/local目录下: 2.建立 ...
- CentOS7.3 安装配置 Nginx、MariaDB、PHP
CentOS7.3 安装配置 Nginx.MariaDB.PHP 配置 nginx 安装参数并安装 配置 以下参数也可以在后期通过配置 conf 文件进行配置 基本配置如下 ./configure - ...
最新文章
- 教你9招最有效防电脑辐射方法
- 浏览器要是能这么做就好了
- java中对象 引用的概念_java中的对象 方法 引用 等一些抽象的概念是什么意思呢?...
- 一个咸鱼的python_一个咸鱼的Python爬虫之路(三):爬取网页图片
- php百度地图api的geocoder,百度地图API提供Geocoder类
- cordova android 开发,Cordova开发App入门(一)创建android项目
- 易观分析联合中小银行联盟发布海南数字经济指数,敬请期待!
- 微信小程序上传照片到服务器
- Post-processing of merged bean definition failed; spring cloud Eureka 启动报错
- java邮件发送 qq与163邮箱互发和qq和163邮箱发送其他邮箱实例
- 使用 Vue 和 epub.js 制作电子书阅读器
- word转html java代码_用java实现word转html
- Adobe全家桶系列百度云(含最新软件安装包+安装教程)
- 使用nodejs + wecharty打造你的个人微信机器人
- UVM--Sequencer和Sequence
- java 从已知日期计算干支纪日_天干地支纪日纪时计算公式
- 【AI学习总结】均方误差(Mean Square Error,MSE)与交叉熵(Cross Entropy,CE)损失函数
- 【Linux 命令】chroot
- c语言编程曹冲称象,《曹冲称象》教学设计
- clusterProfiler安装
热门文章
- git clean使用方法
- Pillow(PIL)入门教程(非常详细)
- 正余弦转化之诱导公式:“奇变偶不变、符号看象限”
- UVA1153 顾客是上帝 Keep the Customer Satisfied(贪心)
- TP-LINK路由器手动设置网关、DNS、开启DHCP并指定地址池IP范围
- U盘被写保护无法格式化的解决方法
- 含泪整理最优质QuickTime软件插件素材,你想要的这里都有
- 塑料废物管理行业调研报告 - 市场现状分析与发展前景预测
- cad解除块的快捷命令_Auto CAD2007解除块快捷键是什么呢?
- win10 1903错误应用程序无法正常启动0xc0000135解决