自动化部署必备技能—搭建YUM仓库

YUM主要用于自动安装、升级rpm软件包,它能自动查找并解决rpm包之间的依赖关系。要成功的使用YUM工具安装更新软件或系统,就需要有一个包含各种rpm软件包的repository(软件仓库),这个软件仓库我们习惯称为yum源。网络上有大量的yum源,但由于受到网络环境的限制,导致软件安装耗时过长甚至失败。特别是当有大量服务器大量软件包需要安装时,缓慢的进度条令人难以忍受。因此我们在优化系统时,都会更换国内的源。

相比较而言,本地YUM源服务器最大优点是局域网的快速网络连接和稳定性。有了局域网中的YUM源服务器,即便在Internet连接中断的情况下,也不会影响其他YUM客户端的软件安装和升级。

1.1 服务端配置

mkdir -p
/application/yum/centos6/x86_64/    ß1.创建yum仓库目录,rpm包都上至此目录

yum -y install createrepo                ß2.安装createrepo软件

createrepo -pdo
/application/yum/centos6/x86_64/ /application/yum/centos6/x86_64/            ß3.初始化repodata索引文件

cd /application/yum/centos6/x86_64/       ß4.进入需要提供仓库的目录

python -m SimpleHTTPServer 80 &>/dev/null &   ß5.可以用Apache或nginx提供web服务,但用Python的http模块更简单,适用于内网环境, 可以通过浏览器输入本机IP查看。

createrepo –update /application/yum/centos6/x86_64/        ß6.每加入一个rpm包就要更新一下

sed -i ‘s#keepcache=0#keepcache=1#g’
/etc/yum.conf          ß修改yum配置文件keepacache=0改为1,保存下载过的软件

cachedir=/var/cache/yum/$basearch/$releasever         ß安装包存储目录=
/var/cache/yum/x86_64/6/base/packages

1.2客户端配置

cd /etc/yum.repos.d

[root@B yum.repos.d]# vi oldboy.repo          ß连接本地yum源

[xuliangwei]

name=Server

baseurl=http://10.0.0.5

enable=1

gpgcheck=0

[root@YUM ~]# yum
–-enablerepo=xuliangwei –disablerepo=base,extras,updates,epel list ß指定使用xuliangwei库(临时生效)

或:

[root@oldboy yum.repos.d]# vim
/etc/yum.repos.d/CentOS-Base.repo

# 在每一个启动的源加上

# enabled=0#改为1就启用,没有此参数也是启用。

[base]

…………

enabled=0

 

[updates]

…………

enabled=0

 

[extras]

…………

enabled=0

# 还有其他开启的仓库就使用这个办法关闭

2.Yum服务配置文件

2.1全局配置文件

main部分定义了全局配置选项,整个yum配置文件应该只有一个main,位于/etc/yum.cof

[root@XuBuSi ~]# cat /etc/yum.conf

[main]

cachedir=/var/cache/yum/$basearch/$releasever         ßyum缓存的目录,存储下载的rpm包和数据库

keepcache=0   ß安装完成后是否保留软件包,0为不保留(默认为0),1为保留

debuglevel=2   ßDebug信息输出等级,范围为0-10,缺省为2

logfile=/var/log/yum.log ß日志文件位置

exactarch=1     ß有1和0两个选项,设置为1,则yum只会安装和系统架构匹配的软件包。

obsoletes=1     ß update的参数,相当于upgrade,允许更新陈旧的RPM包。

gpgcheck=1     ß

plugins=1 ß是否启用插件,默认1为允许,0表示不允许

installonly_limit=5

bugtracker_url=http://bugs.centos.org/set_project.php?project_id=16&ref=http://bugs.centos.org/bug_report_page.php?category=yum

distroverpkg=centos-release ß指定一个软件包,yum会根据这个包判断发行版本

2.2yum仓库配置文件

repository部分定义了每个源服务器的具体配置,可以有一到多个,位于/etc/yum.repos.d/目录下的各文件中

