4.2 配置zabbix数据库
1.配置mariadb安装源
登入mariadb服务器,在Linux主机上添加mariadb数据库的安装源,安装命令如下:
wget https://downloads.mariadb.com/MariaDB/mariadb_repo_setup
chmod u+x mariadb_repo_setup
./mariadb_repo_setup
[root@mariadb ~]# wget https://downloads.mariadb.com/MariaDB/mariadb_repo_setup
--2024-11-08 16:03:42-- https://downloads.mariadb.com/MariaDB/mariadb_repo_setup
Resolving downloads.mariadb.com (downloads.mariadb.com)... 104.18.135.24, 104.17.191.14, 2606:4700:1002:2bc::672e:387f, ...
Connecting to downloads.mariadb.com (downloads.mariadb.com)|104.18.135.24|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 36734 (36K) [application/octet-stream]
Saving to: ‘mariadb_repo_setup’
mariadb_repo_setup 100%[==========================================================================================================>] 35.87K 81.3KB/s in 0.4s
2024-11-08 16:03:46 (81.3 KB/s) - ‘mariadb_repo_setup’ saved [36734/36734]
[root@mariadb ~]#
[root@mariadb ~]#
[root@mariadb ~]# chmod u+x mariadb_repo_setup
[root@mariadb ~]# ./mariadb_repo_setup
# [info] Checking for script prerequisites.
# [info] MariaDB Server version 11.rolling 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.
Unable to read consumer identity
This system is not registered with an entitlement server. You can use subscription-manager to register.
0 files removed
[root@mariadb ~]# cat /etc/yum.repos.d/mariadb.repo
[mariadb-main]
name = MariaDB Server
baseurl = https://dlm.mariadb.com/repo/mariadb-server/11.rolling/yum/rhel/8/x86_64
gpgkey = file:///etc/pki/rpm-gpg/MariaDB-Server-GPG-KEY
gpgcheck = 1
enabled = 1
module_hotfixes = 1
[mariadb-maxscale]
# To use the latest stable release of MaxScale, use "latest" as the version
# To use the latest beta (or stable if no current beta) release of MaxScale, use "beta" as the version
name = MariaDB MaxScale
baseurl = https://dlm.mariadb.com/repo/maxscale/latest/yum/rhel/8/x86_64
gpgkey = file:///etc/pki/rpm-gpg/MariaDB-MaxScale-GPG-KEY
gpgcheck = 1
enabled = 1
[mariadb-tools]
name = MariaDB Tools
baseurl = https://downloads.mariadb.com/Tools/rhel/8/x86_64
gpgkey = file:///etc/pki/rpm-gpg/MariaDB-Enterprise-GPG-KEY
gpgcheck = 1
enabled = 1
[root@mariadb ~]#
2.安装并启动mariadb数据库
在Linux主机上安装mariadb数据库,安装和启动命令如下:
[root@mariadb ~]# dnf install mariadb-server
Updating Subscription Management repositories.
Unable to read consumer identity
This system is not registered with an entitlement server. You can use subscription-manager to register.
MariaDB Server 66 kB/s | 739 kB 00:11
MariaDB MaxScale 968 B/s | 7.0 kB 00:07
MariaDB Tools 352 B/s | 4.3 kB 00:12
8.10 68 MB/s | 8.7 MB 00:00
8.10 60 MB/s | 2.4 MB 00:00
Dependencies resolved.
====================================================================================================================================================================================================
Package Architecture Version Repository Size
====================================================================================================================================================================================================
Installing:
MariaDB-server x86_64 11.5.2-1.el8 mariadb-main 27 M
Installing dependencies:
MariaDB-client x86_64 11.5.2-1.el8 mariadb-main 17 M
MariaDB-common x86_64 11.5.2-1.el8 mariadb-main 88 k
MariaDB-shared x86_64 11.5.2-1.el8 mariadb-main 131 k
galera-4 x86_64 26.4.19-1.el8 mariadb-main 1.7 M
liburing x86_64 1.0.7-3.el8 server2 24 k
socat x86_64 1.7.4.1-1.el8 server1 323 k
Installing weak dependencies:
MariaDB-client-compat noarch 11.5.2-1.el8 mariadb-main 11 k
MariaDB-server-compat noarch 11.5.2-1.el8 mariadb-main 8.9 k
Transaction Summary
====================================================================================================================================================================================================
Install 9 Packages
Total download size: 46 M
Installed size: 239 M
Is this ok [y/N]: y
Downloading Packages:
(1/9): MariaDB-client-compat-11.5.2-1.el8.noarch.rpm 3.6 kB/s | 11 kB 00:03
(2/9): MariaDB-common-11.5.2-1.el8.x86_64.rpm 12 kB/s | 88 kB 00:07
(3/9): MariaDB-server-compat-11.5.2-1.el8.noarch.rpm 5.9 kB/s | 8.9 kB 00:01
(4/9): MariaDB-shared-11.5.2-1.el8.x86_64.rpm 71 kB/s | 131 kB 00:01
(5/9): galera-4-26.4.19-1.el8.x86_64.rpm 682 kB/s | 1.7 MB 00:02
(6/9): socat-1.7.4.1-1.el8.x86_64.rpm 36 MB/s | 323 kB 00:00
(7/9): liburing-1.0.7-3.el8.x86_64.rpm 13 MB/s | 24 kB 00:00
(8/9): MariaDB-server-11.5.2-1.el8.x86_64.rpm 1.2 MB/s | 27 MB 00:22
(9/9): MariaDB-client-11.5.2-1.el8.x86_64.rpm 91 kB/s | 17 MB 03:10
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Total 250 kB/s | 46 MB 03:10
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
Preparing : 1/1
Installing : MariaDB-shared-11.5.2-1.el8.x86_64 1/9
Running scriptlet: MariaDB-shared-11.5.2-1.el8.x86_64 1/9
Installing : MariaDB-common-11.5.2-1.el8.x86_64 2/9
Installing : liburing-1.0.7-3.el8.x86_64 3/9
Installing : MariaDB-client-compat-11.5.2-1.el8.noarch 4/9
Installing : MariaDB-client-11.5.2-1.el8.x86_64 5/9
Installing : socat-1.7.4.1-1.el8.x86_64 6/9
Running scriptlet: galera-4-26.4.19-1.el8.x86_64 7/9
Installing : galera-4-26.4.19-1.el8.x86_64 7/9
Running scriptlet: galera-4-26.4.19-1.el8.x86_64 7/9
Installing : MariaDB-server-compat-11.5.2-1.el8.noarch 8/9
Running scriptlet: MariaDB-server-11.5.2-1.el8.x86_64 9/9
Installing : MariaDB-server-11.5.2-1.el8.x86_64 9/9
Running scriptlet: MariaDB-server-11.5.2-1.el8.x86_64 9/9
2024-11-08 16:11:00 0 [Warning] mariadbd: io_uring_queue_init() failed with ENOSYS: check seccomp filters, and the kernel version (newer than 5.1 required)
2024-11-08 16:11:00 0 [Warning] InnoDB: liburing disabled: falling back to innodb_use_native_aio=OFF
Two all-privilege accounts were created.
One is root@localhost, it has no password, but you need to
be system 'root' user to connect. Use, for example, sudo mysql
The second is mysql@localhost, it has no password either, but
you need to be the system 'mysql' user to connect.
After connecting you can set the password, if you would need to be
able to connect as any of these users with a password and without sudo
See the MariaDB Knowledgebase at https://mariadb.com/kb
Please report any problems at https://mariadb.org/jira
The latest information about MariaDB is available at https://mariadb.org/.
Consider joining MariaDB's strong and vibrant community:
https://mariadb.org/get-involved/
Verifying : MariaDB-client-11.5.2-1.el8.x86_64 1/9
Verifying : MariaDB-client-compat-11.5.2-1.el8.noarch 2/9
Verifying : MariaDB-common-11.5.2-1.el8.x86_64 3/9
Verifying : MariaDB-server-11.5.2-1.el8.x86_64 4/9
Verifying : MariaDB-server-compat-11.5.2-1.el8.noarch 5/9
Verifying : MariaDB-shared-11.5.2-1.el8.x86_64 6/9
Verifying : galera-4-26.4.19-1.el8.x86_64 7/9
Verifying : socat-1.7.4.1-1.el8.x86_64 8/9
Verifying : liburing-1.0.7-3.el8.x86_64 9/9
Installed products updated.
Installed:
MariaDB-client-11.5.2-1.el8.x86_64 MariaDB-client-compat-11.5.2-1.el8.noarch MariaDB-common-11.5.2-1.el8.x86_64 MariaDB-server-11.5.2-1.el8.x86_64 MariaDB-server-compat-11.5.2-1.el8.noarch
MariaDB-shared-11.5.2-1.el8.x86_64 galera-4-26.4.19-1.el8.x86_64 liburing-1.0.7-3.el8.x86_64 socat-1.7.4.1-1.el8.x86_64
Complete!
[root@mariadb ~]#
[root@mariadb ~]# systemctl enable mariadb
Created symlink /etc/systemd/system/multi-user.target.wants/mariadb.service → /usr/lib/systemd/system/mariadb.service.
[root@mariadb ~]# systemctl start mariadb
3.安全初始化mariadb数据库
在mariadb数据库安装完成以后,请确保执行以下命令,确保都选择“Y”进行回答,并配置数据库的root密码。
[root@mariadb ~]# /usr/bin/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): <==第一次无密码登入,直接回车
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] y
Enabled successfully!
Reloading privilege tables..
... Success!
You already have your root account protected, so you can safely answer 'n'.
Change the root password? [Y/n] y
New password:
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
... 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
... 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
- 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
... 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!
[root@mariadb ~]#
执行以下命令登入mariadb数据库
[root@mariadb ~]# mariadb -uroot -p
Enter password:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 14
Server version: 11.5.2-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)]>
4.创建zabbix数据库及用户
登入数据库之后,执行以下命令创建zabbix数据库。
进入到mariadb数据库的命令行界面,使用下面命令来创建zabbix数据库,但是不要忘记在第二行、第三行、第四行命令中更改password(密码):
create database zabbix character set utf8mb4 collate utf8mb4_bin;
create user zabbix@'192.168.4.23' identified by 'Oracle123';
create user zabbix@'192.168.4.24' identified by 'Oracle123';
create user zabbix@'192.168.4.25' identified by 'Oracle123';
grant all privileges on zabbix.* to 'zabbix'@'192.168.4.23';
grant all privileges on zabbix.* to 'zabbix'@'192.168.4.24';
grant all privileges on zabbix.* to 'zabbix'@'192.168.4.25';
flush privileges;
quit;
[root@mariadb ~]# mariadb -uroot -p
Enter password:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 14
Server version: 11.5.2-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.001 sec)
MariaDB [(none)]> create user zabbix@'192.168.4.23' identified by 'Oracle123';
Query OK, 0 rows affected (0.002 sec)
MariaDB [(none)]> create user zabbix@'192.168.4.24' identified by 'Oracle123';
Query OK, 0 rows affected (0.001 sec)
MariaDB [(none)]> create user zabbix@'192.168.4.25' identified by 'Oracle123';
Query OK, 0 rows affected (0.001 sec)
MariaDB [(none)]> grant all privileges on zabbix.* to 'zabbix'@'192.168.4.23';
Query OK, 0 rows affected (0.001 sec)
MariaDB [(none)]> grant all privileges on zabbix.* to 'zabbix'@'192.168.4.24';
Query OK, 0 rows affected (0.001 sec)
MariaDB [(none)]> grant all privileges on zabbix.* to 'zabbix'@'192.168.4.25';
Query OK, 0 rows affected (0.001 sec)
MariaDB [(none)]> flush privileges;
Query OK, 0 rows affected (0.001 sec)
MariaDB [(none)]>
5.导入zabbix初始化数据
5.1配置zabbix安装源
在centos Linux或者redhat Linux主机中执行以下安装命令,安装zabbix安装源
dnf install -y https://repo.zabbix.com/zabbix/6.0/rhel/8/x86_64/zabbix-release-latest.el8.noarch.rpm
[root@mariadb ~]# dnf install -y https://repo.zabbix.com/zabbix/6.0/rhel/8/x86_64/zabbix-release-latest.el8.noarch.rpm
Updating Subscription Management repositories.
Unable to read consumer identity
This system is not registered with an entitlement server. You can use subscription-manager to register.
Last metadata expiration check: 0:38:29 ago on Fri 08 Nov 2024 04:11:16 PM CST.
zabbix-release-latest.el8.noarch.rpm 18 kB/s | 19 kB 00:01
Dependencies resolved.
====================================================================================================================================================================================================
Package Architecture Version Repository Size
====================================================================================================================================================================================================
Installing:
zabbix-release noarch 6.0-5.el8 @commandline 19 k
Transaction Summary
====================================================================================================================================================================================================
Install 1 Package
Total size: 19 k
Installed size: 22 k
Is this ok [y/N]: y
Downloading Packages:
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
Preparing : 1/1
Installing : zabbix-release-6.0-5.el8.noarch 1/1
Verifying : zabbix-release-6.0-5.el8.noarch 1/1
Installed products updated.
Installed:
zabbix-release-6.0-5.el8.noarch
Complete!
[root@mariadb ~]#
5.2安装zabbix数据库模块
[root@mariadb ~]# dnf install -y zabbix-sql-scripts
Updating Subscription Management repositories.
Unable to read consumer identity
This system is not registered with an entitlement server. You can use subscription-manager to register.
Zabbix Official Repository - x86_64 47 kB/s | 493 kB 00:10
Zabbix Official Repository (non-supported) - x86_64 784 B/s | 1.4 kB 00:01
Zabbix Official Repository (Agent2 Plugins) - x86_64 915 B/s | 1.7 kB 00:01
Dependencies resolved.
====================================================================================================================================================================================================
Package Architecture Version Repository Size
====================================================================================================================================================================================================
Installing:
zabbix-sql-scripts noarch 6.0.35-release1.el8 zabbix 8.3 M
Transaction Summary
====================================================================================================================================================================================================
Install 1 Package
Total download size: 8.3 M
Installed size: 10 M
Downloading Packages:
zabbix-sql-scripts-6.0.35-release1.el8.noarch.rpm 42 kB/s | 8.3 MB 03:21
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Total 42 kB/s | 8.3 MB 03:21
Zabbix Official Repository - x86_64 1.6 MB/s | 1.7 kB 00:00
Importing GPG key 0xA14FE591:
Userid : "Zabbix LLC <packager@zabbix.com>"
Fingerprint: A184 8F53 52D0 22B9 471D 83D0 082A B56B A14F E591
From : /etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX-A14FE591
Key imported successfully
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
Preparing : 1/1
Installing : zabbix-sql-scripts-6.0.35-release1.el8.noarch 1/1
Verifying : zabbix-sql-scripts-6.0.35-release1.el8.noarch 1/1
Installed products updated.
Installed:
zabbix-sql-scripts-6.0.35-release1.el8.noarch
Complete!
5.3导入元数据
现在将zabbix初始化数据库结构和数据导入新创建的zabbix数据库中,这包含了数据库的表结构和一些初始化数据,比如初始账号、密码,以及开箱即用的模板,导入密令如下:
zcat /usr/share/zabbix-sql-scripts/mysql/server.sql.gz | /usr/bin/mariadb -h192.168.4.23 -uzabbix -pOracle123 zabbix
[root@mariadb ~]# zcat /usr/share/zabbix-sql-scripts/mysql/server.sql.gz | /usr/bin/mariadb -h192.168.4.23 -uzabbix -pOracle123 zabbix
[root@mariadb ~]# /usr/bin/mariadb
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 17
Server version: 11.5.2-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)]> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
| zabbix |
+--------------------+
5 rows in set (0.001 sec)
MariaDB [(none)]> use zabbix;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
MariaDB [zabbix]> show tables;
+----------------------------+
| Tables_in_zabbix |
+----------------------------+
| acknowledges |
| actions |
| alerts |
| auditlog |
| autoreg_host |
| conditions |
| config |
| config_autoreg_tls |
| corr_condition |
| corr_condition_group |
| corr_condition_tag |
| corr_condition_tagpair |
| corr_condition_tagvalue |
| corr_operation |
| correlation |
| dashboard |
| dashboard_page |
| dashboard_user |
| dashboard_usrgrp |
| dbversion |
| dchecks |
| dhosts |
| drules |
| dservices |
| escalations |
| event_recovery |
| event_suppress |
| event_tag |
| events |
| expressions |
| functions |
| globalmacro |
| globalvars |
| graph_discovery |
| graph_theme |
| graphs |
| graphs_items |
| group_discovery |
| group_prototype |
| ha_node |
| history |
| history_log |
| history_str |
| history_text |
| history_uint |
| host_discovery |
| host_inventory |
| host_tag |
| hostmacro |
| hosts |
| hosts_groups |
| hosts_templates |
| housekeeper |
| hstgrp |
| httpstep |
| httpstep_field |
| httpstepitem |
| httptest |
| httptest_field |
| httptest_tag |
| httptestitem |
| icon_map |
| icon_mapping |
| ids |
| images |
| interface |
| interface_discovery |
| interface_snmp |
| item_condition |
| item_discovery |
| item_parameter |
| item_preproc |
| item_rtdata |
| item_tag |
| items |
| lld_macro_path |
| lld_override |
| lld_override_condition |
| lld_override_opdiscover |
| lld_override_operation |
| lld_override_ophistory |
| lld_override_opinventory |
| lld_override_opperiod |
| lld_override_opseverity |
| lld_override_opstatus |
| lld_override_optag |
| lld_override_optemplate |
| lld_override_optrends |
| maintenance_tag |
| maintenances |
| maintenances_groups |
| maintenances_hosts |
| maintenances_windows |
| media |
| media_type |
| media_type_message |
| media_type_param |
| module |
| opcommand |
| opcommand_grp |
| opcommand_hst |
| opconditions |
| operations |
| opgroup |
| opinventory |
| opmessage |
| opmessage_grp |
| opmessage_usr |
| optemplate |
| problem |
| problem_tag |
| profiles |
| proxy_autoreg_host |
| proxy_dhistory |
| proxy_history |
| regexps |
| report |
| report_param |
| report_user |
| report_usrgrp |
| rights |
| role |
| role_rule |
| script_param |
| scripts |
| service_alarms |
| service_problem |
| service_problem_tag |
| service_status_rule |
| service_tag |
| services |
| services_links |
| sessions |
| sla |
| sla_excluded_downtime |
| sla_schedule |
| sla_service_tag |
| sysmap_element_trigger |
| sysmap_element_url |
| sysmap_shape |
| sysmap_url |
| sysmap_user |
| sysmap_usrgrp |
| sysmaps |
| sysmaps_element_tag |
| sysmaps_elements |
| sysmaps_link_triggers |
| sysmaps_links |
| tag_filter |
| task |
| task_acknowledge |
| task_check_now |
| task_close_problem |
| task_data |
| task_remote_command |
| task_remote_command_result |
| task_result |
| timeperiods |
| token |
| trends |
| trends_uint |
| trigger_depends |
| trigger_discovery |
| trigger_queue |
| trigger_tag |
| triggers |
| users |
| users_groups |
| usrgrp |
| valuemap |
| valuemap_mapping |
| widget |
| widget_field |
+----------------------------+
173 rows in set (0.001 sec)
MariaDB [zabbix]>
zabbix数据库的配置到这里就完成了。接下来进行zabbix server的安装部署。