美丽安子 發表於 2024-2-18 11:59:00

CentOS 7 系统更新和内核升级

<p><strong>安装必要的功能</strong>:<code>wget</code><strong>和</strong><code>vim</code>后面会用到,以免出现问题</p>
<pre class="highlighter-prismjs language-bash prismjs-lines-highlighted" tabindex="0"><code>yum -y install wget vim</code></pre>
<p><strong>处理yum源</strong>:更换为阿里的yum源</p>
<p><strong>备份原始文件:</strong></p>
<pre class="highlighter-prismjs prismjs-lines-highlighted language-bash" tabindex="0"><code>cd /etc/yum.repos.d/
mkdir /etc/yum.repos.d/bak
mv /etc/yum.repos.d/*.repo /etc/yum.repos.d/bak</code></pre>
<p><span style="color: rgba(0, 0, 0, 1)"><strong>下载阿里的yum源仓库配置文件:</strong></span></p>
<pre class="highlighter-prismjs prismjs-lines-highlighted language-bash" tabindex="0"><code>wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
wget -O /etc/yum.repos.d/epel.repo https://mirrors.aliyun.com/repo/epel-7.repo</code></pre>
<p><span style="color: rgba(0, 0, 0, 1)"><strong>检查仓库配置文件和备份:</strong></span></p>
<pre class="highlighter-prismjs prismjs-lines-highlighted language-bash" tabindex="0"><code># ls
bakCentOS-Base.repoepel.repo
#</code></pre>
<p><strong>验证仓库配置</strong>:运行&nbsp;<code class=" inline">yum repolist all</code>或&nbsp; <code class=" inline">yum repolist</code> 来查看所有可用的仓库,并确认新仓库是否已被正确添加:</p>
<pre class="highlighter-prismjs prismjs-lines-highlighted language-bash" tabindex="0"><code># yum repolist all
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
* base: mirrors.aliyun.com
* centosplus: mirrors.aliyun.com
* extras: mirrors.aliyun.com
* updates: mirrors.aliyun.com
repo id               repo name                                                 status
base/7/x86_64         CentOS-7 - Base - mirrors.aliyun.com                      enabled: 10,072
centosplus/7/x86_64   CentOS-7 - Plus - mirrors.aliyun.com                      disabled
contrib/7/x86_64      CentOS-7 - Contrib - mirrors.aliyun.com                   disabled
epel/x86_64             Extra Packages for Enterprise Linux 7 - x86_64            enabled: 13,787
epel-debuginfo/x86_64   Extra Packages for Enterprise Linux 7 - x86_64 - Debug    disabled
epel-source             Extra Packages for Enterprise Linux 7 - x86_64 - Source   disabled
extras/7/x86_64         CentOS-7 - Extras - mirrors.aliyun.com                  enabled:    519
updates/7/x86_64      CentOS-7 - Updates - mirrors.aliyun.com                   enabled:5,742
repolist: 33,312
#</code></pre>
<p><strong>CentOS-Base.repo配置文件:</strong>包含对、、、、源的配置,可通过修改<code>enabled=0</code>(禁用)或<code>enabled=1</code>(启用)来控制开关</p>
<p><strong>epel.repo配置文件:</strong>包含对、、源的配置,可通过修改<code>enabled=0</code>(禁用)或<code>enabled=1</code>(启用)来控制开关</p>
<p>以下是对每个仓库的简要解读:</p>
<ol>
<li>
<p><strong>CentOS-7 - Base</strong>:</p>
<ul>
<li><code>CentOS-7 - Base</code> 仓库包含了 CentOS 7 发行版的核心软件包,包括系统的基础组件和服务。这些软件包提供了构建 CentOS 7 系统所需的基本功能和工具,例如核心工具、系统服务、库等。<code>Base</code> 仓库是构建整个 CentOS 系统的基础。</li>
</ul>
</li>
<li>
<p><strong>CentOS-7 - Plus</strong>:</p>
<ul>
<li><code>CentOS-7 - Plus</code> 仓库包含了一些额外的、不是核心但仍然有用的软件包。这些软件包可能提供一些附加的工具、应用程序或服务,可以扩展 CentOS 7 系统的功能。<code>Plus</code> 仓库包含了一些不属于 CentOS 发行版核心的软件包,但是它们可以为用户提供额外的功能和选项。<strong><span style="color: rgba(224, 62, 45, 1)">(默认禁用)</span></strong></li>
</ul>
</li>
<li>
<p><strong>CentOS-7 - Contrib</strong>:</p>
<ul>
<li><code>CentOS-7 - Contrib</code> 仓库通常包含了由社区成员提供的、不属于官方发布的软件包。这些软件包可能是社区维护的、测试中的或者不太常见的软件包,不符合 CentOS 发行版的严格标准,因此被放在 <code>Contrib</code> 仓库中。这些软件包可能包含各种类型的软件,包括工具、应用程序、驱动程序等。它们不属于 CentOS 官方软件仓库,但是它们可能对用户来说是有用的。<strong><span style="color: rgba(224, 62, 45, 1)">(默认禁用)</span></strong></li>
</ul>
</li>
<li>
<p><strong>Epel</strong>:</p>
<ul>
<li>
<p><strong>Extra Packages for Enterprise Linux 7 - x86_64</strong>:</p>
<ul>
<li>这个仓库包含了针对 CentOS 7 x86_64 架构的额外软件包。这些软件包通常提供了各种类型的工具、应用程序、库和服务,以扩展 CentOS 系统的功能。</li>
</ul>
</li>
<li>
<p><strong>Extra Packages for Enterprise Linux 7 - x86_64 - Debug</strong>:</p>
<ul>
<li>这个仓库提供了针对 CentOS 7 x86_64 架构的额外软件包的调试信息。调试信息对于开发和调试软件非常有用,它们包含了关于程序运行时的详细信息,帮助开发者诊断和解决问题。<strong><span style="color: rgba(224, 62, 45, 1)">(默认禁用)</span></strong></li>
</ul>
</li>
<li>
<p><strong>Extra Packages for Enterprise Linux 7 - x86_64 - Source</strong>:</p>
<ul>
<li>这个仓库提供了针对 CentOS 7 x86_64 架构的额外软件包的源代码。源代码允许用户查看和修改软件包的代码,以满足特定的需求或者定制软件包。<strong><span style="color: rgba(224, 62, 45, 1)">(默认禁用)</span></strong></li>
</ul>
</li>
</ul>
</li>
<li>
<p><strong>CentOS-7 - Extras</strong>:</p>
<ul>
<li><code>CentOS-7 - Extras</code> 仓库包含了一些额外的、不是核心但仍然有用的软件包。这些软件包通常提供一些附加的工具、应用程序或服务,可以扩展 CentOS 7 系统的功能。<code>Extras</code> 仓库中的软件包通常不是系统的核心组件,但是它们可以为用户提供额外的功能和选项。</li>
</ul>
</li>
<li>
<p><strong>CentOS-7 - Updates</strong>:</p>
<ul>
<li><code>CentOS-7 - Updates</code> 仓库包含了对已发布软件包的更新版本。这些更新通常是为了修复漏洞、增强功能或者修复系统中的 bug。通过定期更新这些软件包,可以保持系统的安全性和稳定性。</li>
</ul>
</li>
</ol>
<pre class="highlighter-prismjs language-bash prismjs-lines-highlighted" tabindex="0"><code># 清除yum缓存
yum clean all
# 重新生成yum缓存
yum makecache
# 检查可用更新
yum check-update
# 执行全部更新
yum -y update</code></pre>
<p><strong>清除&nbsp;<code class=" inline">yum</code>&nbsp;缓存</strong>:通常来说,执行 <code>yum clean all</code> 命令可以清理 Yum 的缓存,这样可以释放磁盘空间并确保系统在更新过程中不会受到旧缓存的影响。因此,在更新系统之前执行 <code>yum clean all</code> 是一个良好的做法。</p>
<p><strong>重新生成<code class=" inline">yum</code> 缓存:</strong><code>yum makecache</code> 命令用于生成 yum 软件包管理器的缓存。在执行 <code>yum makecache</code> 命令后,yum 将会扫描系统中的软件仓库并下载仓库中的软件包列表和元数据,然后将这些信息保存在本地缓存中。这样做可以加快后续执行 yum 命令时的速度,因为 yum 不需要再次从远程仓库下载软件包列表和元数据,而是直接使用本地的缓存数据。</p>
<p>通常情况下,你不需要手动执行 <code>yum makecache</code> 命令,因为 yum 在执行命令时会自动检查并更新缓存。然而,有时手动执行 <code>yum makecache</code> 可以确保你的软件包缓存是最新的,尤其是当你手动添加了新的仓库源或者想要强制刷新缓存时。</p>
<p><strong>检查可用更新</strong>:<code>yum check-update</code> 用于检查可用的更新,但并不执行实际的更新操作。当你运行 <code>yum check-update</code> 时,它会检查所有可用的软件包,并显示哪些软件包有更新版本可用。这个命令可以帮助你了解系统中有哪些软件包可以更新,而不会实际地进行更新操作。</p>
<p><strong>更新软件包</strong>:执行 <code>yum update</code> 命令,更新系统中已安装的软件包到最新可用版本。这个命令会自动下载并安装软件包的更新版本。</p>
<pre class="highlighter-prismjs prismjs-lines-highlighted language-bash" tabindex="0"><code># 更新内核
yum update kernel</code></pre>
<p><strong>更新内核</strong>: 如果更新包括了内核更新,你可以执行 <code>yum update kernel</code> 命令,单独更新系统的内核。这个步骤可能需要重启系统才能生效。</p>
<p>执行了 <code>yum update</code> 后,系统中所有已安装的软件包都会被更新到最新可用版本,包括内核软件包。因此,通常情况下在执行了 <code>yum update</code> 后,系统的内核软件包也会被更新到最新版本。</p>
<p>如果你特别关注内核更新,或者想要单独更新系统的内核软件包,你可以执行 <code>yum update kernel</code> 命令。这样可以确保系统的内核始终是最新的版本,即使在执行 <code>yum update</code> 时可能没有显式地更新内核软件包。</p>
<hr>
<p><strong>**关于 <span style="color: rgba(224, 62, 45, 1)">yum update </span>和 <span style="color: rgba(224, 62, 45, 1)">yum upgrade </span>的区别**</strong></p>
<pre class="highlighter-prismjs language-bash prismjs-lines-highlighted" tabindex="0"><code># 版本更新
yum -y update
# 版本替换并更新(有风险)
yum -y upgrade</code></pre>
<p class=""><code class=" inline">yum update</code>和<code class=" inline">yum upgrade</code>在CentOS 7中的主要区别在于它们处理已安装软件包的方式,以及它们是否更新系统内核。</p>
<ol>
<li>
<p class=""><strong>处理已安装软件包的方式</strong>:</p>
<ul style="list-style-type: square">
<li><code class=" inline">sudo yum update</code>:这个命令会更新所有已安装的软件包到其最新版本,同时保留旧版本的软件包。这意味着,如果有软件包依赖于旧版本的库或其他组件,这些依赖关系不会被破坏。默认情况下,<code class=" inline">yum update</code>会根据<code class=" inline">/etc/yum.conf</code>配置文件中<code class=" inline">obsoletes</code>选项的设置来决定是否删除旧版本的软件包。如果<code class=" inline">obsoletes</code>设置为0(默认设置),则不会删除旧版本。</li>
<li><code class=" inline">sudo yum upgrade</code>:这个命令也会更新所有已安装的软件包到其最新版本,<strong><span style="color: rgba(224, 62, 45, 1)">但它会删除旧版本的软件</span></strong>包。这意味着,<strong><span style="color: rgba(224, 62, 45, 1)">如果有软件包依赖于旧版本的库或其他组件,这些依赖关系可能会被破坏,导致某些软件功能出现问题</span></strong>。</li>
</ul>
</li>
<li>
<p class=""><strong>更新系统内核</strong>:</p>
<ul style="list-style-type: square">
<li>对于系统内核的更新,<code class=" inline">sudo yum update</code>和<code class=" inline">sudo yum upgrade</code>的行为取决于<code class=" inline">/etc/yum.conf</code>配置文件中关于内核更新的设置。通常,在默认配置下,这两个命令都会更新系统内核到最新版本。</li>
</ul>
</li>
</ol>
<p class="">在实际使用中,如果您不确定某个软件包是否依赖于特定版本的库或其他组件,或者您担心更新可能会破坏系统的稳定性,那么使用<code class=" inline">sudo yum update</code>可能更为安全。这是因为它会保留旧版本的软件包,从而减少了因依赖关系问题导致系统崩溃的风险。然而,在正式的生产环境中,建议先在测试环境中进行更新操作,以确保更新不会导致任何不期望的问题。</p>
<hr>
<p>&nbsp;</p>
<p>以下是Epel6的源&nbsp;</p>
<pre class="highlighter-prismjs prismjs-lines-highlighted language-bash" tabindex="0"><code>wget https://mirrors.aliyun.com/repo/epel.repo
wget https://mirrors.aliyun.com/repo/epel-testing.repo</code></pre>
<p>&nbsp;</p><br><br>
来源:https://www.cnblogs.com/Magiclala/p/18019063
頁: [1]
查看完整版本: CentOS 7 系统更新和内核升级