如何在Ubuntu 18.04上安装和配置Zabbix以安全地监视远程服务器-程序员宅基地

技术标签: python  java  linux  mysql  数据库  

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

作者选择了“ 开源倡议”作为“ Write for DOnations”计划的一部分接受捐赠。

介绍 (Introduction)

Zabbix is open-source monitoring software for networks and applications. It offers real-time monitoring of thousands of metrics collected from servers, virtual machines, network devices, and web applications. These metrics can help you determine the current health of your IT infrastructure and detect problems with hardware or software components before customers complain. Useful information is stored in a database so you can analyze data over time and improve the quality of provided services, or plan upgrades of your equipment.

Zabbix是用于网络和应用程序的开源监视软件。 它提供对从服务器,虚拟机,网络设备和Web应用程序收集的数千个指标的实时监视。 这些指标可以帮助您确定IT基础架构的当前运行状况,并在客户抱怨之前检测硬件或软件组件的问题。 有用的信息存储在数据库中,因此您可以随时间分析数据并提高所提供服务的质量,或计划设备的升级。

Zabbix uses several options for collecting metrics, including agentless monitoring of user services and client-server architecture. To collect server metrics, it uses a small agent on the monitored client to gather data and send it to the Zabbix server. Zabbix supports encrypted communication between the server and connected clients, so your data is protected while it travels over insecure networks.

Zabbix使用多种选项来收集指标,包括对用户服务和客户端-服务器体系结构的无代理监视。 为了收集服务器指标,它在受监视的客户端上使用小型代理来收集数据并将其发送到Zabbix服务器。 Zabbix支持服务器与连接的客户端之间的加密通信,因此在不安全的网络上传输数据时,您的数据将受到保护。

The Zabbix server stores its data in a relational database powered by MySQL, PostgreSQL, or Oracle. You can also store historical data in nosql databases like Elasticsearch and TimescaleDB. Zabbix provides a web interface so you can view data and configure system settings.

Zabbix服务器将其数据存储在由MySQLPostgreSQLOracle支持的关系数据库中。 您还可以将历史数据存储在nosql数据库中,例如ElasticsearchTimescaleDB 。 Zabbix提供了一个Web界面,因此您可以查看数据和配置系统设置。

In this tutorial, you will configure two machines. One will be configured as the server, and the other as a client that you’ll monitor. The server will use a MySQL database to record monitoring data and use Apache to serve the web interface.

在本教程中,您将配置两台计算机。 一个将配置为服务器,另一个将配置为您要监视的客户端。 该服务器将使用MySQL数据库记录监视数据,并使用Apache提供Web界面。

先决条件 (Prerequisites)

To follow this tutorial, you will need:

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

  • Two Ubuntu 18.04 servers set up by following the 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 Zabbix; this tutorial will refer to this as the Zabbix 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配置的防火墙。 在一台服务器上,您将安装Zabbix。 本教程将其称为Zabbix服务器 。 它将监视您的第二台服务器; 第二台服务器将被称为第二台Ubuntu服务器

  • The server that will run the Zabbix server needs Apache, MySQL, and PHP installed. Follow this guide to configure those on your Zabbix server.

    将运行Zabbix服务器的服务器需要安装Apache,MySQL和PHP。 请按照本指南在Zabbix服务器上进行配置。

Additionally, because the Zabbix Server is used to access valuable information about your infrastructure that you would not want unauthorized users to access, it’s important that you keep your server secure 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.

此外,由于Zabbix服务器用于访问您不希望未经授权的用户访问的有关基础结构的有价值的信息,因此,通过安装TLS / SSL证书来确保服务器的安全非常重要。 这是可选的,但强烈建议这样做 。 您可以按照Ubuntu 18.04上的“让我们加密”指南获取免费的TLS / SSL证书。

第1步-安装Zabbix服务器 (Step 1 — Installing the Zabbix Server)

First, you need to install Zabbix on the server where you installed MySQL, Apache, and PHP. Log into this machine as your non-root user:

首先,您需要在安装MySQL,Apache和PHP的服务器上安装Zabbix。 以您的非root用户身份登录到此计算机:

  • ssh sammy@zabbix_server_ip_address

    ssh sammy @ zabbix_server_ip_address

Zabbix is available in Ubuntu’s package manager, but it’s outdated, so use the official Zabbix repository to install the latest stable version. Download and install the repository configuration package:

Zabbix在Ubuntu的软件包管理器中可用,但是已经过时了,因此请使用官方的Zabbix存储库来安装最新的稳定版本。 下载并安装存储库配置包:

  • wget https://repo.zabbix.com/zabbix/4.2/ubuntu/pool/main/z/zabbix-release/zabbix-release_4.2-1+bionic_all.deb

    wget https://repo.zabbix.com/zabbix/4.2/ubuntu/pool/main/z/zabbix-release/zabbix-release_ 4.2-1 + bionic_all.deb

  • sudo dpkg -i zabbix-release_4.2-1+bionic_all.deb

    须藤dpkg -i zabbix-release_ 4.2-1 + bionic_all.deb

You will see the following output:

您将看到以下输出:


   
   
    
Output
Selecting previously unselected package zabbix-release. (Reading database ... 61483 files and directories currently installed.) Preparing to unpack zabbix-release_4.2-1+bionic_all.deb ... Unpacking zabbix-release (4.2-1+bionicc) ... Setting up zabbix-release (4.2-1+bionicc) ...

Update the package index so the new repository is included:

更新软件包索引,以便包括新的存储库:

  • sudo apt update

    sudo apt更新

Then install the Zabbix server and web frontend with MySQL database support:

