如何在FreeBSD 12上安装MariaDB 10.3

时间:2020-02-23 14:40:54  来源:igfitidea点击:

如何在FreeBSD 12上安装MariaDB 10.3?
,如何在FreeBSD 12上安装Mariadb 10.3数据库服务器?
MariaDB 10.3是一个多用户多线程SQL数据库服务器。
它是一个社区开发的MySQL关系数据库管理系统的叉子。

MariaDB 10.3功能:

InnoDB被用作默认的存储引擎,而不是XtraDB。
系统版本表
FOR循环
MariaDB Galera集群是一个同步多主集群,现在是MariaDB的标准部分。
序列
InnoDB即时添加列
不可见列
并行复制
多源复制
常用表表达式
存储引擎独立列压缩

以下是在FreeBSD 12上安装和配置MariaDB 10.3的步骤。

第1步:更新端口树

首先使用使用的FreeBSD服务器端口树更新 portsnap命令:

$Hyman@theitroad:~ % su 
 Password:
 Hyman@theitroad:~# portsnap fetch update
 Looking up portsnap.FreeBSD.org mirrors… 5 mirrors found.
 Fetching public key from ec2-ap-southeast-2.portsnap.freebsd.org… done.
 Fetching snapshot tag from ec2-ap-southeast-2.portsnap.freebsd.org… done.
 Fetching snapshot metadata… done.
 Fetching snapshot generated at Sun Dec  9 00:19:28 UTC 2016:
 Extracting snapshot… done.
 Verifying snapshot integrity… done.
 Fetching snapshot tag from ec2-ap-southeast-2.portsnap.freebsd.org… done.
 Fetching snapshot metadata… done.
 Updating from Sun Dec  9 00:19:28 UTC 2016 to Sun Dec  9 19:15:19 UTC 2016.
 Fetching 5 metadata patches… done.
 Applying metadata patches… done.
 Fetching 0 metadata files… done.
 Fetching 78 patches. 
 (78/78) 100.00%  done.                                   
 done.
 Applying patches… 
 done.
 Fetching 3 new ports or files… done.
 /usr/ports was not created by portsnap.
 You must run 'portsnap extract' before running 'portsnap update'.

第一次运行portsnap时,我们需要将快照提取到 /usr/ports

sudo portsnap extract

我们应该在输出结束时获取下面的消息。

Building new INDEX files... done.

确认一切都是最新的。

sudo portsnap fetch update

第2步:安装MariaDB 10.3数据库服务器

可以使用二进制或者端口方法安装MariaDB 10.3.
此安装来自二进制包使用 pkg包管理器。
如果包缓存中提供MariaDB 10.3,则检查Check:

$pkg search mariadb | grep 10.3
mariadb103-client-10.3.11      Multithreaded SQL database (client)
mariadb103-server-10.3.11      Multithreaded SQL database (server)

从输出中,我们可以看到版本10.3.11可用。
使用以下命令安装服务器和客户端:

