nagios4.3.4监控_如何在Ubuntu 18.04上安装Nagios 4并监视服务器

nagios4.3.4监控

The author selected the Open Source Initiative to receive a donation as part of the Write for DOnations program.

作者选择了开放源代码计划来接受捐赠,这是Write for DOnations计划的一部分。

介绍 (Introduction)

Nagios is a popular open-source monitoring system. It keeps an inventory of your servers and monitors them so you know your critical services are up and running. Using a monitoring system like Nagios is an essential tool for any production environment, because by monitoring uptime, CPU usage, or disk space, you can head off problems before they occur, or before your users call you.

Nagios是一种流行的开源监视系统。 它会保留您的服务器清单并对其进行监视,以便您知道关键服务已启动并正在运行。 使用Nagios这样的监视系统对于任何生产环境都是必不可少的工具,因为通过监视正常运行时间,CPU使用率或磁盘空间,您可以在问题发生之前或在用户致电之前解决问题。

In this tutorial, you’ll install Nagios 4 and configure it so you can monitor host resources via Nagios’ web interface. You’ll also set up the Nagios Remote Plugin Executor (NRPE), which runs as an agent on remote hosts so you can monitor their resources.

在本教程中,您将安装Nagios 4并对其进行配置,以便可以通过Nagios的Web界面监视主机资源。 您还将设置Nagios远程插件执行器(NRPE),该代理在远程主机上作为代理运行,以便您监视其资源。

先决条件 (Prerequisites)

To follow this tutorial, you will need:

要遵循本教程,您将需要:

  • Two Ubuntu 18.04 servers set up by following our Initial Server Setup Guide for Ubuntu 18.04, including a non-root user with sudo privileges and a firewall configured with ufw. On one server, you will install Nagios; this tutorial will refer to this as the Nagios server. It will monitor your second server; this second server will be referred to as the second Ubuntu server.

    按照我们的《 Ubuntu 18.04初始服务器设置指南》设置了两台Ubuntu 18.04服务器,其中包括具有sudo特权的非root用户和配​​置了ufw的防火墙。 在一台服务器上,您将安装Nagios; 本教程将其称为Nagios服务器 。 它将监视您的第二台服务器; 第二台服务器将被称为第二台Ubuntu服务器

  • The server that will run the Nagios server needs Apache and PHP installed. Follow this guide to configure those on one of your servers. You can skip the MySQL steps in that tutorial.

    将要运行Nagios服务器的服务器需要安装Apache和PHP。 按照本指南在您的一台服务器上进行配置。 您可以跳过该教程中MySQL步骤。

Typically, Nagios runs behind a hardware firewall or VPN. If your Nagios server is exposed to the public internet, you should secure the Nagios web interface by installing a TLS/SSL certificate. This is optional but strongly encouraged. You can follow the Let’s Encrypt on Ubuntu 18.04 guide to obtain the free TLS/SSL certificate.

通常,Nagios在硬件防火墙或VPN后面运行。 如果您的Nagios服务器暴露在公共互联网上,则应通过安装TLS / SSL证书来保护Nagios Web界面。 这是可选的,但强烈建议这样做 。 您可以按照Ubuntu 18.04上的“让我们加密”指南获取免费的TLS / SSL证书。

This tutorial assumes that your servers have private networking enabled so that monitoring happens on the private network rather than the public network. If you don’t have private networking enabled, you can still follow this tutorial by replacing all the references to private IP addresses with public IP addresses.

本教程假定您的服务器已启用专用网络,因此监视是在专用网络而不是公共网络上进行的。 如果没有启用专用网络,则仍然可以按照本教程进行操作,将所有对专用IP地址的引用替换为公共IP地址。

第1步-安装Nagios 4 (Step 1 — Installing Nagios 4)

There are multiple ways to install Nagios, but you’ll install Nagios and its components from source to ensure you get the latest features, security updates, and bug fixes.

有多种安装Nagios的方法,但是您将从源代码安装Nagios及其组件,以确保获得最新功能,安全更新和错误修复。

Log in to your server that runs Apache. In this tutorial, we’ll call this the Nagios server:

