Zabbix是一个著名的开源监控解决方案,在维护网络基础设施的健康和性能方面发挥着关键作用。
在 Rocky Linux 9 上安装 Zabbix
第 1 步。第一步是将系统更新到最新版本的软件包列表。为此,请运行以下命令:
<span class="pln">sudo dnf update sudo dnf upgrade</span>
第 2 步。安装依赖项。
首先安装Zabbix所需的依赖项:
<span class="pln">sudo dnf install epel</span><span class="pun">-</span><span class="pln">release sudo dnf install httpd wget mariadb</span><span class="pun">-</span><span class="pln">server mariadb php php</span><span class="pun">-</span><span class="pln">common php</span><span class="pun">-</span><span class="pln">mysqlnd php</span><span class="pun">-</span><span class="pln">gd php</span><span class="pun">-</span><span class="pln">xml php</span><span class="pun">-</span><span class="pln">mbstring php</span><span class="pun">-</span><span class="pln">bcmath php</span><span class="pun">-</span><span class="pln">json php</span><span class="pun">-</span><span class="pln">ldap php</span><span class="pun">-</span><span class="pln">pear php</span><span class="pun">-</span><span class="pln">xmlrpc php</span><span class="pun">-</span><span class="pln">ldap php</span><span class="pun">-</span><span class="pln">net</span><span class="pun">-</span><span class="pln">ldap2 php</span><span class="pun">-</span><span class="pln">gd php</span><span class="pun">-</span><span class="pln">gettext </span><span class="pun">-</span><span class="pln">y</span>
现在,启动并启用 Apache 和 MariaDB 服务:
<span class="pln">sudo systemctl start httpd mariadb sudo systemctl enable httpd mariadb</span>
第 3 步。为 Zabbix 配置 MariaDB。
在创建Zabbix数据库之前,保护MariaDB安装至关重要。运行以下命令,为 MariaDB 根用户设置安全密码:
<span class="pln">sudo mysql_secure_installation</span>
接下来,创建Zabbix数据库和用户:
<span class="pln">sudo mysql </span><span class="pun">-</span><span class="pln">u root </span><span class="pun">-</span><span class="pln">p</span>
出现提示时,输入 MariaDB 根密码。进入MariaDB shell后,为Zabbix创建一个数据库和一个专用用户:
<span class="typ">MariaDB</span> <span class="pun">[(</span><span class="pln">none</span><span class="pun">)]></span><span class="pln"> CREATE DATABASE zabbixdb character </span><span class="kwd">set</span><span class="pln"> utf8 collate utf8_bin</span><span class="pun">;</span> <span class="typ">MariaDB</span> <span class="pun">[(</span><span class="pln">none</span><span class="pun">)]></span><span class="pln"> CREATE USER </span><span class="str">'zabbixuser'</span><span class="pun">@</span><span class="str">'localhost'</span><span class="pln"> IDENTIFIED BY </span><span class="str">'your-strong-password'</span><span class="pun">;</span> <span class="typ">MariaDB</span> <span class="pun">[(</span><span class="pln">none</span><span class="pun">)]></span><span class="pln"> GRANT ALL PRIVILEGES ON zabbixdb</span><span class="pun">.*</span><span class="pln"> TO </span><span class="str">'zabbixuser'</span><span class="pun">@</span><span class="str">'localhost'</span><span class="pun">;</span> <span class="typ">MariaDB</span> <span class="pun">[(</span><span class="pln">none</span><span class="pun">)]></span><span class="pln"> FLUSH PRIVILEGES</span><span class="pun">;</span> <span class="typ">MariaDB</span> <span class="pun">[(</span><span class="pln">none</span><span class="pun">)]></span><span class="pln"> EXIT</span><span class="pun">;</span>
第 4 步。在 Rocky Linux 9 上安装 Zabbix。
要安装Zabbix,你需要添加官方的Zabbix存储库。方法如下:
<span class="pln">sudo rpm </span><span class="pun">-</span><span class="typ">Uvh</span><span class="pln"> https</span><span class="pun">:</span><span class="com">//repo.zabbix.com/zabbix/6.5/rocky/9/x86_64/zabbix-release-6.5-2.el9.noarch.rpm</span>
现在,是时候安装Zabbix服务器,前端和代理包了:
<span class="pln">sudo dnf install zabbix</span><span class="pun">-</span><span class="pln">server</span><span class="pun">-</span><span class="pln">mysql zabbix</span><span class="pun">-</span><span class="pln">web</span><span class="pun">-</span><span class="pln">mysql zabbix</span><span class="pun">-</span><span class="pln">agent</span>
第5步。数据库初始化。
将Zabbix的初始数据库模式导入到新创建的:zabbixdb
<span class="pln">sudo zcat </span><span class="pun">/</span><span class="pln">usr</span><span class="pun">/</span><span class="pln">share</span><span class="pun">/</span><span class="pln">doc</span><span class="pun">/</span><span class="pln">zabbix</span><span class="pun">-</span><span class="pln">server</span><span class="pun">-</span><span class="pln">mysql</span><span class="pun">*/</span><span class="pln">create</span><span class="pun">.</span><span class="pln">sql</span><span class="pun">.</span><span class="pln">gz </span><span class="pun">|</span><span class="pln"> mysql </span><span class="pun">-</span><span class="pln">u zabbixuser </span><span class="pun">-</span><span class="pln">p zabbixdb</span>
第 6 步。配置Zabbix服务器。
编辑Zabbix服务器配置文件以指定数据库连接详细信息:
<span class="pln">sudo nano </span><span class="pun">/</span><span class="pln">etc</span><span class="pun">/</span><span class="pln">zabbix</span><span class="pun">/</span><span class="pln">zabbix_server</span><span class="pun">.</span><span class="pln">conf</span>
找到以下行并相应地修改它们:
<span class="typ">DBHost</span><span class="pun">=</span><span class="pln">localhost </span><span class="typ">DBName</span><span class="pun">=</span><span class="pln">zabbixdb </span><span class="typ">DBUser</span><span class="pun">=</span><span class="pln">zabbixuser </span><span class="typ">DBPassword</span><span class="pun">=</span><span class="pln">your</span><span class="pun">-</span><span class="pln">strong</span><span class="pun">-</span><span class="pln">password</span>
步骤 7.配置Zabbix前端。
现在编辑Zabbix前端配置文件:
<span class="pln">sudo nano </span><span class="pun">/</span><span class="pln">etc</span><span class="pun">/</span><span class="pln">zabbix</span><span class="pun">/</span><span class="pln">web</span><span class="pun">/</span><span class="pln">zabbix</span><span class="pun">.</span><span class="pln">conf</span><span class="pun">.</span><span class="pln">php</span>
查找并修改以下行:
<span class="pln">$DB</span><span class="pun">[</span><span class="str">'TYPE'</span><span class="pun">]</span> <span class="pun">=</span> <span class="str">'MYSQL'</span><span class="pun">;</span><span class="pln"> $DB</span><span class="pun">[</span><span class="str">'SERVER'</span><span class="pun">]</span> <span class="pun">=</span> <span class="str">'localhost'</span><span class="pun">;</span><span class="pln"> $DB</span><span class="pun">[</span><span class="str">'PORT'</span><span class="pun">]</span> <span class="pun">=</span> <span class="str">'0'</span><span class="pun">;</span><span class="pln"> $DB</span><span class="pun">[</span><span class="str">'DATABASE'</span><span class="pun">]</span> <span class="pun">=</span> <span class="str">'zabbixdb'</span><span class="pun">;</span><span class="pln"> $DB</span><span class="pun">[</span><span class="str">'USER'</span><span class="pun">]</span> <span class="pun">=</span> <span class="str">'zabbixuser'</span><span class="pun">;</span><span class="pln"> $DB</span><span class="pun">[</span><span class="str">'PASSWORD'</span><span class="pun">]</span> <span class="pun">=</span> <span class="str">'your-strong-password'</span><span class="pun">;</span>
最后,通过运行以下命令,对Zabbix服务器进行访问,使其能够在启动时自动启动:
<span class="pln">sudo systemctl start zabbix</span><span class="pun">-</span><span class="pln">server zabbix</span><span class="pun">-</span><span class="pln">agent sudo systemctl enable zabbix</span><span class="pun">-</span><span class="pln">server zabbix</span><span class="pun">-</span><span class="pln">agent</span>
第8步。访问Zabbix Web界面。
成功安装后,打开您的 Web 浏览器并导航到您的 Rocky Linux 服务器的 IP 地址或主机名,后跟 (例如,)。您将看到Zabbix登录页面。/zabbix
http://your_server_ip/zabbix
使用以下默认凭据登录:
- 用户名:
Admin
- 密码:
zabbix
感谢您使用本教程在您的 Rocky Linux 9 系统上安装 Zabbix 监控工具。有关其他帮助或有用信息,我们建议您查看Zabbix官方网站。