然后安装带有MySQL数据库支持的Zabbix服务器和Web前端:

  • sudo apt install zabbix-server-mysql zabbix-frontend-php

    sudo apt安装zabbix-server-mysql zabbix-frontend-php

Also, install the Zabbix agent, which will let you collect data about the Zabbix server status itself.

另外,安装Zabbix代理,它将允许您收集有关Zabbix服务器状态本身的数据。

  • sudo apt install zabbix-agent

    sudo apt安装zabbix-agent

Before you can use Zabbix, you have to set up a database to hold the data that the Zabbix server will collect from its agents. You can do this in the next step.

在使用Zabbix之前,您必须建立一个数据库来保存Zabbix服务器将从其代理收集的数据。 您可以在下一步中执行此操作。

第2步-为Zabbix配置MySQL数据库 (Step 2 — Configuring the MySQL Database for Zabbix)

You need to create a new MySQL database and populate it with some basic information in order to make it suitable for Zabbix. You’ll also create a specific user for this database so Zabbix isn’t logging into MySQL with the root account.

您需要创建一个新MySQL数据库并使用一些基本信息填充它,以使其适合Zabbix。 您还将为此数据库创建一个特定的用户,以便Zabbix不会使用root帐户登录MySQL。

Log into MySQL as the root user using the root password that you set up during the MySQL server installation:

使用您在MySQL服务器安装期间设置的root密码,以root用户身份登录到MySQL:

  • mysql -uroot -p

    mysql -uroot -p

Create the Zabbix database with UTF-8 character support:

创建具有UTF-8字符支持的Zabbix数据库:

  • create database zabbix character set utf8 collate utf8_bin;

    创建数据库zabbix字符集utf8整理utf8_bin;

Then create a user that the Zabbix server will use, give it access to the new database, and set the password for the user:

然后创建一个Zabbix服务器将使用的用户,授予它对新数据库的访问权限,并设置该用户的密码:

  • grant all privileges on zabbix.* to zabbix@localhost identified by 'your_zabbix_mysql_password';

    授予所有权限上ZABBIX *到ZABBIX @localhost通过“your_zabbix_mysql_password”标识。

Then apply these new permissions:

然后应用以下新权限:

  • flush privileges;

    同花顺特权;

That takes care of the user and the database. Exit out of the database console.

那会照顾用户和数据库。 退出数据库控制台。

  • quit;

    退出;

Next you have to import the initial schema and data. The Zabbix installation provided you with a file that sets this up.

接下来,您必须导入初始架构和数据。 Zabbix安装为您提供了一个设置文件。

Run the following command to set up the schema and import the data into the zabbix database. Use zcat since the data in the file is compressed.

运行以下命令来设置架构并将数据导入到zabbix数据库中。 由于文件中的数据已压缩,因此请使用zcat

  • zcat /usr/share/doc/zabbix-server-mysql/create.sql.gz | mysql -uzabbix -p zabbix

    zcat的/usr/share/doc/zabbix-server-mysql/create.sql.gz | mysql -uzabbix -p zabbix

Enter the password for the zabbix MySQL user that you configured when prompted.

输入在提示时配置的zabbix MySQL用户的密码。

This command will not output any errors if it was successful. If you see the error ERROR 1045 (28000): Access denied for userzabbix@'localhost' (using password: YES) then make sure you used the password for the zabbix user and not the root user.

如果成功,此命令将不会输出任何错误。 如果看到错误ERROR 1045 (28000): Access denied for user zabbix @'localhost' (using password: YES) ERROR 1045 (28000): Access denied for user @'localhost' (using password: YES)确保为zabbix用户而不是root用户使用了密码。

In order for the Zabbix server to use this database, you need to set the database password in the Zabbix server configuration file. Open the configuration file in your preferred text editor. This tutorial will use nano:

为了让Zabbix服务器使用此数据库,您需要在Zabbix服务器配置文件中设置数据库密码。 在首选的文本编辑器中打开配置文件。 本教程将使用nano

  • sudo nano /etc/zabbix/zabbix_server.conf

    须藤纳米/etc/zabbix/zabbix_server.conf

Look for the following section of the file:

查找文件的以下部分:

/etc/zabbix/zabbix_server.conf
/etc/zabbix/zabbix_server.conf
### Option: DBPassword                           
#       Database password. Ignored for SQLite.   
#       Comment this line if no password is used.
#                                                
# Mandatory: no                                  
# Default:                                       
# DBPassword=

These comments in the file explain how to connect to the database. You need to set the DBPassword value in the file to the password for your database user. Add this line below those comments to configure the database:

文件中的这些注释说明了如何连接到数据库。 您需要将文件中的DBPassword值设置为数据库用户的密码。 在这些注释下面添加以下行以配置数据库:

/etc/zabbix/zabbix_server.conf
/etc/zabbix/zabbix_server.conf
...
DBPassword=your_zabbix_mysql_password

Save and close zabbix_server.conf by pressing CTRL+X, followed by Y and then ENTER if you’re using nano.

保存并关闭zabbix_server.conf是按CTRL+X ,然后按Y ,然后按ENTER如果您使用的是nano

That takes care of the Zabbix server configuration. Next, you will make some modifications to your PHP setup in order for the Zabbix web interface to work properly.

这将负责Zabbix服务器配置。 接下来,您将对PHP设置进行一些修改,以使Zabbix Web界面正常工作。

第3步-为Zabbix配置PHP (Step 3 — Configuring PHP for Zabbix)

The Zabbix web interface is written in PHP and requires some special PHP server settings. The Zabbix installation process created an Apache configuration file that contains these settings. It is located in the directory /etc/zabbix and is loaded automatically by Apache. You need to make a small change to this file, so open it up with the following:

