如何在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

智能推荐

874计算机科学基础综合,2018年四川大学874计算机科学专业基础综合之计算机操作系统考研仿真模拟五套题...-程序员宅基地

文章浏览阅读1.1k次。一、选择题1. 串行接口是指( )。A. 接口与系统总线之间串行传送,接口与I/0设备之间串行传送B. 接口与系统总线之间串行传送,接口与1/0设备之间并行传送C. 接口与系统总线之间并行传送,接口与I/0设备之间串行传送D. 接口与系统总线之间并行传送,接口与I/0设备之间并行传送【答案】C2. 最容易造成很多小碎片的可变分区分配算法是( )。A. 首次适应算法B. 最佳适应算法..._874 计算机科学专业基础综合题型

XShell连接失败:Could not connect to '192.168.191.128' (port 22): Connection failed._could not connect to '192.168.17.128' (port 22): c-程序员宅基地

文章浏览阅读9.7k次,点赞5次,收藏15次。连接xshell失败,报错如下图,怎么解决呢。1、通过ps -e|grep ssh命令判断是否安装ssh服务2、如果只有客户端安装了,服务器没有安装,则需要安装ssh服务器,命令:apt-get install openssh-server3、安装成功之后,启动ssh服务,命令:/etc/init.d/ssh start4、通过ps -e|grep ssh命令再次判断是否正确启动..._could not connect to '192.168.17.128' (port 22): connection failed.

杰理之KeyPage【篇】_杰理 空白芯片 烧入key文件-程序员宅基地

文章浏览阅读209次。00000000_杰理 空白芯片 烧入key文件

一文读懂ChatGPT,满足你对chatGPT的好奇心_引发对chatgpt兴趣的表述-程序员宅基地

文章浏览阅读475次。2023年初,“ChatGPT”一词在社交媒体上引起了热议,人们纷纷探讨它的本质和对社会的影响。就连央视新闻也对此进行了报道。作为新传专业的前沿人士,我们当然不能忽视这一热点。本文将全面解析ChatGPT,打开“技术黑箱”,探讨它对新闻与传播领域的影响。_引发对chatgpt兴趣的表述

中文字符频率统计python_用Python数据分析方法进行汉字声调频率统计分析-程序员宅基地

文章浏览阅读259次。用Python数据分析方法进行汉字声调频率统计分析木合塔尔·沙地克;布合力齐姑丽·瓦斯力【期刊名称】《电脑知识与技术》【年(卷),期】2017(013)035【摘要】该文首先用Python程序,自动获取基本汉字字符集中的所有汉字,然后用汉字拼音转换工具pypinyin把所有汉字转换成拼音,最后根据所有汉字的拼音声调,统计并可视化拼音声调的占比.【总页数】2页(13-14)【关键词】数据分析;数据可..._汉字声调频率统计

linux输出信息调试信息重定向-程序员宅基地

文章浏览阅读64次。最近在做一个android系统移植的项目,所使用的开发板com1是调试串口,就是说会有uboot和kernel的调试信息打印在com1上(ttySAC0)。因为后期要使用ttySAC0作为上层应用通信串口,所以要把所有的调试信息都给去掉。参考网上的几篇文章,自己做了如下修改,终于把调试信息重定向到ttySAC1上了,在这做下记录。参考文章有:http://blog.csdn.net/longt..._嵌入式rootfs 输出重定向到/dev/console

随便推点

uniapp 引入iconfont图标库彩色symbol教程_uniapp symbol图标-程序员宅基地

文章浏览阅读1.2k次,点赞4次,收藏12次。1,先去iconfont登录,然后选择图标加入购物车 2,点击又上角车车添加进入项目我的项目中就会出现选择的图标 3,点击下载至本地,然后解压文件夹,然后切换到uniapp打开终端运行注:要保证自己电脑有安装node(没有安装node可以去官网下载Node.js 中文网)npm i -g iconfont-tools(mac用户失败的话在前面加个sudo,password就是自己的开机密码吧)4,终端切换到上面解压的文件夹里面,运行iconfont-tools 这些可以默认也可以自己命名(我是自己命名的_uniapp symbol图标

C、C++ 对于char*和char[]的理解_c++ char*-程序员宅基地

文章浏览阅读1.2w次,点赞25次,收藏192次。char*和char[]都是指针,指向第一个字符所在的地址,但char*是常量的指针,char[]是指针的常量_c++ char*

Sublime Text2 使用教程-程序员宅基地

文章浏览阅读930次。代码编辑器或者文本编辑器,对于程序员来说,就像剑与战士一样,谁都想拥有一把可以随心驾驭且锋利无比的宝剑,而每一位程序员,同样会去追求最适合自己的强大、灵活的编辑器,相信你和我一样,都不会例外。我用过的编辑器不少,真不少~ 但却没有哪款让我特别心仪的,直到我遇到了 Sublime Text 2 !如果说“神器”是我能给予一款软件最高的评价,那么我很乐意为它封上这么一个称号。它小巧绿色且速度非

对10个整数进行按照从小到大的顺序排序用选择法和冒泡排序_对十个数进行大小排序java-程序员宅基地

文章浏览阅读4.1k次。一、选择法这是每一个数出来跟后面所有的进行比较。2.冒泡排序法,是两个相邻的进行对比。_对十个数进行大小排序java

物联网开发笔记——使用网络调试助手连接阿里云物联网平台(基于MQTT协议)_网络调试助手连接阿里云连不上-程序员宅基地

文章浏览阅读2.9k次。物联网开发笔记——使用网络调试助手连接阿里云物联网平台(基于MQTT协议)其实作者本意是使用4G模块来实现与阿里云物联网平台的连接过程,但是由于自己用的4G模块自身的限制,使得阿里云连接总是无法建立,已经联系客服返厂检修了,于是我在此使用网络调试助手来演示如何与阿里云物联网平台建立连接。一.准备工作1.MQTT协议说明文档(3.1.1版本)2.网络调试助手(可使用域名与服务器建立连接)PS:与阿里云建立连解释,最好使用域名来完成连接过程,而不是使用IP号。这里我跟阿里云的售后工程师咨询过,表示对应_网络调试助手连接阿里云连不上

<<<零基础C++速成>>>_无c语言基础c++期末速成-程序员宅基地

文章浏览阅读544次,点赞5次,收藏6次。运算符与表达式任何高级程序设计语言中,表达式都是最基本的组成部分,可以说C++中的大部分语句都是由表达式构成的。_无c语言基础c++期末速成