www.hj8828.com 1

CentOS配置本地yum源/Ali云yum源/1陆三yuan源,并配置yum源的优先级,centos1六三yuan

www.hj8828.com,CentOS配置本地yum源/阿里云yum源/16三yuan源,并配置yum源的优先级,centos1陆三yuan

2、把默许的CentOS Yum源修改成国内的aliyun Yum源

Ali云官方教程:http://mirrors.aliyun.com/help/centos

  1. 设置Centos后暗中认可的Yum源如下

[root@kangvcar ~]# 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
  1. 把默认Yum源备份(可选)

[root@kangvcar ~]# mkdir /opt/centos-yum.bak
[root@kangvcar ~]# mv /etc/yum.repos.d/* /opt/centos-yum.bak/
  1. 下载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@kangvcar ~]# cat /etc/redhat-release        //查看系统的版本
CentOS Linux release 7.2.1511 (Core)
[root@kangvcar ~]# 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]
  1. 免除缓存

[root@kangvcar ~]# yum clean all
Loaded plugins: fastestmirror
Cleaning repos: base extras updates
Cleaning up everything
Cleaning up list of fastest mirrors
[root@kangvcar ~]# yum makecache        //把Yum源缓存到本地,加快软件的搜索好安装速度
[root@kangvcar ~]# yum list        //总共列出了9954个包

2.常用相关命令

  1 安装
    yum install 全体设置
    yum install package壹 安装钦定的装置包package一
    yum groupinsall group一 安装程序组group1
    yum install yum-fastestmirror 自动寻觅最快镜像插件
    yum install yumex 安装yum图形窗口插件
    yum grouplist

  ② 翻新和晋级
    yum update 全体更新
    yum update package一 更新钦定程序包package1
    yum check-update 检查可更新的先后
    yum upgrade package一 进级钦点程序包package1
    yum groupupdate group一 进级程序组group一

  3 查找和出示
    yum info package一 显示安装包消息package1
    yum list 显示全数曾经设置和可以设置的先后包
    yum list package壹 彰显内定程序包安装意况package1
    yum groupinfo group一 显示程序组group一音讯yum search string
依据主要字string查找安装包
    yum grouplist 查看恐怕批量安装的列表

  4 删除程序
    yum remove &$12四; erase package一 删除程序包package一
    yum groupremove group壹 删除程序组group壹
    yum deplist package一 查看程序package壹重视情状

  伍 清除缓存
    yum clean packages 清除缓存目录下的软件包
    yum clean headers 清除缓存目录下的 headers
    yum clean oldheaders 清除缓存目录下旧的 headers
    yum clean, yum clean all (= yum clean packages; yum clean
oldheaders) 清除缓存目录下的软件包及旧的headers
    yum clean all

肆.免除缓存

[root@kangvcar ~]# yum clean all
Loaded plugins: fastestmirror
Cleaning repos: base extras updates
Cleaning up everything
Cleaning up list of fastest mirrors
[root@kangvcar ~]# yum makecache        //把yum源缓存到本地,加快软件的搜索好安装速度
[root@kangvcar ~]# yum list        //总共列出了9951个包

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

由于设置centos后的暗中认可Yum源为centos的法定地址,所以在境内采纳极慢以致不能够访问,所以一般的做法都以把暗许的Yum源替换到aliyun的Yum源或然1陆三等国内的Yum源(下文介绍如何安顿)。
不过上述的秘诀都是索要互连网的,当未有网络的时候就不能运用了,所以还有贰个常用的措施就是用Centos的ISO镜像搭建当地Yum源,那样设置软件的快慢就能火速,缺点是唯恐有些包未有。

  1. 安装Centos后私下认可的Yum源如下

[root@kangvcar ~]# 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
  1. 把默认Yum源备份(可选)

[root@kangvcar ~]# mkdir /opt/centos-yum.bak
[root@kangvcar ~]# mv /etc/yum.repos.d/* /opt/centos-yum.bak/
  1. 在虚拟机上挂载CentOS镜像文件
