實驗環境介紹
使用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 -h
Filesystem 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/
# ls
CentOS-Base.repo CentOS-Debuginfo.repo CentOS-Media.repo CentOS-Vault.repo
# rename repo repo.bak *
# ls
CentOS-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 - Localinfo
baseurl=file:///media
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6
enabled=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 all
Loaded plugins: fastestmirror, security
Cleaning repos: local
Cleaning up Everything
7.驗證本地數據倉庫是否可用
#yum repolist all
Loaded plugins: fastestmirror, security
Determining fastest mirrors
local | 4.0 kB 00:00 ...
local/primary_db | 4.4 MB 00:00 ...
repo id repo name status
local CentOS-6 - Localinfo enabled: 6,381
repolist: 6,381
8.安裝createrepo,vsftp,ftp軟件件
檢查createrepo有無安裝, 該軟件包用於生成RPM依賴關系及分組信息
# yum info createrepo
Loaded plugins: fastestmirror, security
Loading mirror speeds from cached hostfile
Available Packages
Name : createrepo
Arch : noarch
Version : 0.9.9
Release : 17.el6
Size : 94 k
Repo : local
Summary : Creates a common metadata repository
URL : http://createrepo.baseurl.org/
License : GPLv2
Description : This utility will generate a common metadata repository from a directory of
: rpm packages.
看到那個 Available Packages 了嗎,就說明該軟件未安裝,其它軟件都可以使用這個方法進行檢查.我在下面就不一個個貼出來了.
下面直接安裝
# yum -y install createrepo
Loaded plugins: fastestmirror, security
Loading mirror speeds from cached hostfile
Setting up Install Process
Resolving 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 Resolution
Dependencies Resolved
===================================================================================================================================
Package Arch Version Repository Size
===================================================================================================================================
 
Installing:
createrepo noarch 0.9.9-17.el6 local 94 k
Installing 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 k
Transaction Summary
===================================================================================================================================
Install 3 Package(s)
Total download size: 192 k
Installed size: 518 k
Downloading Packages:
-----------------------------------------------------------------------------------------------------------------------------------
Total 5.1 MB/s | 192 kB 00:00
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running 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/3
Installed:
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倉庫.