在RHEL8上安装Zabbix 6.0 LTS

首先

Zabbix6.0 LTS于2022年02月15日发布。
距离5.0 LTS已经一年九个月,新增了原生HA功能和Kubernetes监控功能。
本文将总结Zabbix6.0在RHEL8上安装的步骤。
Zabbix6.0.1发布说明。

系统配置

这次使用的软件和版本如下:
· Zabbix:Zabbix 6.0.1
· 操作系统:RHEL8.5
· Web服务器:Apache HTTP Server 2.4.37
· PHP:PHP 7.2.24
· 数据库管理系统:MariaDB 10.6.7

环境和前提条件
• 将适用服务器连接至互联网
• 将Zabbix服务器、相关软件包和Zabbix代理一体化地部署在一台服务器上
• 禁用SELinux功能进行部署
• 每个步骤需要以拥有root权限的用户执行
• 开启防火墙对HTTP(80/tcp)、HTTPS(443/tcp)、10050/tcp和10051/tcp的访问

1. 安装MariaDB

使用dnf命令安装MariaDB时,在RHEL8上会安装MariaDB 10.3版本。但是,在Zabbix6.0中,支持的是MariaDB 10.5.X至10.6.X,因此需要从MariaDB的仓库中引入,而不是从标准仓库中引入。值得注意的是,在MariaDB的仓库中,如果不明确指定版本,将会安装最新的10.7.x版本,这也不在Zabbix的支持范围内。因此,需要使用–mariadb-server-version选项来指定Zabbix支持的版本。

1.1 下载 mariadb_repo_setup。

 # curl -O https://downloads.mariadb.com/MariaDB/mariadb_repo_setup
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 30081  100 30081    0     0  29931      0  0:00:01  0:00:01 --:--:-- 29931

1.2 设定MariaDB仓库

使用 mariadb-server-version,指定版本为 10.6。

# bash mariadb_repo_setup --mariadb-server-version mariadb-10.6

# [info] Checking for script prerequisites.
# [info] MariaDB Server version 10.6 is valid
# [info] Repository file successfully written to /etc/yum.repos.d/mariadb.repo
# [info] Adding trusted package signing keys...
/etc/pki/rpm-gpg ~
~
# [info] Successfully added trusted package signing keys
# [info] Cleaning package cache...
Updating Subscription Management repositories.
41 files removed

1.3 安装 MariaDB

# dnf install MariaDB-server
(出力省略)
# mariadb --version
mariadb  Ver 15.1 Distrib 10.6.7-MariaDB, for Linux (x86_64) using readline 5.1

1.4 启动 MariaDB

# systemctl start mariadb
# systemctl enable mariadb

1.5 MariaDB的配置设置

为了设置mysql的root密码和删除不需要的设置,我们将使用mysql_secure_installation进行安全初始设置。

# mariadb-secure-installation

NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!

In order to log into MariaDB to secure it, we'll need the current
password for the root user. If you've just installed MariaDB, and
haven't set the root password yet, you should just press enter here.

Enter current password for root (enter for none):      <- Enterを入力
OK, successfully used password, moving on...

Setting the root password or using the unix_socket ensures that nobody
can log into the MariaDB root user without the proper authorisation.

You already have your root account protected, so you can safely answer 'n'.

Switch to unix_socket authentication [Y/n] n       <- unix_socket認証を使用しないのでnを入力
 ... skipping.

You already have your root account protected, so you can safely answer 'n'.

Change the root password? [Y/n] y                  <- yを入力
New password:                                      <- DBユーザ-rootのパスワード
Re-enter new password:                             <- 再度パスワードを入力
Password updated successfully!
Reloading privilege tables..
 ... Success!


By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB 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? [Y/n] y          <- 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? [Y/n] y      <- yを入力(rootのリモートログイン禁止)
 ... Success!

By default, MariaDB 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? [Y/n] y  <- yを入力(不要なDBを削除)
 - 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? [Y/n] y        <- yを入力
 ... Success!