![](https://upload-images.jianshu.io/upload_images/2640591-51a1e9598dd31898)

挂载ISO镜像

[root@kangvcar ~]# mount -t iso9660 /dev/sr0 /opt/centos
mount: /dev/sr0 is write-protected, mounting read-only
  1. 编写repo文件并指向镜像的挂载目录

[root@kangvcar ~]# vi /etc/yum.repos.d/local.repo  
[local]
name=local
baseurl=file:///opt/centos
enabled=1
gpgcheck=0
  1. 铲除缓存

[root@kangvcar ~]# yum clean all
Loaded plugins: fastestmirror
Cleaning repos: local
Cleaning up everything
Cleaning up list of fastest mirrors
[root@kangvcar ~]# yum makecache        //把Yum源缓存到本地,加快软件的搜索好安装速度
[root@kangvcar ~]# yum list        //列出了3780个包

5.优化yum源,配置国内镜像

一)备份原有数据源配置
    mv /etc/yum.repos.d/CentOS-Base.repo
/etc/yum.repos.d/CentOS-Base.repo.backup

二)启用国内镜像(二选一)
    curl -o /etc/yum.repos.d/CentOS-Base.repo
http://mirrors.163.com/.help/CentOS6-Base-163.repo

    wget -O /etc/yum.repos.d/CentOS-Base.repo
http://mirrors.163.com/.help/CentOS6-Base-163.repo
    wget -O /etc/yum.repos.d/CentOS-Base.repo
http://mirrors.aliyun.com/repo/Centos-6.repo
[Centos5.x 7.x]
    wget -O /etc/yum.repos.d/CentOS-Base.repo
http://mirrors.aliyun.com/repo/Centos-5.repo
    wget -O /etc/yum.repos.d/CentOS-Base.repo
http://mirrors.aliyun.com/repo/Centos-7.repo

三)安装命令
    yum clean all
    yum makecache

四)测试通过yum命令使用国内镜像安装使用
    yum install mysql

2、把暗中同意的CentOS yum源修改成国内的aliyun yum源

Ali云官方教程:

三、把私下认可的CentOS Yum源修改成国内的1陆3源

16三法定教程:http://mirrors.163.com/.help/centos.html

  1. 安装Centos后暗中认可的Yum源如下

[root@kangvcar ~]# 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
  1. 把默认Yum源备份(可选)

[root@kangvcar ~]# mkdir /opt/centos-yum.bak
[root@kangvcar ~]# mv /etc/yum.repos.d/* /opt/centos-yum.bak/
  1. 下载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@kangvcar ~]# cat /etc/redhat-release        //查看系统的版本
CentOS Linux release 7.2.1511 (Core)
[root@kangvcar ~]# 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]
  1. 排除缓存

[root@kangvcar ~]# yum clean all
Loaded plugins: fastestmirror
Cleaning repos: base extras updates
Cleaning up everything
Cleaning up list of fastest mirrors
[root@kangvcar ~]# yum makecache        //把Yum源缓存到本地,加快软件的搜索好安装速度
[root@kangvcar ~]# yum list        //总共列出了9951个包

四.基于Centos镜像+Apache搭建公共yum货仓(外网可访问)

1)安装相应的软件
    [root@hadoop102 yum.repos.d]#yum install -y httpd

贰)开启httpd使用浏览器访问http://hadoop102:80
(假如访问不通,检查防火墙是或不是开启了80端口或关闭防火墙)
    [root@hadoop102 yum.repos.d]#service httpd start

3)将YUM源配置到httpd(Apache Server)中,内网别的节点可访问
    [root@hadoop102 html]# mkdir Packages
    [root@hadoop102 html]# chown admin:admin Packages/
    [root@hadoop102 html]# cp -r /mnt/cdrom/Packages/*
/var/www/html/Packages/

四)撤销从前挂载的镜像
[root@hadoop102 yum.repos.d]#umount /mnt/cdrom

五)在浏览器中做客http://hadoop102/Packages/
(暗中认可访问80端口)

www.hj8828.com 1

图片.png

6)施行创设饭店命令:createrepo 路线
    [root@hadoop102 Packages]# createrepo ./

7)让此外部须求要安装RPM包的服务器指向那个YUM源
    [root@hadoop103 /]# cd /etc/yum.repos.d/
    [root@hadoop103 yum.repos.d]# cp CentOS-Base.repo
CentOS-Base.repo.bak
    [root@hadoop103 yum.repos.d]# vim CentOS-Base.repo

[base]
name=CentOS-hadoop102
baseurl=http://hadoop102/Packages
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6