[root@XuBuSi ~]# ll /etc/yum.repos.d/

CentOS-Base.repo   ß网络源的配置文件

CentOS-Media.repo         ß本地源的配置文件

epel.repo ß第三方源的配置文件

2.3配置本地yum

[root@XuBuSi ~]# grep -v “^#”
/etc/yum.repos.d/CentOS-Media.repo

 

[c6-media]

name=CentOS-$releasever – Media

baseurl=file:///media/CentOS/

file:///media/cdrom/       ß修改为/mnt/cdrom(即为光盘挂载点)

file:///media/cdrecorder/

gpgcheck=1

enabled=0 ß改为1就启动,没有此参数也是启用。

gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6

#当然也可以像上面自己写一个文件,然后指定为下载点即可。

3.企业yum仓库搭建实战

上面只是将自己制作的rpm包,放入yum源。但还有一种企业需求,说的更具体一点,平时学生上课yum安装软件都是从公网下载的,占用带宽,因此在学校里搭建一个内网yum服务器,但又考虑到学生回家也要使用yum安装软件,如果yum软件的数据库文件repodata不一样,就会有问题。因此我想到的解决方法就是直接使用公网yum源的repodata。

 

镜像同步公网yum源上游yum源必须要支持rsync协议,否则不能使用rsync进行同步。http://mirrors.ustc.edu.cn/status/

CentOS官方标准源:rsync://mirrors.ustc.edu.cn/centos/

epel源:rsync://mirrors.ustc.edu.cn/epel/

同步命令:

# 使用rsync同步yum源,为了节省带宽、磁盘和下载时间,我只同步了CentOS6的rpm包,这样所有的rpm包只占用了21G,全部同步需要300G左右。

# 同步base源,小技巧,我们安装系统的光盘镜像含有部分rpm包,大概3G,这些就不用重新下载。

/usr/bin/rsync -av
rsync://mirrors.ustc.edu.cn/centos/6/os/x86_64/
/data/yum_data/centos/6/os/x86_64/

/usr/bin/rsync -av
rsync://mirrors.ustc.edu.cn/centos/6/extras/x86_64/
/data/yum_data/centos/6/extras/x86_64/

/usr/bin/rsync -av rsync://mirrors.ustc.edu.cn/centos/6/updates/x86_64/
/data/yum_data/centos/6/updates/x86_64/

# epel源

/usr/bin/rsync -av –exclude=debug
rsync://mirrors.ustc.edu.cn/epel/6/x86_64/ /data/yum_data/epel/6/x86_64/

学生使用内网yum源方法

# 可以自建一个内网dns,如果没有,可使用hosts解析。

echo
‘192.168.0.200 mirrors.aliyun.com’ >>/etc/hosts

转自:http://www.xuliangwei.com/xubusi/40.html

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

搭建CentOS在线yum源镜像服务器

时间:2014-09-04 00:48来源:osyunwei.com 作者:osyunwei.com 举报 点击:5827次

说明:

操作系统:CentOS 6.x

IP地址:192.168.21.188

实现目的:同步CentOS镜像站点的内容到此服务器,并且通过配置http服务器,能够向外提供yum服务

准备篇:

一、安装http服务器

这里使用Nginx服务器提供http服务

关于Nginx服务器搭建,参考:CentOS安装配置LNMP服务器(Nginx+PHP+MySQL)

http://www.osyunwei.com/archives/5910.html

二、系统约定

Nginx站点根目录:/usr/local/nginx/html

服务器执行脚本文件存放目录:/home/crontab

三、开始Nginx目录浏览功能

vi /usr/local/nginx/conf/nginx.conf #编辑配置文件,在http {下面添加以下内容:

autoindex on; #开启nginx目录浏览功能

autoindex_exact_size off; #文件大小从KB开始显示

autoindex_localtime on; #显示文件修改时间为服务器本地时间

:wq! #保存,退出

service nginx reload #重新加载配置

参考:Nginx开启目录浏览功能

