centos 7--配置yum仓库

Centos 7–配置yum仓库

一、配置本地光盘yum源

1、默认系统安装源的备份,一定要做,不然新建任何yum源都会报错

mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.bak

2、创建挂载目录

[root@localhost ~]# mkdir /media/cdrom

3、编辑永久挂载配置文件

root@localhost ~]# vim /etc/fstab 
#
/# /etc/fstab
/# Created by anaconda on Wed Jul 17 05:42:08 2019
#
/# Accessible filesystems, by reference, are maintained under '/dev/disk'
/# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#
/dev/mapper/centos-root /                       xfs     defaults        0 0
UUID=f80b644c-4266-4069-80a1-6329833fb132 /boot                   xfs     defaults        0 0
/dev/mapper/centos-swap swap                    swap    defaults        0 0
/dev/cdrom /media/cdrom iso9660 defaults 0 0

4、挂载目录

[root@localhost ~]# mount -a

没有报错就ok,报错请检查配置文件。如未检查开机不会正常进入系统,会要求你输入密码后更改fstab文件。

5、编辑yum源配置文件

[root@localhost cdrom]# vim /etc/yum.repos.d/xixi.repo 
[xixi]
name=xixi
baseurl=file:///media/cdrom
enabled=1
gpgcheck=0

6 、
分别执行命令 :
yum clean all

[root@localhost cdrom]# yum clean all
Loaded plugins: fastestmirror, langpacks
Cleaning repos: xixi
Cleaning up list of fastest mirrors

yum makecache

[root@localhost cdrom]# yum makecache 
Loaded plugins: fastestmirror, langpacks
Determining fastest mirrors
xixi                                                                                                                                                                 | 3.6 kB  00:00:00     
(1/4): xixi/group_gz                                                                                                                                                 | 166 kB  00:00:00     
(2/4): xixi/primary_db                                                                                                                                               | 3.1 MB  00:00:00     
(3/4): xixi/filelists_db                                                                                                                                             | 3.2 MB  00:00:00     
(4/4): xixi/other_db                                                                                                                                                 | 1.3 MB  00:00:00     
Metadata Cache Created

8、看到以上步骤基本已经成功了,如果需要测试可以随便安装一个程序检测是否成功

[root@localhost cdrom]# yum install -y httpd
Loaded plugins: fastestmirror, langpacks
Determining fastest mirrors
xixi                                                                                                                                                                 | 3.6 kB  00:00:00     
(1/2): xixi/group_gz                                                                                                                                                 | 166 kB  00:00:00     
(2/2): xixi/primary_db                                                                                                                                               | 3.1 MB  00:00:00     
Resolving Dependencies
--> Running transaction check
---> Package httpd.x86_64 0:2.4.6-88.el7.centos will be installed
--> Processing Dependency: httpd-tools = 2.4.6-88.el7.centos for package: httpd-2.4.6-88.el7.centos.x86_64
--> Processing Dependency: /etc/mime.types for package: httpd-2.4.6-88.el7.centos.x86_64
--> Processing Dependency: libaprutil-1.so.0()(64bit) for package: httpd-2.4.6-88.el7.centos.x86_64
--> Processing Dependency: libapr-1.so.0()(64bit) for package: httpd-2.4.6-88.el7.centos.x86_64
--> Running transaction check
---> Package apr.x86_64 0:1.4.8-3.el7_4.1 will be installed
---> Package apr-util.x86_64 0:1.5.2-6.el7 will be installed
---> Package httpd-tools.x86_64 0:2.4.6-88.el7.centos will be installed
---> Package mailcap.noarch 0:2.1.41-2.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

二、配置网络yum源

yum源地址详细列表请看:
https://blog.csdn.net/thlchina/article/details/97136893

1、首先保证你的网络是可以上网的,不管是虚拟机还是物理机。