登录到运行Apache的服务器。 在本教程中,我们将其称为Nagios服务器

  • ssh sammy@your_nagios_server_ip

    ssh sammy @ your_nagios_server_ip

Because you’re building Nagios and its components from source, you must install a few development libraries to complete the build, including compilers, development headers, and OpenSSL.

因为要从源代码构建Nagios及其组件,所以必须安装一些开发库来完成构建,包括编译器,开发标头和OpenSSL。

Update your package lists to ensure you can download the latest versions of the prerequisites:

更新软件包列表,以确保您可以下载必备软件的最新版本:

  • sudo apt update

    sudo apt更新

Then install the required packages:

然后安装所需的软件包:

  • sudo apt install autoconf gcc make unzip libgd-dev libmcrypt-dev libssl-dev dc snmp libnet-snmp-perl gettext

    sudo apt install autoconf gcc make解压缩libgd-dev libmcrypt-dev libssl-dev dc snmp libnet-snmp-perl gettext

With the prerequisites installed, you can install Nagios itself. Download the source code for the latest stable release of Nagios Core. Go to the Nagios downloads page, and click the Skip to download link below the form. Copy the link address for the latest stable release so you can download it to your Nagios server.

安装了先决条件后,您可以安装Nagios本身。 下载Nagios Core最新稳定版本的源代码。 转到Nagios下载页面 ,然后单击表格下方的跳过下载链接。 复制最新稳定版本的链接地址,以便可以将其下载到Nagios服务器。

Download the release to your home directory with the curl command:

使用curl命令将发行版下载到您的主目录:

  • cd ~

    光盘〜
  • curl -L -O https://github.com/NagiosEnterprises/nagioscore/archive/nagios-4.4.4.tar.gz

    curl -L -O https://github.com/NagiosEnterprises/nagioscore/archive/nagios- 4.4.4 .tar.gz

Extract the Nagios archive:

提取Nagios存档:

  • tar zxf nagios-4.4.4.tar.gz

    tar zxf nagios- 4.4.4 .tar.gz

Then change to the extracted directory:

然后转到提取的目录:

  • cd nagioscore-nagios-4.4.4

    光盘nagioscore-nagios- 4.4.4

Before building Nagios, run the configure script and specify the Apache configs directory:

在构建Nagios之前,请运行configure脚本并指定Apache configs目录:

  • ./configure --with-httpd-conf=/etc/apache2/sites-enabled

    ./configure --with-httpd-conf = / etc / apache2 / sites-enabled

Note: If you want Nagios to send emails using Postfix, you must install Postfix and configure Nagios to use it by adding --with-mail=/usr/sbin/sendmail to the configure command. We won’t cover Postfix in this tutorial, but if you choose to use Postfix and Nagios later, you’ll need to reconfigure and reinstall Nagios to use Postfix support.

注意:如果要让Nagios使用Postfix发送电子邮件,则必须安装Postfix并通过将--with-mail=/usr/sbin/sendmailconfigure命令来配置Nagios以使用它。 我们不会在本教程中介绍Postfix,但是如果您以后选择使用Postfix和Nagios,则需要重新配置并重新安装Nagios才能使用Postfix支持。

You’ll see the following output from the configure command:

您将从configure命令中看到以下输出:


   
   
Output
*** Configuration summary for nagios 4.4.4 2019-07-29 ***: General Options: ------------------------- Nagios executable: nagios Nagios user/group: nagios,nagios Command user/group: nagios,nagios Event Broker: yes Install ${prefix}: /usr/local/nagios Install ${includedir}: /usr/local/nagios/include/nagios Lock file: /run/nagios.lock Check result directory: /usr/local/nagios/var/spool/checkresults Init directory: /lib/systemd/system Apache conf.d directory: /etc/apache2/sites-enabled Mail program: /bin/mail Host OS: linux-gnu IOBroker Method: epoll Web Interface Options: ------------------------ HTML URL: http://localhost/nagios/ CGI URL: http://localhost/nagios/cgi-bin/ Traceroute (used by WAP): Review the options above for accuracy. If they look okay, type 'make all' to compile the main program and CGIs.