Zabbix Web界面是用PHP编写的,并且需要一些特殊PHP服务器设置。 Zabbix安装过程创建了一个包含这些设置的Apache配置文件。 它位于目录/etc/zabbix ,由Apache自动加载。 您需要对此文件进行一些小的更改,因此请使用以下命令将其打开:

  • sudo nano /etc/zabbix/apache.conf

    须藤纳米/etc/zabbix/apache.conf

The file contains PHP settings that meet the necessary requirements for the Zabbix web interface. However, the timezone setting is commented out by default. To make sure that Zabbix uses the correct time, you need to set the appropriate timezone.

该文件包含满足Zabbix Web界面必要要求PHP设置。 但是,默认情况下已注释掉时区设置。 为了确保Zabbix使用正确的时间,您需要设置适当的时区。

/etc/zabbix/apache.conf
/etc/zabbix/apache.conf
...
<IfModule mod_php7.c>
    php_value max_execution_time 300
    php_value memory_limit 128M
    php_value post_max_size 16M
    php_value upload_max_filesize 2M
    php_value max_input_time 300
    php_value always_populate_raw_post_data -1
    # php_value date.timezone Europe/Riga
</IfModule>

Uncomment the timezone line, highlighted in the preceding code block, and change it to your timezone. You can use this list of supported time zones to find the right one for you. Then save and close the file.

取消注释在前面的代码块中突出显示的时区行,并将其更改为您的时区。 您可以使用此支持的时区列表为您找到合适的时区 。 然后保存并关闭文件。

Now restart Apache to apply these new settings.

现在,重新启动Apache以应用这些新设置。

  • sudo systemctl restart apache2

    sudo systemctl重新启动apache2

You can now start the Zabbix server.

现在,您可以启动Zabbix服务器。

  • sudo systemctl start zabbix-server

    sudo systemctl启动zabbix服务器

Then check whether the Zabbix server is running properly:

然后检查Zabbix服务器是否正常运行:

  • sudo systemctl status zabbix-server

    sudo systemctl状态zabbix服务器

You will see the following status:

您将看到以下状态:


   
   
    
Output
● zabbix-server.service - Zabbix Server Loaded: loaded (/lib/systemd/system/zabbix-server.service; disabled; vendor preset: enabled) Active: active (running) since Fri 2019-04-05 08:50:54 UTC; 3s ago Process: 16497 ExecStart=/usr/sbin/zabbix_server -c $CONFFILE (code=exited, status=0/SUCCESS) ...

Finally, enable the server to start at boot time:

最后,启用服务器在引导时启动:

  • sudo systemctl enable zabbix-server

    sudo systemctl启用zabbix服务器

The server is set up and connected to the database. Next, set up the web frontend.

服务器已设置并连接到数据库。 接下来,设置Web前端。

Note: As mentioned in the Prerequisites section, it is recommended that you enable SSL/TLS on your server. You can follow this tutorial now to obtain a free SSL certificate for Apache on Ubuntu 18.04. After obtaining your SSL/TLS certificates, you can come back and complete this tutorial.

注意:如“先决条件”部分所述,建议您在服务器上启用SSL / TLS。 您现在可以按照本教程操作,以在Ubuntu 18.04上获得Apache的免费SSL证书。 获得SSL / TLS证书后,您可以返回并完成本教程。

第4步-配置Zabbix Web界面的设置 (Step 4 — Configuring Settings for the Zabbix Web Interface)

The web interface lets you see reports and add hosts that you want to monitor, but it needs some initial setup before you can use it. Launch your browser and go to the address http://zabbix_server_name/zabbix/. On the first screen, you will see a welcome message. Click Next step to continue.

Web界面使您可以查看报告并添加要监视的主机,但是在使用之前需要进行一些初始设置。 启动浏览器,然后转到地址http:// zabbix_server_name /zabbix/ 。 在第一个屏幕上,您将看到一条欢迎消息。 单击下一步继续。

On the next screen, you will see the table that lists all of the prerequisites to run Zabbix.

在下一个屏幕上,您将看到该表,其中列出了运行Zabbix的所有先决条件。

All of the values in this table must be OK, so verify that they are. Be sure to scroll down and look at all of the prerequisites. Once you’ve verified that everything is ready to go, click Next step to proceed.

该表中的所有值都必须为OK ,因此请验证它们是否正确。 确保向下滚动并查看所有先决条件。 确认一切准备就绪后,请单击下一步继续。

The next screen asks for database connection information.

下一个屏幕询问数据库连接信息。

You told the Zabbix server about your database, but the Zabbix web interface also needs access to the database to manage hosts and read data. Therefore enter the MySQL credentials you configured in Step 2 and click Next step to proceed.

您向Zabbix服务器介绍了数据库,但是Zabbix Web界面还需要访问数据库以管理主机和读取数据。 因此,输入在步骤2中配置MySQL凭据,然后单击“下一步”继续。

On the next screen, you can leave the options at their default values.

在下一个屏幕上,您可以将选项保留为默认值。

The Name is optional; it is used in the web interface to distinguish one server from another in case you have several monitoring servers. Click Next step to proceed.

名称是可选的; 如果您有多台监视服务器,则在Web界面中使用它将一台服务器与另一台服务器区分开。 单击下一步继续。

The next screen will show the pre-installation summary so you can confirm everything is correct.

下一个屏幕将显示安装前摘要,因此您可以确认所有内容正确。

Click Next step to proceed to the final screen.

单击下一步进入最终屏幕。

The web interface setup is complete! This process creates the configuration file /usr/share/zabbix/conf/zabbix.conf.php which you could back up and use in the future. Click Finish to proceed to the login screen. The default user is Admin and the password is zabbix.

