网上学习资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。

需要这份系统化的资料的朋友,可以点击这里获取!

一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!

那么在html下面建立以下目录:

mkdir –p /usr/local/nginx-1.11.2/html/CentOS-YUM/CentOS/version_6.6/64bit/
mkdir –p /usr/local/nginx-1.11.2/html/CentOS-YUM/CentOS/version_7.0/64bit/
mkdir –p /usr/local/nginx-1.11.2/html/CentOS-YUM/Aliyun/version_6.6/64bit/
mkdir –p /usr/local/nginx-1.11.2/html/CentOS-YUM/Aliyun/version_7.0/64bit/
且不要忘记给目录增加可读和可执行权限,否则在web页面显示不出来。

Chmod –R +x /usr/local/nginx-1.11.2/html/

在web的index.html首页里面添加指向文件目录的超链接:


ALL of the packages in the below:


Aliyun

These packagers from of CentOS ISO.

CentOS

These packagers from of “Internet service provider”.

Please replace the file and fill in the following content:

Way: /etc/yum.repos.d/CentOS-Base.repo


五、修改当前系统yum来源repo文件

文件位置:/etc/yum.repos.d/CentOS-Base.repo

1.首先对此文件进行备份,因为当前系统的所有yum软件包的安装或者更新都是来自于这个文件的指定路径的更新。

cp –p /etc/yum.repos.d/CentOS-Base.repo(空格)/etc/yum.repos.d/CentOS-Base.repo.back

