Linux 管理员 - 系统更新
CentOS 7 系统可以通过三种方式更新-
手动
自动
针对重大安全问题手动更新并配置自动更新
在生产环境中,建议为生产服务器手动更新。或者至少制定一个更新计划,以便管理员可以确保对业务运营至关重要的服务。
一个简单的安全更新可能会导致常见应用程序出现递归问题,需要管理员升级和重新配置,这似乎是合理的。因此,在首先在开发服务器和台式机中进行测试之前,不要在生产中安排自动更新。
手动更新 CentOS 7
要更新 CentOS 7,我们需要熟悉
yum 命令。
yum 用于处理 CentOS 7 中的软件包存储库。
yum 是常用的工具-
更新 CentOS 7 Linux 系统
搜索包
安装软件包
检测并安装软件包所需的依赖项
为了使用
yum 进行更新,您的 CentOS 服务器需要连接到 Internet。大多数配置会安装一个基本系统,然后使用
yum 查询 CentOS 主存储库以获取软件包中的附加功能并应用系统更新。
我们已经使用
yum 安装了一些软件包。使用
yum 时,您将始终需要以 root 用户身份执行此操作。或具有 root 访问权限的用户。因此,让我们搜索并安装一个名为
nano 的易于使用的文本编辑器。
[root@centos rdc]# yum search nano
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
* base: mirror.rackspace.com
* epel: mirror.chpc.utah.edu
* extras: repos.forethought.net
* updates: repos.forethought.net
======================================================================
N/S matched: nano
======================================================================
nano.x86_64 : A small text editor
nodejs-nano.noarch : Minimalistic couchdb driver for Node.js
perl-Time-Clock.noarch : Twenty-four hour clock object with nanosecond precision
Name and summary matches only, use "search all" for everything.
[root@centos rdc]#
现在,让我们安装
nano 文本编辑器。
[root@centos rdc]# yum install nano
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
* base: mirror.keystealth.org
* epel: pubmirror1.math.uh.edu
* extras: centos.den.host-engine.com
* updates: repos.forethought.net
Resolving Dependencies
--> Running transaction check
---> package nano.x86_64 0:2.3.1-10.el7 will be installed
--> Finished Dependency Resolution
Dependencies Resolved
================================================================================
package Arch
Version Repository Size
================================================================================
Installing:
nano x86_64
2.3.1-10.el7 base 440 k
Transaction Summary
Install 1 Package
Total download size: 440 k
Installed size: 1.6 M
Is this ok [y/d/N]: y
Downloading packages:
nano-2.3.1-10.el7.x86_64.rpm
| 440 kB 00:00:00
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : nano-2.3.1-10.el7.x86_64
1/1
Verifying : nano-2.3.1-10.el7.x86_64
1/1
Installed:
nano.x86_64 0:2.3.1-10.el7
Complete!
[root@centos rdc]#
我们已经安装了 nano 文本编辑器。 IMO 这种方法比在网站上搜索实用程序和手动运行安装程序要容易得多。此外,存储库使用数字签名来验证包,确保它们来自 yum 的可信来源。在信任新存储库时,由管理员来验证真实性。这就是为什么厌倦第三方存储库被认为是最佳做法的原因。
Yum 也可以用来删除一个包。
[root@centos rdc]# yum remove nano
Loaded plugins: fastestmirror, langpacks
Resolving Dependencies
--> Running transaction check
---> package nano.x86_64 0:2.3.1-10.el7 will be erased
--> Finished Dependency Resolution
Dependencies Resolved
现在让我们检查更新。
[root@centos rdc]# yum list updates
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
* base: mirror.keystealth.org
* epel: pubmirror1.math.uh.edu
* extras: centos.den.host-engine.com
* updates: repos.forethought.net
Updated Packages
NetworkManager.x86_64 1:1.4.0-17.el7_3 updates
NetworkManager-adsl.x86_64 1:1.4.0-17.el7_3 updates
NetworkManager-glib.x86_64 1:1.4.0-17.el7_3 updates
NetworkManager-libnm.x86_64 1:1.4.0-17.el7_3 updates
NetworkManager-team.x86_64 1:1.4.0-17.el7_3 updates
NetworkManager-tui.x86_64 1:1.4.0-17.el7_3 updates
NetworkManager-wifi.x86_64 1:1.4.0-17.el7_3 updates
audit.x86_64 2.6.5-3.el7_3.1 updates
audit-libs.x86_64 2.6.5-3.el7_3.1 updates
audit-libs-python.x86_64
如图所示,我们有几十个更新等待安装。实际上,由于我们尚未配置自动更新,因此总共有大约 100 个更新。因此,让我们安装所有待处理的更新。
[root@centos rdc]# yum update
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
* base: mirrors.usc.edu
* epel: pubmirror1.math.uh.edu
* extras: repos.forethought.net
* updates: repos.forethought.net
Resolving Dependencies
--> Running transaction check
---> package NetworkManager.x86_64 1:1.4.0-14.el7_3 will be updated
---> package NetworkManager.x86_64 1:1.4.0-17.el7_3 will be an update
selinux-policy noarch 3.13.1102.el7_3.15 updates 414 k
selinux-policy-targeted noarch 3.13.1102.el7_3.15 updates 6.4 M
systemd x86_64 21930.el7_3.7 updates 5.2 M
systemd-libs x86_64 21930.el7_3.7 updates 369 k
systemd-python x86_64 21930.el7_3.7 updates 109 k
systemd-sysv x86_64 21930.el7_3.7 updates 63 k
tcsh x86_64 6.18.01-13.el7_3.1 updates 338 k
tzdata noarch 2017a1.el7 updates 443 k
tzdata-java noarch 2017a1.el7 updates 182 k
wpa_supplicant x86_64 1:2.021.el7_3 updates 788 k
Transaction Summary
===============================================================================
Install 2 Packages
Upgrade 68 Packages
Total size: 196 M
Total download size: 83 M
Is this ok [y/d/N]:
按下"y"键后,CentOS 7 的更新将开始。
yum 更新时经历的一般过程是-
检查当前包
在存储库中查找更新的软件包
计算更新包所需的依赖项
下载更新
安装更新
现在,让我们确保我们的系统是最新的-
[root@centos rdc]# yum list updates
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
* updates: mirror.compevo.com
[root@centos rdc]#
如您所见,未列出任何更新。
为 YUM 配置自动更新
在企业环境中,如前所述,自动更新可能是也可能不是首选的安装方法。让我们回顾一下使用 yum 配置自动更新的步骤。
首先,我们安装一个名为
yum-cron 的包。
[root@centos rdc]# yum-y install yum-cron
Install 1 Package
Total download size: 61 k
Installed size: 51 k
Downloading packages:
yum-cron-3.4.3-150.el7.centos.noarch.rpm
| 61 kB 00:00:01
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : yum-cron-3.4.3-150.el7.centos.noarch
1/1
Verifying : yum-cron-3.4.3-150.el7.centos.noarch
1/1
Installed:
yum-cron.noarch 0:3.4.3-150.el7.centos
Complete!
[root@centos rdc]#
默认情况下,
yum-cron 只会下载更新而不安装它们。是否自动安装更新由管理员决定。最大的警告是:某些更新需要重新启动系统。此外,某些更新可能需要在服务再次运行之前更改配置。
在以下情况下更新依赖项可能会产生递归问题-
yum 推荐了某个库的更新
该库仅支持 Apache Server 2.4,但我们有服务器 2.3
我们的商业网站依赖于特定版本的 PHP
为库安装的新版本 Apache 需要升级 PHP
我们的生产网络应用程序尚未使用较新的 PHP 版本进行测试
Yum 可能会在没有通知的情况下自动升级 Apache 和 PHP,除非配置为不这样做。
如果所有 5 种情况都出现,则可能导致从早上头疼到可能泄露用户数据的安全隐患。虽然上述例子是一场完美的风暴,但我们从不希望这种情况发生。
由于更新重新启动和重新配置可能导致停机,因此管理员可以访问从恢复服务所需的时间造成的潜在收入损失的可能情况。例如,对于拥有数百万客户的每天价值数百万美元的电子商务网站而言,这种做法可能不够保守。
现在让我们配置
yum-cron 以自动安装系统更新。
[root@centos rdc]# vim /etc/yum/yum-cron.conf
# Whether updates should be applied when they are available. Note
# that download_updates must also be yes for the update to be applied.
apply_updates = yes
我们想将
apply_updates = no 更改为
apply_updates = yes。现在让我们为
yum-cron 配置更新间隔。
同样,是否使用自动更新和按需安装更新可能是一把双刃剑,需要管理员针对每种独特情况进行考虑。