YUM源
一、定义
YUM(全称为 Yellow dog Updater, Modified)是一个在 Fedora 和 RedHat 以及 CentOS 中的 Shell 前端软件包管理器。基于RPM包管理,能够从指定的服务器自动下载RPM包并且安装,**可以自动处理依赖性关系,并且一次安装所有依赖的软件包,无须繁琐地一次次下载、安装。**
二、在线YUM源(当前虚拟机必须可连通外网)
使用阿里或者华为的在线源网站,找到路径,在线安装
阿里云开发者社区:阿里在线源网站,里边提供NTP授时服务,DNS服务等。 阿里巴巴开源镜像站-OPSX镜像站-阿里云开发者社区
-
CentOS过期源(centos-vault):centos-vault镜像_centos-vault下载地址_centos-vault安装教程-阿里巴巴开源镜像站
1、进入yum.repos.d文件夹中,清除现有的repo文件,现有repo文件来源为CentOS官方的在线源
[root@localhost ~]# cd /etc/yum.repos.d
[root@localhost yum.repos.d]# ls
CentOS-Base.repo CentOS-Debuginfo.repo CentOS-Media.repo CentOS-Vault.repo
CentOS-CR.repo CentOS-fasttrack.repo CentOS-Sources.repo
[root@localhost yum.repos.d]# mkdir yum
[root@localhost yum.repos.d]# mv *.repo yum
[root@localhost yum.repos.d]# ls
yum
2、粘贴在线源命令行
wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
或者
curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
[root@localhost yum.repos.d]# wget -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
[root@localhost yum.repos.d]# ls
Centos-7.repo CentOS-Base.repo yum
3、验证
安装的base url路径为http的阿里云在线文件
[root@localhost yum.repos.d]# cat 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
4、使用 ,安装rpm包
[root@localhost yum.repos.d]# yum install httpd
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: mirrors.aliyun.com
* extras: mirrors.aliyun.com
* updates: mirrors.aliyun.com
Resolving Dependencies
--> Running transaction check
---> Package httpd.x86_64 0:2.4.6-99.el7.centos.1 will be installed
--> Processing Dependency: httpd-tools = 2.4.6-99.el7.centos.1 for package: httpd-2.4.6-99.el7.centos.1.x86_64
--> Processing Dependency: /etc/mime.types for package: httpd-2.4.6-99.el7.centos.1.x86_64
--> Processing Dependency: libaprutil-1.so.0()(64bit) for package: httpd-2.4.6-99.el7.centos.1.x86_64
--> Processing Dependency: libapr-1.so.0()(64bit) for package: httpd-2.4.6-99.el7.centos.1.x86_64
--> Running transaction check
---> Package apr.x86_64 0:1.4.8-7.el7 will be installed
---> Package apr-util.x86_64 0:1.5.2-6.el7_9.1 will be installed
---> Package httpd-tools.x86_64 0:2.4.6-99.el7.centos.1 will be installed
---> Package mailcap.noarch 0:2.1.41-2.el7 will be installed
--> Finished Dependency Resolution
Dependencies Resolved
======================================================================================================================
Package Arch Version Repository Size
======================================================================================================================
Installing:
httpd x86_64 2.4.6-99.el7.centos.1 updates 2.7 M
Installing for dependencies:
apr x86_64 1.4.8-7.el7 base 104 k
apr-util x86_64 1.5.2-6.el7_9.1 updates 92 k
httpd-tools x86_64 2.4.6-99.el7.centos.1 updates 94 k
mailcap noarch 2.1.41-2.el7 base 31 k
Transaction Summary
======================================================================================================================
Install 1 Package (+4 Dependent packages)
Total download size: 3.0 M
Installed size: 10 M
Is this ok [y/d/N]: y
Downloading packages:
(1/5): apr-1.4.8-7.el7.x86_64.rpm | 104 kB 00:00:00
(2/5): apr-util-1.5.2-6.el7_9.1.x86_64.rpm | 92 kB 00:00:00
(3/5): httpd-2.4.6-99.el7.centos.1.x86_64.rpm | 2.7 MB 00:00:00
(4/5): httpd-tools-2.4.6-99.el7.centos.1.x86_64.rpm | 94 kB 00:00:00
(5/5): mailcap-2.1.41-2.el7.noarch.rpm | 31 kB 00:00:00
----------------------------------------------------------------------------------------------------------------------
Total 4.7 MB/s | 3.0 MB 00:00:00
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : apr-1.4.8-7.el7.x86_64 1/5
Installing : apr-util-1.5.2-6.el7_9.1.x86_64 2/5
Installing : httpd-tools-2.4.6-99.el7.centos.1.x86_64 3/5
Installing : mailcap-2.1.41-2.el7.noarch 4/5
Installing : httpd-2.4.6-99.el7.centos.1.x86_64 5/5
Verifying : httpd-2.4.6-99.el7.centos.1.x86_64 1/5
Verifying : mailcap-2.1.41-2.el7.noarch 2/5
Verifying : apr-1.4.8-7.el7.x86_64 3/5
Verifying : httpd-tools-2.4.6-99.el7.centos.1.x86_64 4/5
Verifying : apr-util-1.5.2-6.el7_9.1.x86_64 5/5
Installed:
httpd.x86_64 0:2.4.6-99.el7.centos.1
Dependency Installed:
apr.x86_64 0:1.4.8-7.el7 apr-util.x86_64 0:1.5.2-6.el7_9.1 httpd-tools.x86_64 0:2.4.6-99.el7.centos.1
mailcap.noarch 0:2.1.41-2.el7
Complete!
三、本地YUM源
1、使用光盘中的repodata提供的本地YUM源
挂载光盘到 /mnt下
[root@localhost ~]# mount /dev/cdrom /mnt/
mount: /dev/sr0 is write-protected, mounting read-only
[root@localhost ~]# ls /mnt/
CentOS_BuildTag EULA images LiveOS repodata RPM-GPG-KEY-CentOS-Testing-7
EFI GPL isolinux Packages RPM-GPG-KEY-CentOS-7 TRANS.TBL
2、进入/etc/yum.repos.d文件夹中,创建yum文本
[root@localhost ~]# cd /etc/yum.repos.d/
[root@localhost yum.repos.d]# ls
yum
[root@localhost yum.repos.d]# vim abc.repo
[cuiyue_id] --- //ID号,自定义,固定格式
name = cuiyue_name --- //名称,自定义,固定格式
baseurl = file:///mnt/ --- //基础路径,file://为固定格式,/mnt为路径
gpgcheck = 0 --- //对rpm包的合法性不进行验证
enable = 1 --- //确认生效
[os]
name = os
baseurl = file:///mnt/
gpgcheck = 0
enable = 1
3、验证
查看repolist列表
[root@localhost yum.repos.d]#
[root@localhost yum.repos.d]# cat abc.repo
[os]
name = os
baseurl = file:///mnt/
gpgcheck = 0
enable = 1
[root@localhost yum.repos.d]# yum repolist all
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
os | 3.6 kB 00:00:00
(1/2): os/group_gz | 166 kB 00:00:00
(2/2): os/primary_db | 3.1 MB 00:00:00
repo id repo name status
os os enabled: 4,021 repolist: 4,021
//可以看到repo id和repo name是我们在repo文件中所设置的,一共在我们设置的本地Yum文件库中,找寻到4021个rpm安装文件
4、使用,安装rpm包
[root@localhost yum.repos.d]# yum install gcc*
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
Resolving Dependencies
--> Running transaction check
---> Package gcc.x86_64 0:4.8.5-36.el7 will be installed
--> Processing Dependency: cpp = 4.8.5-36.el7 for package: gcc-4.8.5-36.el7.x86_64
--> Processing Dependency: glibc-devel >= 2.2.90-12 for package: gcc-4.8.5-36.el7.x86_64
--> Processing Dependency: libmpfr.so.4()(64bit) for package: gcc-4.8.5-36.el7.x86_64
--> Processing Dependency: libmpc.so.3()(64bit) for package: gcc-4.8.5-36.el7.x86_64
---> Package gcc-c++.x86_64 0:4.8.5-36.el7 will be installed
--> Processing Dependency: libstdc++-devel = 4.8.5-36.el7 for package: gcc-c++-4.8.5-36.el7.x86_64
---> Package gcc-gfortran.x86_64 0:4.8.5-36.el7 will be installed
--> Processing Dependency: libquadmath-devel = 4.8.5-36.el7 for package: gcc-gfortran-4.8.5-36.el7.x86_64
--> Processing Dependency: libquadmath = 4.8.5-36.el7 for package: gcc-gfortran-4.8.5-36.el7.x86_64
--> Processing Dependency: libgfortran = 4.8.5-36.el7 for package: gcc-gfortran-4.8.5-36.el7.x86_64
--> Processing Dependency: libgfortran.so.3()(64bit) for package: gcc-gfortran-4.8.5-36.el7.x86_64
---> Package gcc-gnat.x86_64 0:4.8.5-36.el7 will be installed
--> Processing Dependency: libgnat-devel = 4.8.5-36.el7 for package: gcc-gnat-4.8.5-36.el7.x86_64
--> Processing Dependency: libgnat = 4.8.5-36.el7 for package: gcc-gnat-4.8.5-36.el7.x86_64
---> Package gcc-objc.x86_64 0:4.8.5-36.el7 will be installed
--> Processing Dependency: libobjc = 4.8.5-36.el7 for package: gcc-objc-4.8.5-36.el7.x86_64
--> Processing Dependency: libobjc.so.4()(64bit) for package: gcc-objc-4.8.5-36.el7.x86_64
---> Package gcc-objc++.x86_64 0:4.8.5-36.el7 will be installed
--> Running transaction check
---> Package cpp.x86_64 0:4.8.5-36.el7 will be installed
---> Package glibc-devel.x86_64 0:2.17-260.el7 will be installed
--> Processing Dependency: glibc-headers = 2.17-260.el7 for package: glibc-devel-2.17-260.el7.x86_64
--> Processing Dependency: glibc-headers for package: glibc-devel-2.17-260.el7.x86_64
---> Package libgfortran.x86_64 0:4.8.5-36.el7 will be installed
---> Package libgnat.x86_64 0:4.8.5-36.el7 will be installed
---> Package libgnat-devel.x86_64 0:4.8.5-36.el7 will be installed
---> Package libmpc.x86_64 0:1.0.1-3.el7 will be installed
---> Package libobjc.x86_64 0:4.8.5-36.el7 will be installed
---> Package libquadmath.x86_64 0:4.8.5-36.el7 will be installed
---> Package libquadmath-devel.x86_64 0:4.8.5-36.el7 will be installed
---> Package libstdc++-devel.x86_64 0:4.8.5-36.el7 will be installed
---> Package mpfr.x86_64 0:3.1.1-4.el7 will be installed
--> Running transaction check
---> Package glibc-headers.x86_64 0:2.17-260.el7 will be installed
--> Processing Dependency: kernel-headers >= 2.2.1 for package: glibc-headers-2.17-260.el7.x86_64
--> Processing Dependency: kernel-headers for package: glibc-headers-2.17-260.el7.x86_64
--> Running transaction check
---> Package kernel-headers.x86_64 0:3.10.0-957.el7 will be installed
--> Finished Dependency Resolution
Dependencies Resolved
======================================================================================================================
Package Arch Version Repository Size
======================================================================================================================
Installing:
gcc x86_64 4.8.5-36.el7 os 16 M
gcc-c++ x86_64 4.8.5-36.el7 os 7.2 M
gcc-gfortran x86_64 4.8.5-36.el7 os 6.7 M
gcc-gnat x86_64 4.8.5-36.el7 os 13 M
gcc-objc x86_64 4.8.5-36.el7 os 5.7 M
gcc-objc++ x86_64 4.8.5-36.el7 os 6.2 M
Installing for dependencies:
cpp x86_64 4.8.5-36.el7 os 5.9 M
glibc-devel x86_64 2.17-260.el7 os 1.1 M
glibc-headers x86_64 2.17-260.el7 os 683 k
kernel-headers x86_64 3.10.0-957.el7 os 8.0 M
libgfortran x86_64 4.8.5-36.el7 os 300 k
libgnat x86_64 4.8.5-36.el7 os 966 k
libgnat-devel x86_64 4.8.5-36.el7 os 2.7 M
libmpc x86_64 1.0.1-3.el7 os 51 k
libobjc x86_64 4.8.5-36.el7 os 79 k
libquadmath x86_64 4.8.5-36.el7 os 189 k
libquadmath-devel x86_64 4.8.5-36.el7 os 52 k
libstdc++-devel x86_64 4.8.5-36.el7 os 1.5 M
mpfr x86_64 3.1.1-4.el7 os 203 k
Transaction Summary
======================================================================================================================
Install 6 Packages (+13 Dependent packages)
Total download size: 76 M
Installed size: 189 M
Is this ok [y/d/N]: y
Downloading packages:
----------------------------------------------------------------------------------------------------------------------
Total 86 MB/s | 76 MB 00:00:00
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : mpfr-3.1.1-4.el7.x86_64 1/19
Installing : libmpc-1.0.1-3.el7.x86_64 2/19
Installing : libquadmath-4.8.5-36.el7.x86_64 3/19
Installing : libgfortran-4.8.5-36.el7.x86_64 4/19
Installing : cpp-4.8.5-36.el7.x86_64 5/19
Installing : libstdc++-devel-4.8.5-36.el7.x86_64 6/19
Installing : kernel-headers-3.10.0-957.el7.x86_64 7/19
Installing : glibc-headers-2.17-260.el7.x86_64 8/19
Installing : glibc-devel-2.17-260.el7.x86_64 9/19
Installing : gcc-4.8.5-36.el7.x86_64 10/19
Installing : gcc-c++-4.8.5-36.el7.x86_64 11/19
Installing : libquadmath-devel-4.8.5-36.el7.x86_64 12/19
Installing : libobjc-4.8.5-36.el7.x86_64 13/19
Installing : gcc-objc-4.8.5-36.el7.x86_64 14/19
Installing : libgnat-devel-4.8.5-36.el7.x86_64 15/19
Installing : libgnat-4.8.5-36.el7.x86_64 16/19
Installing : gcc-gnat-4.8.5-36.el7.x86_64 17/19
Installing : gcc-objc++-4.8.5-36.el7.x86_64 18/19
Installing : gcc-gfortran-4.8.5-36.el7.x86_64 19/19
Verifying : libgnat-4.8.5-36.el7.x86_64 1/19
Verifying : glibc-devel-2.17-260.el7.x86_64 2/19
Verifying : cpp-4.8.5-36.el7.x86_64 3/19
Verifying : libgnat-devel-4.8.5-36.el7.x86_64 4/19
Verifying : gcc-objc-4.8.5-36.el7.x86_64 5/19
Verifying : gcc-4.8.5-36.el7.x86_64 6/19
Verifying : libobjc-4.8.5-36.el7.x86_64 7/19
Verifying : gcc-gfortran-4.8.5-36.el7.x86_64 8/19
Verifying : mpfr-3.1.1-4.el7.x86_64 9/19
Verifying : gcc-objc++-4.8.5-36.el7.x86_64 10/19
Verifying : libgfortran-4.8.5-36.el7.x86_64 11/19
Verifying : kernel-headers-3.10.0-957.el7.x86_64 12/19
Verifying : libmpc-1.0.1-3.el7.x86_64 13/19
Verifying : libquadmath-4.8.5-36.el7.x86_64 14/19
Verifying : gcc-c++-4.8.5-36.el7.x86_64 15/19
Verifying : gcc-gnat-4.8.5-36.el7.x86_64 16/19
Verifying : glibc-headers-2.17-260.el7.x86_64 17/19
Verifying : libquadmath-devel-4.8.5-36.el7.x86_64 18/19
Verifying : libstdc++-devel-4.8.5-36.el7.x86_64 19/19
Installed:
gcc.x86_64 0:4.8.5-36.el7 gcc-c++.x86_64 0:4.8.5-36.el7 gcc-gfortran.x86_64 0:4.8.5-36.el7
gcc-gnat.x86_64 0:4.8.5-36.el7 gcc-objc.x86_64 0:4.8.5-36.el7 gcc-objc++.x86_64 0:4.8.5-36.el7
Dependency Installed:
cpp.x86_64 0:4.8.5-36.el7 glibc-devel.x86_64 0:2.17-260.el7
glibc-headers.x86_64 0:2.17-260.el7 kernel-headers.x86_64 0:3.10.0-957.el7
libgfortran.x86_64 0:4.8.5-36.el7 libgnat.x86_64 0:4.8.5-36.el7
libgnat-devel.x86_64 0:4.8.5-36.el7 libmpc.x86_64 0:1.0.1-3.el7
libobjc.x86_64 0:4.8.5-36.el7 libquadmath.x86_64 0:4.8.5-36.el7
libquadmath-devel.x86_64 0:4.8.5-36.el7 libstdc++-devel.x86_64 0:4.8.5-36.el7
mpfr.x86_64 0:3.1.1-4.el7
Complete!