1.用Centos镜像搭建本地yum源
在配置网络yum之前我们先卸载旧的yum,并下载CentOS的对应软件包安装,这一步配置yum源都要操作
[[email protected] tools]# rpm -aq|grep yum
yum-metadata-parser-1.1.2-16.el6.x86_64
yum-rhn-plugin-0.9.1-58.el6.noarch
yum-3.2.29-69.el6.noarch
[[email protected] tools]# rpm -aq|grep yum|xargs rpm -e --nodeps
[[email protected] tools]#
[[email protected] tools]# rpm -aq|grep yum|xargs rpm -e --nodeps
rpm: no packages given for erase
wget http://mirrors.163.com/centos/6/os/x86_64/Packages/python-iniparse-0.3.1-2.1.el6.noarch.rpm
wget http://mirrors.163.com/centos/6/os/x86_64/Packages/python-urlgrabber-3.9.1-11.el6.noarch.rpm
wget http://mirrors.163.com/centos/6/os/x86_64/Packages/yum-3.2.29-81.el6.centos.noarch.rpm
wget http://mirrors.163.com/centos/6/os/x86_64/Packages/yum-metadata-parser-1.1.2-16.el6.x86_64.rpm
wget http://mirrors.163.com/centos/6/os/x86_64/Packages/yum-plugin-fastestmirror-1.1.30-40.el6.noarch.rpm
[[email protected] ~]# cd /home/linzhongniao/tools/
[[email protected] tools]# ls
yum-3.2.29-81.el6.centos.noarch.rpm python-iniparse-0.3.1-2.1.el6.noarch.rpm yum-metadata-parser-1.1.2-16.el6.x86_64.rpmpython-urlgrabber-3.9.1-11.el6.noarch.rpm yum-plugin-fastestmirror-1.1.30-40.el6.noarch.rpm
[[email protected] tools]# rpm -ivh *
1.1 安装完centos后默认的yum源如下
[[email protected] yum.repos.d]# ll
总用量 24
-rw-r--r--. 1 root root 1991 5月 19 2016 CentOS-Base.repo
-rw-r--r--. 1 root root 647 5月 19 2016 CentOS-Debuginfo.repo
-rw-r--r--. 1 root root 289 5月 19 2016 CentOS-fasttrack.repo
-rw-r--r--. 1 root root 630 5月 19 2016 CentOS-Media.repo
-rw-r--r--. 1 root root 6259 5月 19 2016 CentOS-Vault.repo
1.2 备份默认yum源
[[email protected] ~]# mkdir -p /home/yum.repos.d
[[email protected] ~]# mv /etc/yum.repos.d/* /home/yum.repos.d/
1.3 编写repo文件 并指向镜像的挂载目录
[[email protected] ~]# mount /dev/cdrom /media/
mount: block device /dev/sr0 is write-protected, mounting read-only
[[email protected] ~]# vi /etc/yum.repos.d/local.repo
[local]
name=local
baseurl=file:///media/
enabled=1
gpgcheck=0
1.4 清楚缓存
[[email protected] ~]# yum clean all
已加载插件:fastestmirror
Cleaning repos: local
清理一切
Cleaning up list of fastest mirrors
1.5 将yum源缓存到本地,加快安装速度
[[email protected] ~]# yum makecache
已加载插件:fastestmirror
Determining fastest mirrors
local | 4.0 kB 00:00 ...
local/group_gz | 226 kB 00:00 ...
local/filelists_db | 6.3 MB 00:00 ...
local/primary_db | 4.7 MB 00:00 ...
local/other_db | 2.8 MB 00:00 ...
元数据缓存已建立
1.6 列出软件包
[[email protected] ~]# yum list
2.将默认的yum源改成aliyun yum源
阿里云官方教程:http://mirrors.aliyun.com/help/centos
2.1 备份yum源
[[email protected] ~]# mv /etc/yum.repos.d/* /home/yum.repos.d/
2.2 下载aliyun yum源repo文件对应自己系统下载
各系统对应的yum源repo文件
CentOS 5
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-5.repo
或者
curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-5.repo
CentOS 6
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repo
或者
curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repo
CentOS 7
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
或者
curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
[[email protected] ~]# cat /etc/redhat-release 查看系统版本
CentOS release 6.8 (Final)
[[email protected] ~]# wget -o /etc/yum.repos.d/centos.repo wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repo
[[email protected] ~]# wget -o /etc/yum.repos.d/centos.txt wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repo
[[email protected] ~]# ll /etc/yum.repos.d/
总用量 8
-rw-r--r--. 1 root root 2572 7月 2 2014 CentOS-Base.repo
-rw-r--r--. 1 root root 793 3月 7 04:53 centos.txt
2.3 清除缓存
[[email protected] ~]# yum clean all
已加载插件:fastestmirror
Cleaning repos: local
清理一切
Cleaning up list of fastest mirrors
[[email protected] ~]# yum makecache 把yum源缓存到本地,加快安装速度
已加载插件:fastestmirror
Determining fastest mirrors
local | 4.0 kB 00:00 ...
local/group_gz | 226 kB 00:00 ...
local/filelists_db | 6.3 MB 00:00 ...
local/primary_db | 4.7 MB 00:00 ...
local/other_db | 2.8 MB 00:00 ...
[[email protected] ~]# yum list
3.把默认centos yum源换成163源
163官方教程:http://mirrors.163.com/.help/centos.html
3.1 Centos默认yum源如下
[[email protected] yum.repos.d]# ll
总用量 24
-rw-r--r--. 1 root root 1991 5月 19 2016 CentOS-Base.repo
-rw-r--r--. 1 root root 647 5月 19 2016 CentOS-Debuginfo.repo
-rw-r--r--. 1 root root 289 5月 19 2016 CentOS-fasttrack.repo
-rw-r--r--. 1 root root 630 5月 19 2016 CentOS-Media.repo
-rw-r--r--. 1 root root 6259 5月 19 2016 CentOS-Vault.repo
3.2 备份yum源文件
[[email protected] ~]# mv /etc/yum.repos.d/* /home/yum.repos.d/
3.3 下载163 yum源repo文件
各系统版本对应的repo文件
CentOS 5
wget -O /etc/yum.repos.d/CentOS5-Base-163.repo http://mirrors.163.com/.help/CentOS5-Base-163.repo
CentOS 6
wget -O /etc/yum.repos.d/CentOS6-Base-163.repo http://mirrors.163.com/.help/CentOS6-Base-163.repo
CentOS 7
wget -O /etc/yum.repos.d/CentOS7-Base-163.repo http://mirrors.163.com/.help/CentOS7-Base-163.repo
[[email protected] ~]# cat /etc/redhat-release 查看系统版本
CentOS release 6.8 (Final)
[[email protected] ~]# wget -O /etc/yum.repos.d/CentOS6-Base-163.repo http://mirrors.163.com/.help/CentOS6-Base-163.repo
--2018-03-07 06:11:02-- http://mirrors.163.com/.help/CentOS6-Base-163.repo
正在解析主机 mirrors.163.com... 59.111.0.251
正在连接 mirrors.163.com|59.111.0.251|:80... 已连接。
已发出 HTTP 请求,正在等待回应... 200 OK
长度:2006 (2.0K) [application/octet-stream]
正在保存至: “/etc/yum.repos.d/CentOS6-Base-163.repo”
100%[============================================================================================>] 2,006 --.-K/s in 0.001s
2018-03-07 06:11:03 (1.97 MB/s) - 已保存 “/etc/yum.repos.d/CentOS6-Base-163.repo” [2006/2006])
[[email protected] ~]# ll /etc/yum.repos.d/
总用量 4
-rw-r--r--. 1 root root 2006 12月 1 2016 CentOS6-Base-163.repo
3.4 清除缓存
[[email protected] ~]# yum clean all
已加载插件:fastestmirror
Cleaning repos: local
清理一切
Cleaning up list of fastest mirrors
[[email protected] ~]# yum makecache 把yum源缓存到本地,加快安装速度
已加载插件:fastestmirror
Determining fastest mirrors
local | 4.0 kB 00:00 ...
local/group_gz | 226 kB 00:00 ...
local/filelists_db | 6.3 MB 00:00 ...
local/primary_db | 4.7 MB 00:00 ...
local/other_db | 2.8 MB 00:00 ...
[[email protected] ~]# yum list
4.修改yum源的优先级
当既有本地源又有网络源的时候,我们安装软件的时候当然希望按着本地yum源去安装,当找不到安装包的时候在用网络软安装,那么这里就涉及了一个优先级的问题。
4.1 查看是否安装了优先级的插件
[[email protected] ~]# rpm -qa | grep yum-plugin-
yum-plugin-fastestmirror-1.1.30-37.el6.noarch
我们看没有安装yum-plugin-priorities.noarch这个插件
4.2 安装yum-plugin-priorities.noarch插件
[[email protected] ~]# yum install yum-plugin-priorities.noarch -y
4.3 查看插件是否可用
[[email protected] ~]# cat /etc/yum/pluginconf.d/priorities.conf
[main]
enabled = 1 1表示可用,0为禁用
4.4 修改本地yum源优先使用
[[email protected] ~]# cp /home/yum.repos.d/local.repo /etc/yum.repos.d/
[[email protected] ~]# ll /etc/yum.repos.d/
总用量 8
-rw-r--r--. 1 root root 2006 12月 1 2016 CentOS6-Base-163.repo
-rw-r--r--. 1 root root 63 3月 7 06:34 local.repo
[[email protected] ~]# cat /etc/yum.repos.d/local.repo
[local]
name=local
baseurl=file:///media/
enabled=1
gpgcheck=0
priority=1
添加priority=1,数字越小优先级越高,也可以修改网络源的priority的值
原文地址:http://blog.51cto.com/10642812/2083645
时间: 2024-11-08 11:31:07