1、挂载光盘
[root@linuxclient ~]# mount /dev/cdrom /media/
mount: block device /dev/sr0 is write-protected, mounting read-only
mount: block device /dev/sr0 is write-protected, mounting read-only
2、备份系统的repo文件
[root@linuxclient ~]# cd /etc/yum.repos.d/
[root@linuxclient yum.repos.d]# ls
CentOS6-Base-163.repo rhel-source.repo
[root@linuxclient yum.repos.d]# mkdir bak
[root@linuxclient yum.repos.d]# mv *.repo bak/
[root@linuxclient yum.repos.d]# ls
bak
[root@linuxclient yum.repos.d]# ls
CentOS6-Base-163.repo rhel-source.repo
[root@linuxclient yum.repos.d]# mkdir bak
[root@linuxclient yum.repos.d]# mv *.repo bak/
[root@linuxclient yum.repos.d]# ls
bak
3、创建本地的repo文件
[root@linuxclient yum.repos.d]# cat local.repo
[Local]
baseurl=file:///media/Server
gpgcheck=1
enabled=1
[Local]
baseurl=file:///media/Server
gpgcheck=1
enabled=1
4、导入密钥(如果上面的gpgcheck=0,这一步可以跳过)
5、清除缓存
[root@linuxclient yum.repos.d]# yum clean all
Loaded plugins: product-id, refresh-packagekit, security, subscription-manager
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
Repository 'Local' is missing name in configuration, using id
Cleaning repos: Local
Cleaning up Everything
Loaded plugins: product-id, refresh-packagekit, security, subscription-manager
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
Repository 'Local' is missing name in configuration, using id
Cleaning repos: Local
Cleaning up Everything
6、重新生成缓存
[root@linuxclient yum.repos.d]# yum makecache
Loaded plugins: product-id, refresh-packagekit, security, subscription-manager
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
Repository 'Local' is missing name in configuration, using id
Local | 3.9 kB 00:00 ...
Local/group_gz | 204 kB 00:00 ...
Local/filelists_db | 3.8 MB 00:00 ...
Local/primary_db | 3.1 MB 00:00 ...
Local/other_db | 1.6 MB 00:00 ...
Metadata Cache Created
Loaded plugins: product-id, refresh-packagekit, security, subscription-manager
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
Repository 'Local' is missing name in configuration, using id
Local | 3.9 kB 00:00 ...
Local/group_gz | 204 kB 00:00 ...
Local/filelists_db | 3.8 MB 00:00 ...
Local/primary_db | 3.1 MB 00:00 ...
Local/other_db | 1.6 MB 00:00 ...
Metadata Cache Created
7、根据以上步骤编写脚本
[root@precise ~]# cat createlocalyum.sh
#!/bin/bash
cd /etc/yum.repos.d/
mkdir bak
mv *.repo bak/
cat << EOF > local.repo
[Local]
baseurl=file:///media/Server
gpgcheck=1
enabled=1
EOF
rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-*
yum clean all
yum makecache