http://www.osyunwei.com/archives/5051.html

系统运维  www.osyunwei.com  温馨提醒:qihang01原创内容©版权所有,转载请注明出处及原文链

安装篇:

一、创建镜像文件存放目录

mkdir -p /usr/local/nginx/html/centos #CentOS官方标准源

mkdir -p /usr/local/nginx/html/repoforge #第三方rpmforge源

mkdir -p /usr/local/nginx/html/epel #第三方epel源

说明:这里创建三个文件夹,分别存放CentOS官方标准源、第三方的rpmforge源和epel源

二、确定以上三个yum源上游源的同步镜像地址

1、CentOS官方标准源:rsync://mirrors.ustc.edu.cn/centos/

2、rpmforge源:rsync://mirrors.ispros.com.bd/repoforge/

3、epel源:rsync://mirrors.ustc.edu.cn/epel/

备注:上游yum源必须要支持rsync协议,否则不能使用rsync进行同步。

参考:

CentOS官方标准源:

rsync://mirrors.kernel.org/centos

rpmforge源:

http://apt.sw.be/

rsync://ftp-stud.fht-esslingen.de/dag

epel源:

http://mirrors.fedoraproject.org/publiclist/EPEL/

rsync://mirrors.kernel.org/fedora-epel

三、创建以上三个yum源同步脚本,并且设定脚本自动执行

mkdir -p /home/crontab #创建目录

vi /home/crontab/yum_rsync.sh #添加以下代码

#!/bin/sh

/usr/bin/rsync -avrt rsync://mirrors.ustc.edu.cn/centos/ –exclude-from=/usr/local/nginx/html/exclude_centos.list /usr/local/nginx/html/centos/

/usr/bin/rsync -avrt rsync://mirrors.ispros.com.bd/repoforge/ –exclude-from=/usr/local/nginx/html/exclude_repoforge.list /usr/local/nginx/html/repoforge/

/usr/bin/rsync -avrt rsync://mirrors.ustc.edu.cn/epel/ –exclude-from=/usr/local/nginx/html/exclude_epel.list /usr/local/nginx/html/epel/

:wq! #保存退出

chmod +x /home/crontab/yum_rsync.sh #添加脚本执行权限

备注:运行此脚本前,先要创建好同步目录及不需要同步的目录列表文件

cd /usr/local/nginx/html/   #进入目录

touch exclude_centos.list   #创建文件

touch exclude_repoforge.list   #创建文件

touch exclude_epel.list   #创建文件

把不需要同步的目录写到上面对应的文件中,每行一个目录

例如:

vi exclude_epel.list

4/

4AS/

4ES/

4WS/

:wq! #保存退出

四、添加脚本定时执行任务

vi /etc/crontab  #在最后一行添加以下代码

0 1 * * * root /home/crontab/yum_rsync.sh #设置每天凌晨1点整开始执行脚本

:wq! #保存退出

service crond restart #重启

测试篇:

一、安装rsync同步软件

yum install rsync xinetd #安装

vi /etc/xinetd.d/rsync #编辑配置文件,设置开机启动rsync

disable = no #修改为

/etc/init.d/xinetd start #启动(CentOS中是以xinetd 来管理Rsync服务的)

:wq! #保存退出

二、执行同步脚本

sh /home/crontab/yum_rsync.sh

注意:等待脚本执行完毕,首次同步,耗费的时间比较长!

三、根据不同版本创建三个yum源的repo配置文件

cd /etc/yum.repos.d/ #进入目录

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

1、CentOS官方标准源:

CentOS 5.x系列:

vi /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 – huanqiu.com

baseurl=http://192.168.21.188/centos/$releasever/os/$basearch/

#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os

gpgcheck=1

gpgkey=http://192.168.21.188/centos/RPM-GPG-KEY-CentOS-5

#released updates

[updates]

name=CentOS-$releasever – Updates – huanqiu.com

baseurl=http://192.168.21.188/centos/$releasever/updates/$basearch/

