如果我執行以下命令:
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}
這種方法的優點在於,可以每週對伺服器套用更新和安全補丁,而資料庫更新僅在每個季度的計畫維護視窗期間執行。 (當然,除非一些非常重要的東西需要被推出)。