[root@clinet ~]# ping www.baidu.com
PING www.baidu.com (180.97.33.108) 56(84) bytes of data.
64 bytes from 180.97.33.108 (180.97.33.108): icmp_seq=1 ttl=128 time=34.9 ms
64 bytes from 180.97.33.108 (180.97.33.108): icmp_seq=2 ttl=128 time=36.1 ms
64 bytes from 180.97.33.108 (180.97.33.108): icmp_seq=3 ttl=128 time=45.1 ms
64 bytes from 180.97.33.108 (180.97.33.108): icmp_seq=4 ttl=128 time=35.3 ms
64 bytes from 180.97.33.108 (180.97.33.108): icmp_seq=5 ttl=128 time=35.9 ms
64 bytes from 180.97.33.108 (180.97.33.108): icmp_seq=6 ttl=128 time=34.9 ms
64 bytes from 180.97.33.108 (180.97.33.108): icmp_seq=7 ttl=128 time=36.7 ms
^C
--- www.baidu.com ping statistics ---
7 packets transmitted, 7 received, 0% packet loss, time 15056ms
rtt min/avg/max/mdev = 34.951/37.035/45.152/3.369 ms

2、默认系统安装源的备份(或删除/etc/yum.repos.d/CentOS-Base.repo)一定要做,不然新建任何yum源makecache时会报错

mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.bak

3、下载yum源配置文件,以下为阿里云镜像站为例,每个镜像站相对应的系统都有帮助说明,不会的去看看。

centos 7--配置yum仓库_第1张图片4、执行帮助文档的下载说明wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo

[root@clinet ~]# wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
--2019-07-25 14:48:51--  http://mirrors.aliyun.com/repo/Centos-7.repo
Resolving mirrors.aliyun.com (mirrors.aliyun.com)... 118.112.15.8, 119.147.158.242, 119.147.158.241, ...
Connecting to mirrors.aliyun.com (mirrors.aliyun.com)|118.112.15.8|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 2523 (2.5K) [application/octet-stream]
Saving to:/etc/yum.repos.d/CentOS-Base.repo’

100%[==================================================================================================================================================>] 2,523       --.-K/s   in 0.003s  

2019-07-25 14:48:51 (943 KB/s) -/etc/yum.repos.d/CentOS-Base.repo’ saved [2523/2523]

5、查看yum配置文件、执行yum clean all 、makecache命令

[root@clinet ~]# cat /etc/yum.repos.d/CentOS-Base.repo 
/# CentOS-Base.repo
#
/# The mirror system uses the connecting IP address of the client and the
/# update status of each mirror to pick mirrors that are updated to and
/# geographically close to the client.  You should use this for CentOS updates
/# unless you are manually picking other mirrors.
#
/# If the mirrorlist= does not work for you, as a fall back you can try the 
/# remarked out baseurl= line instead.
#
#
 
[base]
name=CentOS-$releasever - Base - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/$releasever/os/$basearch/
        http://mirrors.aliyuncs.com/centos/$releasever/os/$basearch/
        http://mirrors.cloud.aliyuncs.com/centos/$releasever/os/$basearch/
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
 
#released updates 
[updates]
name=CentOS-$releasever - Updates - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/$releasever/updates/$basearch/
        http://mirrors.aliyuncs.com/centos/$releasever/updates/$basearch/
        http://mirrors.cloud.aliyuncs.com/centos/$releasever/updates/$basearch/
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
 
#additional packages that may be useful
[extras]
name=CentOS-$releasever - Extras - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/$releasever/extras/$basearch/
        http://mirrors.aliyuncs.com/centos/$releasever/extras/$basearch/
        http://mirrors.cloud.aliyuncs.com/centos/$releasever/extras/$basearch/
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
 
#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-$releasever - Plus - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/$releasever/centosplus/$basearch/
        http://mirrors.aliyuncs.com/centos/$releasever/centosplus/$basearch/
        http://mirrors.cloud.aliyuncs.com/centos/$releasever/centosplus/$basearch/
gpgcheck=1
enabled=0
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
 