#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates

gpgcheck=1

gpgkey=http://192.168.21.188/centos/RPM-GPG-KEY-CentOS-5

#packages used/produced in the build but not released

[addons]

name=CentOS-$releasever – Addons – huanqiu.com

baseurl=http://192.168.21.188/centos/$releasever/addons/$basearch/

#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=addons

gpgcheck=1

gpgkey=http://192.168.21.188/centos/RPM-GPG-KEY-CentOS-5

#additional packages that may be useful

[extras]

name=CentOS-$releasever – Extras – huanqiu.com

baseurl=http://192.168.21.188/centos/$releasever/extras/$basearch/

#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras

gpgcheck=1

gpgkey=http://192.168.21.188/centos/RPM-GPG-KEY-CentOS-5

#additional packages that extend functionality of existing packages

[centosplus]

name=CentOS-$releasever – Plus – huanqiu.com

baseurl=http://192.168.21.188/centos/$releasever/centosplus/$basearch/

#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=centosplus

gpgcheck=1

enabled=0

gpgkey=http://192.168.21.188/centos/RPM-GPG-KEY-CentOS-5

#contrib – packages by Centos Users

[contrib]

name=CentOS-$releasever – Contrib – huanqiu.com

baseurl=http://192.168.21.188/centos/$releasever/contrib/$basearch/

#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=contrib

gpgcheck=1

enabled=0

gpgkey=http://192.168.21.188/centos/RPM-GPG-KEY-CentOS-5

:wq! #保存退出

#########################

CentOS 6.x系列:

vi /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 – huanqiu.com

baseurl=http://192.168.21.188/centos/$releasever/os/$basearch/

#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os

gpgcheck=1

gpgkey=http://192.168.21.188/centos/RPM-GPG-KEY-CentOS-6

#released updates

[updates]

name=CentOS-$releasever – Updates – huanqiu.com

baseurl=http://192.168.21.188/centos/$releasever/updates/$basearch/

#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates

gpgcheck=1

gpgkey=http://192.168.21.188/centos/RPM-GPG-KEY-CentOS-6

#additional packages that may be useful

[extras]

name=CentOS-$releasever – Extras – huanqiu.com

baseurl=http://192.168.21.188/centos/$releasever/extras/$basearch/

#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras

gpgcheck=1

gpgkey=http://192.168.21.188/centos/RPM-GPG-KEY-CentOS-6

#additional packages that extend functionality of existing packages

[centosplus]

name=CentOS-$releasever – Plus – huanqiu.com

baseurl=http://192.168.21.188/centos/$releasever/centosplus/$basearch/

#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=centosplus

gpgcheck=1

enabled=0

gpgkey=http://192.168.21.188/centos/RPM-GPG-KEY-CentOS-6

#contrib – packages by Centos Users

[contrib]

name=CentOS-$releasever – Contrib – huanqiu.com

baseurl=http://192.168.21.188/centos/$releasever/contrib/$basearch/

#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=contrib

gpgcheck=1

enabled=0

gpgkey=http://192.168.21.188/centos/RPM-GPG-KEY-CentOS-6

:wq! #保存退出

#########################

CentOS 7.x系列:

vi /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

#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os

baseurl=http://192.168.21.188/centos/$releasever/os/$basearch/

gpgcheck=1

gpgkey=http://192.168.21.188/centos/RPM-GPG-KEY-CentOS-7

#released updates

[updates]

name=CentOS-$releasever – Updates

#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates

baseurl=http://192.168.21.188/centos/$releasever/updates/$basearch/

gpgcheck=1

gpgkey=http://192.168.21.188/centos/RPM-GPG-KEY-CentOS-7

#additional packages that may be useful

[extras]

name=CentOS-$releasever – Extras

#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras

baseurl=http://192.168.21.188/centos/$releasever/extras/$basearch/

gpgcheck=1

gpgkey=http://192.168.21.188/centos/RPM-GPG-KEY-CentOS-7