Cleaning up...

All done!  If you've completed all of the above steps, your MariaDB
installation should now be secure.

Thanks for using MariaDB!

编辑MariaDB的配置文件,设置默认字符编码等。需要注意的是,在MariaDB10.6中,默认情况下已启用了以前推荐的innodb_file_per_table参数,因此无需进行设置。此外,由于Zabbix6.0开始支持utf8mb4,所以字符编码需设置为”utf8mb4″。

$ vi /etc/my.cnf.d/mariadb-server.cnf
(略)
[mysqld]
character-set-server = utf8mb4
collation-server     = utf8mb4_bin
skip-character-set-client-handshake
(略)

为了反映设置更改,将重新启动MariaDB。

# systemctl restart mariadb

2. Zabbix安装

根据官方网站的步骤进行导入。 de chū .)

2.1 注册 Zabbix LLC 仓库

由于可能会发布新版本的软件包,请在以下官方仓库中确认:https://repo.zabbix.com/zabbix/6.0/rhel/8/x86_64/
进行仓库注册后,请清除缓存。

# rpm -Uvh https://repo.zabbix.com/zabbix/6.0/rhel/8/x86_64/zabbix-release-6.0-1.el8.noarch.rpm
# dnf clean all

2.2 安装Zabbix服务器和Zabbix代理包。

安装Zabbix Server相关的软件包和Zabbix Agent。

# dnf -y install zabbix-server-mysql zabbix-web-mysql zabbix-apache-conf zabbix-sql-scripts zabbix-selinux-policy zabbix-agent zabbix-web-japanese

3. Zabbix的初始设置

3.1 创建用于Zabbix的数据库。

我将在MariaDB上创建数据库和用户。

# mysql -uroot -p
Enter password:           <- DBユーザ-rootのパスワードを入力
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 3
Server version: 10.6.7-MariaDB MariaDB Server

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> create database zabbix character set utf8mb4 collate utf8mb4_bin;
Query OK, 1 row affected (0.000 sec)

MariaDB [(none)]> create user zabbix@localhost identified by '<DBユーザzabbixのパスワードを入力>';
Query OK, 0 rows affected (0.004 sec)

MariaDB [(none)]> grant all privileges on zabbix.* to zabbix@localhost;
Query OK, 0 rows affected (0.002 sec)

MariaDB [(none)]> quit;
Bye

将DB模式和初始数据导入到Zabbix。

# zcat /usr/share/doc/zabbix-sql-scripts/mysql/server.sql.gz | mysql -uzabbix -p zabbix
Enter password:         <- DBユーザーzabbixのパスワードを入力 

3.2 Zabbix 服务器的配置

编辑Zabbix Server的配置文件,并将Zabbix数据库的密码设置为DBPassword。

# vi /etc/zabbix/zabbix_server.conf
DBPassword=<DBユーザzabbixのパスワード>

3.3 配置Zabbix代理

编辑Zabbix Agent的配置文件,并设置连接到的Zabbix Server和Agent主机名。

$ vi /etc/zabbix/zabbix_agent2.conf
# 監視通信を許可するZabbix ServerのIPアドレス
# 今回の構成では、Zabbix Server自身にAgentを導入しているので値を変更しない
# Zabbix Server以外のマシンにAgentを構成する場合は、Zabbix ServerのIPアドレスを指定する
Server=127.0.0.1

# ActiveCheckのデータ送信先Zabbix Server IPアドレス
# 今回の構成では、Zabbix Server自身にAgentを導入しているので値を変更しない
ServerActive=127.0.0.1

# Agentのホスト名(OSのhostnameではなく、zabbixに登録するホスト名)
Hostname=Zabbix server
↓
Hostname=<ホスト名>

启动服务并启用自动启动。

# systemctl restart zabbix-server zabbix-agent httpd php-fpm
# systemctl enable zabbix-server zabbix-agent httpd php-fpm

3.5 Zabbix前端的配置

スクリーンショット 2022-03-02 16.53.01.png
bannerAds