centos6.4搭建基於ftp的yum源讓本地局域網服務器使用


1. 掛載centos6.4 DVD鏡像
[root@centos64 ~]# mount /dev/cdrom /mnt

2. 安裝vsftp軟件,啟動vsftpd服務,拷貝centos6.4 DVD內容到ftp的匿名用戶某一目錄。
[root@centos64 Packages]# rpm -ivh vsftpd-2.2.2-11.el6_3.1.x86_64.rpm
Preparing...                ########################################### [100%]
   1:vsftpd                 ########################################### [100%]
[root@centos64 Packages]#
[root@centos64 Packages]#
[root@centos64 Packages]# chkconfig vsftpd on
[root@centos64 Packages]#
[root@centos64 Packages]# cd /var/ftp/
[root@centos64 ftp]#
[root@centos64 ftp]#
[root@centos64 ftp]# ls
pub
[root@centos64 ftp]# rm -rf pub/
[root@centos64 ftp]# service vsftpd start
Starting vsftpd for vsftpd:                                [  OK  ]
[root@centos64 ftp]# mkdir centos6.4-x86_64 centos5.9-x86_64 ##順便練centos5.9的軟件源也一起搭建起來
[root@centos64 ftp]# cd centos6.4-x86_64/
[root@centos64 centos6.4-x86_64]#
[root@centos64 centos6.4-x86_64]# cp -rp /mnt/* .

3. 創建依賴關系數據庫
[root@centos64 ~]# cd /mnt/Packages/
[root@centos64 Packages]# rpm -ivh createrepo-0.9.9-17.el6.noarch.rpm
[root@centos64 Packages]# createrepo -g /var/ftp/centos6.4-x86_64/repodata/repomd.xml /var/ftp/centos6.4-x86_64/
Spawning worker 0 with 3955 pkgs
Workers Finished
Gathering worker results

Saving Primary metadata
Saving file lists metadata
Saving other metadata
Generating sqlite DBs
Sqlite DBs complete
[root@centos64 Packages]#

4. yum的客戶端需要修改yum配置文件:
移走/etc/yum.repos.d/所有的.repo文件。
[root@centos64 ~]# cd /etc/yum.repos.d/
[root@centos64 yum.repos.d]# ls
CentOS-Base.repo  CentOS-Debuginfo.repo  CentOS-Media.repo  CentOS-Vault.repo  epel.repo  epel-testing.repo
[root@centos64 yum.repos.d]# mkdir bak
[root@centos64 yum.repos.d]# mv CentOS-Base.repo  CentOS-Debuginfo.repo  CentOS-Media.repo  CentOS-Vault.repo bak/
[root@centos64 yum.repos.d]# ls
bak  epel.repo  epel-testing.repo
[root@centos64 yum.repos.d]# vi centos6.4.repo
[root@centos64 yum.repos.d]#
[root@centos64 yum.repos.d]# more centos6.4.repo
[centos6.4]
name=centos6.4
baseurl=ftp://192.168.1.64/centos6.4-x86_64/
enabled=1
[root@centos64 yum.repos.d]#
[root@centos64 yum.repos.d]# yum list all
如果出現如下帶有centos6.4的標記,說明成功
......
yum-plugin-aliases.noarch                                      1.1.30-14.el6                             centos6.4                               
yum-plugin-changelog.noarch                                    1.1.30-14.el6                             centos6.4                               
yum-plugin-downloadonly.noarch                                 1.1.30-14.el6                             centos6.4                               
yum-plugin-security.noarch                                     1.1.30-14.el6                             centos6.4  
......

5. 同樣的方法搭建centos5.9的yum源
說明:這里有個大大的陷阱,當你把centos5.9的DVD源復制到centos6的系統,然后用centos6的createrepo命令創建依賴數據庫的時候,發現雖然沒有報錯,但是這樣的源,在centos5客戶端yum 安裝的時候,報效驗錯誤的提示。如下:
[root@centos59 yum.repos.d]# yum list all
Loaded plugins: fastestmirror, security
Loading mirror speeds from cached hostfile
centos5.9/primary_db                                                                                                                            | 2.0 MB     00:00     
ftp://192.168.1.64/centos5.9-x86_64/repodata/d219ce6ac81a48dc4b3295d72b6e26ea0cecd3b03f9a1c1655132d53508ad965-primary.sqlite.bz2: [Errno -3] Error performing checksum
Trying other mirror.
Error: failure: repodata/d219ce6ac81a48dc4b3295d72b6e26ea0cecd3b03f9a1c1655132d53508ad965-primary.sqlite.bz2 from centos5.9: [Errno 256] No more mirrors to try.
[root@centos59 yum.repos.d]#
原因是:centos6中的createrepo 命令,是用的是 光碟 Rackages/路徑,而centos5中用的是 CentOS/路徑,所以問題就出來了。原來校驗的時候,centos5的軟件包只能用centos5中的createrepos命令。
解決方法是: 把centos6中的/var/ftp/ 用nfs掛載到 centos5的 /var/ftp/ 同樣路徑下,用centos5的createrepo命令生成依賴數據庫。
在centos6下面,裝上nfs並掛載,如下:
[root@centos64 centos5.9-x86_64]# more /etc/exports
/var/ftp *(rw,sync)
[root@centos64 centos5.9-x86_64]#
centos5.9上面掛載命令如下:  mount  192.168.1.65:/var/ftp   /var/ftp