#additional packages that extend functionality of existing packages

[centosplus]

name=CentOS-$releasever – Plus

#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=centosplus

baseurl=http://192.168.21.188/centos/$releasever/centosplus/$basearch/

gpgcheck=1

enabled=0

gpgkey=http://192.168.21.188/centos/RPM-GPG-KEY-CentOS-7

:wq! #保存退出

#########################

或者参考:https://lug.ustc.edu.cn/wiki/mirrors/help/centos

把里面的http://mirrors.ustc.edu.cn/替换为http://192.168.21.188/

2、rpmforge源:

CentOS 5.x系列:

vi /etc/yum.repos.d/rpmforge.repo #添加以下代码

[rpmforge]

name = RHEL $releasever – RPMforge.net – dag

baseurl = http://192.168.21.188/repoforge/redhat/el5/en/$basearch/rpmforge

enabled = 1

protect = 0

gpgkey=http://192.168.21.188/repoforge/RPM-GPG-KEY-rpmforge

gpgcheck = 1

[rpmforge-extras]

name = RHEL $releasever – RPMforge.net – extras

baseurl = http://192.168.21.188/repoforge/redhat/el5/en/$basearch/extras

enabled = 0

protect = 0

gpgkey=http://192.168.21.188/repoforge/RPM-GPG-KEY-rpmforge

gpgcheck = 1

[rpmforge-testing]

name = RHEL $releasever – RPMforge.net – testing

baseurl = http://192.168.21.188/repoforge/redhat/el5/en/$basearch/testing

enabled = 0

protect = 0

gpgkey=http://192.168.21.188/repoforge/RPM-GPG-KEY-rpmforge

gpgcheck = 1

:wq! #保存退出

#########################

系统运维  www.osyunwei.com  温馨提醒:qihang01原创内容©版权所有,转载请注明出处及原文链

CentOS 6.x系列:

vi /etc/yum.repos.d/rpmforge.repo #添加以下代码

[rpmforge]

name = RHEL $releasever – RPMforge.net – dag

baseurl = http://192.168.21.188/repoforge/redhat/el6/en/$basearch/rpmforge

enabled = 1

protect = 0

gpgkey=http://192.168.21.188/repoforge/RPM-GPG-KEY-rpmforge

gpgcheck = 1

[rpmforge-extras]

name = RHEL $releasever – RPMforge.net – extras

baseurl = http://192.168.21.188/repoforge/redhat/el6/en/$basearch/extras

enabled = 0

protect = 0

gpgkey=http://192.168.21.188/repoforge/RPM-GPG-KEY-rpmforge

gpgcheck = 1

[rpmforge-testing]

name = RHEL $releasever – RPMforge.net – testing

baseurl = http://192.168.21.188/repoforge/redhat/el6/en/$basearch/testing

enabled = 0

protect = 0

gpgkey=http://192.168.21.188/repoforge/RPM-GPG-KEY-rpmforge

gpgcheck = 1

:wq! #保存退出

#########################

CentOS 7.x系列:

vi /etc/yum.repos.d/rpmforge.repo #添加以下代码

[rpmforge]

name = RHEL $releasever – RPMforge.net – dag

baseurl = http://192.168.21.188/repoforge/redhat/el7/en/$basearch/rpmforge

enabled = 1

protect = 0

gpgkey=http://192.168.21.188/repoforge/RPM-GPG-KEY-rpmforge

gpgcheck = 1

[rpmforge-extras]

name = RHEL $releasever – RPMforge.net – extras

baseurl = http://192.168.21.188/repoforge/redhat/el7/en/$basearch/extras

enabled = 0

protect = 0

gpgkey=http://192.168.21.188/repoforge/RPM-GPG-KEY-rpmforge

gpgcheck = 1

[rpmforge-testing]

name = RHEL $releasever – RPMforge.net – testing

baseurl = http://192.168.21.188/repoforge/redhat/el7/en/$basearch/testing

enabled = 0

protect = 0

