RHEL本地yum源
一、挂载本地镜像做yum源(环境:RHEL6.5 64位 VM11)
1、进入/etc/yum.repos.d目录,
[root@localhost yum.repos.d]# ls
packagekit-media.repo rhel-source.repo
备份文件:
# cp rhel-source.repo rhel-source.repo.bak
# cp packagekit-media.repo packagekit-media.repo.bak
[root@localhost yum.repos.d]# ls
packagekit-media.repo rhel-source.repo
packagekit-media.repo.bak rhel-source.repo.bak
修改.repo文件,
# vim rhel-source.repo
在末尾加上如下内容(这里注意:不要添加中文注释,否则会报错):
[Server] name=Red Hat Enterprise Linux Server baseurl=file:///mnt/dcrom #本地iso的挂载路径 enabled=1 #可以使用yum gpgcheck=0 #设置不检查gpgkey gpgkey=file:///mnt/dcrom/RPM-GPG-KEY-RedHat-release # 配置gpgkey的路径
2、修改yumRepo.py配置文件
方法一:直接修改文件
[root@localhost yum.repos.d]# cd /usr/lib/python2.6/site-packages/yum [root@localhost yum]# vim yumRepo.py
找到第802行,修改代码
802 # remote = url + '/' + relative #原代码 803 remote = "/mnt/dcrom" + '/' + relative
方法二:执行命令
# sed -i "s#remote = url +'/' + relative#remote = '/mnt/dcrom' + '/' + relative#g" /usr/lib/python2.6/site-packages/yum/yumRepo.py
3、在VM设置中添加镜像文件并挂载
在终端中进行如下操作:
# mkdir /mnt/dcrom
# mount /dev/cdrom1 /mnt/dcrom/
4、导入导入rpm的签名信息并清除缓存
# rpm --import /mnt/dcrom/RPM-GPG-KEY-redhat-release
#yum clean all
5、测试yum(系统默认没有安装ftp):
[root@localhost yum]# yum list | grep vsftpd This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register. vsftpd.x86_64 2.2.2-11.el6_4.1 @Server [root@localhost yum]# yum install vsftpd
6、可能遇到的错误及解决方法:
错误一:进程锁定,不能清除缓存
# 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. Existing lock /var/run/yum.pid: another copy is running as pid 2267. Another app is currently holding the yum lock; waiting for it to exit... The other application is: PackageKit Memory : 48 M RSS (365 MB VSZ) Started: Sat Nov 23 01:28:11 2013 - 10:00 ago State : Sleeping, pid: 2267
解决方法:
# kill -9 2267
# yum clean all
错误二:yum损坏
# yum clean Traceback (most recent call last): File "/usr/bin/yum", line 4, in <module> import yum File "/usr/lib/python2.6/site-packages/yum/__init__.py", line 55, in <module> import rpmsack File "/usr/lib/python2.6/site-packages/yum/rpmsack.py", line 38, in <module> import yum.depsolve File "/usr/lib/python2.6/site-packages/yum/depsolve.py", line 30, in <module> from transactioninfo import TransactionMember File "/usr/lib/python2.6/site-packages/yum/transactioninfo.py", line 32, in <module> from sqlitesack import YumAvailablePackageSqlite File "/usr/lib/python2.6/site-packages/yum/sqlitesack.py", line 26, in <module> import yumRepo File "/usr/lib/python2.6/site-packages/yum/yumRepo.py", line 202 compressed_fv ] repo.cachedir + '/' + fname ^ SyntaxError: invalid syntax # yum Traceback (most recent call last): File "/usr/bin/yum", line 4, in <module> import yum File "/usr/lib/python2.6/site-packages/yum/__init__.py", line 55, in <module> import rpmsack File "/usr/lib/python2.6/site-packages/yum/rpmsack.py", line 38, in <module> import yum.depsolve File "/usr/lib/python2.6/site-packages/yum/depsolve.py", line 30, in <module> from transactioninfo import TransactionMember File "/usr/lib/python2.6/site-packages/yum/transactioninfo.py", line 32, in <module> from sqlitesack import YumAvailablePackageSqlite File "/usr/lib/python2.6/site-packages/yum/sqlitesack.py", line 26, in <module> import yumRepo File "/usr/lib/python2.6/site-packages/yum/yumRepo.py", line 202 compressed_fv ] repo.cachedir + '/' + fname ^ SyntaxError: invalid syntax You have new mail in /var/spool/mail/root
解决方法:卸载yum,并重新安装
# rpm -qa|grep yum #查询yum有关的包 # rpm -e yum-utils #类似用"rpm -e 包的名字"方式卸载
然后通过挂载的镜像文件找到对应的包,"# rpm -ivh 包的名字“安装即可
错误三:字符集错误
UnicodeDecodeError: 'ascii' codec can't decode byte 0xe4 in position 0: ordinal not in range(128)
解决方法:
#yum clean all #rm -f /var/lib/rpm/__db* #rpm --rebuilddb #yum update # vim /etc/yum.conf 找到下面一行: plugins=1 #替换为plugins=0
错误四:yum不能用了
# rpm -qa|grep yum rpmdb: /var/lib/rpm/__db.002: 没有那个文件或目录 error: db3 error(2) from dbenv->open: 没有那个文件或目录 error: cannot open Packages index using db3 - 没有那个文件或目录 (2) error: cannot open Packages database in /var/lib/rpm rpmdb: /var/lib/rpm/__db.002: 没有那个文件或目录 error: db3 error(2) from dbenv->open: 没有那个文件或目录 error: cannot open Packages database in /var/lib/rpm [root@bogon Packages]# rpm -e yum rpmdb: /var/lib/rpm/__db.002: 没有那个文件或目录 error: db3 error(2) from dbenv->open: 没有那个文件或目录 error: cannot open Packages index using db3 - 没有那个文件或目录 (2) error: cannot open Packages database in /var/lib/rpm rpmdb: /var/lib/rpm/__db.002: 没有那个文件或目录 error: db3 error(2) from dbenv->open: 没有那个文件或目录 error: cannot open Packages database in /var/lib/rpm error: package yum is not installed
解决方法:
执行以下命令即可搞定: rm -rf /var/lib/rpm/__db*
7、参考网址:
http://www.2cto.com/os/201309/244278.html
http://bbs.chinaunix.net/thread-4112642-1-1.html
CentOS7下配置本地yum源
修改自网址:http://my.oschina.net/jast90/blog/292726#OSC_h2_4
系统:CentOS7 everything
1、挂载光盘
# mkdir /mnt/data
# mount /dev/cdrom /mnt/data/
2、创建本地仓库
# mkdir -p /yumrepo/local
# cp -rvf /mnt/data/Packages /yumrepo/local/
3、安装createrepo
# rpm -ivh createrepo-0.9.9-23.el7.noarch.rpm #在镜像文件Packages目录下
4、创建repo文件
# cd etc/yum.repos.d/
# vi myrepo.repo
添加内容如下:
[myrepo] name=This is my repo enabled=1 gpgcheck=0 baseurl=file:///mnt/data
5、假如yum group到刚刚创建的本地仓库
# createrepo -g /mnt/data/repodata/2bc0054a9f0f4cd3d2806d983edbe3d0dfc484d9f275d12be79eb67a040ba942-c7-x86_64-comps.xml /srv/my/repo/
6、测试grouplist
# yum grouplist Loaded plugins: fastestmirror, langpacks There is no installed groups file. Maybe run: yum groups mark convert (see man yum) Loading mirror speeds from cached hostfile * base: mirrors.pubyun.com * extras: mirrors.pubyun.com * updates: mirror.neu.edu.cn Available environment groups: Minimal Install Compute Node Infrastructure Server File and Print Server Basic Web Server Virtualization Host Server with GUI GNOME Desktop KDE Plasma Workspaces Development and Creative Workstation Available Groups: Compatibility Libraries Console Internet Tools Development Tools Graphical Administration Tools Legacy UNIX Compatibility Scientific Support Security Tools Smart Card Support System Administration Tools System Management Done