通过
cat /CentOS-Base.repo打开的可以看到如下所示:(
因为当前系统是7

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- r e l e a s e v e r − B a s e m i r r o r l i s t = h t t p : / / m i r r o r l i s t . c e n t o s . o r g / ? r e l e a s e = releasever - Base mirrorlist=http://mirrorlist.centos.org/?release= releaseverBasemirrorlist=http://mirrorlist.centos.org/?release=releasever&arch=KaTeX parse error: Expected 'EOF', got '&' at position 9: basearch&̲repo=os&infra=infra
#baseurl=http://mirror.centos.org/centos/ r e l e a s e v e r / o s / releasever/os/ releasever/os/basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

#released updates
[updates]
name=CentOS- r e l e a s e v e r − U p d a t e s m i r r o r l i s t = h t t p : / / m i r r o r l i s t . c e n t o s . o r g / ? r e l e a s e = releasever - Updates mirrorlist=http://mirrorlist.centos.org/?release= releaseverUpdatesmirrorlist=http://mirrorlist.centos.org/?release=releasever&arch=KaTeX parse error: Expected 'EOF', got '&' at position 9: basearch&̲repo=updates&in…infra
#baseurl=http://mirror.centos.org/centos/ r e l e a s e v e r / u p d a t e s / releasever/updates/ releasever/updates/basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

#additional packages that may be useful
[extras]
name=CentOS- r e l e a s e v e r − E x t r a s m i r r o r l i s t = h t t p : / / m i r r o r l i s t . c e n t o s . o r g / ? r e l e a s e = releasever - Extras mirrorlist=http://mirrorlist.centos.org/?release= releaseverExtrasmirrorlist=http://mirrorlist.centos.org/?release=releasever&arch=KaTeX parse error: Expected 'EOF', got '&' at position 9: basearch&̲repo=extras&inf…infra
#baseurl=http://mirror.centos.org/centos/ r e l e a s e v e r / e x t r a s / releasever/extras/ releasever/extras/basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS- r e l e a s e v e r − P l u s m i r r o r l i s t = h t t p : / / m i r r o r l i s t . c e n t o s . o r g / ? r e l e a s e = releasever - Plus mirrorlist=http://mirrorlist.centos.org/?release= releaseverPlusmirrorlist=http://mirrorlist.centos.org/?release=releasever&arch=KaTeX parse error: Expected 'EOF', got '&' at position 9: basearch&̲repo=centosplus…infra
#baseurl=http://mirror.centos.org/centos/ r e l e a s e v e r / c e n t o s p l u s / releasever/centosplus/ releasever/centosplus/basearch/
gpgcheck=1
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

#contrib - packages by Centos Users
[contrib]
name=CentOS- r e l e a s e v e r − C o n t r i b m i r r o r l i s t = h t t p : / / m i r r o r l i s t . c e n t o s . o r g / ? r e l e a s e = releasever - Contrib mirrorlist=http://mirrorlist.centos.org/?release= releaseverContribmirrorlist=http://mirrorlist.centos.org/?release=releasever&arch=KaTeX parse error: Expected 'EOF', got '&' at position 9: basearch&̲repo=contrib&in…infra
#baseurl=http://mirror.centos.org/centos/ r e l e a s e v e r / c o n t r i b / releasever/contrib/ releasever/contrib/basearch/
gpgcheck=1
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

由此可以看出当前是CentOS-7的linux系统,使用的是标准的CentOS官方源

2.因为当前的系统是CentOS-7的版本,那么如果从CentOS官方现在就进行同步,那么同步到的只能是CentOS7的版本的所有yum源,那么相对的如果要同步6版本的yum源,将CentOS-Base.repo的文件内的7的版本号更改为6就可以了。即:

3.接下来去阿里云的官方网站下载阿里云的CentOS-Base.repo文件,如下所示:

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

这里是三个版本的阿里云yum源下载地址,这里下载6和7就可以了。就下载到

/etc/yum.repos.d/Aliyun/的目录下面就好了。而Aliyun的CentOS-6.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/ r e l e a s e v e r / o s / releasever/os/ releasever/os/basearch/

http://mirrors.aliyuncs.com/centos/ r e l e a s e v e r / o s / releasever/os/ releasever/os/basearch/

#mirrorlist=http://mirrorlist.centos.org/?release=KaTeX parse error: Expected 'EOF', got '&' at position 11: releasever&̲arch=basearch&repo=os

gpgcheck=1

gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-
6

#released updates

[updates]

name=CentOS-$releasever - Updates - mirrors.aliyun.com

failovermethod=priority

baseurl=http://mirrors.aliyun.com/centos/ r e l e a s e v e r / u p d a t e s / releasever/updates/ releasever/updates/basearch/

http://mirrors.aliyuncs.com/centos/ r e l e a s e v e r / u p d a t e s / releasever/updates/ releasever/updates/basearch/

#mirrorlist=http://mirrorlist.centos.org/?release=KaTeX parse error: Expected 'EOF', got '&' at position 11: releasever&̲arch=basearch&repo=updates

gpgcheck=1

gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-
6

#additional packages that may be useful

[extras]

name=CentOS-$releasever - Extras - mirrors.aliyun.com

failovermethod=priority

baseurl=http://mirrors.aliyun.com/centos/ r e l e a s e v e r / e x t r a s / releasever/extras/ releasever/extras/basearch/

http://mirrors.aliyuncs.com/centos/ r e l e a s e v e r / e x t r a s / releasever/extras/ releasever/extras/basearch/

#mirrorlist=http://mirrorlist.centos.org/?release=KaTeX parse error: Expected 'EOF', got '&' at position 11: releasever&̲arch=basearch&repo=extras

gpgcheck=1

gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-
6

#additional packages that extend functionality of existing packages

[centosplus]

name=CentOS-$releasever - Plus - mirrors.aliyun.com

failovermethod=priority

baseurl=http://mirrors.aliyun.com/centos/ r e l e a s e v e r / c e n t o s p l u s / releasever/centosplus/ releasever/centosplus/basearch/

http://mirrors.aliyuncs.com/centos/ r e l e a s e v e r / c e n t o s p l u s / releasever/centosplus/ releasever/centosplus/basearch/

#mirrorlist=http://mirrorlist.centos.org/?release=KaTeX parse error: Expected 'EOF', got '&' at position 11: releasever&̲arch=basearch&repo=centosplus

gpgcheck=1

enabled=0

gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-
6

#contrib - packages by Centos Users

[contrib]

name=CentOS-$releasever - Contrib - mirrors.aliyun.com

failovermethod=priority

baseurl=http://mirrors.aliyun.com/centos/ r e l e a s e v e r / c o n t r i b / releasever/contrib/ releasever/contrib/basearch/

http://mirrors.aliyuncs.com/centos/ r e l e a s e v e r / c o n t r i b / releasever/contrib/ releasever/contrib/basearch/

#mirrorlist=http://mirrorlist.centos.org/?release=KaTeX parse error: Expected 'EOF', got '&' at position 11: releasever&̲arch=basearch&repo=contrib

gpgcheck=1

enabled=0

gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-
6

==================================================================

而同样的,如果需要7也可以直接修改文件内的版本号。

六、进行同步脚本的创建并执行同步

vim /etc/yum.repos.d/yum.reposync.sh


#!bin/bash
reposync –p /usr/local/nginx-1.11.2/html/CentOS-YUM/CentOS/version_7.0/64bit/
/usr/bin/sed -i “s/7/6/g” grep 7 -rl /etc/yum.repos.d/CentOS-Base.repo
reposync –p /usr/local/nginx-1.11.2/html/CentOS-YUM/CentOS/version_6.6/64bit/
cat /etc/yum.repos.d/Aliyun/CentOS-6.repo > /etc/yum.repos.d/CentOS-Base.repo
reposync –p /usr/local/nginx-1.11.2/html/CentOS-YUM/Aliyun/version_6.6/64bit/
/usr/bin/sed -i “s/6/7/g” grep 6 -rl /etc/yum.repos.d/CentOS-Base.repo
reposync –p /usr/local/nginx-1.11.2/html/CentOS-YUM/Aliyun/version_7.0/64bit/
cat /etc/yum.repos.d/CentOS-Base.repo.back > /etc/yum.repos.d/CentOS-Base.repo


脚本内一共九行命令。

第二行中的“-p”意思为指定同步到目录,此行同步CentOS7的版本yum源

第三行是替换CentOS-Base.repo文本中的所有数字为7的数字更改为6

第四行是同步CentOS6的版本yum源

第五行是将阿里云的CentOS-Base.repo文件对CentOS官方CentOS-Base.repo的文件进行替换所有内容。

第六行开始同步阿里云的6版本的yum源

第七行更改阿里云的CentOS-Base.repo文件为7版本

第八行开始同步阿里云的7版本的yum源

第九行进行还原替换,将阿里云的CentOS-Base.repo 文件替换为CentOS官方6版本的CentOS-Base.repo文件,以便下次,跟这两个官方进行计划同步的时候可以方便些。

(我试过将两个yum源repo文件合并,但是会出错,当然不排除还有其他方式。)

完成以后,执行这个文件,要给这个文件添加执行权限

chmod +x yum.reposync.sh

然后执行脚本

sh yum.reposync.sh

等待下载同步完成。。。。。

同步完成以后,就可以在相应的目录下面看到各种rpm的安装包:

注意如果是同步到比如这个目录:

/usr/local/nginx-1.11.2/html/CentOS-YUM/CentOS/version_7.0/64bit/

那么在64bit的目录下面就会生成三个目录,是跟官方源同步的:

Base/

Extras/

Updates/

这样yum源的server端就建立好了。然后进行建仓,即yum源仓库,供client端检索使用:

(因为建仓最终的目的也是可供client来进行检索的,所以得每个Packages目录都要建成仓库,所以建仓的时候,

目录到指到最底层的Packages,而-np更新的时候只用指定到64bit的目录就可以了,否则会重复建立base、extras、updates三个目录进行下载)

createrepo -p /usr/local/nginx-1.11.2/html/CentOS-YUM/CentOS/version_6.6/64bit/base/Packages
createrepo -p /usr/local/nginx-1.11.2/html/CentOS-YUM/CentOS/version_7.0/64bit/base/Packages
createrepo -p /usr/local/nginx-1.11.2/html/CentOS-YUM/Aliyun/version_6.6/64bit/base/Packages
createrepo -p /usr/local/nginx-1.11.2/html/CentOS-YUM/Aliyun/version_7.0/64bit/base/Packages

当然也可以是,比如:

createrepo -p /usr/local/nginx-1.11.2/html/CentOS-YUM/Aliyun/version_7.0/64bit/base/Packages (空格) /usr/local/nginx-1.11.2/html/CentOS-YUM/Aliyun/version_7.0/64bit/base/Packages

当yum源仓库建立好以后,会在对应的目录下面出现“repodata”的目录。如下图所示:

接下来client端配置后就可以直接使用这些YUM源。

七、客户端Client的yum配置:

1.安装优先级软件:

使用yum来安装yum install -y yum-plugin-priorities

这个是优先级工具,可以控制client端进行yum源的先后使用查找。

2.首先对client端的/etc/yum.repos.d/目录下的repo文件进行更改。

mkdir –p /etc/yum.repos.d/back

mv /etc/yum.repos.d/*/etc/yum.repos.d/back/

vim /etc/yum.repos.d/CentOS-Base.repo


[mylocal]

name=source_from_localserver 
#这里是整合到server端的centos6的光盘镜像yum源

baseurl=http://10.20.0.50/centos/6.6/x86_64/Packagers/

gpgcheck=0

enable=1

priority=1   
#这里的priority就是上面安装的优先级工具,设定从小到大

[Aliyun_6.6_base]

name=source_from_localserver

baseurl=http://10.20.0.50/CentOS-YUM/Aliyun/version_6.6/64bit/base/Packages

gpgcheck=0

enable=1

priority=2

[Centos_6.6_base]

name=source_from_localserver

baseurl=http://10.20.0.50/CentOS-YUM/CentOS/version_6.6/64bit/base/Packages

gpgcheck=0

enable=1

priority=3

[Aliyun_6.6_extras]

name=source_from_localserver

baseurl=http://10.20.0.50/CentOS-YUM/Aliyun/version_6.6/64bit/extras/Packages

gpgcheck=0

enable=1

priority=4

[Centos_6.6_extras]

name=source_from_localserver

网上学习资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。

需要这份系统化的资料的朋友,可以点击这里获取!

一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!

Logo

旨在为数千万中国开发者提供一个无缝且高效的云端环境,以支持学习、使用和贡献开源项目。

更多推荐