gpgkey=http://192.168.21.188/repoforge/RPM-GPG-KEY-rpmforge

gpgcheck = 1

:wq! #保存退出

#########################

3、epel源:

CentOS 5.x系列:

vi /etc/yum.repos.d/epel.repo #添加以下代码

[epel]

name=Extra Packages for Enterprise Linux 5 – $basearch

baseurl=http://192.168.21.188/epel/5/$basearch

failovermethod=priority

enabled=1

gpgcheck=1

gpgkey =http://192.168.21.188/epel/RPM-GPG-KEY-EPEL-5

[epel-debuginfo]

name=Extra Packages for Enterprise Linux 5 – $basearch – Debug

baseurl=http://192.168.21.188/epel/5/$basearch/debug

failovermethod=priority

enabled=0

gpgkey =http://192.168.21.188/epel/RPM-GPG-KEY-EPEL-5

gpgcheck=1

[epel-source]

name=Extra Packages for Enterprise Linux 5 – $basearch – Source

baseurl=http://192.168.21.188/epel/5/SRPMS

failovermethod=priority

enabled=0

gpgkey =http://192.168.21.188/epel/RPM-GPG-KEY-EPEL-5

gpgcheck=1

:wq! #保存退出

#########################

CentOS 6.x系列:

vi /etc/yum.repos.d/epel.repo #添加以下代码

[epel]

name=Extra Packages for Enterprise Linux 6 – $basearch

baseurl=http://192.168.21.188/epel/6/$basearch

failovermethod=priority

enabled=1

gpgcheck=1

gpgkey =http://192.168.21.188/epel/RPM-GPG-KEY-EPEL-6

[epel-debuginfo]

name=Extra Packages for Enterprise Linux 6 – $basearch – Debug

baseurl=http://192.168.21.188/epel/6/$basearch/debug

failovermethod=priority

enabled=0

gpgkey =http://192.168.21.188/epel/RPM-GPG-KEY-EPEL-6

gpgcheck=1

[epel-source]

name=Extra Packages for Enterprise Linux 6 – $basearch – Source

baseurl=http://192.168.21.188/epel/6/SRPMS

failovermethod=priority

enabled=0

gpgkey =http://192.168.21.188/epel/RPM-GPG-KEY-EPEL-6

gpgcheck=1

:wq! #保存退出

#########################

CentOS 7.x系列:

vi /etc/yum.repos.d/epel.repo #添加以下代码

[epel]

name=Extra Packages for Enterprise Linux 7 – $basearch

baseurl=http://192.168.21.188/epel/beta/7/$basearch

failovermethod=priority

enabled=1

gpgcheck=1

gpgkey =http://192.168.21.188/epel/RPM-GPG-KEY-EPEL-7

[epel-debuginfo]

name=Extra Packages for Enterprise Linux 7 – $basearch – Debug

baseurl=http://192.168.21.188/epel/beta/7/$basearch/debug

failovermethod=priority

enabled=0

gpgkey =http://192.168.21.188/epel/RPM-GPG-KEY-EPEL-7

gpgcheck=1

[epel-source]

name=Extra Packages for Enterprise Linux 7 – $basearch – Source

baseurl=http://192.168.21.188/epel/beta/7/SRPMS

failovermethod=priority

enabled=0

gpgkey =http://192.168.21.188/epel/RPM-GPG-KEY-EPEL-7

gpgcheck=1

:wq! #保存退出

#########################

四、测试yum源是否配置正确

1、当前系统版本为CentOS 6.x,以此为例

cd /etc/yum.repos.d/

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

vi 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 – huanqiu.com

baseurl=http://192.168.21.188/centos/$releasever/os/$basearch/

#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os

gpgcheck=1

gpgkey=http://192.168.21.188/centos/RPM-GPG-KEY-CentOS-6

#released updates

[updates]

name=CentOS-$releasever – Updates – huanqiu.com

baseurl=http://192.168.21.188/centos/$releasever/updates/$basearch/