下面是在centos5中執行的createrepo命令:

[root@centos59 CentOS]# createrepo -g /var/ftp/centos5.9-x86_64/repodata/repomd.xml /var/ftp/centos5.9-x86_64/
3579/3579 - CentOS/patch-2.5.4-31.el5.x86_64.rpm                                x86_64.rpm
Saving Primary metadata
Saving file lists metadata
Saving other metadata
[root@centos59 CentOS]#
執行上面的命令后,還是發現錯誤依舊
[root@centos59 yum.repos.d]# yum list all
Loaded plugins: fastestmirror, security
Loading mirror speeds from cached hostfile
centos5.9/primary_db                                                                                                                            | 2.0 MB     00:00     
ftp://192.168.1.64/centos5.9-x86_64/repodata/d219ce6ac81a48dc4b3295d72b6e26ea0cecd3b03f9a1c1655132d53508ad965-primary.sqlite.bz2: [Errno -3] Error performing checksum
Trying other mirror.
Error: failure: repodata/d219ce6ac81a48dc4b3295d72b6e26ea0cecd3b03f9a1c1655132d53508ad965-primary.sqlite.bz2 from centos5.9: [Errno 256] No more mirrors to try.
[root@centos59 yum.repos.d]#
然后直接在centos6中清空掉 centos5.9-x86_64/repodata/ 中的垃圾數據,對比centos5.9 DVD源光盤鏡像中的 repodata/ 目錄,清空掉以前 centos6 的createrepo命令生成的垃圾文件,並且在centos5 中重命名一下centos5.9.repo 就好了。因為可能在centos5.9中有緩存的緣故。

 

===============以后碰到了如下問題:

以上方法只是解決了yum -y install XXXXX的 安裝問題,但是對於 yum groupinstall 安裝的時候,就會報錯,如下:

[root@BG-DB:/etc/yum.repos.d]$yum grouplist
Setting up Group Process
centos5.9/group                                                                                         | 1.1 kB     00:00     
ftp://192.168.1.202/repodata/repomd.xml: [Errno -1] Metadata file does not match checksum
Trying other mirror.
Failed to add groups file for repository: centos5.9 - None
Error: No group data available for configured repositories
[root@BG-DB:/etc/yum.repos.d]$

原來沒有在yum端創建組數據庫,需要在yum源中

【centos5.X】需要如下方法執行:
[root@server202:/var/ftp/centos5.9-x86_64]$createrepo -g  repodata/comps.xml .   ##注意,這里和上面的不同,這個是組的數據庫配置。
3579/3579 - CentOS/xorg-x11-drv-cirrus-1.1.0-2.fc6.x86_64.rpm                   pm6_64.rpm
Saving Primary metadata
Saving file lists metadata
Saving other metadata
[root@server202:/var/ftp/centos5.9-x86_64]$

【centos6.X】需要如下方法執行:

[root@centos65dvd centos6.5-x86_64]# createrepo -g repodata/b4e0b9342ef85d3059ff095fa7f140f654c2cb492837de689a58c581207d9632-c6-x86_64-comps.xml .    ## centos6.X這里面的組文件和centos5.X 不一樣
Spawning worker 0 with 3995 pkgs

--------------------------------------------------------------------------------------
做完上面的后,yum客戶端用如下三條命令后,然后就可以“列出組軟件包”了
yum clean all
yum makecache
yum list
如下:
[root@BG-DB:/etc/yum.repos.d]$more centos5.9.repo
[centos5.9]
name=centos5.9
baseurl=ftp://192.168.1.202/
enabled=1
gpgcheck=0
[root@BG-DB:/etc/yum.repos.d]$
[root@BG-DB:/etc/yum.repos.d]$yum grouplist
Setting up Group Process
Installed Groups:
   Administration Tools
   Dialup Networking Support
   Editors
   FTP Server
   Legacy Network Server
   Mail Server
   MySQL Database
   Network Servers
   System Tools
Available Groups:
   Authoring and Publishing
   Base
   Cluster Storage
   Clustering
   DNS Name Server
   Development Libraries
   Development Tools
   Eclipse
   Engineering and Scientific
   GNOME Desktop Environment
   GNOME Software Development
   Games and Entertainment
   Graphical Internet
   Graphics
   HyperV
   Java Development
   KDE (K Desktop Environment)
   KDE Software Development
   KVM
   Legacy Software Development
   Legacy Software Support
   News Server
   Office/Productivity
   OpenFabrics Enterprise Distribution
   PostgreSQL Database
   Printing Support
   Server Configuration Tools
   Sound and Video
   Text-based Internet
   Web Server
   Windows File Server
   X Software Development
   X Window System
   Xen
Done
[root@BG-DB:/etc/yum.repos.d]$


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM