centos yum源本地配置

在CentOS系统中,yum源是用于安装、更新和删除软件包的工具,配置本地yum源、阿里云yum源和163yuan源可以让我们更方便地获取所需的软件包,我们还需要配置yum源的优先级,以便在多个源之间进行选择,本文将详细介绍如何配置这些yum源以及设置优先级。

配置本地yum源

1、我们需要下载所需的软件包,可以通过访问官方网站或者使用wget命令下载,下载nginx软件包:

centos yum源本地配置

wget http://nginx.org/download/nginx-1.20.1.tar.gz

2、解压下载的软件包:

tar -zxvf nginx-1.20.1.tar.gz

3、将解压后的软件包移动到/usr/local/src目录下:

mv nginx-1.20.1 /usr/local/src/

4、创建一个新的RPM包:

cd /usr/local/src/nginx-1.20.1
rpmbuild -ba nginx.spec

5、将生成的RPM包复制到/var/www/html目录下:

centos yum源本地配置

cp /usr/local/src/nginx-1.20.1/root/usr/local/nginx-1.20.1-1.el7.ngx.x86_64.rpm /var/www/html/

配置阿里云yum源

1、下载阿里云的CentOS镜像文件:

wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo

2、清除缓存并生成新的缓存:

yum clean all && yum makecache

配置163yuan源

1、下载163yuan的CentOS镜像文件:

wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.163.com/centos/7/os/x86_64/Packages/centos-7-os-x86_64-Packages.repo

2、清除缓存并生成新的缓存:

centos yum源本地配置

yum clean all && yum makecache

配置yum源的优先级

在CentOS系统中,我们可以使用yum配置文件来设置yum源的优先级,默认情况下,系统会优先使用官方的CentOS源,为了设置其他源的优先级,我们需要编辑yum配置文件,可以使用文本编辑器打开/etc/yum.repos.d/CentOS-Base.repo文件,然后按照以下顺序添加其他源:

[base]  官方源,优先级最低,最后加载
name=CentOS-$releasever Base mirrors.centos.org
baseurl=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os&infra=$infra
gpgcheck=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
阿里云源,优先级次之,位于官方源之后加载
[base] name=CentOS-$releasever Base mirrors.aliyuncs.com baseurl=http://mirrors.aliyuncs.com/centos/$releasever/os/$basearch/ gpgcheck=1 gpgkey=http://mirrors.aliyuncs.com/centos/RPM-GPG-KEY-CentOS-7 gpgcheck=1 gpgkey=http://mirrors.aliyuncs.com/centos/RPM-GPG-KEY-CentOS-7  163yuan源,优先级最高,位于阿里云源之前加载 [base] name=CentOS-$releasever Base mirrors.163yun.com baseurl=http://mirrors.163yun.com/centos/$releasever/os/$basearch/ gpgcheck=1 gpgkey=http://mirrors.163yun.com/centos/RPM-GPG-KEY-CentOS-7 gpgcheck=1 gpgkey=http://mirrors.163yun.com/centos/RPM-GPG-KEY-CentOS-7 enabled=1 autorefresh=1 priority=99  自定义源,优先级最低,位于所有其他源之后加载 [custom] name=Custom CentOS $releasever $basearch baseurl=http://mycustommirrorserver:port/path enable=0 skip_if_unavailable=True priority=-99  保存并退出文本编辑器

相关问题与解答

问题1:为什么需要配置多个yum源?

答:配置多个yum源的原因有以下几点:一是提高软件包的下载速度,因为不同的yum源可能分布在不同的地理位置;二是增加软件包的可用性,如果某个yum源不可用,我们还可以从其他源获取所需的软件包;三是方便管理和维护,我们可以针对不同的需求选择合适的yum源。

原创文章,作者:K-seo,如若转载,请注明出处:https://www.kdun.cn/ask/325175.html

(0)
K-seoK-seoSEO优化员
上一篇 2024年2月19日 21:45
下一篇 2024年2月19日 21:52

相关推荐

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注

免备案 高防CDN 无视CC/DDOS攻击 限时秒杀,10元即可体验  (专业解决各类攻击)>>点击进入