您的位置:首页 > 其它

架设内部yum服务器

2016-02-17 13:13 323 查看
yum(Yellow dog Updater, Modified) 是一个与apt类似的软件包管理器,在Fedora,Redhat,SUSE,CentOS等Linux发行版中采用。

软件包管理器可以解决rpm的依赖管理问题,使得软件的安装、升级更加容易。

yum使用中心仓库(repository)最为软件源,管理软件包,而各Linux系统通过yum的配置连接到这个源来获取软件包。

Table of Contents

1 理由
2 规划
3 架设
4 使用

1 理由

尽管有很多的免费镜像提供yum源服务,但是还是有必要建立自己的yum服务器,主要出于以下几点考虑:
网络速度:访问互联网可能比较慢
节省带宽:如果有大量的服务器,架设自己的yum源可以有效节省互联网带宽
联网限制:对于有些内网服务器,不能连接到互联网
对于RHEL(Redhat Enterprise Linux),需要购买服务
便于发布自己开发的rpm包

2 规划

本公司服务器操作系统主要是RHEL和CentOS,所以希望同时提供这些操作系统的yum源。
由于没有购买RHEL服务,所以RHEL源使用DVD中的文件构建一个“静态”的源。
而CentOS则可以与一个发布的源进行同步,以保持更新。官方认可的镜像服务可以在 http://www.centos.org/modules/tinycontent/index.php?id=32 查找速度较快并且支持rsync的镜像,但是我找到了一个国内的镜像不在该列表中:
mirrors.ustc.edu.cn/centos/. 这个镜像支持rsync 服务,可以进行同步更新。
yum源的规划如下: http://dev.mycompony.com/mirrors/ centos/
centos源,其目录结构与其他镜像站点相同
rhel/ RHEL源 6Server/ 5erver/ os/ x8664/ # 将RHEL dvd的iso光盘文件挂载到此目录 updates/ x8664/ # 使用mirrordir从ftp://ftp.redhat.com/redhat/linux/updates/rhn/5Server/x86_64/ 同步
custom/ x8664/ # 自己开发的内部使用的软件包 Packages/ # 打包的rpm文件 repodata/ # 用createrepo生成的索引文件 RPM-GPG-KEY-redhat-5Server RPM-GPG-KEY-redhat-6Server CentOS-mycompany.repo RHEL-mycompany.repo

3 架设

yum源可以使用http或ftp提供服务,这里使用nginx作为webserver,提供http方式的访问。
1.在/path/to/your/mirrors 创建好上面规划的目录结构。
对于centos,使用命令:

    rsync -avrt rsync://mirrors.ustc.edu.cn/centos/ –exclude=debug/ –exclude=i386/ –exclude=isos/ /path/to/your/mirrors/centos 

可以实现同步。也可以将此命令加入crontab,我设置的周期是每天同步。
对于RHEL,分成几个部分:

1)用dvd镜像文件提供基本的软件包,只需要将RHEL dvd的iso光盘文件挂载到对应的目录即可,同时为了方便,可以将其中的RPM-GPG-KEY文件复制到/path/to/your/mirrors/RHEL目录下面,并按照版本命名。 

2)对于rhn提供的updates,也可以建立一个镜像。由于redhat.com不提供rsync服务,需要用mirrordir实现同步: 

   mirrordir ftp://ftp.redhat.com/redhat/linux/updates/rhn/5Server/x86_64/ /var/files/mirrors/RHEL/5Server/updates/x86_64

如果没有安装mirrordir,可以从 http://genotec.linux.tucows.com/files/mirrordir-0.10.49.tar.gz 下载。
该命令也可以加入到crontab的计划任务中以实现定期同步。
3)如果有一下内部开发的软件包,可以创建一个custom文件夹,将发布的rpm放到其中的Packages目录,再通过命令: 

   cd path/to/your/mirrors/RHEL/5server/custom/x8664 createrepo -o . Packages 

创建索引文件

4 使用

为了便于使用,可以提供写好的repo文件,用户只需放到/etc/yum.repos.d/目录下,再执行yum update 即可。这里创建了CentOS-mycompany.repo 和 RHEL-mycompany.repo 放到/path/to/your/mirrors目录下,分别用于CentOS和RHEL。
在repo文件中可以尽量使用变量,以提高通用性。常用的变量包括:
$releasever,发行版的版本
$arch,cpu体系(划分过于细致,在repo文件中一般不使用,而是使用下面的$basearch)
$basearch,cpu的基本体系组
我的两个repo文件参考如下:
RHEL-mycompany.repo:

[base]
name=RHEL-mycompany - Base
baseurl=http://dev.mycompany.com/mirrors/RHEL/$releasever/os/$basearch/
enabled=1
gpgcheck=1
gpgkey=http://dev.mycompany.com/mirrors/centos/RPM-GPG-KEY-redhat-$releasever

[updates]
name=RHEL-mycompany - Update
baseurl=http://dev.mycompany.com/mirrors/RHEL/$releasever/updates/$basearch/
enabled=1
gpgcheck=1
gpgkey=http://dev.mycompany.com/mirrors/centos/RPM-GPG-KEY-redhat-$releasever

[extras]
name=RHEL-mycompany - Extra
baseurl=http://dev.mycompany.com/mirrors/RHEL/$releasever/extras/$basearch/
enabled=1
gpgcheck=1
gpgkey=http://dev.mycompany.com/mirrors/centos/RPM-GPG-KEY-redhat-$releasever

[custom]
name=RHEL-mycompany - Custom
baseurl=http://dev.mycompany.com/mirrors/RHEL/$releasever/custom/$basearch/
enabled=1
gpgcheck=1
gpgkey=http://dev.mycompany.com/mirrors/centos/RPM-GPG-KEY-redhat-$releasever


CentOS-mycompany.repo:

[base]
name=CentOS-mycompany - Base
baseurl=http://dev.mycompany.com/mirrors/centos/$releasever/os/$basearch/
gpgchecksever=1
gpgkey=http://dev.mycompany.com/mirrors/centos/RPM-GPG-KEY-CentOS-$releasever

#released updates
[update]
name=CentOS-mycompany - Updates
baseurl=http://dev.mycompany.com/mirrors/centos/$releasever/updates/$basearch/
gpgcheck=1
gpgkey=http://dev.mycompany.com/mirrors/centos/RPM-GPG-KEY-CentOS-$releasever

#additional packages that may be useful
[extras]
name=CentOS-mycompany - Extras
baseurl=http://dev.mycompany.com/mirrors/centos/$releasever/extras/$basearch/
gpgcheck=1
gpgkey=http://dev.mycompany.com/mirrors/centos/RPM-GPG-KEY-CentOS-$releasever

#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-mycompany - Plus
baseurl=http://dev.mycompany.com/mirrors/centos/$releasever/centosplus/$basearch/
gpgcheck=1
enabled=0
gpgkey=http://dev.mycompany.com/mirrors/centos/RPM-GPG-KEY-CentOS-$releasever

#contrib - packages by Centos Users
[contrib]
name=CentOS-mycompany - Contrib
baseurl=http://dev.mycompany.com/mirrors/centos/$releasever/contrib/$basearch/
gpgcheck=1
enabled=0
gpgkey=http://dev.mycompany.com/mirrors/centos/RPM-GPG-KEY-CentOS-$releasever

#packages of mycompany
[custom]
name=CentOS-mycompany - custom
baseurl=http://dev.mycompany.com/mirrors/centos/$releasever/custom/$basearch/
gpgcheck=1
enabled=0
gpgkey=http://dev.mycompany.com/mirrors/centos/RPM-GPG-KEY-CentOS-$releasever


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