Web界面设置已完成! 此过程将创建配置文件/usr/share/zabbix/conf/zabbix.conf.php ,您将来可以备份和使用它。 单击完成进入登录屏幕。 默认用户为Admin ,密码为zabbix

Before you log in, set up the Zabbix agent on your second Ubuntu server.

登录之前,请在第二台Ubuntu服务器上设置Zabbix代理。

步骤5 —安装和配置Zabbix代理 (Step 5 — Installing and Configuring the Zabbix Agent)

Now you need to configure the agent software that will send monitoring data to the Zabbix server.

现在,您需要配置代理软件,该代理软件会将监视数据发送到Zabbix服务器。

Log in to the second Ubuntu server:

登录第二台Ubuntu服务器:

  • ssh sammy@second_ubuntu_server_ip_address

    ssh sammy @ second_ubuntu_server_ip_address

Then, just like on the Zabbix server, run the following commands to install the repository configuration package:

然后,就像在Zabbix服务器上一样,运行以下命令来安装存储库配置包:

  • wget https://repo.zabbix.com/zabbix/4.2/ubuntu/pool/main/z/zabbix-release/zabbix-release_4.2-1+bionic_all.deb

    wget https://repo.zabbix.com/zabbix/4.2/ubuntu/pool/main/z/zabbix-release/zabbix-release_ 4.2-1 + bionic_all.deb

  • sudo dpkg -i zabbix-release_4.2-1+bionic_all.deb

    须藤dpkg -i zabbix-release_ 4.2-1 + bionic_all.deb

Next, update the package index:

接下来,更新包索引:

  • sudo apt update

    sudo apt更新

Then install the Zabbix agent:

然后安装Zabbix代理:

  • sudo apt install zabbix-agent

    sudo apt安装zabbix-agent

While Zabbix supports certificate-based encryption, setting up a certificate authority is beyond the scope of this tutorial, but you can use pre-shared keys (PSK) to secure the connection between the server and agent.

尽管Zabbix支持基于证书的加密,但是设置证书授权超出了本教程的范围,但是您可以使用预共享密钥(PSK)来保护服务器和代理之间的连接。

First, generate a PSK:

首先,生成一个PSK:

  • sudo sh -c "openssl rand -hex 32 > /etc/zabbix/zabbix_agentd.psk"

    sudo sh -c“ openssl rand -hex 32> /etc/zabbix/zabbix_agentd.psk”

Show the key so you can copy it somewhere. You will need it to configure the host.

显示密钥,以便将其复制到某个地方。 您将需要它来配置主机。

  • cat /etc/zabbix/zabbix_agentd.psk

    猫/etc/zabbix/zabbix_agentd.psk

The key will look something like this:

密钥将如下所示:


   
   
    
Output
12eb854dea38ac9ee7d1ded2d74cee6262b0a56710f6946f7913d674ab82cdd4

Now edit the Zabbix agent settings to set up its secure connection to the Zabbix server. Open the agent configuration file in your text editor:

现在,编辑Zabbix代理设置以设置其与Zabbix服务器的安全连接。 在文本编辑器中打开代理配置文件:

  • sudo nano /etc/zabbix/zabbix_agentd.conf

    须藤纳米/etc/zabbix/zabbix_agentd.conf

Each setting within this file is documented via informative comments throughout the file, but you only need to edit some of them.

该文件中的每个设置都会通过整个文件中的信息性注释进行记录,但是您只需要对其进行一些编辑即可。

First you have to edit the IP address of the Zabbix server. Find the following section:

首先,您必须编辑Zabbix服务器的IP地址。 查找以下部分:

/etc/zabbix/zabbix_agentd.conf
/etc/zabbix/zabbix_agentd.conf
...
### Option: Server
#       List of comma delimited IP addresses (or hostnames) of Zabbix servers.
#       Incoming connections will be accepted only from the hosts listed here.
#       If IPv6 support is enabled then '127.0.0.1', '::127.0.0.1', '::ffff:127.0.0.1' are treated equally.
#
# Mandatory: no
# Default:
# Server=

Server=127.0.0.1
...

Change the default value to the IP of your Zabbix server:

将默认值更改为Zabbix服务器的IP:

/etc/zabbix/zabbix_agentd.conf
/etc/zabbix/zabbix_agentd.conf
...
Server=zabbix_server_ip_address
...

Next, find the section that configures the secure connection to the Zabbix server and enable pre-shared key support. Find the TLSConnect section, which looks like this:

接下来,找到配置与Zabbix服务器的安全连接并启用预共享密钥支持的部分。 找到TLSConnect部分,如下所示:

/etc/zabbix/zabbix_agentd.conf
/etc/zabbix/zabbix_agentd.conf
...
### Option: TLSConnect
#       How the agent should connect to server or proxy. Used for active checks.
#       Only one value can be specified:
#               unencrypted - connect without encryption
#               psk         - connect using TLS and a pre-shared key
#               cert        - connect using TLS and a certificate
#
# Mandatory: yes, if TLS certificate or PSK parameters are defined (even for 'unencrypted' connection)
# Default:
# TLSConnect=unencrypted
...

Then add this line to configure pre-shared key support:

然后添加以下行以配置预共享密钥支持:

/etc/zabbix/zabbix_agentd.conf
/etc/zabbix/zabbix_agentd.conf
...
TLSConnect=psk
...

Next, locate the TLSAccept section, which looks like this:

接下来,找到TLSAccept部分,如下所示:

