
- 什么是MariaDB服務器?
- MariaDB Server 10.5中的新功能:
- 環境規格:
- 第一步:更新CentOS 8軟體包
- 第二步:CentOS 8中安裝MariaDB Yum存盤庫
- 第三步:CentOS 8上安裝MariaDB Server 10.5
- 第四步:MariaDB 資料庫用戶密碼設定
- 第五步:MariaDB服務器配置資料庫安全性
什么是MariaDB服務器?
MariaDB是一個免費的開源RDBMS(關系資料庫管理系統),MariaDB是MySQL資料庫的一個分支,由MySQL專案的某些原始開發人員維護,就像其前身一樣,MariaDB主要用作[基于PHP的服務器]的后端資料庫,許多FOSS(自由和開源軟體)實用程式還將MariaDB用作其資料存盤庫,
MariaDB服務器具有高度的可擴展性,可以用作[基于Standalone]或[Galera的MariaDB集群]環境,
MariaDB Server 10.5.3于2020年5月12日發布,具有許多新功能和一些重大更改,這是撰寫本文時的最新版本,
MariaDB Server 10.5中的新功能:
MariaDB Server 10.5中的一些更改和功能包括:
- 所有以前以mysql開頭的二進制檔案現在都以mariadb開頭,并帶有對應的mysql命令的 符號鏈接
- S3存盤引擎-用于將MariaDB表歸檔在Amazon S3或實作S3 API的任何第三方公共或私有云中
- S3表和磁區S3表都是可發現的,這意味著,如果您創建磁區的S3表,則該磁區表及其磁區都可以由另一臺有權訪問S3存盤的服務器直接使用,
- 通過分割SUPER特權來添加新特權,以便可以對每個用戶可以執行的操作進行更精細的調整
- 加快二進制行記錄代碼的速度
- 提高連接速度(最高25%)
您可以在MariaDB官方網站上查看MariaDB 10.5.3中新功能的完整串列,
環境規格:
- CPU:3.4 GHz(2核)
- 記憶體:2 GB
- 儲存空間:20 GB
- 作業系統:CentOS 8.2
- 主機名:mariadb.lianglab.cn
- IP地址:192.168.6.200/24
第一步:更新CentOS 8軟體包
使用ssh工具以root用戶身份連接到mariadb.lianglab.cn,
最佳實踐使用最新Linux軟體包
[root@couchdb ~]# hostnamectl set-hostname mariadb.lianglab.cn
[root@mariadb ~]# dnf update -y
Dependencies resolved.
Nothing to do.
Complete!
第二步:CentOS 8中安裝MariaDB Yum存盤庫
MariaDB Server 10.5.3是最新版本,因此在CentOS 8 yum存盤庫中不可用,
MariaDB提供了一個正式的yum存盤庫,我們可以使用它在CentOS 8上安裝MariaDB Server 10.5 ,
【1】創建yum存盤庫檔案,如下所示,
[root@mariadb-01 ~]# vi /etc/yum.repos.d/MariaDB.repo
在此檔案中添加以下指令,
# MariaDB 10.5 CentOS repository list - lianglab created 2020-12-26
# https://www.cnblogs.com/lianglab/
# http://downloads.mariadb.org/mariadb/repositories/
[mariadb]
name = MariaDB
baseurl = http://yum.mariadb.org/10.5/centos8-amd64
module_hotfixes=1
gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
gpgcheck=1
【2】MariaDB yum存盤庫構建快取,
[root@mariadb ~]# dnf clean all
44 files removed
[root@mariadb ~]# dnf makecache
CentOS-8 - Base - mirrors.tongdun.cn 1.2 MB/s | 3.9 kB 00:00
CentOS-8 - Extras - mirrors.tongdun.cn 817 kB/s | 1.5 kB 00:00
CentOS-8 - AppStream - mirrors.tongdun.cn 2.7 MB/s | 4.3 kB 00:00
MariaDB 1.7 kB/s | 2.9 kB 00:01
bintray--apache-couchdb-rpm 2.1 kB/s | 1.3 kB 00:00
Extra Packages for Enterprise Linux 8 - x86_64 2.7 MB/s | 4.7 kB 00:00
Extra Packages for Enterprise Linux 8 - x86_64 - Debug 1.6 MB/s | 3.0 kB 00:00
Extra Packages for Enterprise Linux 8 - x86_64 - Source 2.1 MB/s | 3.5 kB 00:00
Metadata cache created.

第三步:CentOS 8上安裝MariaDB Server 10.5
【1】我們已經添加了MariaDB yum存盤庫,現在我們可以使用dnf命令輕松安裝MariaDB Server ,
[root@mariadb ~]# dnf install -y MariaDB-server
Last metadata expiration check: 0:00:26 ago on Sat 26 Dec 2020 09:55:49 PM CST.
Dependencies resolved.
=============================================================================================================
Package Architecture Version Repository Size
=============================================================================================================
Installing:
MariaDB-server x86_64 10.5.8-1.el8 mariadb 27 M
Installing dependencies:
MariaDB-client x86_64 10.5.8-1.el8 mariadb 13 M
MariaDB-common x86_64 10.5.8-1.el8 mariadb 87 k
MariaDB-shared x86_64 10.5.8-1.el8 mariadb 115 k
galera-4 x86_64 26.4.6-1.el8 mariadb 13 M
socat x86_64 1.7.3.3-2.el8 AppStream 302 k
===========================================省略=====================================================
Downloading Packages:
(1/6): socat-1.7.3.3-2.el8.x86_64.rpm 6.2 MB/s | 302 kB 00:00
(2/6): MariaDB-common-10.5.8-1.el8.x86_64.rpm 6.8 kB/s | 87 kB 00:12
(3/6): MariaDB-shared-10.5.8-1.el8.x86_64.rpm 27 kB/s | 115 kB 00:04
[MIRROR] MariaDB-server-10.5.8-1.el8.x86_64.rpm: Curl error (28): Timeout was reached for http://yum.mariadb.org/10.5/centos8-amd64/rpms/MariaDB-server-10.5.8-1.el8.x86_64.rpm [Operation too slow. Less than 1000 bytes/sec transferred the last 30 seconds]
[MIRROR] galera-4-26.4.6-1.el8.x86_64.rpm: Curl error (28): Timeout was reached for http://yum.mariadb.org/10.5/centos8-amd64/rpms/galera-4-26.4.6-1.el8.x86_64.rpm [Operation too slow. Less than 1000 bytes/sec transferred the last 30 seconds]
===========================================省略=====================================================
[root@mariadb tdops]# dnf -y install galera-4-26.4.6-1.el8.x86_64.rpm MariaDB-server-10.5.8-1.el8.x86_64.rpm MariaDB-client-10.5.8-1.el8.x86_64.rpm
Installed:
MariaDB-client-10.5.8-1.el8.x86_64 MariaDB-common-10.5.8-1.el8.x86_64 MariaDB-server-10.5.8-1.el8.x86_64 MariaDB-shared-10.5.8-1.el8.x86_64
galera-4-26.4.6-1.el8.x86_64
Complete!
[root@mariadb tdops]# dnf install -y MariaDB-server
Last metadata expiration check: 0:21:18 ago on Sat 26 Dec 2020 09:55:49 PM CST.
Package MariaDB-server-10.5.8-1.el8.x86_64 is already installed.
Dependencies resolved.
Nothing to do.
Complete!
【2】啟動MariaDB服務,
[root@mariadb-01 ~]# systemctl enable --now mariadb.service
Created symlink /etc/systemd/s[root@mariadb tdops]# systemctl enable --now mariadb.service
Created symlink /etc/systemd/system/multi-user.target.wants/mariadb.service → /usr/lib/systemd/system/mariadb.service.
【3】驗證MariaDB服務的狀態和監聽的埠
[root@mariadb-01 ~]# systemctl status mariadb.service
a mariadb.service - MariaDB 10.5.3 database server
Loaded: loaded (/usr/lib/systemd/system/mariadb.service; enabled; vendor pre>
Drop-In: /etc/systemd/system/mariadb.service.d
aamigrated-from-my.cnf-settings.conf
Active: active (running) since Fri 2020-05-29 13:59:04 PKT; 12s ago
Docs: man:mysqld(8)
https://mariadb.com/kb/en/library/systemd/
Process: 12496 ExecStartPost=/bin/sh -c systemctl unset-environment _WSREP_ST>
Process: 12475 ExecStartPre=/bin/sh -c [ ! -e /usr/bin/galera_recovery ] && V>
Process: 12473 ExecStartPre=/bin/sh -c systemctl unset-environment _WSREP_STA>
Main PID: 12485 (mysqld)
Status: "Taking your SQL requests now..."
Tasks: 11 (limit: 5916)
Memory: 75.8M
CGroup: /system.slice/mariadb.service
aa12485 /usr/sbin/mysqld
May 29 13:59:04 mariadb-01.centlinux.com mysqld[12485]: 2020-05-29 13:59:04 0 [>
May 29 13:59:04 mariadb-01.centlinux.com mysqld[12485]: 2020-05-29 13:59:04 0 [>
May 29 13:59:04 mariadb-01.centlinux.com mysqld[12485]: 2020-05-29 13:59:04 0 [>
May 29 13:59:04 mariadb-01.centlinux.com mysqld[12485]: 2020-05-29 13:59:04 0 [>
May 29 13:59:04 mariadb-01.centlinux.com mysqld[12485]: 2020-05-29 13:59:04 0 [>
May 29 13:59:04 mariadb-01.centlinux.com mysqld[12485]: 2020-05-29 13:59:04 0 [>
[root@mariadb tdops]# netstat -anptl | grep mariadb
tcp6 0 0 :::3306 :::* LISTEN 125273/mariadbd
[root@mariadb tdops]#

第四步:MariaDB 資料庫用戶密碼設定
- Linux的根用戶可以連接到MariaDB的服務器MariaDB的根用戶無需任何密碼
- Linux mysql用戶可以無需任何密碼即可作為MariaDB mysql用戶連接到MariaDB服務器
為了允許其他Linux用戶以root或mysql用戶身份登錄,我們需要為這些資料庫用戶設定密碼,
【1】使用新的mariadb命令連接MariaDB服務器,
[root@mariadb ~]# mariadb -u root
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 3
Server version: 10.5.8-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 |
| test |
+--------------------+
4 rows in set (0.001 sec)
MariaDB [(none)]>
【2】為root和mysql用戶設定強密碼為lianglab@123
MariaDB [(none)]> alter user 'root'@'localhost' identified by 'lianglab@123';
Query OK, 0 rows affected (0.001 sec)
MariaDB [(none)]> alter user 'mysql'@'localhost' identified by 'lianglab@123';
Query OK, 0 rows affected (0.001 sec)
【3】重新加載特權表,
MariaDB [(none)]> flush privileges;
Query OK, 0 rows affected (0.001 sec)
【4】列出MariaDB服務器中的可用資料庫,
MariaDB [(none)]> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| test |
+--------------------+
4 rows in set (0.001 sec)
【5】從MariaDB shell退出,
MariaDB [(none)]> exit
Bye
【6】我們的MariaDB Server 10.5已成功安裝,

博主站點:https://www.cnblogs.com/lianglab/
第五步:MariaDB服務器配置資料庫安全性
我們可以選擇洗掉測驗資料庫并限制root用戶的遠程登錄,
我們可以使用新的mariadb-secure-installation命令,
[root@mariadb ~]# 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): ##輸入我們創建的密碼lianglab@123
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
... skipping.
You already have your root account protected, so you can safely answer 'n'.
Change the root password? [Y/n] n
... skipping.
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 ~]#

我們已經在CentOS 8.2上成功安裝MariaDB Server 10.5并配置管理員用戶和資料庫安全性,
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/240837.html
標籤:其他
上一篇:資料全景洞察概念簡介
下一篇:Oracle 19c物理備庫搭建
