创建本地yum源的三种方法

======================================= Section 1: 方法1

  1. 创建dvdrom的挂载点(可忽略)
    mkdir /mnt/dvdrom

2、挂载DVD ISO镜像
[root@bz /]# ll /dev/dvd*
lrwxrwxrwx 1 root root 3 Jun 22 18:27 /dev/dvd1 -> sr0
lrwxrwxrwx 1 root root 3 Jun 22 18:27 /dev/dvdrw1 -> sr0
[root@bz /]# umount /mnt
[root@bz /]# mount -t iso9660 /dev/dvd1 /mnt
mount: block device /dev/sr0 is write-protected, mounting read-only
[root@bz /]# umount /mnt
[root@bz /]# mount -t iso9660 /dev/sr0 /mnt/ =>安装盘已装载到本地光驱
[root@bz /]# mount -o loop -t iso9660 /Stage/oel-6.5-x86_64-dvd.iso /mnt =>只有本地iso镜像

3、安装 createrepo(两种方式)
cd /mnt/Packages <--------具体路径查看本地光盘。
rpm -ivh createrepo-x.y.z.rpm <--------x.y.z根据光盘有所不同。

安装如下三个包
rpm -ivh deltarpm-*
rpm -ivh python-deltarpm-*
rpm -ivh createrepo-*

以OEL6U5为例:
rpm -ivh deltarpm-3.5-0.5.20090913git.el6.x86_64.rpm
rpm -ivh python-deltarpm-3.5-0.5.20090913git.el6.x86_64.rpm
rpm -ivh createrepo-0.9.9-18.0.1.el6.noarch.rpm

4、创建安装源(本次直接利用挂载点里的安装源)
3、添加安装源

rm -rf /etc/yum.repos.d/base.repo
cat >> /etc/yum.repos.d/base.repo << EOF
[base_install]
name=oracle
baseurl=file:///mnt/Server
enabled=1
gpgcheck=0
EOF

4、更新安装源

[root@bz yum.repos.d]# yum clean all
Loaded plugins: refresh-packagekit, security
Cleaning repos: InstallMedia base_install public_ol6_UEKR3_latest public_ol6_latest
Cleaning up Everything
[root@bz yum.repos.d]# yum update
Loaded plugins: refresh-packagekit, security
base_install | 3.7 kB 00:00 …
base_install/primary_db | 3.0 MB 00:00 …
http://public-yum.oracle.com/repo/OracleLinux/OL6/UEKR3/latest/x86_64/repodata/repomd.xml: [Errno 14] PYCURL ERROR 6 - “Couldn’t resolve host ‘public-yum.oracle.com’”
Trying other mirror.
Error: Cannot retrieve repository metadata (repomd.xml) for repository: public_ol6_UEKR3_latest. Please verify its path and try again

出现上述报错时,可将oel默认的公共yum源文件删掉
[root@bz yum.repos.d]# cd /etc/yum.repos.d/
[root@bz yum.repos.d]# ll
total 12
-rw-r–r-- 1 root root 75 Jun 22 18:48 base.repo
-rw-r–r-- 1 root root 98 Nov 26 2013 packagekit-media.repo
-rw-r–r--. 1 root root 2545 May 25 12:40 public-yum-ol6.repo
[root@bz yum.repos.d]# mv public-yum-ol6.repo public-yum-ol6.repo.20140622
[root@bz yum.repos.d]# yum clean all
Loaded plugins: refresh-packagekit, security
Cleaning repos: InstallMedia base_install
Cleaning up Everything
[root@bz yum.repos.d]# yum update
Loaded plugins: refresh-packagekit, security
base_install | 3.7 kB 00:00 …
base_install/primary_db | 3.0 MB 00:00 …
Setting up Update Process
No Packages marked for Update
[root@bz yum.repos.d]#

======================================= Section 2: 方法2
1、建立以下文件夹

[root@bz /]$ mkdir /mnt/dvd
[root@bz /]$ mkdir /mnt/dvd/repo/suse -p
[root@bz /]$ mkdir /mnt/dvd/repo/repodata

2、挂载DVD ISO镜像

[root@bz /]# mount -t iso9660 /dev/sr0 /mnt/
mount: block device /dev/sr0 is write-protected, mounting read-only
[root@bz /]$ mount --bind /mnt/dvd/Packages/ /mnt/dvd/repo/suse/

3、拷贝文件到指定目录

[root@bz /]$ cp /mnt/dvd/repodata/repomd.xml /mnt/dvd/repo/repodata/ -p

4、创建安装源
[root@bz /]$ cd /mnt/dvd/repo/
[root@ocp repo]# ls -l
total 668
drwxr-xr-x 2 root root 679936 Nov 26 2013 suse
drwxr-xr-x 2 root root 4096 Jun 1 23:33 repodata
[root@ocp repo]# createrepo -g repodata/repomd.xml .
Spawning worker 0 with 3754 pkgs
Workers Finished
Gathering worker results

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

5、添加安装源

[root@ocp repo]$ cd /etc/yum.repos.d/
[root@ocp yum.repos.d]$ cat >> /etc/yum.repos.d/iso.repo <<EOF
[dvd-repo]
name=dvd-repo
baseurl=file:///mnt/dvd/repo
enabled=1
gpgcheck=0
EOF

6、更新安装源

[root@bz /]$ yum clean all
Loaded plugins: refresh-packagekit, security
Cleaning repos: dvd-repo
Cleaning up Everything
[root@bz /]$ yum update
Loaded plugins: refresh-packagekit, security
dvd-repo | 3.6 kB 00:00 …
dvd-repo/primary_db | 3.5 MB 00:00 …
Setting up Update Process
No Packages marked for Update

设置更新进程
不升级任何软件包
值得注意的是,在利用此安装源的时候,就必须移除此目录的其他文件。

======================================= Section 3: 只有操作系统安装文件的全部RPM包,做yum源
1、安装createrepo(操作系统已注册且联网情况下可直接yum install createrepo -y)
cd /home/RPM
rpm -ivh deltarpm-*
rpm -ivh python-deltarpm-*
rpm -ivh createrepo-*

2、只有RPM包安装源
[[email protected] home]# createrepo /home/RPM
1399/3596 - java-1.6.0-openjdk-devel-1.6.0.0-1.41.1.10.4.el6.x86_64.rpm
iso-8859-1 encoding on Ville Skytt[email protected] - 2.8.2-2

3596/3596 - mod_wsgi-3.2-1.el6.x86_64.rpm
Saving Primary metadata
Saving file lists metadata
Saving other metadata
[[email protected] home]#

3、在/etc/yum.repos.d中的添加源配置文件
cat >> /etc/yum.repos.d/rpm.repo <<EOF
[rpm-repo]
name=rpm-repo
baseurl=file:///home/RPM/
enabled=1
gpgcheck=0
EOF

4、更新安装源
[[email protected] home]# yum clean all
Loaded plugins: refresh-packagekit, security
Cleaning repos: dvd-repo
Cleaning up Everything
[root@oel6u5 yum.repos.d]# yum update
Loaded plugins: refresh-packagekit, security
dvd-repo | 3.0 kB 00:00 …
dvd-repo/primary_db | 22 MB 00:00 …
Setting up Update Process
No Packages marked for Update
[root@oel6u5 yum.repos.d]#

值得注意的是,在利用此安装源的时候,就必须的移除此目录的其他文件。

猜你喜欢

转载自blog.csdn.net/seaship/article/details/86286200