$sudo pkg install mariadb103-server mariadb103-client
 Updating FreeBSD repository catalogue…
 FreeBSD repository is up to date.
 All repositories are up to date.
 The following 6 package(s) will be affected (of 0 checked):
 New packages to be INSTALLED:
     mariadb103-server: 10.3.11
     mariadb103-client: 10.3.11
     libedit: 3.1.20160329_2,1
     unixODBC: 2.3.7
     galera: 25.3.24
     boost-libs: 1.68.0_1
 Number of packages to be installed: 6
 The process will require 406 MiB more space.
 44 MiB to be downloaded.
 Proceed with this action? [y/N]: y
 [1/6] Fetching mariadb103-server-10.3.11.txz: 100%   29 MiB 159.5kB/s    03:11    
 [2/6] Fetching mariadb103-client-10.3.11.txz: 100%    2 MiB 101.4kB/s    00:17    
 [3/6] Fetching libedit-3.1.20160329_2,1.txz: 100%  123 KiB 125.6kB/s    00:01    
 [4/6] Fetching unixODBC-2.3.7.txz: 100%  456 KiB  93.5kB/s    00:05    
 [5/6] Fetching galera-25.3.24.txz: 100%  802 KiB 117.3kB/s    00:07    
 [6/6] Fetching boost-libs-1.68.0_1.txz: 100%   12 MiB 134.6kB/s    01:32    
 Checking integrity… done (0 conflicting)
 [1/6] Installing libedit-3.1.20160329_2,1…
 [1/6] Extracting libedit-3.1.20160329_2,1: 100%
 [2/6] Installing boost-libs-1.68.0_1…
 [2/6] Extracting boost-libs-1.68.0_1: 100%
 [3/6] Installing mariadb103-client-10.3.11…
 [3/6] Extracting mariadb103-client-10.3.11: 100%
 [4/6] Installing unixODBC-2.3.7…
 [4/6] Extracting unixODBC-2.3.7: 100%
 [5/6] Installing galera-25.3.24…
 [5/6] Extracting galera-25.3.24: 100%
 [6/6] Installing mariadb103-server-10.3.11…
 ===> Creating groups.
 Creating group 'mysql' with gid '88'.
 ===> Creating users
 Creating user 'mysql' with uid '88'.
 [6/6] Extracting mariadb103-server-10.3.11: 100%
 Message from boost-libs-1.68.0_1:
 You have built the Boost library with thread support.
 Don't forget to add -pthread to your linker options when
 linking your code.
 Message from mariadb103-client-10.3.11:

第3步:启动并启用MySQL-Server服务

在FreeBSD 12服务器上安装MariaDB数据库服务器后,我们需要在配置它之前启动服务。
在终端中的以下命令进行配置以启用 mysql-server服务启动系统启动。

$sudo sysrc mysql_enable="YES"
mysql_enable:  -> YES

然后启动服务。

sudo service mysql-server start

第4步:硬化MariaDB服务器安装

运行命令 mysql_secure_installation要硬化MariaDB数据库服务器。

$mysql_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
 you haven't set the root password yet, the password will be blank,
 so you should just press enter here.
 Enter current password for root (enter for none): 
 OK, successfully used password, moving on…
 Setting the root password ensures that nobody can log into the MariaDB
 root user without the proper authorisation.
 Set 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用户PasswordRemove匿名用户Disallow root用户远程LoginSremove测试数据库并访问完成它,使用root用户进行测试访问权限

$mysql -u root -p
 Enter password: <Enter password>
 Welcome to the MariaDB monitor.  Commands end with ; or \g.
 Your MariaDB connection id is 17
 Server version: 10.3.11-MariaDB FreeBSD Ports
 Copyright (c) 2000, 2016, Oracle, MariaDB Corporation Ab and others.
 Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
 MariaDB [(none)]> SELECT VERSION();
 +-----------------+
 | VERSION()       |
 +-----------------+
 | 10.3.11-MariaDB |
 +-----------------+
 1 row in set (0.001 sec)
 MariaDB [(none)]> QUIT
 Bye

第5步:将MariaDB服务器服务绑定到localhost

默认情况下,MariaDB服务绑定到所有可用的网络接口,可以从:

$sockstat -4 -6 | grep 3306
mysql mysqld 1350 21 tcp46 *:3306 *:*

如果我们没有从网络连接到数据库服务器的服务,则可以将其限制为localhost。

# sysrc mysql_args="--bind-address=127.0.0.1"
mysql_args: -> --bind-address=127.0.0.1

你需要重新启动 mysql-server经过这种变化

# service mysql-server restart
Stopping mysql.
Waiting for PIDS: 1350, 1350.
Starting mysql.

验证更改:

# sockstat -4 -6 | grep mysql
mysql mysqld 1614 21 tcp4 127.0.0.1:3306 *:*

我们已经成功在FreeBSD 12上安装MariaDB 10.3。