一、本地yum
1. 创建目录、挂载光盘以及安装createrepo
[[email protected] ~]# mkdir/mnt/cdrom ←用于挂载光盘
[[email protected] ~]# mkdir-vp /yum/localrepo ←用于存放光盘中的rpm包
mkdir: 已创建目录 "/yum"
mkdir: 已创建目录 "/yum/localrepo"
[[email protected] ~]# mount/dev/cdrom /mnt/cdrom/
mount: block device /dev/sr0 is write-protected, mounting read-only
[[email protected] ~]# cp/mnt/cdrom/Packages/* /yum/localrepo/ ←将光盘中所有rpm包复制到/yum/localrepo下
[[email protected] Packages]#rpm -ivh createrepo-0.9.9-18.el6.noarch.rpm
warning: createrepo-0.9.9-18.el6.noarch.rpm: Header V3 RSA/SHA1Signature, key ID c105b9de: NOKEY
error: Failed dependencies:
python-deltarpm is needed by createrepo-0.9.9-18.el6.noarch
注:从上面我们可以看出存在依赖关系,我们需要先安装python-deltarpm包,那接下来我们就把它装上!
[[email protected] Packages]#rpm -ivh python-deltarpm-3.5-0.5.20090913git.el6.x86_64.rpm
warning: python-deltarpm-3.5-0.5.20090913git.el6.x86_64.rpm: HeaderV3 RSA/SHA256 Signature, key ID c105b9de: NOKEY
error: Failed dependencies:
deltarpm = 3.5-0.5.20090913git.el6 is needed bypython-deltarpm-3.5-0.5.20090913git.el6.x86_64
注:我们发现这个包也有依赖包,继续装!
[[email protected] Packages]#rpm -ivh deltarpm-3.5-0.5.20090913git.el6.x86_64.rpm
warning: deltarpm-3.5-0.5.20090913git.el6.x86_64.rpm: Header V3RSA/SHA256 Signature, key ID c105b9de: NOKEY
Preparing... ########################################### [100%]
1:deltarpm ###########################################[100%]
注:deltarpm-3.5-0.5.20090913git.el6.x86_64.rpm这个包安装成功了,继续安装上一个包。
[[email protected] Packages]#rpm -ivh python-deltarpm-3.5-0.5.20090913git.el6.x86_64.rpm
warning: python-deltarpm-3.5-0.5.20090913git.el6.x86_64.rpm: HeaderV3 RSA/SHA256 Signature, key ID c105b9de: NOKEY
Preparing... ########################################### [100%]
1:python-deltarpm ########################################### [100%]
注:解决依赖关系后尝试安装createrepo这个包。
[[email protected] Packages]#rpm -ivh createrepo-0.9.9-18.el6.noarch.rpm
warning: createrepo-0.9.9-18.el6.noarch.rpm: Header V3 RSA/SHA1Signature, key ID c105b9de: NOKEY
Preparing... ########################################### [100%]
1:createrepo ########################################### [100%]
注:createrepo安装成功。(由于每个操作系统安装的环境、系统版本的不同,依赖关系可能也不相同,大家按照我的方法安装就好了)
2. 创建以.repo结尾的文件
[[email protected] Packages]# cd /etc/yum.repos.d/
[[email protected] yum.repos.d]# ls
CentOS-Base.repo CentOS-Media.repo
CentOS-Debuginfo.repo CentOS-Vault.repo
[[email protected] yum.repos.d]# rm ./* ←删除所有系统自带的repo文件
rm:是否删除普通文件 "./CentOS-Base.repo"?y
rm:是否删除普通文件 "./CentOS-Debuginfo.repo"?y
rm:是否删除普通文件 "./CentOS-Media.repo"?y
rm:是否删除普通文件 "./CentOS-Vault.repo"?y
[[email protected] yum.repos.d]# vim local.repo ←创建一个名为local.repo的文件并编辑
[Base]
name=localrepo
baseurl=file:///yum/localrepo
enable=1
gpgcheck=0
注:
[Base]:代表容器的名字。中括号一定要存在,里面的名字可以随意修改,但是不能有两个相同的容器名称,否则yum会不知道该到哪里去找容器相关软件列表文件。
name:只是说明一下这个容器的意义而已,重要性不高!
baseurl:这个非常重要,应为后面接的是容器的实际地址。
示例:
ftp://ftp容器地址
http://web容器地址
file:///本地容器地址(前两个/是协议分隔符最后一个/代表本地的根)
enable=1:就是让这个容器被启动,如果不想启动可以使用enable=0
gpgcheck=0:指定是否要查阅rpm文件内的数字证书我们这里不查阅!
其他内容请自行查阅!!!!!!.
[[email protected] localrepo]#ls -l | grep repodata ←查看是否存在yum的索引文件
注:不存在yum的索引文件
[[email protected]]# createrepo /yum/localrepo/ ←创建分组信息
Spawning worker 0 with 3995 pkgs
Workers Finished
Gathering worker results
Saving Primary metadata
Saving file lists metadata
Saving other metadata
Generating sqlite DBs
Sqlite DBs complete
[[email protected] yum.repos.d]# cd /yum/localrepo/
[[email protected] localrepo]# ls -l | grep repodata
drwxr-xr-x 2 root root 4096 7月 23 01:04 repodata
注:我们可以发现通过createrepo创建出了yum的索引文件
[[email protected] yum.repos.d]#yum clean all ←清空缓存
Loaded plugins: fastestmirror, refresh-packagekit, security
Cleaning repos: Base
Cleaning up Everything
[[email protected] localrepo]#yum makecache ←建立新缓存
Loaded plugins: fastestmirror, refresh-packagekit, security
Determining fastest mirrors
Base | 2.9kB 00:00 ...
Base/filelists_db | 4.1 MB 00:00 ...
Base/primary_db | 3.3 MB 00:00 ...
Base/other_db | 1.8 MB 00:00 ...
Metadata Cache Created
[[email protected] localrepo]#yum -y install mysql ←安装MySQL测试
Loaded plugins: fastestmirror, refresh-packagekit, security
Loading mirror speeds from cached hostfile
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package mysql.x86_64 0:5.1.71-1.el6 will be installed
--> Finished Dependency Resolution
Dependencies Resolved
===================================================================
Package Arch Version Repository Size
===================================================================
Installing:
mysql x86_64 5.1.71-1.el6 Base 893 k
Transaction Summary
===================================================================
Install 1 Package(s)
Total download size: 893 k
Installed size: 2.4 M
Downloading Packages:
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
Installing :mysql-5.1.71-1.el6.x86_64 1/1
Verifying : mysql-5.1.71-1.el6.x86_64 1/1
Installed:
mysql.x86_640:5.1.71-1.el6
Complete!
注:MySQL安装成功,本地yum制作成功!
二、网络yum
网易(163)yum源是国内最好的yum源之一 ,无论是速度还是软件版本,都非常的不错,将yum源设置为163yum,可以提升软件包安装和更新的速度,同时避免一些常见软件版本无法找到。具体设置方法如下:
1、 进入yum源配置目录
[[email protected] localrepo]# cd /etc/yum.repos.d/
2、 重命名系统自带yum源并下载新的yum源
[[email protected] yum.repos.d]# mv local.repo local.repo.bak ←重命名是因为更改文件名后系统就不会识别出该yum源,这样也不会将系统自带的yum源丢失
[[email protected]ntos6 yum.repos.d]# wget http://mirrors.163.com/.help/CentOS6-Base-163.repo ←下载网易的yum源
--2016-07-23 02:01:38-- http://mirrors.163.com/.help/CentOS6-Base-163.repo
正在解析主机 mirrors.163.com... 123.58.173.185,123.58.173.186
正在连接 mirrors.163.com|123.58.173.185|:80... 已连接。
已发出 HTTP 请求,正在等待回应... 200 OK
长度:2006 (2.0K) [application/octet-stream]
正在保存至: “CentOS6-Base-163.repo”
100%[=========================>]2,006 --.-K/s in 0s
2016-07-2302:01:43 (142 MB/s) - 已保存 “CentOS6-Base-163.repo” [2006/2006])
3、 更新完yum源后,执行下面命令更新yum配置,使操作立即生效
[[email protected] yum.repos.d]# yum makecache
Loaded plugins: fastestmirror,refresh-packagekit, security
Loading mirror speeds from cached hostfile
base | 3.7kB 00:00
base/group_gz | 226 kB 00:00
base/filelists_db | 6.4 MB 00:11
base/primary_db | 4.7 MB 00:08
base/other_db | 2.8 MB 00:05
extras | 3.4kB 00:00
extras/filelists_db | 38 kB 00:00
extras/prestodelta | 1.3 kB 00:00
extras/primary_db |37 kB 00:00
extras/other_db | 51 kB 00:00
updates | 3.4 kB 00:00
updates/filelists_db | 1.1 MB 00:01
updates/prestodelta | 91 kB 00:00
updates/primary_db | 1.4 MB 00:02
updates/other_db | 17 MB 00:31
MetadataCache Created
4、 除了网易之外,国内还有其他不错的yum源,比如中科da和搜狐的,大家可以根据自己需求来下载
中科大的yum源:
wgethttp://centos.ustc.edu.cn/CentOS-Base.repo
sohu的yum源
wgethttp://mirrors.sohu.com/help/CentOS-Base-sohu.repo
理论上讲,这些yum源redhat系统以及fedora也是可以用 的,但是没有经过测试,需要的站长可以自己测试一下。
以上内容参考:http://blog.chinaunix.net/uid-23683795-id-3477603.html