这是对yum命令的补充    Yum命令

  


一、用Centos镜像搭建本地yum源

由于安装centos后的默认yum源为centos的官方地址,所以在国内使用很慢甚至无法访问,所以一般的做法都是把默认的yum源替换成aliyun的yum源或者163等国内的yum源(下文介绍如何配置)。
但是以上的方法都是需要网络的,当没有网络的时候就无法使用了,所以还有一个常用的方法就是用Centos的iso镜像搭建本地yum源,这样安装软件的速度就会飞快,缺点是可能有些包没有。 .安装Centos后默认的yum源如下 [root@huhy ~]# ll /etc/yum.repos.d/
total
-rw-r--r--. root root Dec CentOS-Base.repo
-rw-r--r--. root root Dec CentOS-CR.repo
-rw-r--r--. root root Dec CentOS-Debuginfo.repo
-rw-r--r--. root root Dec CentOS-fasttrack.repo
-rw-r--r--. root root Dec CentOS-Media.repo
-rw-r--r--. root root Dec CentOS-Sources.repo
-rw-r--r--. root root Dec CentOS-Vault.repo
.把默认yum源备份(可选) [root@huhy ~]# mkdir /opt/centos-yum.bak
[root@huhy ~]# mv /etc/yum.repos.d/* /opt/centos-yum.bak/
3.在虚拟机上挂载CentOS镜像文件 这里写图片描述 [root@huhy ~]# mount -t iso9660 /dev/sr0 /opt/centos
mount: /dev/sr0 is write-protected, mounting read-only
4.编写repo文件并指向镜像的挂载目录 [root@huhy ~]# vi /etc/yum.repos.d/local.repo
[local]
name=local
baseurl=file:///opt/centos
enabled=1
gpgcheck=0
5.清除缓存 [root@huhy ~]# yum clean all
Loaded plugins: fastestmirror
Cleaning repos: local
Cleaning up everything
Cleaning up list of fastest mirrors
[root@huhy ~]# yum makecache //把yum源缓存到本地,加快软件的搜索好安装速度
[root@huhy ~]# yum list //列出了3780个包 二、把默认的CentOS yum源修改成国内的aliyun yum源 阿里云官方教程:http://mirrors.aliyun.com/help/centos 1.安装Centos后默认的yum源如下 [root@huhy ~]# 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源备份(可选) [root@huhy ~]# mkdir /opt/centos-yum.bak
[root@huhy ~]# mv /etc/yum.repos.d/* /opt/centos-yum.bak/ 3.下载aliyun yum源repo文件(对应自己的系统版本下载即可) #各系统版本repo文件对应的下载操作
CentOS 5
wget -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
CentOS 7
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo [root@huhy ~]# cat /etc/redhat-release //查看系统的版本
CentOS Linux release 7.2.1511 (Core)
[root@huhy ~]# wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
--2017-06-20 06:43:08-- http://mirrors.aliyun.com/repo/Centos-7.repo
Resolving mirrors.aliyun.com (mirrors.aliyun.com)... 112.124.140.210, 115.28.122.210
Connecting to mirrors.aliyun.com (mirrors.aliyun.com)|112.124.140.210|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 2573 (2.5K) [application/octet-stream]
Saving to: ‘/etc/yum.repos.d/CentOS-Base.repo’
100%[=======================================================================================================>] 2,573 --.-K/s in 0s
2017-06-20 06:43:08 (118 MB/s) - ‘/etc/yum.repos.d/CentOS-Base.repo’ saved [2573/2573] 4.清除缓存 [root@huhy ~]# yum clean all
Loaded plugins: fastestmirror
Cleaning repos: base extras updates
Cleaning up everything
Cleaning up list of fastest mirrors
[root@huhy ~]# yum makecache //把yum源缓存到本地,加快软件的搜索好安装速度
[root@huhy ~]# yum list //总共列出了9954个包
三、把默认的CentOS yum源修改成国内的163源 163官方教程:http://mirrors.163.com/.help/centos.html 1.安装Centos后默认的yum源如下 [root@huhy ~]# 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源备份(可选) [root@huhy ~]# mkdir /opt/centos-yum.bak
[root@huhy ~]# mv /etc/yum.repos.d/* /opt/centos-yum.bak/
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
[root@huhy ~]# cat /etc/redhat-release //查看系统的版本
CentOS Linux release 7.2.1511 (Core)
[root@huhy ~]# wget -O /etc/yum.repos.d/CentOS7-Base-163.repo http://mirrors.163.com/.help/CentOS7-Base-163.repo
--2017-06-20 06:29:47-- http://mirrors.163.com/.help/CentOS7-Base-163.repo
Resolving mirrors.163.com (mirrors.163.com)... 123.58.173.185, 123.58.173.186
Connecting to mirrors.163.com (mirrors.163.com)|123.58.173.185|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 1572 (1.5K) [application/octet-stream]
Saving to: ‘/etc/yum.repos.d/CentOS7-Base-163.repo’
100%[=======================================================================================================>] 1,572 --.-K/s in 0s
2017-06-20 06:29:47 (293 MB/s) - ‘/etc/yum.repos.d/CentOS7-Base-163.repo’ saved [1572/1572] 4.清除缓存 [root@huhy ~]# yum clean all
Loaded plugins: fastestmirror
Cleaning repos: base extras updates
Cleaning up everything
Cleaning up list of fastest mirrors
[root@huhy ~]# yum makecache //把yum源缓存到本地,加快软件的搜索好安装速度
[root@huhy ~]# yum list //总共列出了9951个包 四、修改yum源的优先级 ps:当既有本地yum源又有163源的时候,我们在装软件包的时候当然希望先用本地的yum源去安装,本地找不到可用的包时再使用163源去安装软件,这里就涉及到了优先级的问题,yum提供的插件yum-plugin-priorities.noarch可以解决这个问题 1.查看系统是否安装了优先级的插件 [root@huhy ~]# rpm -qa | grep yum-plugin-
yum-plugin-fastestmirror-1.1.31-34.el7.noarch
//这里看到没有安装yum-plugin-priorities.noarch这个插件
[root@huhy ~]# yum search yum-plugin-priorities
//用search查看是否有此插件可用
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: mirrors.aliyun.com
* extras: mirrors.aliyun.com
* updates: mirrors.aliyun.com
====================================================== N/S matched: yum-plugin-priorities =======================================================
yum-plugin-priorities.noarch : plugin to give priorities to packages from different repos 2.安装yum-plugin-priorities.noarch插件 [root@huhy ~]# yum -y install yum-plugin-priorities.noarch 3.查看插件是否启用 [root@huhy ~]# cat /etc/yum/pluginconf.d/priorities.conf
[main]
enabled = 1 //1为启用;0为禁用 4.修改本地yum源优先使用 [root@huhy ~]# ll /etc/yum.repos.d/
total 8
-rw-r--r--. 1 root root 2573 May 15 2015 CentOS-Base.repo
-rw-r--r--. 1 root root 67 Jun 20 06:04 local.repo
//有两个repo文件
[root@huhy ~]# vi /etc/yum.repos.d/local.repo
[local]
name=local
baseurl=file:///opt/centos
enabled=1
gpgcheck=0
priority=1
//在原基础上加入priority=1 ;数字越小优先级越高
//可以继续修改其他源的priority值,经测试仅配置本地源的优先级为priority=1就会优先使用本地源了 5.测试 配置优先级前:(使用阿里云yum源)
[root@huhy ~]# yum -y install vim
Dependencies Resolved
=================================================================================================================================================
Package Arch Version Repository Size
=================================================================================================================================================
Installing:
vim-enhanced x86_64 2:7.4.160-1.el7_3.1 updates 1.0 M
Updating for dependencies:
vim-common x86_64 2:7.4.160-1.el7_3.1 updates 5.9 M
省略··· 配置优先级后:(使用本地yum源)
[root@huhy ~]# yum -y install vim
Dependencies Resolved
=================================================================================================================================================
Package Arch Version Repository Size
=================================================================================================================================================
Installing:
vim-enhanced x86_64 2:7.4.160-1.el7 local 1.0 M
Installing for dependencies:
gpm-libs x86_64 1.20.7-5.el7 local 32 k
perl x86_64 4:5.16.3-286.el7 local 8.0 M
perl-Carp noarch 1.26-244.el7 local 19 k
perl-Encode x86_64 2.51-7.el7 local 1.5 M
perl-Exporter noarch 5.68-3.el7