/etc/zabbix/zabbix_agentd.conf
/etc/zabbix/zabbix_agentd.conf
...
### Option: TLSAccept
#       What incoming connections to accept.
#       Multiple values can be specified, separated by comma:
#               unencrypted - accept connections without encryption
#               psk         - accept connections secured with TLS and a pre-shared key
#               cert        - accept connections secured with TLS and a certificate
#
# Mandatory: yes, if TLS certificate or PSK parameters are defined (even for 'unencrypted' connection)
# Default:
# TLSAccept=unencrypted
...

Configure incoming connections to support pre-shared keys by adding this line:

通过添加以下行来配置传入连接以支持预共享密钥:

/etc/zabbix/zabbix_agentd.conf
/etc/zabbix/zabbix_agentd.conf
...
TLSAccept=psk
...

Next, find the TLSPSKIdentity section, which looks like this:

接下来,找到TLSPSKIdentity部分,如下所示:

/etc/zabbix/zabbix_agentd.conf
/etc/zabbix/zabbix_agentd.conf
...
### Option: TLSPSKIdentity
#       Unique, case sensitive string used to identify the pre-shared key.
#
# Mandatory: no
# Default:
# TLSPSKIdentity=
...

Choose a unique name to identify your pre-shared key by adding this line:

通过添加以下行,选择一个唯一的名称来标识您的预共享密钥:

/etc/zabbix/zabbix_agentd.conf
/etc/zabbix/zabbix_agentd.conf
...
TLSPSKIdentity=PSK 001
...

You’ll use this as the PSK ID when you add your host through the Zabbix web interface.

通过Zabbix Web界面添加主机时,将其用作PSK ID

Then set the option that points to your previously created pre-shared key. Locate the TLSPSKFile option:

然后设置指向您先前创建的预共享密钥的选项。 找到TLSPSKFile选项:

/etc/zabbix/zabbix_agentd.conf
/etc/zabbix/zabbix_agentd.conf
...
### Option: TLSPSKFile
#       Full pathname of a file containing the pre-shared key.
#
# Mandatory: no
# Default:
# TLSPSKFile=
...

Add this line to point the Zabbix agent to your PSK file you created:

添加以下行以将Zabbix代理指向您创建的PSK文件:

/etc/zabbix/zabbix_agentd.conf
/etc/zabbix/zabbix_agentd.conf
...
TLSPSKFile=/etc/zabbix/zabbix_agentd.psk
...

Save and close the file. Now you can restart the Zabbix agent and set it to start at boot time:

保存并关闭文件。 现在,您可以重新启动Zabbix代理并将其设置为在启动时启动:

  • sudo systemctl restart zabbix-agent

    sudo systemctl重新启动zabbix-agent
  • sudo systemctl enable zabbix-agent

    sudo systemctl启用zabbix-agent

For good measure, check that the Zabbix agent is running properly:

为确保正常,请检查Zabbix代理是否正常运行:

  • sudo systemctl status zabbix-agent

    sudo systemctl状态zabbix-agent

You will see the following status, indicating the agent is running:

您将看到以下状态,指示代理正在运行:


   
   
    
Output
● zabbix-agent.service - Zabbix Agent Loaded: loaded (/lib/systemd/system/zabbix-agent.service; enabled; vendor preset: enabled) Active: active (running) since Fri 2019-04-05 09:03:04 UTC; 1s ago ...

The agent will listen on port 10050 for connections from the server. Configure UFW to allow connections to this port:

代理将在端口10050上侦听来自服务器的连接。 配置UFW以允许连接到该端口:

  • sudo ufw allow 10050/tcp

    sudo ufw允许10050 / 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的更多信息。

Your agent is now ready to send data to the Zabbix server. But in order to use it, you have to link to it from the server’s web console. In the next step, you will complete the configuration.

您的代理现在可以将数据发送到Zabbix服务器了。 但是要使用它,您必须从服务器的Web控制台链接到它。 在下一步中,您将完成配置。

第6步-将新主机添加到Zabbix服务器 (Step 6 — Adding the New Host to the Zabbix Server)

Installing an agent on a server you want to monitor is only half of the process. Each host you want to monitor needs to be registered on the Zabbix server, which you can do through the web interface.

在要监视的服务器上安装代理程序仅完成了一半。 您要监视的每个主机都需要在Zabbix服务器上注册,您可以通过Web界面进行注册。

Log in to the Zabbix Server web interface by navigating to the address http://zabbix_server_name/zabbix/.

通过导航到地址http:// zabbix_server_name /zabbix/登录到Zabbix Server Web界面。

When you have logged in, click on Configuration, and then Hosts in the top navigation bar. Then click the Create host button in the top right corner of the screen. This will open the host configuration page.

登录后,单击“ 配置” ,然后单击顶部导航栏中的“ 主机 ”。 然后,单击屏幕右上角的“ 创建主机”按钮。 这将打开主机配置页面。

Adjust the Host name and IP address to reflect the host name and IP address of your second Ubuntu server, then add the host to a group. You can select an existing group, for example Linux servers, or create your own group. The host can be in multiple groups. To do this, enter the name of an existing or new group in the Groups field and select the desired value from the proposed list.

调整主机名IP地址以反映第二台Ubuntu服务器的主机名和IP地址,然后将该主机添加到组中。 您可以选择一个现有的组,例如Linux服务器 ,或创建自己的组。 主机可以位于多个组中。 为此,请在“ 组”字段中输入现有或新组的名称,然后从建议的列表中选择所需的值。

Once you’ve added the group, click the Templates tab.

添加组后,单击“ 模板”选项卡。

Type Template OS Linux in the Search field and then click Add to add this template to the host.

在“ 搜索”字段中键入Template OS Linux ,然后单击“ 添加”以将该模板添加到主机。

