您的位置:首页 > 理论基础 > 计算机网络

yum 本地源及网络源的配置汇总

2014-09-04 20:49 337 查看
yum 本地源及网络源的配置汇总
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------

yum 本地源的配置
[root@jesse ~]# cd /etc/yum.repos.d/
[root@jesse yum.repos.d]# ls
CentOS-Base.repo CentOS-Media.repo
[root@jesse yum.repos.d]# mv CentOS-Base.repo CentOS-Base.repo.BAK
[root@jesse yum.repos.d]# ls
CentOS-Base.repo.BAK CentOS-Media.repo
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------
[root@jesse yum.repos.d]# vi CentOS-Media.repo
#本地yum源修改成以下配置文件即可
# CentOS-Media.repo
#
# This repo is used to mount the default locations for a CDROM / DVD on
# CentOS-5. You can use this repo and yum to install items directly off the
# DVD ISO that we release.
#
# To use this repo, put in your DVD and use it with the other repos too:
# yum --enablerepo=c5-media [command]
#
# or for ONLY the media repo, do this:
#
# yum --disablerepo=\* --enablerepo=c5-media [command]

[c5-media]
name=CentOS-$releasever - Media
baseurl=file:///mnt/
gpgcheck=0
enabled=1

#wq 保存并退出
#/mount /dev/cdrom mnt
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------
网络源的配置详解:
[root@jesse ~]# cd /etc/yum.repos.d/
[root@jesse yum.repos.d]# ls
CentOS-Base.repo CentOS-Media.repo

[root@jesse yum.repos.d]# vi CentOS-Base.repo
#以下是我修改好的网络源
#改动地点:1注释掉了mirrorlist开头得行,打开baseurl开头的行2:将mirror.centos.org修改成了mirrors.sohu.com
#批量替换方法:vi 命令模式下输入%s/mirror.centos.org/mirrors.sohu.com/g
[base]
name=CentOS-$releasever - Base
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os
baseurl=http://mirrors.sohu.com/centos/$releasever/os/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-5

#released updates
[updates]
name=CentOS-$releasever - Updates
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates
baseurl=http://mirrors.sohu.com/centos/$releasever/updates/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-5

#packages used/produced in the build but not released
[addons]
name=CentOS-$releasever - Addons
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=addons
baseurl=http://mirrors.sohu.com/centos/$releasever/addons/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-5

#additional packages that may be useful
[extras]
name=CentOS-$releasever - Extras
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras
baseurl=http://mirrors.sohu.com/centos/$releasever/extras/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-5

#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://mirrors.sohu.com/centos/$releasever/centosplus/$basearch/
gpgcheck=1
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-5

#contrib - packages by Centos Users
[contrib]
name=CentOS-$releasever - Contrib
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=contrib
baseurl=http://mirrors.sohu.com/centos/$releasever/contrib/$basearch/
gpgcheck=1
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-5

#以上是配置好的较快的网络更新源
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------
默认情况下:yum 安装好后的rpm包会被自动清除,如果我们想不自动清除的话,
[root@jesse ~]# vi /etc/yum.conf
[main]
cachedir=/var/cache/yum
keepcache=1 #将这里的0修改为1
debuglevel=2
#保存退出
#我们安装好后的软件存放的位置:/var/cache/yum/base/packages