最新文章

  1. javac 导入第三方jar包
  2. Dapper 数据操作框架
  3. UE4 VR 模式全屏 4.13
  4. java中用spring实现数组类型输出
  5. android 监听短信并发送到服务器
  6. PHP的$_SERVER['PHP_SELF']造成的XSS漏洞攻击及其解决方案
  7. tokudb
  8. c文件操作 (转)
  9. Ubuntu14.04安装中文输入法以及解决Gedit中文乱码问题[转载]
  10. discuz2.0升级后不能自动跳转问题
  11. Django用户认证系统(三)组与权限
  12. 关于Git补丁文件交互
  13. 有关Color和Drawable你所不知道的那些内容
  14. js--javascript中字符串常用操作总结、JS字符串操作大全
  15. Spring MVC 使用介绍(十五)数据验证 (二)依赖注入与方法级别验证
  16. BOM 浏览器对象模型_同源限制
  17. 2018-2019-2 网络对抗技术 20165304 Exp6 信息搜集与漏洞扫描
  18. 1_translation_1
  19. 求两个排序数组中位数 C++
  20. PAT L2-022 重排链表

热门文章

  1. mongo数据查询操作
  2. 记一次使用mybatis进行like 模糊查询遇到的问题
  3. C/C++求职宝典21个重点笔记(常考笔试面试点)
  4. 后台线程(daemon)
  5. flex弹性布局学习总结
  6. GCD之后台程序运行
  7. Centos7.X通过rpm包安装Docker
  8. karma + jasmine 构建前端自动化测试
  9. 使用javacv,解码socket接收的H264码流(byte[]),转为yuv处理,最后再合成转为H264
  10. RestfulAPI超简单入门