Next, navigate to the Encryption tab. Select PSK for both Connections to host and Connections from host. Then set PSK identity to PSK 001, which is the value of the TLSPSKIdentity setting of the Zabbix agent you configured previously. Then set PSK value to the key you generated for the Zabbix agent. It’s the one stored in the file /etc/zabbix/zabbix_agentd.psk on the agent machine.

接下来,导航到“ 加密”选项卡。 选择“ PSK”作为“ 主机 连接”和“主机连接” 。 然后将PSK身份设置为PSK 001 ,这是您先前配置的Zabbix代理的TLSPSKIdentity设置的值。 然后将PSK值设置为您为Zabbix代理生成的密钥。 它是存储在代理计算机上的文件/etc/zabbix/zabbix_agentd.psk中的文件。

Finally, click the Add button at the bottom of the form to create the host.

最后,单击表单底部的“ 添加”按钮以创建主机。

You will see your new host in the list. Wait for a minute and reload the page to see green labels indicating that everything is working fine and the connection is encrypted.

您将在列表中看到新的主机。 等待一分钟,然后重新加载页面,以查看绿色标签,指示一切正常,并且连接已加密。

If you have additional servers you need to monitor, log in to each host, install the Zabbix agent, generate a PSK, configure the agent, and add the host to the web interface following the same steps you followed to add your first host.

如果需要监视其他服务器,请登录到每个主机,安装Zabbix代理,生成PSK,配置代理,然后按照添加第一个主机的相同步骤将主机添加到Web界面。

The Zabbix server is now monitoring your second Ubuntu server. Now, set up email notifications to be notified about problems.

Zabbix服务器现在正在监视第二台Ubuntu服务器。 现在,设置电子邮件通知以通知有关问题。

步骤7 —配置电子邮件通知 (Step 7 — Configuring Email Notifications)

Zabbix automatically supports several types of notifications: email, Jabber, SMS, etc. You can also use alternative notification methods, such as Telegram or Slack. You can see the full list of integrations here.

Zabbix自动支持多种通知类型:电子邮件, Jabber ,SMS等。您还可以使用其他通知方法,例如Telegram或Slack。 您可以在此处查看集成的完整列表。

The simplest communication method is email, and this tutorial will configure notifications for this media type.

最简单的通信方法是电子邮件,本教程将为此媒体类型配置通知。

Click on Administration, and then Media types in the top navigation bar. You will see the list of all media types. Click on Email.

单击管理 ,然后单击顶部导航栏中的媒体类型 。 您将看到所有媒体类型的列表。 点击电子邮件

Adjust the SMTP options according to the settings provided by your email service. This tutorial uses Gmail’s SMTP capabilities to set up email notifications; if you would like more information about setting this up, see How To Use Google’s SMTP Server.

根据您的电子邮件服务提供的设置调整SMTP选项。 本教程使用Gmail的SMTP功能来设置电子邮件通知。 如果您想了解有关设置的更多信息,请参见如何使用Google的SMTP服务器

Note: If you use 2-Step Verification with Gmail, you need to generate an App Password for Zabbix. You don’t need to remember it, you’ll only have to enter an App password once during setup. You will find instructions on how to generate this password in the Google Help Center.

注意:如果对Gmail使用两步验证,则需要为Zabbix生成一个应用密码。 您无需记住它,设置过程中只需输入一次应用密码。 您可以在Google帮助中心中找到有关如何生成此密码的说明

You can also choose the message format—html or plain text. Finally, click the Update button at the bottom of the form to update the email parameters.

您还可以选择消息格式-html或纯文本。 最后,单击表单底部的“ 更新”按钮以更新电子邮件参数。

Now, create a new user. Click on Administration, and then Users in the top navigation bar. You will see the list of users. Then click the Create user button in the top right corner of the screen. This will open the user configuration page.

现在,创建一个新用户。 单击管理 ,然后单击顶部导航栏中的用户 。 您将看到用户列表。 然后,单击屏幕右上角的“ 创建用户”按钮。 这将打开用户配置页面。

Enter the new username in the Alias field and set up a new password. Next, add the user to the administrator’s group. Type Zabbix administrators in the Groups field and select it from the proposed list.

别名字段中输入新的用户名并设置新密码。 接下来,将用户添加到管理员组。 在“ 组”字段中键入Zabbix administrators ,然后从建议的列表中选择它。

Once you’ve added the group, click the Media tab and click on the Add underlined link. You will see a pop-up window.

添加组后,单击“ 媒体”选项卡,然后单击“ 添加带下划线的链接”。 您将看到一个弹出窗口。

Enter your email address in the Send to field. You can leave the rest of the options at the default values. Click the Add button at the bottom to submit.

发送到字段中输入您的电子邮件地址。 您可以将其余选项保留为默认值。 单击底部的添加按钮以提交。

Now navigate to the Permissions tab. Select Zabbix Super Admin from the User type drop-down menu.

现在导航到“ 权限”选项卡。 从用户类型下拉菜单中选择Zabbix Super Admin

Finally, click the Add button at the bottom of the form to create the user.

最后,单击表单底部的“ 添加”按钮以创建用户。

Now you need to enable notifications. Click on the Configuration tab, and then Actions in the top navigation bar. You will see a pre-configured action, which is responsible for sending notifications to all Zabbix administrators. You can review and change the settings by clicking on its name. For the purposes of this tutorial, use the default parameters. To enable the action, click on the red Disabled link in the Status column.

现在,您需要启用通知。 单击配置选项卡,然后在顶部导航栏的动作 。 您将看到一个预配置的操作,该操作负责向所有Zabbix管理员发送通知。 您可以通过单击其名称来查看和更改设置。 就本教程而言,请使用默认参数。 要启用该操作,请单击“ 状态”列中红色的“ 已禁用”链接。

