CentOS 7系统可以三种方式更新:
手动
自动
手动更新主要安全问题并配置自动更新
在生产环境中,建议使用手动更新生产服务器.或者至少建立一个更新计划,以便管理员可以确保对业务运营至关重要的服务.
简单的安全更新可能导致需要通过升级和重新配置的常见应用程序的递归问题.管理员.因此,在首先在开发服务器和台式机中进行测试之前,要小心安排生产中的自动更新.
手动更新CentOS 7
要更新CentOS 7,我们希望熟悉 yum 命令. yum 用于处理CentOS 7中的软件包存储库. yum 是常用于去的工具;
更新CentOS 7 Linux系统
搜索软件包
安装软件包
检测并安装包所需的依赖项
为了使用 yum 进行更新,您的CentOS服务器需要是连接到互联网.大多数配置将安装基本系统,然后使用 yum 查询主CentOS存储库以获取包中的其他功能并应用系统更新.
我们已经使用 yum 安装一些软件包.使用 yum 时,您将始终需要以root用户身份执行此操作.或具有root访问权限的用户.因此,让我们搜索并安装一个名为 nano 的易于使用的文本编辑器.
[root@centos rdc]# yum search nanoLoaded plugins: fastestmirror, langpacksLoading 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 editornodejs-nano.noarch : Minimalistic couchdb driver for Node.jsperl-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 nanoLoaded plugins: fastestmirror, langpacksLoading mirror speeds from cached hostfile * base: mirror.keystealth.org * epel: pubmirror1.math.uh.edu * extras: centos.den.host-engine.com * updates: repos.forethought.netResolving Dependencies--> Running transaction check---> Package nano.x86_64 0:2.3.1-10.el7 will be installed--> Finished Dependency ResolutionDependencies Resolved================================================================================ Package ArchVersion Repository Size ================================================================================ Installing: nano x86_64 2.3.1-10.el7 base 440 k Transaction SummaryInstall 1 PackageTotal download size: 440 kInstalled size: 1.6 MIs this ok [y/d/N]: yDownloading packages:nano-2.3.1-10.el7.x86_64.rpm| 440 kB 00:00:00Running transaction checkRunning transaction testTransaction test succeededRunning transaction Installing : nano-2.3.1-10.el7.x86_641/1 Verifying : nano-2.3.1-10.el7.x86_641/1 Installed: nano.x86_64 0:2.3.1-10.el7 Complete![root@centos rdc]#
我们已经安装了纳米文本编辑器.这种方法IMO比在网站上搜索实用程序和手动运行安装程序要容易得多.此外,存储库使用数字签名来验证包,确保它们来自可靠的yum源.管理员在信任新存储库时验证真实性.这就是为什么厌倦第三方存储库被认为是最佳做法.
Yum也可用于删除包.
[root @ centos rdc] #yum remove nano 加载的插件:fastermirror,langpacks 解析依赖关系 - >正在运行交易支票 --->包nano.x86_64 0:2.3.1-10.el7将被删除 - >完成的依赖性解决方案已解决的依赖关系
现在让我们检查更新.
[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 ResolutionDependencies Resolved Now let's check for updates.[root@centos rdc]# yum list updatesLoaded plugins: fastestmirror, langpacksLoading mirror speeds from cached hostfile * base: mirror.keystealth.org * epel: pubmirror1.math.uh.edu * extras: centos.den.host-engine.com * updates: repos.forethought.netUpdated PackagesNetworkManager.x86_64 1:1.4.0-17.el7_3 updatesNetworkManager-adsl.x86_64 1:1.4.0-17.el7_3 updatesNetworkManager-glib.x86_64 1:1.4.0-17.el7_3 updatesNetworkManager-libnm.x86_64 1:1.4.0-17.el7_3 updatesNetworkManager-team.x86_64 1:1.4.0-17.el7_3 updatesNetworkManager-tui.x86_64 1:1.4.0-17.el7_3 updatesNetworkManager-wifi.x86_64 1:1.4.0-17.el7_3 updatesaudit.x86_64 2.6.5-3.el7_3.1 updatesaudit-libs.x86_64 2.6.5-3.el7_3.1 updatesaudit-libs-python.x86_64
As如图所示,我们有几十个待更新的更新.实际上,由于我们尚未配置自动更新,因此总共有大约100个更新.因此,让我们安装所有挂起的更新.
[root@centos rdc]# yum updateLoaded plugins: fastestmirror, langpacksLoading mirror speeds from cached hostfile * base: mirrors.usc.edu * epel: pubmirror1.math.uh.edu * extras: repos.forethought.net * updates: repos.forethought.netResolving 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-cronInstall 1 PackageTotal download size: 61 kInstalled size: 51 kDownloading packages:yum-cron-3.4.3-150.el7.centos.noarch.rpm| 61 kB 00:00:01Running transaction checkRunning transaction testTransaction test succeededRunning transaction Installing : yum-cron-3.4.3-150.el7.centos.noarch1/1 Verifying : yum-cron-3.4.3-150.el7.centos.noarch1/1Installed: 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
我们的生产Web应用程序尚未使用较新的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 配置更新间隔.
同样,是否使用自动更新并按需安装更新可能是一把双刃剑,需要管理员会考虑每种独特情况.