#contrib - packages by Centos Users
[contrib]
name=CentOS-$releasever - Contrib - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/$releasever/contrib/$basearch/
        http://mirrors.aliyuncs.com/centos/$releasever/contrib/$basearch/
        http://mirrors.cloud.aliyuncs.com/centos/$releasever/contrib/$basearch/
gpgcheck=1
enabled=0
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7

···
以上就是yum源的配置文件内容,只需要下载好即可。

清理缓存

[root@clinet ~]# yum clean all
Loaded plugins: fastestmirror, langpacks
Cleaning repos: base extras updates xixi
Cleaning up list of fastest mirrors

重建缓存索引

[root@clinet ~]# yum makecache 
Loaded plugins: fastestmirror, langpacks
Determining fastest mirrors
 * base: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
base                                                                                                                                                                 | 3.6 kB  00:00:00     
extras                                                                                                                                                               | 3.4 kB  00:00:00     
updates                                                                                                                                                              | 3.4 kB  00:00:00     
xixi                                                                                                                                                                 | 3.6 kB  00:00:00     
(1/16): base/7/x86_64/group_gz                                                                                                                                       | 166 kB  00:00:00     
(2/16): extras/7/x86_64/filelists_db                                                                                                                                 | 246 kB  00:00:00     
(3/16): extras/7/x86_64/primary_db                                                                                                                                   | 205 kB  00:00:00     
(4/16): extras/7/x86_64/other_db                                                                                                                                     | 127 kB  00:00:00     
(5/16): updates/7/x86_64/filelists_db                                                                                                                                | 4.6 MB  00:00:01     
(6/16): updates/7/x86_64/prestodelta                                                                                                                                 | 829 kB  00:00:00     
(7/16): base/7/x86_64/other_db                                                                                                                                       | 2.6 MB  00:00:02     
(8/16): updates/7/x86_64/other_db                                                                                                                                    | 659 kB  00:00:00     
(9/16): xixi/group_gz                                                                                                                                                | 166 kB  00:00:00     
(10/16): xixi/filelists_db                                                                                                                                           | 3.2 MB  00:00:00     
(11/16): xixi/primary_db                                                                                                                                             | 3.1 MB  00:00:00     
(12/16): xixi/other_db                                                                                                                                               | 1.3 MB  00:00:00     
(13/16): updates/7/x86_64/primary_db                                                                                                                                 | 6.5 MB  00:00:01     
base/7/x86_64/primary_db       FAILED                                          
http://mirrors.cloud.aliyuncs.com/centos/7/os/x86_64/repodata/6614b3605d961a4aaec45d74ac4e5e713e517debb3ee454a1c91097955780697-primary.sqlite.bz2: [Errno 14] curl#6 - "Could not resolve host: mirrors.cloud.aliyuncs.com; Unknown error"
Trying other mirror.
(14/16): base/7/x86_64/primary_db                                                                                                                                    | 6.0 MB  00:00:01     
base/7/x86_64/filelists_db     FAILED                                          
http://mirrors.aliyuncs.com/centos/7/os/x86_64/repodata/a0ec5a4708a1026db100d4799c404c9ed48a9371a4bab234a1355f86628a244a-filelists.sqlite.bz2: [Errno 14] curl#7 - "Failed connect to mirrors.aliyuncs.com:80; Connection refused"
Trying other mirror.
extras/7/x86_64/prestodelta    FAILED                                          
http://mirrors.aliyuncs.com/centos/7/extras/x86_64/repodata/5bfd3d5f07606011226e556e87d978ca1dfe51a63e18d793182900d5bbc702b5-prestodelta.xml.gz: [Errno 14] curl#7 - "Failed connect to mirrors.aliyuncs.com:80; Connection refused"
Trying other mirror.
(15/16): extras/7/x86_64/prestodelta                                                                                                                                 |  65 kB  00:00:00     
(16/16): base/7/x86_64/filelists_db                                                                                                                                  | 7.1 MB  00:00:01     
Metadata Cache Created

其他镜像站的配置大同小异,这里就不一一列举了

你可能感兴趣的:(linux)