构建本地YUM源服务器

       

如何构建本地源

通过从 DVD 光盘、YUM 客户端缓存目录(/var/cache/yum/)以及 Internet 下载等途径获取需

要的 rpm 包,可以组建基于本地文件系统的 rpm 软件包仓库。进一步结合使用 HTTP 或 FTP 协议

的服务软件,即可构建一个位于本地局域网的高速 YUM"源"服务器。

本例中使用 RHEL5 安装光盘(DVD)中的软件包组成软件仓库,并结合 VSFTPD 服务,提

供基于 FTP 方式的简易 YUM 源。实现的主要步骤如下。

1. 安装 vsftpd、createrepo 软件包

createrepo 工具主要用于收集目录中 rpm 包文件的头信息,以创建 repodata 软件仓库数

据(经 gzip 压缩的 xml 文件)。
[root@yumserver ~]# mkdir -p /media/cdrom
[root@yumserver ~]# mount /dev/cdrom /media/cdrom
mount: block device /dev/cdrom is write-protected, mounting read-only
[root@yumserver ~]# cd /media/cdrom/Server/
[root@yumserver Server]# rpm -ivh createrepo-0.4.4-2.fc6.noarch.rpm
vsftpd-2.0.5-10.el5.i386.rpm
warning: createrepo-0.4.4-2.fc6.noarch.rpm: Header V3 DSA signature: NOKEY, key ID
37017186
Preparing...########################################### [100%]
1:vsftpd########################################### [ 50%]
2:createrepo###########################################  [100%]

2. 准备软件库目录

注意要保证/var/ftp/rhel5 目录有足够的可用空间(在本例中最好大于 3GB),以便存放复

制的软件包。必要时可以使用单独的硬盘分区(挂载到/var/ftp/rhel5 目录中)。

[root@yumserver Server]# mkdir -p /var/ftp/rhel5/
[root@yumserver Server]# cp -prf /media/cdrom/* /var/ftp/rhel5/
查看复制好的目录结构:Cluster、ClusterStorage、Server、VT——主要是光盘中包含 rpm

软件包的几个文件夹)。

[root@yumserver Server]# ls -lh /var/ftp/rhel5/ | grep ^d
drwxr-xr-x 3 root root 6.0K 2007-03-18 Cluster
drwxr-xr-x 3 root root 6.0K 2007-03-18 ClusterStorage
drwxr-xr-x 4 root root 2.0K 2007-03-18 p_w_picpaths
drwxr-xr-x 2 root root 2.0K 2007-03-18 isolinux
drwxr-xr-x 3 root root 330K 2007-03-18 Server
drwxr-xr-x 3 root root 6.0K 2007-03-18 VT
3. 创建 repository 仓库信息文件

在各个软件包目录中分别执行 createrepo 命令,生成当前目录下的 repodata 数据。使用

-g 选项可以指定用于创建组信息的 xml 文件模板。

[root@yumserver ~]# cd /var/ftp/rhel5/Cluster/
[root@yumserver Cluster]# createrepo -g repodata/comps-rhel5-cluster.xml ./

[root@yumserver Cluster]# cd /var/ftp/rhel5/ClusterStorage/
[root@yumserver ClusterStorage]# createrepo -g repodata/comps-rhel5-cluster-st.xml ./

[root@yumserver ClusterStorage]# cd /var/ftp/rhel5/Server/
[root@yumserver Server]# createrepo -g repodata/comps-rhel5-server-core.xml ./

[root@yumserver Server]# cd /var/ftp/rhel5/VT/
[root@yumserver VT]# createrepo -g repodata/comps-rhel5-vt.xml ./

[root@yumserver VT]# rm -rf /var/ftp/rhel5/*/.olddata/ //清除旧的数据文件
4. 配置启动 vsftpd 服务(开启默认的匿名 FTP 服务即可)

[root@yumserver ~]# chkconfig --level 2345 vsftpd on
[root@yumserver ~]# service vsftpd start
若 FTP 服务无法访问,请参考以下配置重新启动 vsftpd 服务:

[root@yumserver ~]# vi /etc/vsftpd/vsftpd.conf
anonymous_enable=yes
local_enable=NO
write_enable=no
dirmessage_enable=YES
xferlog_enable=YES
connect_from_port_20=YES
pasv_enable=YES
pasv_max_port=3200
pasv_min_port=3100
xferlog_std_format=YES
listen=YES
listen_address=192.168.0.11
pam_service_name=vsftpd
tcp_wrappers=yes
//服务器的 IP 地址
[root@yumserver ~]# service vsftpd restart
 

1.3 使用 yum 工具安装软件

最常用的 YUM 客户端工具是字符模式下的 yum 命令,在 RHEL5 系统中由默认安装的
yum-3.0.1-5.el5 软件包提供。RHEL5 系统还提供了一个图形 YUM 工具 pirut,该工具只是 yum 工

具的一个 X 图形前端。
 

1.3.1 设置 YUM 源位置

使用 YUM 源服务器之前,必须为客户端建立指定的配置文件,设置好源服务器的位置和可用

目录等选项。


[root@client ~]# cd /etc/yum.repos.d/
[root@client yum.repos.d]# vi rhel5-pkgs-yumsvr.repo
[Cluster]
name=Cluster Directory
baseurl=ftp://192.168.0.11/rhel5/Cluster
enabled=1
gpgcheck=0

[ClusterStorage]
//启用该目录
//不检查 gpg key
//新建配置文件,名称自定
name=ClusterStorage Directory
baseurl=ftp://192.168.0.11/rhel5/ClusterStorage
enabled=1
gpgcheck=0

[Server]
name=Server Directory
baseurl=ftp://192.168.0.11/rhel5/Server
enabled=1
gpgcheck=0

[VT]
name=VT Directory
baseurl=ftp://192.168.0.11/rhel5/VT
enabled=1
gpgcheck=0

[root@client yum.repos.d]# yum clean all
//更新缓存
 

1.3.2 使用 yum 命令

1. 列表查看软件包信息

可以使用 list 选项查看软件包相关的各项信息。
[root@client ~]# yum list updates
[root@client ~]# yum list installed
[root@client ~]# yum list available
[root@client ~]# yum list available lynx*
[root@client ~]# yum info installed bind
//查看有哪些可用于升级的软件包
//查看本机已安装的软件包
//查看 yum 源中所有可用的软件包
//查看 yum 源中以 lynx 开头的软件包
//查看已安装的 bind 软件包的信息
 

2. 软件包升级、卸载、安装

升级(update)、卸载(remove)、安装(install)软件包时,系统会自动检查并解决软件

包之间的依赖关系。开始各项操作前,系统会提示用户按 y 键进行确认(如果希望系统自动回答为 y,可以在 yum 命令后增加-y 选项)。
[root@client ~]# yum -y update
[root@client ~]# yum update bind
//升级所有可用的软件包,由系统自动确认
//升级 bind 软件包
[root@client ~]# yum remove net-snmp-utils
[root@client ~]# yum install lynx
//卸载 net-snmp-utils 软件包
//安装 lynx 软件包
 

1.3.3 使用图形工具"添加删除程序"

在 RHEL5 系统中,进入 X-Windows 图形模式以后,可以使用系统自带的"添加删除程序"工具

(pirut)进行软件包的升级、安装、卸载等管理。

点击GNOME面板菜单组"应用程序"中的"添加删除程序",或者运行"pirut"就可以打开该工具

(如图 1.1所示)。运行RHEL5 提供的系统配置链接"system-config-packages"也可以打开该工具。
 

构建本地YUM源服务器_linux