服务器端:
1、 由于yum安装支持三种协议:file://、ftp://和http://,因此如果是使用本地文件作为源,则可直接使用file:\\协议,否则需要先准备好ftp或者http服务。这次测试的是ftp源,因此需要配置好ftp服务,并且要把ftp服务配置为可匿名登录,并且要把rpm包都放在ftp匿名登录的root目录下面。Vsftp匿名登录的配置为:
anonymous_enable=YES
anon_root=/share(这个为vsftp匿名登录的root目录,并且其属性不能为/etc/vsftp/ftpusers,/etc/vsftp/user_list文件中所配置的用户,否则不能匿名登录)
如果不配置匿名登录或者匿名登录root目录设置不对会出现如下错误:
[root@srcbdc yum.repos.d]# yum list
Loaded plugins: aliases, rhnplugin, security
This system is not registered with RHN.
RHN support will be disabled. ftp://yumserver/RHEL/Server/repodata/repomd.xml: [Errno 4] IOError: [Errno ftp error] 550 Failed to change directory.
Trying other mirror.
Error: Cannot retrieve repository metadata (repomd.xml) for repository: RHEL-Server. Please verify its path and try again
2、 先检查yum是否已安装,如果没有安装可以从光盘里面安装
[root@srcbdc ~]# rpm -qa|grep yum
yum-security-1.1.16-13.el5
yum-rhn-plugin-0.5.4-13.el5
yum-metadata-parser-1.1.2-3.el5
yum-updatesd-0.9-2.el5
yum-aliases-1.1.16-13.el5
yum-3.2.22-20.el5
3、 安装另一个用于yum的包createrepo
[root@srcbdc Server]# rpm -ivh createrepo-0.4.11-3.el5.noarch.rpm
warning: createrepo-0.4.11-3.el5.noarch.rpm: Header V3 DSA signature: NOKEY, key ID 37017186
Preparing... ########################################### [100%]
1:createrepo ########################################### [100%]
这个工具主要是用来生产yum所需要用到的安装包关系的数据库。
4、 把系统盘中的Server目录和VT目录拷贝到新的目录里面,我的是从ISO文件里面复制出来的
先挂载ISO文件
[root@srcbdc ~]# mount -o loop /instsvr/ISO/rhel-server-6.2-x86_64-dvd.iso /mnt
Copy文件
[root@srcbdc ~]# mkdir -p /instsvr/RHEL6.2/x64
[root@srcbdc ~]# cp -r /mnt/ /instsvr/RHEL6.2/x64
5、 创建rpm关系数据库
[root@srcbdc ~]# createrepo -g /instsvr/RHEL6.2/x64/Server/repodata/*comps-rhel6-Server.xml -o /instsvr/RHEL6.2/x64/Server -i /instsvr/RHEL6.2/x64/Server/listing /instsvr/RHEL6.2/x64/Packages/
[root@srcbdc ~]# createrepo -g /instsvr/RHEL6.2/x64/HighAvailability/repodata/*comps-rhel6-HighAvailability.xml -o /instsvr/RHEL6.2/x64/HighAvailability -i /instsvr/RHEL6.2/x64/HighAvailability/listing /instsvr/RHEL6.2/x64/Packages/
[root@srcbdc ~]# createrepo -g /instsvr/RHEL6.2/x64/LoadBalancer/repodata/*comps-rhel6-LoadBalancer.xml -o /instsvr/RHEL6.2/x64/LoadBalancer -i /instsvr/RHEL6.2/x64/LoadBalancer/listing /instsvr/RHEL6.2/x64/Packages/
[root@srcbdc ~]# createrepo -g /instsvr/RHEL6.2/x64/ResilientStorage/repodata/*comps-rhel6-ResilientStorage.xml -o /instsvr/RHEL6.2/x64/ResilientStorage -i /instsvr/RHEL6.2/x64/ResilientStorage/listing /instsvr/RHEL6.2/x64/Packages/
[root@srcbdc ~]# createrepo -g /instsvr/RHEL6.2/x64/ScalableFileSystem/repodata/*comps-rhel6-ScalableFileSystem.xml -o /instsvr/RHEL6.2/x64/ScalableFileSystem -i /instsvr/RHEL6.2/x64/ScalableFileSystem/listing /instsvr/RHEL6.2/x64/Packages/

创建rpm包的link文件:[root@srcbdc ~]# cd /instsvr/RHEL6.2/x64/Server
[root@srcbdc ScalableFileSystem]# for i in `cat listing`; do ln -s ../Packages/$i $i; done
[root@srcbdc ~]# cd /instsvr/RHEL6.2/x64/HighAvailability
[root@srcbdc ScalableFileSystem]# for i in `cat listing`; do ln -s ../Packages/$i $i; done
[root@srcbdc ~]# cd /instsvr/RHEL6.2/x64/LoadBalancer
[root@srcbdc ScalableFileSystem]# for i in `cat listing`; do ln -s ../Packages/$i $i; done
[root@srcbdc ~]# cd /instsvr/RHEL6.2/x64/ResilientStorage
[root@srcbdc ScalableFileSystem]# for i in `cat listing`; do ln -s ../Packages/$i $i; done
[root@srcbdc ~]# cd /instsvr/RHEL6.2/x64/ScalableFileSystem
[root@srcbdc ScalableFileSystem]# for i in `cat listing`; do ln -s ../Packages/$i $i; done

