实验环境介绍
使用Vmware Workstation新建两台虚拟机,安装CentOS release 6.4 (Final) x86_64
两台主机的iptables与SELinux都已经关闭了
CentOS1 计划安装YUM数据仓库 IP为192.168.80.3
CentOS2 计划充当客户端 IP为192.168.80.4

通过光盘,搭建本地yum服务器

本次实验计划通过vsftp来充当YUM数据仓库,需要预装如下软件:

vsftp, ftp, createrepo

以上软件我们先通过挂载光盘,搭建本地源的方式,来安装

1.挂载光盘

# mount /dev/cdrom /media/mount: block device /dev/sr0 is write-protected, mounting read-only

2.检查是否挂载成功

# df -hFilesystem            Size  Used Avail Use% Mounted on/dev/mapper/VolGroup-lv_root                       18G  2.0G   15G  13% /tmpfs                 495M     0  495M   0% /dev/shm/dev/sda1             485M   33M  427M   8% /boot/dev/sr0              4.1G  4.1G     0 100% /media

/media 已经挂载上来了

3.确认repomd.xml的路径

# find /media/ -name repomd.xml/media/repodata/repomd.xml

YUM需要读取软件依赖关系文件repomd.xml

但不同光盘,这个文件的置位置可能并不一样,比如我手上另一个rhel的光盘镜像

# mount -o loop rhel-server-5.4-i386-dvd.iso /mnt# find /mnt/ -name repomd.xml/mnt/Cluster/repodata/repomd.xml/mnt/ClusterStorage/repodata/repomd.xml/mnt/Server/repodata/repomd.xml/mnt/VT/repodata/repomd.xml

可以看到,/mnt目录下面,并没有/repodata目录,如果我们在下面配置YUM客户端时,直接指定数据仓库的路径为/mnt时就会出错,为了以防万一我们先确认该文件所在位置.

4.备份repo文件

# cd /etc/yum.repos.d/# lsCentOS-Base.repo  CentOS-Debuginfo.repo  CentOS-Media.repo  CentOS-Vault.repo# rename repo repo.bak *# lsCentOS-Base.repo.bak  CentOS-Debuginfo.repo.bak  CentOS-Media.repo.bak  CentOS-Vault.repo.bak

5.新建新的YUM客户端配置文件CentOS-Local.repo

我们可以使用 CentOS-Debuginfo.repo.bak 文件来做一个模板

# cp -a CentOS-Debuginfo.repo.bak CentOS-Local.repo# vi /etc/yum.repos.d/CentOS-Local.repo[local]name=CentOS-6 - Localinfobaseurl=file:///mediagpgcheck=1gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6enabled=1

几点说明:

[local]:
YUM容器的标签,名字可以随便取,但在本地所有源中不能重复
name:
YUM容器的名字,对容器进行说明描述,并不重要,但同样不能重复
baseurl:
YUM容器的具体路径,还记得我们上面记录的repomd.xml文件路径吗,这边记录的容器路径,一般是是该文件所在路径的上上个目录,在这就是/media
gpgcheck=1
安装时进行数字签名检查,没有数字签名不允许安装,当gpgcheck=0时,不进行检查
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6
指定数字签名的公钥所在位置,公钥一般放置在/etc/pki/rpm-gpg/目录下
enable=1 1代表启用这个容器,0代表不可用

6.清除YUM缓存

# yum clean allLoaded plugins: fastestmirror, securityCleaning repos: localCleaning up Everything

7.验证本地数据仓库是否可用

#yum repolist allLoaded plugins: fastestmirror, securityDetermining fastest mirrorslocal                                                                                                       | 4.0 kB     00:00 ...local/primary_db                                                                                            | 4.4 MB     00:00 ...repo id                                             repo name                                                        statuslocal                                               CentOS-6 - Localinfo                                             enabled: 6,381repolist: 6,381

8.安装createrepo,vsftp,ftp软件件

检查createrepo有无安装, 该软件包用于生成RPM依赖关系及分组信息

# yum info createrepoLoaded plugins: fastestmirror, securityLoading mirror speeds from cached hostfileAvailable PackagesName        : createrepoArch        : noarchVersion     : 0.9.9Release     : 17.el6Size        : 94 kRepo        : localSummary     : Creates a common metadata repositoryURL         : http://createrepo.baseurl.org/License     : GPLv2Description : This utility will generate a common metadata repository from a directory of            : rpm packages.

看到那个 Available Packages 了吗,就说明该软件未安装,其它软件都可以使用这个方法进行检查.我在下面就不一个个贴出来了.

下面直接安装

# yum -y install createrepoLoaded plugins: fastestmirror, securityLoading mirror speeds from cached hostfileSetting up Install ProcessResolving Dependencies--> Running transaction check---> Package createrepo.noarch 0:0.9.9-17.el6 will be installed--> Processing Dependency: python-deltarpm for package: createrepo-0.9.9-17.el6.noarch--> Running transaction check---> Package python-deltarpm.x86_64 0:3.5-0.5.20090913git.el6 will be installed--> Processing Dependency: deltarpm = 3.5-0.5.20090913git.el6 for package: python-deltarpm-3.5-0.5.20090913git.el6.x86_64--> Running transaction check---> Package deltarpm.x86_64 0:3.5-0.5.20090913git.el6 will be installed--> Finished Dependency ResolutionDependencies Resolved=================================================================================================================================== Package                          Arch                    Version                                     Repository              Size===================================================================================================================================Installing: createrepo                       noarch                  0.9.9-17.el6                                local                   94 kInstalling for dependencies: deltarpm                         x86_64                  3.5-0.5.20090913git.el6                     local                   71 k python-deltarpm                  x86_64                  3.5-0.5.20090913git.el6                     local                   27 kTransaction Summary===================================================================================================================================Install       3 Package(s)Total download size: 192 kInstalled size: 518 kDownloading Packages:-----------------------------------------------------------------------------------------------------------------------------------Total                                                                                              5.1 MB/s | 192 kB     00:00   Running rpm_check_debugRunning Transaction TestTransaction Test SucceededRunning Transaction  Installing : deltarpm-3.5-0.5.20090913git.el6.x86_64                                                                         1/3  Installing : python-deltarpm-3.5-0.5.20090913git.el6.x86_64                                                                  2/3  Installing : createrepo-0.9.9-17.el6.noarch                                                                                  3/3  Verifying  : python-deltarpm-3.5-0.5.20090913git.el6.x86_64                                                                  1/3  Verifying  : createrepo-0.9.9-17.el6.noarch                                                                                  2/3  Verifying  : deltarpm-3.5-0.5.20090913git.el6.x86_64                                                                         3/3Installed:  createrepo.noarch 0:0.9.9-17.el6                                                                                               Dependency Installed:  deltarpm.x86_64 0:3.5-0.5.20090913git.el6                    python-deltarpm.x86_64 0:3.5-0.5.20090913git.el6                 Complete!

接下来继续以上步骤,检查是否安装vsftp,ftp,如果没有直接安装.

# yum -y install vsftpd# yum -y install ftp

这样通过本地源,安装所需的软件就结束了.下一篇会接着介绍使用vsftp,搭建一个可供局域网使用的yum仓库.