不知谓何 發表於 2023-8-28 16:06:00

linux一键换源脚本,centos,debian,ubuntu通用脚本

<h1 id="国内使用">国内使用</h1>
<pre><code class="language-python">bash &lt;(curl -sSL https://linuxmirrors.cn/main.sh)

# github地址
bash &lt;(curl -sSL https://raw.githubusercontent.com/SuperManito/LinuxMirrors/main/ChangeMirrors.sh)
# gitee地址
bash &lt;(curl -sSL https://gitee.com/SuperManito/LinuxMirrors/raw/main/ChangeMirrors.sh)

</code></pre>
<h1 id="海外使用">海外使用</h1>
<pre><code class="language-python">bash &lt;(curl -sSL https://linuxmirrors.cn/main.sh) --abroad

# github地址
bash &lt;(curl -sSL https://raw.githubusercontent.com/SuperManito/LinuxMirrors/main/ChangeMirrors.sh) --abroad
# gitee地址
bash &lt;(curl -sSL https://gitee.com/SuperManito/LinuxMirrors/raw/main/ChangeMirrors.sh) --abroad

</code></pre>
<h1 id="命令选项">命令选项</h1>
<table>
<thead>
<tr>
<th>名称</th>
<th>含义</th>
<th>选项值</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>--abroad</code></td>
<td>使用海外软件源</td>
<td>无</td>
</tr>
<tr>
<td><code>--edu</code></td>
<td>使用中国大陆教育网软件源</td>
<td>无</td>
</tr>
<tr>
<td><code>--source</code></td>
<td>指定软件源地址(域名或IP)</td>
<td>地址</td>
</tr>
<tr>
<td><code>--source-security</code></td>
<td>指定 Debian 的 security 软件源地址(域名或IP)</td>
<td>地址</td>
</tr>
<tr>
<td><code>--source-vault</code></td>
<td>指定 CentOS/AlmaLinux 的 vault 软件源地址(域名或IP)</td>
<td>地址</td>
</tr>
<tr>
<td><code>--branch</code></td>
<td>指定软件源分支(路径)</td>
<td>分支名</td>
</tr>
<tr>
<td><code>--branch-security</code></td>
<td>指定 Debian 的 security 软件源分支(路径)</td>
<td>分支名</td>
</tr>
<tr>
<td><code>--branch-vault</code></td>
<td>指定 CentOS/AlmaLinux 的 vault 软件源分支(路径)</td>
<td>分支名</td>
</tr>
<tr>
<td><code>--codename</code></td>
<td>指定 Debian 系操作系统的版本名称</td>
<td>版本名</td>
</tr>
<tr>
<td><code>--web-protocol</code></td>
<td>指定 WEB 协议</td>
<td><code>http</code> 或 <code>https</code></td>
</tr>
<tr>
<td><code>--intranet</code></td>
<td>优先使用内网地址</td>
<td><code>true</code> 或 <code>false</code></td>
</tr>
<tr>
<td><code>--install-epel</code></td>
<td>安装 EPEL 附加软件包</td>
<td><code>true</code> 或 <code>false</code></td>
</tr>
<tr>
<td><code>--only-epel</code></td>
<td>仅更换 EPEL 软件源模式</td>
<td>无</td>
</tr>
<tr>
<td><code>--close-firewall</code></td>
<td>关闭防火墙</td>
<td><code>true</code> 或 <code>false</code></td>
</tr>
<tr>
<td><code>--backup</code></td>
<td>备份原有软件源</td>
<td><code>true</code> 或 <code>false</code></td>
</tr>
<tr>
<td><code>--ignore-backup-tips</code></td>
<td>忽略覆盖备份提示(即不覆盖备份)</td>
<td>无</td>
</tr>
<tr>
<td><code>--updata-software</code></td>
<td>更新软件包</td>
<td><code>true</code> 或 <code>false</code></td>
</tr>
<tr>
<td><code>--clean-cache</code></td>
<td>清理下载缓存</td>
<td><code>true</code> 或 <code>false</code></td>
</tr>
<tr>
<td><code>--print-diff</code></td>
<td>打印源文件修改前后差异</td>
<td><code>true</code> 或 <code>false</code></td>
</tr>
<tr>
<td><code>--help</code></td>
<td>查看帮助菜单</td>
<td>无</td>
</tr>
</tbody>
</table>
<blockquote>
<p>软件源格式 <code>&lt;指定WEB协议&gt;://&lt;软件源地址&gt;/&lt;软件源分支&gt;</code></p>
</blockquote>
<h2 id="示例">示例#</h2>
<h3 id="指定软件源地址">指定软件源地址#</h3>
<p>若不想通过交互选择默认提供的软件源,你可以使用该命令选项指定软件源地址</p>
<pre><code>bash &lt;(curl -sSL https://linuxmirrors.cn/main.sh) \
    --source mirror.example.com
</code></pre>
<h3 id="指定软件源分支">指定软件源分支#</h3>
<p>使用场景:目标软件源有对应系统镜像但是不符合本脚本关于软件源分支设置的默认规则</p>
<p>本脚本为了适配大的环境不会针对某一镜像站独特的镜像分支名称而单独定制,最开始是为了更换国内软件源而设计适配的,默认使用的分支名称如下</p>
<table>
<thead>
<tr>
<th><img src="https://linuxmirrors.cn/assets/images/icon/debian.svg" width="40" height="40"> Debian</th>
<th>debian</th>
</tr>
</thead>
<tbody>
<tr>
<td><img src="https://linuxmirrors.cn/assets/images/icon/ubuntu.svg" width="40" height="40"> Ubuntu</td>
<td>ubuntu/ubuntu-ports</td>
</tr>
<tr>
<td><img src="https://linuxmirrors.cn/assets/images/icon/kali-linux.svg" width="40" height="40"> Kali Linux</td>
<td>kali</td>
</tr>
<tr>
<td><img src="https://linuxmirrors.cn/assets/images/icon/redhat.svg" width="40" height="40"> Red Hat Enterprise Linux</td>
<td>centos/rocky</td>
</tr>
<tr>
<td><img src="https://linuxmirrors.cn/assets/images/icon/fedora.ico" alt="img" loading="lazy"> Fedora</td>
<td>fedora</td>
</tr>
<tr>
<td><img src="https://linuxmirrors.cn/assets/images/icon/centos.svg" width="40" height="40"> CentOS</td>
<td>centos/centos-stream/centos-altarch/centos-vault</td>
</tr>
<tr>
<td><img src="https://linuxmirrors.cn/assets/images/icon/rocky-linux.svg" width="40" height="40"> Rocky Linux</td>
<td>rocky</td>
</tr>
<tr>
<td><img src="https://linuxmirrors.cn/assets/images/icon/almalinux.svg" width="40" height="40"> AlmaLinux</td>
<td>almalinux/almalinux-vault</td>
</tr>
<tr>
<td><img src="https://linuxmirrors.cn/assets/images/icon/opencloudos.png" alt="img" loading="lazy"> OpenCloudOS</td>
<td>opencloudos</td>
</tr>
<tr>
<td><img src="https://linuxmirrors.cn/assets/images/icon/openeuler.ico" alt="img" loading="lazy"> openEuler</td>
<td>openeuler</td>
</tr>
<tr>
<td><img src="https://linuxmirrors.cn/assets/images/icon/opensuse.svg" width="40" height="40"> openSUSE</td>
<td>opensuse</td>
</tr>
<tr>
<td><img src="https://linuxmirrors.cn/assets/images/icon/arch-linux.ico" alt="img" loading="lazy"> Arch Linux</td>
<td>archlinux/archlinuxarm</td>
</tr>
</tbody>
</table>
<p>请看下面的例子</p>
<p><strong>使用阿里云的 Rocky Linux 软件源</strong></p>
<pre><code>bash &lt;(curl -sSL https://linuxmirrors.cn/main.sh) \
--source mirrors.aliyun.com \
--branch rockylinux
</code></pre>
<p>阿里云镜像站的 Rocky Linux 镜像分支名称为 <code>rockylinux</code>,不符合默认规则,但是可以通过命令选项绕过脚本默认规则来实现。</p>
<p>什么是默认规则?参考这几个例子: <code>Debian GNU/Linux =&gt; debian</code>、<code>Rocky Linux =&gt; rocky</code>、<code>AlmaLinux =&gt; almalinux</code></p>
<h3 id="单独更换-epel-源">单独更换 EPEL 源#</h3>
<p>有些时候你会发现想使用的镜像站没有 epel 镜像仓库,那么你可以在第一次运行脚本时不安装或不更换 epel 源然后再单独执行下面的命令</p>
<pre><code>bash &lt;(curl -sSL https://linuxmirrors.cn/main.sh) --only-epel
</code></pre>
<h3 id="自定义-debian-security-源">自定义 Debian Security 源#</h3>
<p>如果你想尽可能提高服务器的安全性则建议使用官方源,因为镜像同步存在延迟</p>
<pre><code>bash &lt;(curl -sSL https://linuxmirrors.cn/main.sh) \
--source-security security.debian.org \
--branch-security debian-security
</code></pre>
<h3 id="指定-debian-系操作系统的版本名称">指定 Debian 系操作系统的版本名称#</h3>
<p>你可以自定义该版本名称,大多数情况下用于升级系统版本,请看下面的例子</p>
<p><strong>升级 Debian 至最新 12 版本 Bookworm</strong></p>
<pre><code>bash &lt;(curl -sSL https://linuxmirrors.cn/main.sh) \
--codename bookworm
</code></pre>
<p>更换软件源后还需要执行系统更新命令才能实现更新操作,并且建议在更新完成并重启系统后重新执行本换源脚本,因为仅更换软件源配置中的系统版本名称可能会在后期使用时产生一些兼容性问题</p>
<h2 id="无人值守">无人值守#</h2>
<p>不通过交互完成换源操作,需要使用大量命令选项来实现,建议熟悉后再使用</p>
<p><strong>参考命令</strong></p>
<pre><code>bash &lt;(curl -sSL https://linuxmirrors.cn/main.sh) \
--source mirror.example.com \
--web-protocol http \
--intranet false \
--install-epel true \
--close-firewall true \
--backup true \
--updata-software false \
--clean-cache false \
--ignore-backup-tips
</code></pre>
<h1 id="记录自httpslinuxmirrorscnuse">记录自:https://linuxmirrors.cn/use/</h1><br><br>
来源:https://www.cnblogs.com/clever-cat/p/17662575.html
頁: [1]
查看完整版本: linux一键换源脚本,centos,debian,ubuntu通用脚本