Now compile Nagios with this command:

现在,使用以下命令编译Nagios:

  • make all

    全部制作

Next create a nagios user and nagios group. They will be used to run the Nagios process:

接下来,创建一个nagios用户和nagios组。 它们将用于运行Nagios流程:

  • sudo make install-groups-users

    sudo make install-groups-users

Now run these make commands to install Nagios binary files, service files, and its sample configuration files:

现在运行以下make命令以安装Nagios二进制文件,服务文件及其示例配置文件:

  • sudo make install

    须藤使安装
  • sudo make install-daemoninit

    sudo make install-daemoninit
  • sudo make install-commandmode

    sudo make install-commandmode
  • sudo make install-config

    须藤制作安装配置

You’ll use Apache to serve Nagios’ web interface, so run the following to install the Apache configuration files and configure its settings:

您将使用Apache服务Nagios的Web界面,因此运行以下命令安装Apache配置文件并配置其设置:

  • sudo make install-webconf

    须藤make install-webconf

Enable the Apache rewrite and cgi modules with the a2enmod command:

使用a2enmod命令启用Apache rewritecgi模块:

  • sudo a2enmod rewrite

    sudo a2enmod重写
  • sudo a2enmod cgi

    须藤a2enmod cgi

In order to issue external commands via the web interface to Nagios, add the web server user, www-data, to the nagios group:

为了通过Web界面向Nagios发出外部命令,请将Web服务器用户www-data添加到nagios组:

  • sudo usermod -a -G nagios www-data

    sudo usermod -a -G nagios www-data

Use the htpasswd command to create an admin user called nagiosadmin that can access the Nagios web interface:

使用htpasswd命令创建一个名为nagiosadmin的管理员用户,该用户可以访问Nagios Web界面:

  • sudo htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin

    须藤htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin

Enter a password at the prompt. Remember this password, as you will need it to access the Nagios web interface.

在提示符下输入密码。 记住该密码,因为访问Nagios Web界面将需要它。

Warning: If you create a user with a name other than nagiosadmin, you will need to edit /usr/local/nagios/etc/cgi.cfg and change all the nagiosadmin references to the user you created.

警告:如果使用nagiosadmin以外的名称创建用户,则需要编辑/usr/local/nagios/etc/cgi.cfg并将所有nagiosadmin引用更改为您创建的用户。

Restart Apache to load the new Apache configuration:

重新启动Apache以加载新的Apache配置:

  • sudo systemctl restart apache2

    sudo systemctl重新启动apache2

You’ve now installed Nagios. But for this to work, it is necessary to install the Nagios Plugins, which you’ll cover in the next step.

您现在已经安装了Nagios。 但是要使其正常工作,有必要安装Nagios插件,您将在下一步中进行介绍。

第2步-安装Nagios插件 (Step 2 — Installing the Nagios Plugins)

Nagios needs plugins to operate properly. The official Nagios Plugins package contains over 50 plugins that allow you to monitor basic services such as uptime, disk usage, swap usage, NTP, and others.

Nagios需要插件才能正常运行。 Nagios官方插件包包含50多个插件,可让您监视基本服务,例如正常运行时间,磁盘使用率,交换使用率,NTP等。

Let’s install the the plugins bundle.

让我们安装插件包。

You can find the latest version of the Nagios Plugins on the official site.

您可以在官方网站上找到最新版本的Nagios插件。

Download it to your home directory with curl:

使用curl其下载到您的主目录:

  • cd ~

    光盘〜
  • curl -L -O https://nagios-plugins.org/download/nagios-plugins-2.2.1.tar.gz

    curl -L -O https://nagios-plugins.org/download/nagios-plugins- 2.2.1 .tar.gz

Extract the NRPE archive and navigate into the extracted directory:

提取NRPE存档并导航到提取的目录:

  • tar zxf nagios-plugins-2.2.1.tar.gz

    tar zxf nagios-plugins- 2.2.1 .tar.gz

  • cd nagios-plugins-2.2.1

    CD的nagios-2.2.1插件-

Next configure their installation:

接下来配置他们的安装:

  • ./configure

    。/配置