Now you are ready to receive alerts. In the next step, you will generate one to test your notification setup.

现在,您可以接收警报了。 在下一步中,您将生成一个用于测试通知设置。

步骤8 —生成测试警报 (Step 8 — Generating a Test Alert)

In this step, you will generate a test alert to ensure everything is connected. By default, Zabbix keeps track of the amount of free disk space on your server. It automatically detects all disk mounts and adds the corresponding checks. This discovery is executed every hour, so you need to wait a while for the notification to be triggered.

在此步骤中,您将生成一个测试警报,以确保一切均已连接。 默认情况下,Zabbix会跟踪服务器上的可用磁盘空间量。 它会自动检测所有磁盘安装并添加相应的检查。 该发现每小时执行一次,因此您需要等待一段时间才能触发通知。

Create a temporary file that’s large enough to trigger Zabbix’s file system usage alert. To do this, log in to your second Ubuntu server if you’re not already connected.

创建一个足以触发Zabbix的文件系统使用情况警报的临时文件。 为此,如果尚未连接,请登录第二台Ubuntu服务器。

  • ssh sammy@second_ubuntu_server_ip_address

    ssh sammy @ second_ubuntu_server_ip_address

Next, determine how much free space you have on the server. You can use the df command to find out:

接下来,确定服务器上有多少可用空间。 您可以使用df命令找出:

  • df -h

    df -h

The command df will report the disk space usage of your file system, and the -h will make the output human-readable. You’ll see output like the following:

命令df将报告文件系统的磁盘空间使用情况, -h将使输出易于阅读。 您将看到类似以下的输出:


   
   
    
Output
Filesystem Size Used Avail Use% Mounted on /dev/vda1 25G 1.2G 23G 5% /

In this case, the free space is 23GB. Your free space may differ.

在这种情况下,可用空间为23GB 。 您的可用空间可能有所不同。

Use the fallocate command, which allows you to pre-allocate or de-allocate space to a file, to create a file that takes up more than 80% of the available disk space. This will be enough to trigger the alert:

使用fallocate命令(该命令可让您为文件预分配或取消分配空间)来创建占用超过80%的可用磁盘空间的文件。 这足以触发警报:

  • fallocate -l 20G /tmp/temp.img

    fallocate -l 20G /tmp/temp.img

After around an hour, Zabbix will trigger an alert about the amount of free disk space and will run the action you configured, sending the notification message. You can check your inbox for the message from the Zabbix server. You will see a message like:

大约一个小时后,Zabbix将触发有关可用磁盘空间量的警报,并将运行您配置的操作,并发送通知消息。 您可以在收件箱中查看来自Zabbix服务器的消息。 您将看到类似以下的消息:


   
   
    
Output
Problem started at 10:37:54 on 2019.04.05 Problem name: Free disk space is less than 20% on volume / Host: Second Ubuntu server Severity: Warning Original problem ID: 34

You can also navigate to the Monitoring tab, and then Dashboard to see the notification and its details.

您还可以导航到“ 监视”选项卡,然后导航到“ 仪表板”以查看通知及其详细信息。

Now that you know the alerts are working, delete the temporary file you created so you can reclaim your disk space:

现在您知道警报正在运行,请删除您创建的临时文件,以便可以回收磁盘空间:

  • rm -f /tmp/temp.img

    rm -f /tmp/temp.img

After a minute Zabbix will send the recovery message and the alert will disappear from main dashboard.

一分钟后,Zabbix将发送恢复消息,并且警报将从主仪表板消失。

结论 (Conclusion)

In this tutorial, you learned how to set up a simple and secure monitoring solution which will help you monitor the state of your servers. It can now warn you of problems, and you have the opportunity to analyze the processes occurring in your IT infrastructure.

在本教程中,您学习了如何设置一个简单而安全的监视解决方案,该解决方案将帮助您监视服务器的状态。 它现在可以警告您出现问题,并且您有机会分析IT基础结构中发生的流程。

To learn more about setting up monitoring infrastructure, check out How To Install Elasticsearch, Logstash, and Kibana (Elastic Stack) on Ubuntu 18.04 and How To Gather Infrastructure Metrics with Metricbeat on Ubuntu 18.04.

要了解有关设置监视基础结构的更多信息,请查看如何在Ubuntu 18.04上安装Elasticsearch,Logstash和Kibana(弹性堆栈),以及如何在Ubuntu 18.04上使用Metricbeat收集基础结构指标

翻译自: https://www.digitalocean.com/community/tutorials/how-to-install-and-configure-zabbix-to-securely-monitor-remote-servers-on-ubuntu-18-04

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/cukw6666/article/details/107986877

智能推荐

没有U盘Win10电脑下如何使用本地硬盘安装Ubuntu20.04(单双硬盘都行)_没有u盘怎么装ubuntu-程序员宅基地

文章浏览阅读3.6k次,点赞2次,收藏2次。DELL7080台式机两块硬盘。_没有u盘怎么装ubuntu

【POJ 3401】Asteroids-程序员宅基地

文章浏览阅读32次。题面Bessie wants to navigate her spaceship through a dangerous asteroid field in the shape of an N x N grid (1 <= N <= 500). The grid contains K asteroids (1 <= K <= 10,000), which are conv...

