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]$