以最少的 MySQL 停机时间来更新大量软件包的好方法

以最少的 MySQL 停机时间来更新大量软件包的好方法

如果我运行以下命令:

apt list --upgradable

然后有许多软件包需要升级:

Listing... Done
grub-common/bionic-updates 2.02-2ubuntu8.23 amd64 [upgradable from: 2.02-2ubuntu8.21]
grub-pc/bionic-updates 2.02-2ubuntu8.23 amd64 [upgradable from: 2.02-2ubuntu8.21]
grub-pc-bin/bionic-updates 2.02-2ubuntu8.23 amd64 [upgradable from: 2.02-2ubuntu8.21]
grub2-common/bionic-updates 2.02-2ubuntu8.23 amd64 [upgradable from: 2.02-2ubuntu8.21]
initramfs-tools/bionic-updates,bionic-updates 0.130ubuntu3.12 all [upgradable from: 0.130ubuntu3.11]
initramfs-tools-bin/bionic-updates 0.130ubuntu3.12 amd64 [upgradable from: 0.130ubuntu3.11]
initramfs-tools-core/bionic-updates,bionic-updates 0.130ubuntu3.12 all [upgradable from: 0.130ubuntu3.11]
intel-microcode/bionic-updates,bionic-security 3.20210216.0ubuntu0.18.04.1 amd64 [upgradable from: 3.20201110.0ubuntu0.18.04.2]
libmysqlclient20/bionic-updates,bionic-security 5.7.34-0ubuntu0.18.04.1 amd64 [upgradable from: 5.7.33-0ubuntu0.18.04.1]
libnss-systemd/bionic-updates 237-3ubuntu10.47 amd64 [upgradable from: 237-3ubuntu10.46]
libpam-systemd/bionic-updates 237-3ubuntu10.47 amd64 [upgradable from: 237-3ubuntu10.46]
libsystemd0/bionic-updates 237-3ubuntu10.47 amd64 [upgradable from: 237-3ubuntu10.46]
libudev1/bionic-updates 237-3ubuntu10.47 amd64 [upgradable from: 237-3ubuntu10.46]
linux-generic/bionic-updates,bionic-security 4.15.0.143.130 amd64 [upgradable from: 4.15.0.142.129]
linux-headers-generic/bionic-updates,bionic-security 4.15.0.143.130 amd64 [upgradable from: 4.15.0.142.129]
linux-image-generic/bionic-updates,bionic-security 4.15.0.143.130 amd64 [upgradable from: 4.15.0.142.129]
linux-libc-dev/bionic-updates,bionic-security 4.15.0-143.147 amd64 [upgradable from: 4.15.0-142.146]
mysql-client-5.7/bionic-updates,bionic-security 5.7.34-0ubuntu0.18.04.1 amd64 [upgradable from: 5.7.33-0ubuntu0.18.04.1]
mysql-client-core-5.7/bionic-updates,bionic-security 5.7.34-0ubuntu0.18.04.1 amd64 [upgradable from: 5.7.33-0ubuntu0.18.04.1]
mysql-server/bionic-updates,bionic-updates,bionic-security,bionic-security 5.7.34-0ubuntu0.18.04.1 all [upgradable from: 5.7.33-0ubuntu0.18.04.1]
mysql-server-5.7/bionic-updates,bionic-security 5.7.34-0ubuntu0.18.04.1 amd64 [upgradable from: 5.7.33-0ubuntu0.18.04.1]
mysql-server-core-5.7/bionic-updates,bionic-security 5.7.34-0ubuntu0.18.04.1 amd64 [upgradable from: 5.7.33-0ubuntu0.18.04.1]
systemd/bionic-updates 237-3ubuntu10.47 amd64 [upgradable from: 237-3ubuntu10.46]
systemd-sysv/bionic-updates 237-3ubuntu10.47 amd64 [upgradable from: 237-3ubuntu10.46]
ubuntu-advantage-tools/bionic-updates 27.0.2~18.04.1 all [upgradable from: 17]
udev/bionic-updates 237-3ubuntu10.47 amd64 [upgradable from: 237-3ubuntu10.46]

以前,当我们使用 升级所有软件包时apt upgrade,我们注意到 MySQL 会宕机,我们需要等到所有软件包都升级完毕后 MySQL 才会重新启动。这会花几分钟时间,并且在等待 MySQL 重新启动时,此服务器上的所有网站都会宕机。

那么,如何在升级服务器上的所有软件包的同时,最大限度地减少 MySQL 停机时间?

例如,我正在考虑使用以下命令仅升级 MySQL 包:

apt --only-upgrade install mysql-client-5.7
apt --only-upgrade install mysql-client-core-5.7
apt --only-upgrade install mysql-server
apt --only-upgrade install mysql-server-5.7
apt --only-upgrade install mysql-server-core-5.7

然后,一旦 MySQL 包升级完毕,就使用一个简单的apt upgrade命令升级所有其他包。

这是减少 MySQL 停机时间的好方法吗?

答案1

通常,我对专用于数据库引擎的生产服务器所做的是hold打包,防止它们被更新,直到我有足够的时间在开发和/或暂存环境中测试更新。

apt你可以这样做:

sudo apt-mark hold {package}

这样就可以安装系统的所有其他更新,而不会破坏数据库中的某些内容。当您准备好更新 MySQL 时,可以像这样删除保留:

sudo apt-mark unhold {package}

这种方法的优点在于,可以每周将更新和安全补丁应用于服务器,而数据库更新仅在每季度的预定维护时段内执行。(当然,除非需要推出真正重要的东西)。

相关内容