#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates

gpgcheck=1

gpgkey=http://192.168.21.188/centos/RPM-GPG-KEY-CentOS-6

#additional packages that may be useful

[extras]

name=CentOS-$releasever – Extras – huanqiu.com

baseurl=http://192.168.21.188/centos/$releasever/extras/$basearch/

#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras

gpgcheck=1

gpgkey=http://192.168.21.188/centos/RPM-GPG-KEY-CentOS-6

#additional packages that extend functionality of existing packages

[centosplus]

name=CentOS-$releasever – Plus – huanqiu.com

baseurl=http://192.168.21.188/centos/$releasever/centosplus/$basearch/

#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=centosplus

gpgcheck=1

enabled=0

gpgkey=http://192.168.21.188/centos/RPM-GPG-KEY-CentOS-6

#contrib – packages by Centos Users

[contrib]

name=CentOS-$releasever – Contrib – huanqiu.com

baseurl=http://192.168.21.188/centos/$releasever/contrib/$basearch/

#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=contrib

gpgcheck=1

enabled=0

gpgkey=http://192.168.21.188/centos/RPM-GPG-KEY-CentOS-6

:wq! #保存退出

#########################

vi rpmforge.repo #添加以下代码

[rpmforge]

name = RHEL $releasever – RPMforge.net – dag

baseurl = http://192.168.21.188/repoforge/redhat/el6/en/$basearch/rpmforge

enabled = 1

protect = 0

gpgkey=http://192.168.21.188/repoforge/RPM-GPG-KEY-rpmforge

gpgcheck = 1

[rpmforge-extras]

name = RHEL $releasever – RPMforge.net – extras

baseurl = http://192.168.21.188/repoforge/redhat/el6/en/$basearch/extras

enabled = 0

protect = 0

gpgkey=http://192.168.21.188/repoforge/RPM-GPG-KEY-rpmforge

gpgcheck = 1

[rpmforge-testing]

name = RHEL $releasever – RPMforge.net – testing

baseurl = http://192.168.21.188/repoforge/redhat/el6/en/$basearch/testing

enabled = 0

protect = 0

gpgkey=http://192.168.21.188/repoforge/RPM-GPG-KEY-rpmforge

gpgcheck = 1

:wq! #保存退出

#########################

vi epel.repo #添加以下代码

[epel]

name=Extra Packages for Enterprise Linux 6 – $basearch

baseurl=http://192.168.21.188/epel/6/$basearch

failovermethod=priority

enabled=1

gpgcheck=1

gpgkey =http://192.168.21.188/epel/RPM-GPG-KEY-EPEL-6

[epel-debuginfo]

name=Extra Packages for Enterprise Linux 6 – $basearch – Debug

baseurl=http://192.168.21.188/epel/6/$basearch/debug

failovermethod=priority

enabled=0

gpgkey =http://192.168.21.188/epel/RPM-GPG-KEY-EPEL-6

gpgcheck=1

[epel-source]

name=Extra Packages for Enterprise Linux 6 – $basearch – Source

baseurl=http://192.168.21.188/epel/6/SRPMS

failovermethod=priority

enabled=0

gpgkey =http://192.168.21.188/epel/RPM-GPG-KEY-EPEL-6

gpgcheck=1

:wq! #保存退出

#########################

系统运维  www.osyunwei.com  温馨提醒:qihang01原创内容©版权所有,转载请注明出处及原文链

yum clean all #清除当前yum缓存

yum makecache #缓存yum源中的软件包信息

yum repolist #列出yum源中可用的软件包

2、使用yum命令安装软件

yum install php #测试CentOS官方标准源

yum install htop #测试rpmforge源

yum install nginx #测试epel源

至此,搭建CentOS在线yum源镜像服务器完成!

转自:http://www.centoscn.com/CentosServer/test/2014/0904/3675.html

Categories: OS

0 Comments

Leave a Reply

Avatar placeholder

Your email address will not be published. Required fields are marked *