工业机器视觉系统的构成与开发过程(理论篇—1)_工业机器视觉系统的构成与开发过程(理论篇—1-程序员宅基地

文章浏览阅读2.6w次,点赞21次,收藏112次。机器视觉则主要是指工业领域视觉的应用研究,例如自主机器人的视觉,用于检测和测量的视觉系统等。它通过在工业领域将图像感知、图像处理、控制理论与软件、硬件紧密结合,并研究解决图像处理和计算机视觉理论在实际应用过程中的问题,以实现高效的运动控制或各种实时操作。_工业机器视觉系统的构成与开发过程(理论篇—1

plt.legend的用法-程序员宅基地

文章浏览阅读5.9w次,点赞32次,收藏58次。legend 传奇、图例。plt.legend()的作用:在plt.plot() 定义后plt.legend() 会显示该 label 的内容,否则会报error: No handles with labels found to put in legend.plt.plot(result_price, color = 'red', label = 'Training Loss') legend作用位置:下图红圈处。..._plt.legend

深入理解 C# .NET Core 中 async await 异步编程思想_netcore async await-程序员宅基地

文章浏览阅读2.2k次,点赞3次,收藏11次。深入理解 C# .NET Core 中 async await 异步编程思想引言一、什么是异步?1.1 简单实例(WatchTV并行CookCoffee)二、深入理解(异步)2.1 当我需要异步返回值时,怎么处理?2.2 充分利用异步并行的高效性async await的秘密引言很久没来CSDN了,快小半年了一直在闲置,也写不出一些带有思想和深度的文章;之前就写过一篇关于async await 的异步理解 ,现在回顾,真的不要太浅和太陋,让人不忍直视!好了,废话不再啰嗦,直入主题:一、什么是异步?_netcore async await

IntelliJ IDEA设置类注释和方法注释带作者和日期_idea作者和日期等注释-程序员宅基地

文章浏览阅读6.5w次,点赞166次,收藏309次。当我看到别人的类上面的多行注释是是这样的:这样的:这样的:好装X啊!我也想要!怎么办呢?往下瞅:跟着我左手右手一个慢动作~~~File--->Settings---->Editor---->File and Code Templates --->Includes--->File Header:之后点applay--..._idea作者和日期等注释

随便推点

发行版Linux和麒麟操作系统下netperf 网络性能测试-程序员宅基地

文章浏览阅读175次。Netperf是一种网络性能的测量工具,主要针对基于TCP或UDP的传输。Netperf根据应用的不同,可以进行不同模式的网络性能测试,即批量数据传输(bulk data transfer)模式和请求/应答(request/reponse)模式。工作原理Netperf工具以client/server方式工作。server端是netserver,用来侦听来自client端的连接,c..._netperf 麒麟

万字长文详解 Go 程序是怎样跑起来的?| CSDN 博文精选-程序员宅基地

文章浏览阅读1.1k次,点赞2次,收藏3次。作者| qcrao责编 | 屠敏出品 | 程序员宅基地刚开始写这篇文章的时候,目标非常大,想要探索 Go 程序的一生:编码、编译、汇编、链接、运行、退出。它的每一步具体如何进行,力图弄清 Go 程序的这一生。在这个过程中,我又复习了一遍《程序员的自我修养》。这是一本讲编译、链接的书,非常详细,值得一看!数年前,我第一次看到这本书的书名,就非常喜欢。因为它模仿了周星驰喜剧..._go run 每次都要编译吗

C++之istringstream、ostringstream、stringstream 类详解_c++ istringstream a >> string-程序员宅基地

文章浏览阅读1.4k次,点赞4次,收藏2次。0、C++的输入输出分为三种:(1)基于控制台的I/O (2)基于文件的I/O (3)基于字符串的I/O 1、头文件[cpp] view plaincopyprint?#include 2、作用istringstream类用于执行C++风格的字符串流的输入操作。 ostringstream类用_c++ istringstream a >> string

MySQL 的 binglog、redolog、undolog-程序员宅基地

文章浏览阅读2k次,点赞3次,收藏14次。我们在每个修改的地方都记录一条对应的 redo 日志显然是不现实的,因此实现方式是用时间换空间,我们在数据库崩了之后用日志还原数据时,在执行这条日志之前,数据库应该是一个一致性状态,我们用对应的参数,执行固定的步骤,修改对应的数据。1,MySQL 就是通过 undolog 回滚日志来保证事务原子性的,在异常发生时,对已经执行的操作进行回滚,回滚日志会先于数据持久化到磁盘上(因为它记录的数据比较少,所以持久化的速度快),当用户再次启动数据库的时候,数据库能够通过查询回滚日志来回滚将之前未完成的事务。_binglog

我的第一个Chrome小插件-基于vue开发的flexbox布局CSS拷贝工具_chrome css布局插件-程序员宅基地

文章浏览阅读3k次。概述之前介绍过 移动Web开发基础-flex弹性布局(兼容写法) 里面有提到过想做一个Chrome插件,来生成flexbox布局的css代码直接拷贝出来用。最近把这个想法实现了,给大家分享下。play-flexbox插件介绍play-flexbox一秒搞定flexbox布局,可直接预览效果,拷贝CSS代码快速用于页面重构。 你也可以通过点击以下链接(codepen示例)查_chrome css布局插件

win10下安装TensorFlow-gpu的流程(包括cuda、cuDnn下载以及安装问题)-程序员宅基地

文章浏览阅读308次。我自己的配置是GeForce GTX 1660 +CUDA10.0+CUDNN7.6.0 + TensorFlow-GPU 1.14.0Win10系统安装tensorflow-gpu(按照步骤一次成功)https://blog.csdn.net/zqxdsy/article/details/103152190环境配置——win10下TensorFlow-GPU安装(GTX1660 SUPER+CUDA10+CUDNN7.4)https://blog.csdn.net/jiDxiaohuo/arti