捌)在那台新的服务器上施行YUM的吩咐
    [root@hadoop103 yum.repos.d]# yum clean all
    [root@hadoop103 yum.repos.d]# yum repolist

玖)测试内网中hadoop拾叁 访问hadoop10二提供的yum旅舍,安装使用
    [root@hadoop103 yum.repos.d]# yum install -y createrepo

一.设置Centos后暗中认可的yum源如下

[[email protected] ~]# 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

4、修改Yum源的事先级

当既有地点Yum源又有1陆三源的时候,大家在装软件包的时候自然期待先用本地的Yum源去安装,本地找不到可用的包时再选取16三源去安装软件,这里就涉嫌到了先行级的题目,Yum提供的插件yum-plugin-priorities.noarch能够消除那些难题

  1. 翻开系统是或不是安装了事先级的插件

[root@kangvcar ~]# rpm -qa | grep yum-plugin-
yum-plugin-fastestmirror-1.1.31-34.el7.noarch        
//这里看到没有安装yum-plugin-priorities.noarch这个插件
[root@kangvcar ~]# 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
  1. 安装yum-plugin-priorities.noarch插件

[root@kangvcar ~]# yum -y install yum-plugin-priorities.noarch
  1. 查阅插件是还是不是启用

[root@kangvcar ~]# cat /etc/yum/pluginconf.d/priorities.conf
[main]
enabled = 1
//1为启用;0为禁用
  1. 修改本地Yum源优用

[root@kangvcar ~]# 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@kangvcar ~]# 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就会优先使用本地源了
  1. 测试

配置优先级前:(使用阿里云Yum源)
[root@kangvcar ~]# 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@kangvcar ~]# 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                             local                       28 k
perl-File-Path                              noarch                      2.09-2.el7                             local                       26 k
perl-File-Temp                              noarch                      0.23.01-3.el7                          local                       56 k
省略···

叁.基于Centos镜像搭建本地yum客栈(仅本地利用)

1)将CentOS-6.8-x86_64-bin-mp5一.iso镜像挂载到/mnt/cdrom目录
    [root@hadoop102 /]# mkdir /mnt/cdrom
    [root@hadoop102 /]# mount -t iso9660 /dev/cdrom /mnt/cdrom

贰)修改本机上的YUM源配置文件,将源指向自个儿
    [root@hadoop102 /]# cd /etc/yum.repos.d/
    [root@hadoop102 yum.repos.d]# cp CentOS-Base.repo
CentOS-Base.repo.bak
    [root@hadoop102 yum.repos.d]# vi CentOS-Base.repo

[base]
name=CentOS-Local
baseurl=file:///mnt/cdrom  # 指向本地挂载的 rpm库
gpgcheck=1
enabled=1   #增加改行,使能
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6

3)清除YUM缓冲
    [root@hadoop102 yum.repos.d]# yum clean all

四)列出可用的YUM源
    [root@hadoop102 yum.repos.d]# yum repolist

5)安装相应的软件举行测试
    [root@hadoop102 yum.repos.d]# rpm -qa |grep createrepo
    [root@hadoop102 yum.repos.d]# yum install -y firefox

2.把默认yum源备份(可选)

[root@kangvcar ~]# mkdir /opt/centos-yum.bak
[root@kangvcar ~]# mv /etc/yum.repos.d/* /opt/centos-yum.bak/

1.概述

      YUM(全名为 Yellow dog Updater,
Modified)是贰个在Fedora和RedHat以及CentOS中的Shell前端软件包管理器。基于RPM包管理,能够从钦点的服务器自动下载RPM包并且安装,可以活动处理注重性关系,并且一回安装具备依赖的软件包,无须繁琐地一遍次下载、安装。

1.装置Centos后暗许的yum源如下

[[email protected] ~]# 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

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

[[email protected] ~]# cat /etc/redhat-release        //查看系统的版本
CentOS Linux release 7.2.1511 (Core)
[[email protected] ~]# 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]

伍.去掉缓存

[root@kangvcar ~]# yum clean all
Loaded plugins: fastestmirror
Cleaning repos: local
Cleaning up everything
Cleaning up list of fastest mirrors
[root@kangvcar ~]# yum makecache        //把yum源缓存到本地,加快软件的搜索好安装速度
[root@kangvcar ~]# yum list        //列出了3780个包