6、 清除yum缓存信息
[root@srcbdc yum.repos.d]# yum clean all
Loaded plugins: aliases, rhnplugin, security
Cleaning up Everything
7、 再使用yum list名称查看rpm包,正常的话会列出所有的rpm包

客户端:客户端就比较好配置了,只需要在/etc/yum.d.repo/目录小添加本地yum源配置文件即可[root@instsvr1 yum.repos.d]# cat rhel6.2-x64.repo
[RHEL6.2-Server-X64]
name=Red Hat Enterprise Linux Install Server
baseurl=ftp://192.168.220.46/RHEL6.2/x64/Server
enabled=1
gpgcheck=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-RedHat-release
[RHEL6.2-HighAvailability-X64]
name=Red Hat Enterprise Linux Install Server
baseurl=ftp://192.168.220.46/RHEL6.2/x64/HighAvailability/
enabled=1
gpgcheck=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release
[RHEL6.2-LoadBalancer-X64]
name=Red Hat Enterprise Linux Install Server
baseurl=ftp://192.168.220.46/RHEL6.2/x64/LoadBalancer/
enabled=1
gpgcheck=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release
[RHEL6.2-ResilientStorage-X64]
name=Red Hat Enterprise Linux Install Server
baseurl=ftp://192.168.220.46/RHEL6.2/x64/ResilientStorage/
enabled=1
gpgcheck=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release
[RHEL6.2-ScalableFileSystem-X64]
name=Red Hat Enterprise Linux Install Server
baseurl=ftp://192.168.220.46/RHEL6.2/x64/ScalableFileSystem/
enabled=1
gpgcheck=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release
[RHEL-RPMS]
name=Red Hat Enterprise Linux Install Server
baseurl=ftp://192.168.220.46/rpms
enabled=1
gpgcheck=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release

【网摘】
repodata 数据库介绍
repodata 数据库中的文件主要是 XML 格式,精确描述一个 rpm 包的详细信息,如依赖关系,包含文件,校验码信息。目前,这个格式被 apt-rpm,smartpm,red carpet 和 yum 支持。

通常有以下几个文件:
repomd.xml (md 意思是 metadata)
repomd.xml 是描述其他 metadata 文件的文件。相当于其他文件的索引。包含其他文件的时间戳和校验值(checksums)。这样客户端只要下载这一个文件(通常很小,几KB),就可以知道其他文件中哪些有“更新”。这也意味只,只要对这一个文件签名,就可以达到对其他文件签名的作用。
primary.xml.[gz]
这个文件存储主要的 metadata 信息,这些信息包括: repomd.xml this is the file that describes the other metadata files. It is like an index file to point to the other files. It contains timestamps and checksums for the other files. This lets a client download this one, small file and know if anything else has changed. This also means that cryptographically (ex: gpg) signing this one file can ensure repository integrity.

primary.xml.[gz] this file stores the primary metadata information. This includes information such as:
name, epoch, version, release, architecture

file size, file location, description, summary, format, checksums header byte-ranges, etc.

dependencies, provides, conflicts, obsoletes, suggests, recommends

file lists for the package for CERTAIN files - specifically files matching: /etc*, *bin/*, /usr/lib/sendmail [1]

filelists.xml.[gz] this file stores the complete file and directory listings for the packages. The package is identified by: name, epoch, version, release, architecture and package checksum id.

other.xml.[gz] this file currently only stores the changelog data from packages. However, this file could be used for any other additional metadata that could be useful for clients.

groups.xml.[gz] this file is tentatively described. The intention is for a common package-groups specification as well. There is still some sections for this format that need to be fleshed out.

可用的网络yum源:
http://mirrors.163.com/centos/6/os/x86_64/
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: