CentOS 8.2部署MariaDB 10.5.3數據庫服務

什麼是MariaDB服務器?


MariaDB是一個免費的開源RDBMS(關係數據庫管理系統)。MariaDB是MySQL數據庫的一個分支,由MySQL項目的某些原始開發人員維護。就像其前身同樣,MariaDB主要用做[基於PHP的服務器]的後端數據庫。許多FOSS(自由和開源軟件)實用程序還將MariaDB用做其數據存儲庫。mysql

MariaDB服務器具備高度的可擴展性,能夠用做[基於Standalone]或[Galera的MariaDB集羣]環境。linux

MariaDB Server 10.5.3於2020年5月12日發佈,具備許多新功能和一些重大更改。這是撰寫本文時的最新版本。sql

MariaDB Server 10.5中的新功能:


MariaDB Server 10.5中的一些更改和功能包括:shell

  • 全部之前以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.cnapache

最佳實踐使用最新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存儲庫中不可用。centos

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
â 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
           ââmigrated-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
           ââ12485 /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用戶以rootmysql用戶身份登陸,咱們須要爲這些數據庫用戶設置密碼。

【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】爲rootmysql用戶設置強密碼爲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並配置管理員用戶和數據庫安全性。

相關文章
相關標籤/搜索