在Kali Linux 2022.x系统上安装MariaDB 10.7
本文介绍如何在Kali Linux 2022.x系统上安装和运行MariaDB 10.7的方法,附在Kali Linux上删除MariaDB服务器的方法。
在Kali Linux上安装和运行MariaDB 10.7的操作步骤
步骤1、更新Kali Linux系统
通过运行以下命令更新已配置源中的包列表:
$ sudo apt update
[sudo] password for jkmutai:
Hit:1 http://ftp.halifax.rwth-aachen.de/kali kali-rolling InRelease
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
All packages are up to date.
如果更新可用,则通过对所有更新执行升级来应用它们。如果更新后存在/var/run/reboot-required文件,则需要重新启动:
sudo apt dist-upgrade -y
[ -f /var/run/reboot-required ] && sudo reboot -f
步骤2、将MariaDB 10.7存储库添加到Kali Linux
在Kali Linux和任何其他基于Debian的系统上安装依赖包以支持存储库管理:
sudo apt update
sudo apt install wget curl gpg gnupg2 software-properties-common apt-transport-https lsb-release ca-certificates
下载用于在支持的Linux操作系统上配置存储库的MariaDB脚本:
wget https://downloads.mariadb.com/MariaDB/mariadb_repo_setup
可以使用以下命令检查脚本使用帮助页面:
$ bash mariadb_repo_setup --help
Kali Linux不在脚本支持的Linux发行版列表中。我们必须在命令选项中提供OS类型和版本。Debian 11(Bullseye)存储库将在我们的Kali Linux系统中配置:
$ sudo bash mariadb_repo_setup --os-type=debian --os-version=bullseye --mariadb-server-version=10.7
# [info] Skipping OS detection and using OS type 'debian' and version 'bullseye' as given on the command line
# [info] Checking for script prerequisites.
# [info] MariaDB Server version 10.7 is valid
# [info] Repository file successfully written to /etc/apt/sources.list.d/mariadb.list
# [info] Adding trusted package signing keys...
# [info] Running apt-get update...
# [info] Done adding trusted package signing keys
脚本将编写一个新文件。这是在Kali Linux上配置的MariaDB回购:
cat /etc/apt/sources.list.d/mariadb.list
在Kali Linux上继续安装MariaDB 10.7之前,请确认存储库正常工作:
$ sudo apt update
Hit:1 https://downloads.mariadb.com/Tools/debian bullseye InRelease
Hit:2 http://ftp.halifax.rwth-aachen.de/kali kali-rolling InRelease
Get:3 https://dlm.mariadb.com/repo/mariadb-server/10.7/repo/debian bullseye InRelease [4634 B]
Get:4 https://dlm.mariadb.com/repo/maxscale/latest/apt bullseye InRelease [6387 B]
Fetched 11.0 kB in 1s (12.2 kB/s)
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
4 packages can be upgraded. Run 'apt list --upgradable' to see them.
步骤3、将MariaDB 10.7安装到Kali Linux
检查已配置存储库中列出的MariaDB的可用版本。你应该发现10.7已经释放出来:
$ apt-cache policy mariadb-server
mariadb-server:
Installed: (none)
Candidate: 1:10.7.3+maria~bullseye
Version table:
1:10.7.3+maria~bullseye 1000
1000 https://dlm.mariadb.com/repo/mariadb-server/10.7/repo/debian bullseye/main amd64 Packages
1000 https://dlm.mariadb.com/repo/mariadb-server/10.7/repo/debian bullseye/main arm64 Packages
1:10.7.1+maria~bullseye 1000
1000 https://dlm.mariadb.com/repo/mariadb-server/10.7/repo/debian bullseye/main amd64 Packages
1000 https://dlm.mariadb.com/repo/mariadb-server/10.7/repo/debian bullseye/main arm64 Packages
1:10.6.5-2 500
500 http://http.kali.org/kali kali-rolling/main amd64 Packages
现在,让我们在Kali Linux上安装MariaDB 10.7服务器和客户端软件包:
sudo apt install mariadb-server mariadb-client
附:修复错误“mariadb-server-core-10.7 : Depends: liburing1 (>= 0.7)”
如果您遇到以下类似的错误:
The following packages have unmet dependencies:
mariadb-server-core-10.7 : Depends: liburing1 (>= 0.7) but it is not installable
E: Unable to correct problems, you have held broken packages.
手动下载并安装版本大于等于0.7的liburing1软件包,地址在http://ftp.us.debian.org/debian/pool/main/libu/liburing/,或使用以下命令下载:
wget http://ftp.us.debian.org/debian/pool/main/libu/liburing/liburing1_0.7-3~bpo10+1_amd64.deb
在Kali Linux系统上本地下载后安装软件包:
$ sudo dpkg -i liburing1_0.7-3~bpo10+1_amd64.deb
Selecting previously unselected package liburing1:amd64.
(Reading database ... 290741 files and directories currently installed.)
Preparing to unpack liburing1_0.7-3~bpo10+1_amd64.deb ...
Unpacking liburing1:amd64 (0.7-3~bpo10+1) ...
Setting up liburing1:amd64 (0.7-3~bpo10+1) ...
Processing triggers for libc-bin (2.33-1) ...
在Kali Linux上重试MariaDB安装:
$ sudo apt install mariadb-server mariadb-client
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following packages were automatically installed and are no longer required:
fonts-roboto-slab libmms0 libofa0
Use 'sudo apt autoremove' to remove them.
The following additional packages will be installed:
mariadb-client-10.7 mariadb-client-core-10.7 mariadb-common mariadb-server-10.7 mariadb-server-core-10.7
Suggested packages:
mailx mariadb-test netcat-openbsd
The following packages will be REMOVED:
default-mysql-server mariadb-client-10.6 mariadb-client-core-10.6 mariadb-server-10.6 mariadb-server-core-10.6
The following NEW packages will be installed:
mariadb-client mariadb-client-10.7 mariadb-client-core-10.7 mariadb-server mariadb-server-10.7 mariadb-server-core-10.7
The following packages will be upgraded:
mariadb-common
1 upgraded, 6 newly installed, 5 to remove and 3 not upgraded.
Need to get 13.8 MB of archives.
After this operation, 4836 kB of additional disk space will be used.
Do you want to continue? [Y/n] y
这一次应该是成功的。可以使用--version命令选项验证已安装的版本:
$ mariadb --version
mariadb Ver 15.1 Distrib 10.7.3-MariaDB, for debian-linux-gnu (x86_64) using readline EditLine wrapper
步骤4、在Kali Linux上启动MariaDB服务
安装程序包后,启动并启用mariadb服务:
sudo systemctl enable mariadb
sudo systemctl start mariadb
状态应显示为正在运行:
$ systemctl status mariadb
通过以sudo用户身份运行mariadb安全安装脚本来保护数据库安装:
$ sudo mariadb-secure-installation
Switch to unix_socket authentication [Y/n] n
Change the root password? [Y/n] y
New password: Enter Password
Re-enter new password: Re-Enter Password
Remove anonymous users? [Y/n] y
Disallow root login remotely? [Y/n] y
Remove test database and access to it? [Y/n] y
Reload privilege tables now? [Y/n] y
测试身份验证是否有效。如果不提供密码,您将收到拒绝访问错误消息:
$ mysql -u root
ERROR 1698 (28000): Access denied for user 'root'@'localhost'
尝试使用-p选项,并在强化过程中为root用户提供密码设置:
$ mysql -u root -p
Enter password:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 52
Server version: 10.7.3-MariaDB-1:10.7.3+maria~bullseye mariadb.org binary distribution
MariaDB [(none)]> exit
如何在Kali Linux上删除MariaDB服务器
如果在任何时候您想删除数据库安装,请从删除MariaDB的服务器包开始:
$ sudo apt purge mariadb-server
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following packages were automatically installed and are no longer required:
fonts-roboto-slab libmms0 libofa0
Use 'sudo apt autoremove' to remove them.
The following packages will be REMOVED:
mariadb-server*
0 upgraded, 0 newly installed, 1 to remove and 3 not upgraded.
After this operation, 10.2 kB disk space will be freed.
Do you want to continue? [Y/n] y
要删除所有数据库数据,请删除/var/lib/mysql/目录:
sudo rm -rf /var/lib/mysql/
最后,删除mariadb客户端包和之前安装但不再需要的所有其他依赖项:
$ sudo apt autoremove mariadb-server mariadb-client
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
Package 'mariadb-server' is not installed, so not removed
The following packages will be REMOVED:
fonts-roboto-slab libmms0 libofa0 mariadb-client
0 upgraded, 0 newly installed, 4 to remove and 3 not upgraded.
After this operation, 650 kB disk space will be freed.
Do you want to continue? [Y/n] y
至此,删除MariaDB服务器完成。
结论
在本文中,我们与您分享了在Kali Linux上安装MariaDB 10.7的过程。安装完成后,我们介绍了服务管理、保护数据库服务器以及如何执行删除的方法。