一用 Centos 镜像搭建本地 yum 源
安装完 linux 系统的默认 yum 源为 centos 的官方地址, 在国内的特殊环境下使用很慢甚至无法访问, 所以一般的做法都是把默认的 yum 源替换成 aliyun 的 yum 源或者 163 等国内的 yum 源
但是以上的方法都是需要网络的, 当没有网络的时候就无法使用了, 所以还有一个常用的方法就是用 Centos 的 iso 镜像搭建本地 yum 源, 这样安装软件的速度就会飞快, 缺点是可能有些需要的包文件本地里没有
- ?
- ?
- # 1. 安装 Centos 后默认的 yum 源如下
- [root@localhost ~]# ll /etc/yum.repos.d/
- total 32
- -rw-r--r--. 1 root root 1664 Dec 9 2015 CentOS-Base.repo
- -rw-r--r--. 1 root root 1309 Dec 9 2015 CentOS-CR.repo
- -rw-r--r--. 1 root root 649 Dec 9 2015 CentOS-Debuginfo.repo
- -rw-r--r--. 1 root root 290 Dec 9 2015 CentOS-fasttrack.repo
- -rw-r--r--. 1 root root 630 Dec 9 2015 CentOS-Media.repo
- -rw-r--r--. 1 root root 1331 Dec 9 2015 CentOS-Sources.repo
- -rw-r--r--. 1 root root 1952 Dec 9 2015 CentOS-Vault.repo
- # 2. 把默认 yum 源备份并建立新 yum 源
- ?
- ?
- # 3. 在虚拟机上挂在 Centos 镜像文件
- ?
- [root@localhost ~]#mount /dev/cdrom /mnt/
- mount: /dev/sr0 is write-protected, mounting read-only
- ?
- # 4. 编写 repo 文件并指向镜像的挂在目录
- vim bendi.repo
- [bash] #库名
- name=bash #库名 (这一行其实可以不用写, 用 yum reipolist 会报个错但不影响使用)
- baseurl=file:///mnt/ #源所在路径
- enabled=1 #1 为启动 0 为不启用
- gpgcheck=0 #检查签名 1 为检测 0 为不检测
- ?
- # 5. 清除缓存
- [root@localhost ~]# yum clean all
- Loaded plugins: fastestmirror
- Cleaning repos: local
- Cleaning up everything
- Cleaning up list of fastest mirrors
- [root@localhost ~]# yum makecache // 把 yum 源缓存到本地, 加快软件的搜索好安装速度
- [rroot@localhost ~]# yum list
- ?
二把默认的 CentOS yum 源修改成国内的 aliyun yum 源
?
这里是: 阿里云官方教程地址
- ?
- # 1. 下载 aliyun yum 源 repo 文件 (对应自己的系统版本下载即可, 需有外网)
- ?
- # 各系统版本 repo 文件对应的下载操作
- CentOS 6
- wget -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
- ?
- # 2. 清楚缓存
- [root@localhost ~]# yum clean all
- Loaded plugins: fastestmirror
- Cleaning repos: base extras updates
- Cleaning up everything
- Cleaning up list of fastest mirrors
- [root@localhost ~]# yum makecache // 把 yum 源缓存到本地, 加快软件的搜索好安装速度
- [root@localhost ~]# yum list
- ?
三修改 yum 源的优先级
ps: 当既有本地 yum 源又有 163 源的时候, 我们在装软件包的时候当然希望先用本地的 yum 源去安装, 本地找不到可用的包时再使用 163 源去安装软件, 这里就涉及到了优先级的问题, yum 提供的插件 yum-plugin-priorities.noarch 可以解决这个问题
?
1. 查看是否安装了 yum-plugin 优先级插件
- [root@localhost ~]#rpm -qa | grep yum-plugin-
- yum-plugin-fastestmirror-1.1.31-42.el7.noarch
- yum-plugin-priorities-1.1.31-42.el7.noarch
之前我安装过所以能查到, 如果未查到请按照以下方法安装
?
2. 安装 yum-plugin-priorities.noarch 插件
- [root@localhost ~]#yum -y install yum-plugin-priorities.noarch
- ?
3. 查看插件是否启用
- [root@localhost ~]#cat /etc/yum/pluginconf.d/priorities.conf
- [main]
- enabled = 1 //1 为启动 0 为禁用
- ?
4. 修改本地 yum 源优先使用
- [cal]
- name=local
- baseurl=file:///mnt
- enabled=1
- gpgcheck=0
- priority=1
- // 在原基础上加入 priority=1 ; 数字越小优先级越高
- // 可以继续修改其他源的 priority 值, 经测试仅配置本地源的优先级为 priority=1 就会优先使用本地源了
- ?
?
来源: http://www.bubuko.com/infodetail-2507381.html