前言
在配置yum源之前,我们先了解一下本地源和网络源的区别: 本地源: 利用挂载系统系统镜像包进行配置,因受限与镜像包,能获取的包相对较少。 网络源:在能连接互联网的服务器上进行配置,配置简单,可选择性强,能获取的包也更多。 了解了我们接下就进行实操
一、本地yum源
1、创建挂载点目录
[root@lk ~]
[root@lk ~]
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/mapper/centos-root 17811456 1386708 16424748 8% /
2、挂载CD(光盘)
[root@lk ~]
mount: /dev/sr0 is write-protected, mounting read-only
3、查看挂载记录
[root@lk ~]
Filesystem Size Used Avail Use% Mounted on
/dev/sr0 4.4G 4.4G 0 100% /mnt/cdrom
4、更改配置文件(查看/etc/yum.repos.d/中的文件)
[root@lk ~]
total 40
-rw-r--r--. 1 root root 1664 Oct 23 2020 CentOS-Base.repo
-rw-r--r--. 1 root root 1309 Oct 23 2020 CentOS-CR.repo
-rw-r--r--. 1 root root 649 Oct 23 2020 CentOS-Debuginfo.repo
-rw-r--r--. 1 root root 314 Oct 23 2020 CentOS-fasttrack.repo
-rw-r--r--. 1 root root 630 Oct 23 2020 CentOS-Media.repo
-rw-r--r--. 1 root root 1331 Oct 23 2020 CentOS-Sources.repo
-rw-r--r--. 1 root root 8515 Oct 23 2020 CentOS-Vault.repo
-rw-r--r--. 1 root root 616 Oct 23 2020 CentOS-x86_64-kernel.repo
5、绕过网络,使用本地安装
[root@lk ~]
[root@lk yum.repos.d]
total 40
-rw-r--r--. 1 root root 1664 Oct 23 2020 CentOS-Base.repo
-rw-r--r--. 1 root root 1309 Oct 23 2020 CentOS-CR.repo
-rw-r--r--. 1 root root 649 Oct 23 2020 CentOS-Debuginfo.repo
-rw-r--r--. 1 root root 314 Oct 23 2020 CentOS-fasttrack.repo
-rw-r--r--. 1 root root 630 Oct 23 2020 CentOS-Media.repo
-rw-r--r--. 1 root root 1331 Oct 23 2020 CentOS-Sources.repo
-rw-r--r--. 1 root root 8515 Oct 23 2020 CentOS-Vault.repo
-rw-r--r--. 1 root root 616 Oct 23 2020 CentOS-x86_64-kernel.repo
[root@lk yum.repos.d]
[root@lk yum.repos.d]
total 40
drwxr-xr-x. 2 root root 6 Sep 20 07:15 bak
-rw-r--r--. 1 root root 1664 Oct 23 2020 CentOS-Base.repo
-rw-r--r--. 1 root root 1309 Oct 23 2020 CentOS-CR.repo
-rw-r--r--. 1 root root 649 Oct 23 2020 CentOS-Debuginfo.repo
-rw-r--r--. 1 root root 314 Oct 23 2020 CentOS-fasttrack.repo
-rw-r--r--. 1 root root 630 Oct 23 2020 CentOS-Media.repo
-rw-r--r--. 1 root root 1331 Oct 23 2020 CentOS-Sources.repo
-rw-r--r--. 1 root root 8515 Oct 23 2020 CentOS-Vault.repo
-rw-r--r--. 1 root root 616 Oct 23 2020 CentOS-x86_64-kernel.repo
[root@lk yum.repos.d]
[root@lk yum.repos.d]
total 0
drwxr-xr-x. 2 root root 220 Sep 20 07:15 bak
6、编辑local.repo文件
[root@lk yum.repos.d]
[root@lk yum.repos.d]
[centos]
name=centos
baseurl=file:///mnt/cdrom
gpgcheck=0
enabled=1
7、清除yum缓存 ,测试yum源
[root@lk yum.repos.d]
Loaded plugins: fastestmirror
Cleaning repos: centos
Cleaning up list of fastest mirrors
Other repos take up 19 M of disk space (use --verbose for details)
Loaded plugins: fastestmirror
Determining fastest mirrors
centos | 3.6 kB 00:00:00
(1/4): centos/group_gz | 153 kB 00:00:00
(2/4): centos/filelists_db | 3.3 MB 00:00:00
(3/4): centos/primary_db | 3.3 MB 00:00:00
(4/4): centos/other_db | 1.3 MB 00:00:00
Metadata Cache Created
[root@lk yum.repos.d]
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
repo id repo name status
centos centos 4,070
repolist: 4,070
出软件包数量,表示已成功配置了
二、阿里网络源yum源
1、查看目录下文件
[root@localhost ~]
[root@localhost yum.repos.d]
total 32
-rw-r--r--. 1 root root 1664 Sep 5 2019 CentOS-Base.repo
-rw-r--r--. 1 root root 1309 Sep 5 2019 CentOS-CR.repo
-rw-r--r--. 1 root root 649 Sep 5 2019 CentOS-Debuginfo.repo
-rw-r--r--. 1 root root 314 Sep 5 2019 CentOS-fasttrack.repo
-rw-r--r--. 1 root root 630 Sep 5 2019 CentOS-Media.repo
-rw-r--r--. 1 root root 1331 Sep 5 2019 CentOS-Sources.repo
-rw-r--r--. 1 root root 6639 Sep 5 2019 CentOS-Vault.repo
2、把/etc/yum.repos.d/下的文件备份到新建目录下
[root@localhost yum.repos.d]
[root@localhost yum.repos.d]
[root@localhost yum.repos.d]
total 0
drwxr-xr-x. 2 root root 187 Sep 20 09:50 bak
3、下载阿里centos7的网络源
[root@localhost yum.repos.d]
[root@localhost yum.repos.d]
[root@localhost yum.repos.d]
total 4
drwxr-xr-x. 2 root root 187 Sep 20 09:50 bak
-rw-r--r--. 1 root root 2523 Aug 4 03:04 CentOS-Base.repo
4、运行yum clean all 清除缓存,运行 yum makecache 生成新的缓存
[root@localhost yum.repos.d]
Loaded plugins: fastestmirror
Existing lock /var/run/yum.pid: another copy is running as pid 18051.
Another app is currently holding the yum lock; waiting for it to exit...
The other application is: yum
Memory : 23 M RSS (344 MB VSZ)
Started: Tue Sep 20 10:05:42 2022 - 00:01 ago
State : Running, pid: 18051
Determining fastest mirrors
* base: mirrors.aliyun.com
* extras: mirrors.aliyun.com
* updates: mirrors.aliyun.com
base | 3.6 kB 00:00
extras | 2.9 kB 00:00
updates | 2.9 kB 00:00
(1/10): base/7/x86_64/group_gz | 153 kB 00:00
(2/10): base/7/x86_64/primary_db | 6.1 MB 00:04
extras/7/x86_64/other_db FAILED
http://mirrors.cloud.aliyuncs.com/centos/7/extras/x86_64/repodata/5ed35184b6160999eff67a1ce6f909e9c507535aafeea94489e2bc7a23bc9fd5-other.sqlite.bz2: [Errno 14] curl
Trying other mirror.
(3/10): base/7/x86_64/filelists_db | 7.2 MB 00:05
(4/10): extras/7/x86_64/filelists_db | 277 kB 00:00
(5/10): extras/7/x86_64/primary_db | 250 kB 00:00
(6/10): base/7/x86_64/other_db | 2.6 MB 00:02
(7/10): updates/7/x86_64/filelists_db | 9.4 MB 00:08
(8/10): extras/7/x86_64/other_db | 149 kB 00:00
(9/10): updates/7/x86_64/other_db | 1.1 MB 00:02
(10/10): updates/7/x86_64/primary_db | 17 MB 00:12
Metadata Cache Created
5、查看所有的仓库
[root@localhost yum.repos.d]
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: 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
extras/7/x86_64 CentOS-7 - Extras - mirrors.aliyun.com enabled: 516
updates/7/x86_64 CentOS-7 - Updates - mirrors.aliyun.com enabled: 4,160
repolist: 14,748
yum源的本地源和网络源配置完毕。
如果对你有所帮助,还望赏个关注鸭 ! ! ! 😜 (⊙o⊙),我们下期再见!!!
|