Now build and install the plugins:

现在构建并安装插件:

  • make

    使
  • sudo make install

    须藤使安装

Now the plugins are installed, but you need one more plugin for monitoring remote servers. Let’s install it next.

现在已经安装了插件,但是您还需要一个插件来监视远程服务器。 接下来安装它。

步骤3 —安装check_nrpe插件 (Step 3 — Installing the check_nrpe Plugin)

Nagios monitors remote hosts using the Nagios Remote Plugin Executor, or NRPE. It consists of two pieces:

Nagios使用Nagios远程插件执行器或NRPE监视远程主机。 它由两部分组成:

  • The check_nrpe plugin that the Nagios server uses.

    Nagios服务器使用的check_nrpe插件。

  • The NRPE daemon, which runs on the remote hosts and sends data to the Nagios server.

    NRPE守护程序在远程主机上运行,​​并将数据发送到Nagios服务器。

Let’s install the check_nrpe plugin on our Nagios server.

让我们在Nagios服务器上安装check_nrpe插件。

Find the download URL for the latest stable release of NRPE at the GitHub page.

GitHub页面上找到 NRPE的最新稳定版本的下载URL。

Download it to your home directory with curl:

使用curl其下载到您的主目录:

  • cd ~

    光盘〜
  • curl -L -O https://github.com/NagiosEnterprises/nrpe/releases/download/nrpe-3.2.1/nrpe-3.2.1.tar.gz

    curl -L -O https://github.com/NagiosEnterprises/nrpe/releases/download/ nrpe-3.2.1 / nrpe-3.2.1 .tar.gz

Extract the NRPE archive:

提取NRPE存档:

  • tar zxf nrpe-3.2.1.tar.gz

    tar zxf nrpe- 3.2.1 .tar.gz

Then change to the extracted directory:

然后转到提取的目录:

  • cd nrpe-3.2.1

    cd nrpe- 3.2.1

Configure the check_nrpe plugin:

配置check_nrpe插件:

  • ./configure

    。/配置

Now build and install check_nrpe plugin:

现在构建并安装check_nrpe插件:

  • make check_nrpe

    使check_nrpe
  • sudo make install-plugin

    sudo make install-plugin

Let’s configure the Nagios server next.

接下来,我们配置Nagios服务器。

第4步-配置Nagios (Step 4 — Configuring Nagios)

Now let’s perform the initial Nagios configuration, which involves editing some configuration files. You only need to perform this section once on your Nagios server.

现在,让我们执行Nagios的初始配置,其中涉及编辑一些配置文件。 您只需要在Nagios服务器上执行一次此部分。

Open the main Nagios configuration file in your preferred text editor. Here, you’ll use nano:

在首选的文本编辑器中打开Nagios主配置文件。 在这里,您将使用nano

  • sudo nano /usr/local/nagios/etc/nagios.cfg

    须藤纳米/usr/local/nagios/etc/nagios.cfg

Find this line in the file:

在文件中找到以下行:

/usr/local/nagios/etc/nagios.cfg
/usr/local/nagios/etc/nagios.cfg
...
#cfg_dir=/usr/local/nagios/etc/servers
...

Uncomment this line by deleting the # character from the front of the line:

通过删除行开头的#字符取消注释该行:

/usr/local/nagios/etc/nagios.cfg
/usr/local/nagios/etc/nagios.cfg
cfg_dir=/usr/local/nagios/etc/servers

Save and close nagios.cfg by pressing CTRL+X, followed by Y, and then ENTER (if you’re using nano).

通过按CTRL+X ,然后按Y ,然后按ENTER (如果您使用nano ),保存并关闭nagios.cfg

Now create the directory that will store the configuration file for each server that you will monitor:

现在创建目录,该目录将存储要监视的每个服务器的配置文件:

  • sudo mkdir /usr/local/nagios/etc/servers

    须藤mkdir / usr / local / nagios / etc / servers

Open the Nagios contacts configuration in your text editor:

在文本编辑器中打开Nagios联系人配置:

  • sudo nano /usr/local/nagios/etc/objects/contacts.cfg

    须藤纳米/usr/local/nagios/etc/objects/contacts.cfg

