在 Ubuntu 中添加 Zabbix 官方仓库
Zabbix 网站提供了各种 Linux 发行版的安装包。
你可以安装这个包,在你的 Ubuntu 操作系统的包管理系统中添加它的官方存储库。
从他们的官方网站下载 Zabbix 5.0 存储库的软件包。
$ wget https://repo.zabbix.com/zabbix/5.0/ubuntu/pool/main/z/zabbix-release/zabbix-release_5.0-1+focal_all.deb
使用 dpkg 命令安装下载包。
$ sudo dpkg -i zabbix-release_5.0-1+focal_all.deb
使用 apt 命令更新适用于 Ubuntu 操作系统的可用软件包列表。
$ sudo apt update
Zabbix 是一种开源监控软件工具,适用于各种 IT 组件,包括网络、服务器、虚拟机 (VM) 和云服务。
本文将介绍如何在 Ubuntu 20.04 LTS 上安装Zabbix。
运行 Zabbix 服务器的 Web 设置
在 Web 浏览器中打开 URL http://zabbix-01.onitroad.com/zabbix/。
如果我们已按照上述方式执行安装,那么我们将看到 Zabbix web setup 的这个欢迎页面。
点击“下一步”。
如果我们正确执行了配置,那么我们将获得所有 Zabbix perquisites 的“OK”状态。
转到“下一步”。
提供 MySQL 服务器的连接详细信息,包括数据库和用户凭据。
点击“下一步”。
输入 Linux 服务器的主机名/IP 地址和端口号。
我们需要提供安装的名称(可选)。
继续“下一步”。
Web 设置将显示我们迄今为止所做的配置。
如果我们对它们感到满意,请单击“下一步”,否则请返回并根据要求进行调整。
配置文件已创建,Zabbix前端安装成功。
以默认的 Zabbix 用户/密码登录,例如:admin/zabbix。
成功登录后,我们将进入 Zabbix 仪表板。
在 Ubuntu 上安装 Zabbix 服务器
我们已成功在 Linux 操作系统中添加 Zabbix 官方存储库。
因此,我们现在可以使用 apt 命令轻松安装此软件。
$ sudo apt install -y zabbix-server-mysql zabbix-frontend-php zabbix-apache-conf zabbix-agent
在 Ubuntu 上安装 MySQL 数据库服务器
在本教程中,我们将 Apache Web 服务器和 MySQL 数据库服务器与 Zabbix 应用程序一起使用。
因此,我们需要有一个 MySQL 数据库服务器。
如果你的网络中没有 MySQL 数据库服务器,那么你必须在 zabbix-01.onitroad.com 机器上安装它。
$ sudo apt install -y mysql-server
安装成功后,查看MySQL服务状态。
$ sudo systemctl status mysql
MySQL 数据库服务已经启动。
使用 mysql_secure_installation 命令配置 MySQL 数据库服务器。
$ sudo mysql_secure_installation Securing the MySQL server deployment. Connecting to MySQL using a blank password. VALIDATE PASSWORD COMPONENT can be used to test passwords and improve security. It checks the strength of password and allows the users to set only those passwords which are secure enough. Would you like to setup VALIDATE PASSWORD component? Press y|Y for Yes, any other key for No: Y There are three levels of password validation policy: LOW Length >= 8 MEDIUM Length >= 8, numeric, mixed case, and special characters STRONG Length >= 8, numeric, mixed case, special characters and dictionary file Please enter 0 = LOW, 1 = MEDIUM and 2 = STRONG: 2 Please set the password for root here. New password: Re-enter new password: Estimated strength of the password: 100 Do you wish to continue with the password provided?(Press y|Y for Yes, any other key for No) : Y By default, a MySQL installation has an anonymous user, allowing anyone to log into MySQL without having to have a user account created for them. This is intended only for testing, and to make the installation go a bit smoother. You should remove them before moving into a production environment. Remove anonymous users? (Press y|Y for Yes, any other key for No) : Y Success. Normally, root should only be allowed to connect from 'localhost'. This ensures that someone cannot guess at the root password from the network. Disallow root login remotely? (Press y|Y for Yes, any other key for No) : Y Success. By default, MySQL comes with a database named 'test' that anyone can access. This is also intended only for testing, and should be removed before moving into a production environment. Remove test database and access to it? (Press y|Y for Yes, any other key for No) : Y - Dropping test database... Success. - Removing privileges on test database... Success. Reloading the privilege tables will ensure that all changes made so far will take effect immediately. Reload privilege tables now? (Press y|Y for Yes, any other key for No) : Y Success. All done!
使用 mysql 命令连接到 MySQL 数据库服务器。
$ sudo mysql -u root -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 15 Server version: 8.0.23-0ubuntu0.20.04.1 (Ubuntu) Copyright (c) 2000, 2021, Oracle and/or its affiliates. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
创建“zabbix”数据库以供监控服务器使用。
mysql> create database zabbix character set utf8 collate utf8_bin; Query OK, 1 row affected, 2 warnings (0.01 sec)
创建数据库用户“zabbix”并设置强密码。
mysql> create user zabbix@localhost identified by 'P@ssw0rd'; Query OK, 0 rows affected (0.01 sec)
将 zabbix 数据库的所有权限授予 zabbix 用户。
mysql> grant all privileges on zabbix.* to zabbix@localhost; Query OK, 0 rows affected (0.00 sec) mysql> quit; Bye
Zabbix 服务器文档提供了一个 SQL 脚本来在 MySQL 数据库中创建它的存储库。
我们可以按如下方式运行此 SQL 脚本。
$ zcat /usr/share/doc/zabbix-server-mysql/create.sql.gz | mysql -u zabbix -p zabbix Enter password:
在 nano 文本编辑器中编辑 Zabbix 服务器配置文件。
$ sudo nano /etc/zabbix/zabbix_server.conf
并在这个文件中设置zabbix数据库用户的密码。
DBPassword=P@ssw0rd
在 nano 文本编辑器中编辑 Apache 配置文件。
$ sudo nano /etc/zabbix/apache.conf
取消注释并设置我们各自的时区。
该指令多次出现,我们应该设置它们中的每一个。
php_value date.timezone America/Santiago
重新启动并启用 Zabbix Server、Agent 和 Apache 服务。
$ sudo systemctl restart zabbix-server zabbix-agent apache2 $ sudo systemctl enable zabbix-server zabbix-agent apache2 Synchronizing state of zabbix-server.service with SysV service script with /lib/systemd/systemd-sysv-install. Executing: /lib/systemd/systemd-sysv-install enable zabbix-server Synchronizing state of zabbix-agent.service with SysV service script with /lib/systemd/systemd-sysv-install. Executing: /lib/systemd/systemd-sysv-install enable zabbix-agent Synchronizing state of apache2.service with SysV service script with /lib/systemd/systemd-sysv-install. Executing: /lib/systemd/systemd-sysv-install enable apache2 Created symlink /etc/systemd/system/multi-user.target.wants/zabbix-server.service → /lib/systemd/system/zabbix-server.service.
通过执行 ufw 命令在 Ubuntu 防火墙中允许 Apache 服务。
$ sudo ufw allow apache Rules updated Rules updated (v6)