我正在运行 MySQL 服务器,并希望通过定期 apt-upgrades 使其保持最新状态。除非我在计划停机期间进行升级,否则我不希望这导致 MySQL 升级!我该如何更改我的 apt-preferences 以避免发生这种情况?
我尝试将其添加到文件 /etc/apt/preferences.d/pin-mysql
Package: mysql-client-5.1
Pin: version 5.1.41-3ubuntu12.7
Pin-Priority: 1001
Package: mysql-client-core-5.1
Pin: version 5.1.41-3ubuntu12.7
Pin-Priority: 1001
Package: mysql-common
Pin: version 5.1.41-3ubuntu12.7
Pin-Priority: 1001
Package: mysql-server
Pin: version 5.1.41-3ubuntu12.7
Pin-Priority: 1001
Package: mysql-server-5.1
Pin: version 5.1.41-3ubuntu12.7
Pin-Priority: 1001
Package: mysql-server-core-5.1
Pin: version 5.1.41-3ubuntu12.7
Pin-Priority: 1001
然后说明软件包已通过“apt-cache policy”固定,输出:
... all package sources here
500 http://security.ubuntu.com/ubuntu/ lucid-security/universe Packages
release v=10.04,o=Ubuntu,a=lucid-security,n=lucid,l=Ubuntu,c=universe
origin security.ubuntu.com
500 http://security.ubuntu.com/ubuntu/ lucid-security/restricted Packages
release v=10.04,o=Ubuntu,a=lucid-security,n=lucid,l=Ubuntu,c=restricted
origin security.ubuntu.com
... etc
Pinned packages:
mysql-server -> 5.1.41-3ubuntu12.7
mysql-server-core-5.1 -> 5.1.41-3ubuntu12.7
mysql-client-core-5.1 -> 5.1.41-3ubuntu12.7
mysql-common -> 5.1.41-3ubuntu12.7
mysql-server-5.1 -> 5.1.41-3ubuntu12.7
mysql-client-5.1 -> 5.1.41-3ubuntu12.7
但是...运行 aptitude safe-upgrade 刚刚更新了 MySQL...我做错了什么?
答案1
如果您想阻止软件包升级,固定并不是最佳选择。您需要做的是保留,您可以了解如何执行此操作在 Ubuntu 在线帮助的此页面上
答案2
尽管我不太清楚 dpkg 和 aptitude 持有之间的区别,但持有似乎是正确的做法。
无论如何 - 以下脚本正在执行我想要的操作并从 aptitude safe-upgrade 中排除软件包列表。
#!/bin/bash
# Stop the mysql packages from upgrading!
# Must run as root! Check presence of the packages-hold.log file to avoid running repeatedly.
PACKAGES="mysql-client-5.1 mysql-client-core-5.1 mysql-common mysql-server mysql-server-5.1 mysql-server-core-5.1 linux-image-server linux-image-2.6.32-28-server"
for PACKAGE in $PACKAGES;
do
/bin/echo $PACKAGE hold | /usr/bin/dpkg --set-selections
done
/usr/bin/aptitude hold $PACKAGES
echo $PACKAGES > /var/log/packages-hold.log
如果不执行 aptitude hold 命令,aptitude 仍会尝试更新标有该dpkg --set-selections
命令的软件包,并且我认为反之亦然。
仅供参考 - 这还会阻止内核映像一直更新。我只对出于高优先级安全原因的更新感兴趣,因为它总是附带重新启动。