Find the email directive and replace its value with your own email address:

查找email指令,并将其值替换为您自己的电子邮件地址:

/usr/local/nagios/etc/objects/contacts.cfg
/usr/local/nagios/etc/objects/contacts.cfg
...
define contact{
        contact_name                    nagiosadmin             ; Short name of user
        use                             generic-contact         ; Inherit default values from generic-contact template (defined above)
        alias                           Nagios Admin            ; Full name of user
        email                           your_email@your_domain.com        ; <<***** CHANGE THIS TO YOUR EMAIL ADDRESS ******
...

Save and exit the editor.

保存并退出编辑器。

Next, add a new command to your Nagios configuration that lets you use the check_nrpe command in Nagios service definitions. Open the file /usr/local/nagios/etc/objects/commands.cfg in your editor:

接下来,将新命令添加到Nagios配置中,使您可以在Nagios服务定义中使用check_nrpe命令。 在编辑器中打开文件/usr/local/nagios/etc/objects/commands.cfg

  • sudo nano /usr/local/nagios/etc/objects/commands.cfg

    须藤纳米/usr/local/nagios/etc/objects/commands.cfg

Add the following to the end of the file to define a new command called check_nrpe:

在文件末尾添加以下内容,以定义一个名为check_nrpe的新命令:

/usr/local/nagios/etc/objects/commands.cfg
/usr/local/nagios/etc/objects/commands.cfg
...
define command{
        command_name check_nrpe
        command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$
}

This defines the name and specifies the command-line options to execute the plugin.

这将定义名称并指定用于执行插件的命令行选项。

Save and exit the editor.

保存并退出编辑器。

Then start Nagios and enable it to start when the server boots:

然后启动Nagios,并在服务器启动时使其启动:

  • sudo systemctl start nagios

    sudo systemctl启动nagios

Nagios is now running, so let’s log in to its web interface.

Nagios现在正在运行,因此让我们登录其Web界面。

第5步-访问Nagios Web界面 (Step 5 — Accessing the Nagios Web Interface)

Open your favorite web browser, and go to your Nagios server by visiting http://nagios_server_public_ip/nagios.

打开您喜欢的Web浏览器,然后访问http:// nagios_server_public_ip /nagios转到您的Nagios服务器。

Enter the login credentials for the web interface in the popup that appears. Use nagiosadmin for the username, and the password you created for that user.

在出现的弹出窗口中输入Web界面的登录凭据。 使用nagiosadmin作为用户名,以及为该用户创建的密码。

After authenticating, you will see the default Nagios home page. Click on the Hosts link in the left navigation bar to see which hosts Nagios is monitoring:

验证后,您将看到默认的Nagios主页。 单击左侧导航栏中的“ 主机”链接,以查看Nagios监视的主机:

As you can see, Nagios is monitoring only “localhost”, or itself.

如您所见,Nagios仅监视“ localhost”或自身。

Let’s monitor our other server with Nagios,

让我们使用Nagios监控其他服务器,

步骤6 —在主机上安装Nagios插件和NRPE守护程序 (Step 6 — Installing Nagios Plugins and NRPE Daemon on a Host)

Let’s add a new host so Nagios can monitor it. You’ll install the Nagios Remote Plugin Executor (NRPE) on the remote host, install some plugins, and then configure the Nagios server to monitor this host.

我们添加一个新主机,以便Nagios可以监视它。 您将在远程主机上安装Nagios远程插件执行器(NRPE),安装一些插件,然后将Nagios服务器配置为监视此主机。

Log in to the second server, which we’ll call the second Ubuntu server:

登录第二台服务器,我们将其称为第二台Ubuntu服务器

  • ssh sammy@your_monitored_server_ip

    ssh sammy @ your_monitored_server_ip

First create a nagios user which will run the NRPE agent:

首先创建一个nagios用户,它将运行NRPE代理:

  • sudo useradd nagios

    须藤useradd nagios

You’ll install NRPE from source, which means you’ll need the same development libraries you installed on the Nagios server in Step 1. Update your package sources and install the NRPE prerequisites:

您将从源代码安装NRPE,这意味着您将需要与在步骤1中在Nagios服务器上安装的开发库相同的库。更新软件包源并安装NRPE必备软件:

  • sudo apt update

    sudo apt更新
  • sudo apt install autoconf gcc libmcrypt-dev make libssl-dev wget dc build-essential gettext

    须藤apt install autoconf gcc libmcrypt-dev make libssl-dev wget dc build-essential gettext

NRPE requires that Nagios Plugins is installed on the remote host. Let’s install this package from source.

NRPE要求将Nagios插件安装在远程主机上。 让我们从源代码安装此软件包。

Find the latest release of Nagios Plugins from the downloads page.

下载页面中找到最新版本的Nagios插件。

Download Nagios Plugins to your home directory with curl:

使用curl将Nagios插件下载到您的主目录:

  • cd ~

    光盘〜
  • curl -L -O https://nagios-plugins.org/download/nagios-plugins-2.2.1.tar.gz

    curl -L -O https://nagios-plugins.org/download/nagios-plugins- 2.2.1 .tar.gz

Extract the Nagios Plugins archive and change to the extracted directory:

提取Nagios插件档案,并转到提取的目录:

  • tar zxf nagios-plugins-2.2.1.tar.gz

    tar zxf nagios-plugins- 2.2.1 .tar.gz

  • cd nagios-plugins-2.2.1

    CD的nagios-2.2.1插件-

Before building Nagios Plugins, configure them with the following command:

在构建Nagios插件之前,请使用以下命令对其进行配置:

  • ./configure

    。/配置

Now compile the plugins:

现在编译插件:

  • make

    使

Then install them by running:

然后通过运行安装它们:

  • sudo make install

    须藤使安装

Next, install NRPE daemon. Find the download URL for the latest stable release of NRPE at the GitHub page just like you did in Step 3. Download the latest stable release of NRPE to your monitored server’s home directory with curl:

接下来,安装NRPE守护程序。 就像在步骤3中一样,在GitHub页面上找到 NRPE的最新稳定版本的下载URL。使用curl可以将NRPE的最新稳定版本下载到受监视服务器的主目录中:

  • cd ~

    光盘〜
  • curl -L -O https://github.com/NagiosEnterprises/nrpe/releases/download/nrpe-3.2.1/nrpe-3.2.1.tar.gz

    curl -L -O https://github.com/NagiosEnterprises/nrpe/releases/download/ nrpe-3.2.1 / nrpe-3.2.1 .tar.gz

Extract the NRPE archive with this command:

使用以下命令提取NRPE存档:

  • tar zxf nrpe-3.2.1.tar.gz

    tar zxf nrpe- 3.2.1 .tar.gz

Then change to the extracted directory:

然后转到提取的目录:

  • cd nrpe-3.2.1

    cd nrpe- 3.2.1

Configure NRPE:

配置NRPE:

  • ./configure

    。/配置

Now build and install NRPE and its startup script with these commands:

现在,使用以下命令构建并安装NRPE及其启动脚本:

  • make nrpe

    使
  • sudo make install-daemon

    sudo make安装守护程序
  • sudo make install-config

    须藤制作安装配置
  • sudo make install-init

    须藤make install-init

Now, let’s update the NRPE configuration file and add some basic checks that Nagios can monitor.

现在,让我们更新NRPE配置文件,并添加Nagios可以监视的一些基本检查。

First, let’s monitor the disk usage of this server. Use the df -h command to look for the root filesystem. You’ll use this filesystem name in the NRPE configuration:

首先,让我们监视此服务器的磁盘使用情况。 使用df -h命令查找根文件系统。 您将在NRPE配置中使用此文件系统名称:

  • df -h /

    df -h /

You’ll see output similar to this:

您将看到类似于以下的输出:


   
   
Output
Filesystem Size Used Avail Use% Mounted on /dev/vda1 25G 1.4G 23G 6% /

Now open /usr/local/nagios/etc/nrpe.cfg file in your editor:

现在,在编辑器中打开/usr/local/nagios/etc/nrpe.cfg文件:

  • sudo nano /usr/local/nagios/etc/nrpe.cfg

    须藤纳米/usr/local/nagios/etc/nrpe.cfg

The NRPE configuration file is very long and full of comments. There are a few lines that you will need to find and modify:

NRPE配置文件非常长且充满注释。 您需要查找和修改以下几行:

  • server_address: Set to the private IP address of the monitored server.

    server_address :设置为受监视服务器的专用IP地址。

  • allowed_hosts: Add the private IP address of your Nagios server to the comma-delimited list.

    allowed_hosts :将Nagios服务器的专用IP地址添加到以逗号分隔的列表中。

  • command[check_hda1]: Change /dev/hda1 to whatever your root filesystem is called.

    command [check_hda1] :将/dev/hda1更改为您的根文件系统所调用的名称。

Locate these settings and alter them appropriately:

找到以下设置并适当地更改它们:

/usr/local/nagios/etc/nrpe.cfg
/usr/local/nagios/etc/nrpe.cfg
...
server_address=second_ubuntu_server_private_ip
...
allowed_hosts=127.0.0.1,::1,your_nagios_server_private_ip
...
command[check_vda1]=/usr/local/nagios/libexec/check_disk -w 20% -c 10% -p /dev/vda1
...

Save and exit the editor. Now you can start NRPE:

保存并退出编辑器。 现在您可以启动NRPE:

  • sudo systemctl start nrpe.service

    sudo systemctl启动nrpe.service

Ensure that the service is running by checking its status:

通过检查其状态来确保该服务正在运行:

  • sudo systemctl status nrpe.service

    sudo systemctl状态为nrpe.service

You’ll see the following output:

您将看到以下输出:


   
   
Output
... Aug 01 06:28:31 client systemd[1]: Started Nagios Remote Plugin Executor. Aug 01 06:28:31 client nrpe[8021]: Starting up daemon Aug 01 06:28:31 client nrpe[8021]: Server listening on 0.0.0.0 port 5666. Aug 01 06:28:31 client nrpe[8021]: Server listening on :: port 5666. Aug 01 06:28:31 client nrpe[8021]: Listening for connections on port 5666 Aug 01 06:28:31 client nrpe[8021]: Allowing connections from: 127.0.0.1,::1,165.22.212.38

Next, allow access to port 5666 through the firewall. If you are using UFW, configure it to allow TCP connections to port 5666 with the following command:

接下来,允许通过防火墙访问端口5666 。 如果使用的是UFW,请使用以下命令将其配置为允许TCP连接到端口5666

  • sudo ufw allow 5666/tcp

    须藤ufw允许5666 / tcp

You can learn more about UFW in How To Set Up a Firewall with UFW on Ubuntu 18.04.

您可以在如何在Ubuntu 18.04上使用UFW设置防火墙中了解有关UFW的更多信息。

Now you can check the communication with the remote NRPE server. Run the following command on the Nagios server:

现在,您可以检查与远程NRPE服务器的通信。 在Nagios服务器上运行以下命令:

  • /usr/local/nagios/libexec/check_nrpe -H second_ubuntu_server_ip

    / usr / local / nagios / libexec / check_nrpe -H second_ubuntu_server_ip

You’ll see the following output:

您将看到以下输出:


   
   
Output
NRPE v3.2.1

Repeat the steps in this section for each additional server you want to monitor.

对要监视的每个其他服务器重复此部分中的步骤。

Once you are done installing and configuring NRPE on the hosts that you want to monitor, you will have to add these hosts to your Nagios server configuration before it will start monitoring them. Let’s do that next.

在要监视的主机上完成NRPE的安装和配置后,您必须将这些主机添加到Nagios服务器配置中,然后才能开始监视它们。 让我们接下来做。

第7步-使用Nagios监视主机 (Step 7 — Monitoring Hosts with Nagios)

To monitor your hosts with Nagios, you’ll add configuration files for each host specifying what you want to monitor. You can then view those hosts in the Nagios web interface.

要使用Nagios监视主机,您将为每个主机添加配置文件,以指定要监视的主机。 然后,您可以在Nagios Web界面中查看那些主机。

On your Nagios server, create a new configuration file for each of the remote hosts that you want to monitor in /usr/local/nagios/etc/servers/. Replace the highlighted word, monitored_server_host_name with the name of your host:

在Nagios服务器上,在/usr/local/nagios/etc/servers/为要监视的每个远程主机创建一个新的配置文件。 用您的主机名替换突出显示的单词“ monitored_server_host_name ”:

  • sudo nano /usr/local/nagios/etc/servers/your_monitored_server_host_name.cfg

    须藤nano / usr / local / nagios / etc / servers / your_monitored_server_host_name .cfg

Add the following host definition, replacing the host_name value with your remote hostname, the alias value with a description of the host, and the address value with the private IP address of the remote host:

添加以下主机定义,将host_name值替换为远程主机名,将alias值替换为主机的描述,并将address值替换为远程主机的私有IP地址:

/usr/local/nagios/etc/servers/your_monitored_server_host_name.cfg
/usr/local/nagios/etc/servers/your_monitored_server_host_name.cfg
define host {
        use                             linux-server
        host_name                       your_monitored_server_host_name
        alias                           My client server
        address                         your_monitored_server_private_ip
        max_check_attempts              5
        check_period                    24x7
        notification_interval           30
        notification_period             24x7
}

With this configuration, Nagios will only tell you if the host is up or down. Let’s add some services to monitor.

使用此配置,Nagios仅会告诉您主机是打开还是关闭。 让我们添加一些要监视的服务。

First, add this block to monitor load average:

首先,添加此块以监视平均负载:

/usr/local/nagios/etc/servers/your_monitored_server_host_name.cfg
/usr/local/nagios/etc/servers/your_monitored_server_host_name.cfg
define service {
        use                             generic-service
        host_name                       your_monitored_server_host_name
        service_description             Load average
        check_command                   check_nrpe!check_load
}

The use generic-service directive tells Nagios to inherit the values of a service template called generic-service, which is predefined by Nagios.

use generic-service指令告诉Nagios继承由Nagios预先定义的称为通用服务的服务模板的值。

Next, add this block to monitor disk usage:

接下来,添加此块以监视磁盘使用情况:

/usr/local/nagios/etc/servers/your_monitored_server_host_name.cfg
/usr/local/nagios/etc/servers/your_monitored_server_host_name.cfg
define service {
        use                             generic-service
        host_name                       your_monitored_server_host_name
        service_description             /dev/vda1 free space
        check_command                   check_nrpe!check_vda1
}

Now save and quit. Restart the Nagios service to put any changes into effect:

现在保存并退出。 重新启动Nagios服务以使所有更改生效:

  • sudo systemctl restart nagios

    sudo systemctl重新启动nagios

After several minutes, Nagios will check the new hosts and you’ll see them in the Nagios web interface. Click on the Services link in the left navigation bar to see all of your monitored hosts and services.

几分钟后,Nagios将检查新主机,您将在Nagios Web界面中看到它们。 单击左侧导航栏中的“ 服务”链接,以查看所有受监视的主机和服务。

结论 (Conclusion)

You’ve installed Nagios on a server and configured it to monitor load average and disk usage of at least one remote machine.

您已在服务器上安装了Nagios,并将其配置为监视至少一台远程计算机的平均负载和磁盘使用情况。

Now that you’re monitoring a host and some of its services, you can start using Nagios to monitor your mission-critical services. You can use Nagios to set up notifications for critical events. For example, you can receive an email when your disk utilization reaches a warning or critical threshold, or a notification when your main website is down. This way you can resolve the situation promptly, or even before a problem occurs.

现在,您正在监视主机及其某些服务,您可以开始使用Nagios监视关键任务服务。 您可以使用Nagios设置紧急事件的通知。 例如,当磁盘使用率达到警告或严重阈值时,您会收到一封电子邮件;当主网站关闭时,您会收到一条通知。 这样,您可以立即解决情况,甚至可以在问题发生之前解决。

翻译自: https://www.digitalocean.com/community/tutorials/how-to-install-nagios-4-and-monitor-your-servers-on-ubuntu-18-04

nagios4.3.4监控

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值