zoukankan      html  css  js  c++  java
  • CentOS 源设置


    安装完CentOS后,系统默认的源可能有限满,这时我们需要添加国内比较好的源。

    一、国内比较好的源
    https://opsx.alibaba.com/mirror                   #阿里源,有帮助文档
    https://mirrors.tuna.tsinghua.edu.cn/             #清华大学源,有帮助文档
    http://mirrors.163.com/                           #网易源,有帮助文档

    二、添加阿里源
    进入阿里源官方网站,点开centos右侧的帮助如下:
    CentOS
    1、备份

    mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup

    2、下载新的CentOS-Base.repo 到/etc/yum.repos.d/

    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

    3、之后运行yum makecache生成缓存

    4、通过这个帮助文件很容易添加5 6 7版本的阿里源,其他站点的源通过对应的帮助文件安装。
    5、可以通过下面的命令先清除原来的缓存,在生成新的缓存
    yum clean all     #生成前先清除原来的缓存
    yum makecache

    三、添加第三方EPEL源
    CentOS自带的yum源中rpm包数量有限,很多时候找不到我们需的软件包,所以我们需要安装包含丰富的第三方YUM源来满足我们的需求。

    1、EPEL(Extra Packages for Enterprise Linux中文翻译为 企业版 Linux 附加软件包,以下简称 EPEL)是一个 Fedora 特别兴趣小组,用以创建、维护以及管理针对企业版 Linux 的一个高质量附加软件包集,面向的对象包括但不限于 红帽企业版 Linux (RHEL)、 CentOS、Scientific Linux (SL)、Oracle Linux (OL) 。作为 Fedora 打包社区的一部分,EPEL 的所有软件包都是 100% 免费且自由的开源软件(FLOSS)。
    EPEL 的软件包通常不会与企业版 Linux 官方源中的软件包发生冲突,或者互相替换文件。EPEL 项目与 Fedora 基本一致,包含完整的构建系统、升级管理器、镜像管理器等等。
    更详细的内容可以查看官方WIKI:https://fedoraproject.org/wiki/EPEL/zh-cn  ,下载地址:http://dl.fedoraproject.org/pub/epel/

    2、官方的EPEL源可能速度比较较慢,这里我们添加阿里的EPEL源,其他站点查看对应的帮助文件,阿里的EPEL源也有帮助文件,如下:
    ##epel 配置方法
    ###1、备份(如有配置其他epel源)

    mv /etc/yum.repos.d/epel.repo /etc/yum.repos.d/epel.repo.backup
    mv /etc/yum.repos.d/epel-testing.repo /etc/yum.repos.d/epel-testing.repo.backup

    2、下载新repo 到/etc/yum.repos.d/

    epel(RHEL 7)

        wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo

    epel(RHEL 6)

        wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-6.repo

    epel(RHEL 5)

        wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-5.repo

    3、可以通过下面的命令先清除原来的缓存,在生成新的缓存
    yum clean all     #生成前先清除原来的缓存
    yum makecache

    4、我们也可以通过”epel-release”这个软件包,这个软件包会自动配置yum的软件仓库。不推荐用这种方法因为官方的epel源有可能慢,还是自己配置epel软件仓库。

    四、添加第三方RepoForge源
    RepoForge原名RPMforge是 RHEL 系统下的软件仓库,拥有 10000 多个软件包,被认为是最安全、最稳定的一个软件仓库。是由 Dag 及其它包装者合作维护的,包括 wine、vlc、mplayer、xmms-mp3 及其它受欢迎的媒体工具。它并不是 Red Hat 或 CentOS 的一部份,但却是为那些发行版本而设计的,可能与EPEL源冲突,使用要注意。

    官方网站:http://repoforge.org/ ,通过官方网站的usage(用法)标签可以查看用法:在http://repoforge.org/use/用法网页,下载CentOS版本与CPU架构
    的rpm安装包,下载后安装这个软件包,就完成了软件源的添加。

    http://repoforge.org/use/网站源下载部分:
    Using RepoForge
    First download the appropriate rpmforge-release package for your distribution:

    EL 7: x86_64
    EL 6: i686, x86_64                #6版本对应的32位和64位,下载系统对应的
    EL 5: i386, x86_64, ppc

    上面官方的可能有点慢,可以去https://mirrors.tuna.tsinghua.edu.cn/help/repoforge/清华大学的repoforge源,有帮助文件,进行安装。

    五、添加第三方RPMFusion源
    如果您使用过Fedora ,相信对 RPMFusion一定不陌生吧,各种音频软件如MPlayer在标准源中是没有的,一般先安装RPMFusion源,之后就可以方便地yum install各种需要的软件啦。但CentOS官方说RPMFusion软件库里面的软件稳定性不如rpmforge。
    RPMFusion官网:http://rpmfusion.org/

    安装源:要添加rpmfusion软件源,首先要安装epel-release这个软件包,前面添加EPEL源时提到过,你可能会担心安装这个软件包会和添加的阿里的EPEL冲突,如果是先添加阿里源,问题不大。然后去RPMFusion官方网站Configuration标签页下载RPM Fusion free for RHEL 6 or compatible like CentOS(自由的)和RPM Fusion nonfree for RHEL 6 or compatible like CentOS(非自由的)这两个安装包进行源的安装,我的系统是6版本所以下这两个,如果不先安装epel-release这个软件包,在进行上面两个软件包安装时会错误。
    软件源下载官方网址:
    https://rpmfusion.org/Configuration

    六、第三方ELRepo源

    ELRepo项目侧重于硬件相关的包来增强你的经验与企业Linux。这包括文件系统驱动、显卡驱动、网络驱动程序、声音驱动、摄像头和视频驱动程序。Repoforge 是 RHEL 系统下的软件仓库,拥有 10000 多个软件包,被认为是最安全、最稳定的一个软件仓库。
    官方网站:http://elrepo.org/  
    官网主页就有软件源的添加方法,按照上面的方法添加就可以了。
    CentOS6为例:

    1、导入公钥:
    rpm --import https://www.elrepo.org/RPM-GPG-KEY-elrepo.org

    2、安装ELRepo 6        #对应我的CentOS6版本

    rpm -Uvh http://www.elrepo.org/elrepo-release-6-8.el6.elrepo.noarch.rpm

    七、 Remi源

    Remi 源大家或许很少听说, 但是我们强烈推荐, 尤其对于不想编译最新版的 linux 使用者, 因为 Remi 源中的软件几乎都是最新稳定版.

    或许您会怀疑稳定不?放心吧, 这些都是 Linux 骨灰级的玩家编译好放进源里的, 他们对于系统环境和软件编译参数的熟悉程度毋庸置疑.

    Remi下载地址:https://rpms.remirepo.net/http://rpms.famillecollet.com/

    安装源:打开Remi官网的Repository Configuration标签进入https://blog.remirepo.net/pages/Config-en网页 ,这里有安装说明,根据说明进行安装就可以了。
    这个原需要EPEL源的支持,所以要先添加EPEL源,上面我们已经添加了,安装CentOS源如下:
    1、下载源安装包
    [root@CentOS ~]# wget https://rpms.remirepo.net/enterprise/remi-release-6.rpm
    2、安装源安装包     
    [root@CentOS ~]# rpm -Uvh remi-release-6.rpm
    3、然后编辑  /etc/yum.repos.d/remi.repo 源文件,将其中 [remi] 下的enabled=0改为1,保存退出,从而启动源完成配置。

    八、添加本地DVD源。
    在服务器不允许联网的情况下经常会用到本地DVD安装光盘的源。
    系统安装完默认会在/etc/yum.repos.d/的源目录下成才一个CentOS-Media.repo 的源文件,我们只要对这个源文件进行相应的设置就行
    1、查看CentOS-Media.repo 文件内容:
    [root@CentOS yum.repos.d]# cat CentOS-Media.repo
    # CentOS-Media.repo
    #
    #  This repo can be used with mounted DVD media, verify the mount point for
    #  CentOS-6.  You can use this repo and yum to install items directly off the
    #  DVD ISO that we release.
    #
    # To use this repo, put in your DVD and use it with the other repos too:
    #  yum --enablerepo=c6-media [command]
    #  
    # or for ONLY the media repo, do this:
    #
    #  yum --disablerepo=* --enablerepo=c6-media [command]
     
    [c6-media]                                                        #源名称,必填
    name=CentOS-$releasever - Media                #源描述,可以不填,但是会有提示
    baseurl=file:///media/CentOS/                         #挂载DVD光驱的可选目录/media/CentOS/ ,这个目录可以因个人方便改变成其他目录
            file:///media/cdrom/                                 #挂载DVD光驱的可选目录/media/cdrom/
            file:///media/cdrecorder/                         #挂载DVD光驱的可选目录/media/cdrecorder/
    gpgcheck=1                                                   #是否开启校验,在yum.conf中已经定义它默认值为1
    enabled=0                                                     #是否开启这个源,enabled=0为关闭,enabled=1为开启
    gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6             #如果开启yum源包校验,则需要导入RPM公钥。
    [root@CentOS yum.repos.d]#

    2、在/media/目录下新建CentOS目录,
    [root@CentOS media]# mkdir CentOS
    [root@CentOS media]# ls
    CentOS

    3、挂在DVD光驱到/media/CentOS/目录,一定要选择和系统版本号一样的系统镜像。
    [root@CentOS ~]# mount /dev/cdrom1 /media/CentOS/

    4、将CentOS-Media.repo 文件的enabled=0 给成enabled=1 ,删除或用#屏蔽file:///media/cdrom/和file:///media/cdrecorder/这两行,
    如果不删除或屏蔽,生成源缓存时会因为找不到对应的文件而报错。


    九、添加完源一定要记得生成缓存,通过下面的命令先清除原来的缓存,在生成新的缓存
    yum clean all         #生成前先清除原来的缓存
    yum makecache   #生成缓存

    十、设置软件源的优先级

    当系统有多个软件源时,要安装某一个软件,并且这个软件在多个源里面都有时,我们肯定希望用最优质的源来下载软件,而且不同的软件源之间并不能保证软件的完全兼容没有冲突。所以我们需要设置软件源的优先级。yum-plugin-priorities 插件可以用来强制保护源。它通过给各个源设定不同的优先级,使得系统管理员可以将某些源(比如官方源)设定为最高优先级,从而保证系统的稳定性(同时也可能无法更新到其它源上提供的软件最新版本)。您需要安装yum-plugin-priorities插件。

    1、安装yum-plugin-priorities插件

    [root@Fedora ~]# yum install yum-plugin-priorities.noarch

    2、查看插件是否可用
    yum-plugin-priorities 插件的配置文件是/etc/yum/pluginconf.d/priorities.conf,先确认其是否存在,后查看
    其内容为:
    [main]
    enabled=1   # 0禁用 1启用

    3、设置优先级
    前两项完成后,您可以编辑/etc/yum.repos.d/目录下所有的.repo文件,给所有的源设置优先级(priority)。priority的优先级为1到99,设置为1即优先级最高,1-10为系统保留,第三方yum源的优先级从11-99 。一般官方的源文件CentOS-Base.repo下有[base],  [updates], [extras]三个源设置为 priority=1 另外两个[CentOSplus],[contrib] 源设置成 priority=2,一个源文件下面可以有多个源。
    其他第三方软件源的源文件中的源源设置为:priority=N (推荐N>10,并且每个类型的源推荐从n0开始,n为1-9的数字,比如10,20,30,这样源下面的细分源以后也方便添加级别)

    4、编辑官方源文件 /etc/yum.repos.d/CentOS-Base.repo 编辑如下:
    -------------------------------------------------------------------------------------------------------
    [root@CentOS yum.repos.d]# vi CentOS-Base.repo
    # CentOS-Base.repo
    #
    # The mirror system uses the connecting IP address of the client and the
    # update status of each mirror to pick mirrors that are updated to and
    # geographically close to the client.  You should use this for CentOS updates
    # unless you are manually picking other mirrors.
    #
    # If the mirrorlist= does not work for you, as a fall back you can try the
    # remarked out baseurl= line instead.
    #
    #
     
    [base]
    name=CentOS-$releasever - Base - mirrors.aliyun.com
    failovermethod=priority
    baseurl=http://mirrors.aliyun.com/centos/$releasever/os/$basearch/
            http://mirrors.aliyuncs.com/centos/$releasever/os/$basearch/
    #mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os
    gpgcheck=1
    gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-6
    priority=1                   #设置[base]源优先级为1
     
    #released updates
    [updates]
    name=CentOS-$releasever - Updates - mirrors.aliyun.com
    failovermethod=priority
    baseurl=http://mirrors.aliyun.com/centos/$releasever/updates/$basearch/
            http://mirrors.aliyuncs.com/centos/$releasever/updates/$basearch/
    #mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates
    gpgcheck=1
    gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-6
    priority=1                  #设置[updates]源优先级为1
     
    #additional packages that may be useful
    [extras]
    name=CentOS-$releasever - Extras - mirrors.aliyun.com
    failovermethod=priority
    baseurl=http://mirrors.aliyun.com/centos/$releasever/extras/$basearch/
            http://mirrors.aliyuncs.com/centos/$releasever/extras/$basearch/
    #mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras
    gpgcheck=1
    gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-6
    priority=1                  #设置[extras]源优先级为1
     
    #additional packages that extend functionality of existing packages
    [centosplus]
    name=CentOS-$releasever - Plus - mirrors.aliyun.com
    failovermethod=priority
    baseurl=http://mirrors.aliyun.com/centos/$releasever/centosplus/$basearch/
            http://mirrors.aliyuncs.com/centos/$releasever/centosplus/$basearch/
    #mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=centosplus
    gpgcheck=1
    enabled=0                   #如果想开启这个源将enabled=0改为enabled=1
    gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-6
    priority=2                  #设置[centosplus]源优先级为2
     
    #contrib - packages by Centos Users
    [contrib]
    name=CentOS-$releasever - Contrib - mirrors.aliyun.com
    failovermethod=priority
    baseurl=http://mirrors.aliyun.com/centos/$releasever/contrib/$basearch/
            http://mirrors.aliyuncs.com/centos/$releasever/contrib/$basearch/
    #mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=contrib
    gpgcheck=1
    enabled=0                   #如果想开启这个源将enabled=0改为enabled=1
    gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-6
    priority=2                  #设置[contrib]源优先级为2
    [root@CentOS yum.repos.d]#
    ----------------------------------------------------------------------------------------------------------
    5、编辑[epel]第三方源优先级
    ----------------------------------------------------------------------------------------------------------
    [root@CentOS yum.repos.d]# vi epel.repo

    [epel]
    name=Extra Packages for Enterprise Linux 6 - $basearch
    baseurl=http://mirrors.aliyun.com/epel/6/$basearch
            http://mirrors.aliyuncs.com/epel/6/$basearch
    #mirrorlist=https://mirrors.fedoraproject.org/metalink?repo=epel-6&arch=$basearch
    failovermethod=priority
    enabled=1
    gpgcheck=0
    gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6
    gpgcheck=11                 #设置[epel]第三方源优先级为11            
     
    [epel-debuginfo]
    name=Extra Packages for Enterprise Linux 6 - $basearch - Debug
    baseurl=http://mirrors.aliyun.com/epel/6/$basearch/debug
            http://mirrors.aliyuncs.com/epel/6/$basearch/debug
    #mirrorlist=https://mirrors.fedoraproject.org/metalink?repo=epel-debug-6&arch=$basearch
    failovermethod=priority
    enabled=0
    gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6
    gpgcheck=0
     
    [epel-source]
    name=Extra Packages for Enterprise Linux 6 - $basearch - Source
    baseurl=http://mirrors.aliyun.com/epel/6/SRPMS
            http://mirrors.aliyuncs.com/epel/6/SRPMS
    #mirrorlist=https://mirrors.fedoraproject.org/metalink?repo=epel-source-6&arch=$basearch
    failovermethod=priority
    enabled=0
    gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6
    gpgcheck=0
    [root@CentOS yum.repos.d]#
    --------------------------------------------------------------------------------------------------------------
    6、其他第三方源的优先级设置这里就不介绍了,/etc/yum.repos.d/目录下文件名后缀为.repo的文件都是源文件,里面对应的源都需要设置,最好不要添加太多源
    官方源和EPEL源就够了,如果这里没有想要的软件在进行其他源的添加,添加过多的源维护起来麻烦,还容易造成软件源的冲突。
    7、特殊情况:在不同优先级的源中都含有同一个包时,它的行为可能就不是我们所需要的。例如,在官方源中有个包:bck.1.11.x86_64.rpm,官方源是最高优先级。在其他的多个源中也有bck这个包的不同版本,比如bck的版本为bck.1.21.x86_64.rpm,通过命令安装bck.1.21.x86_64.rpm
    yum install bck.1.21.x86_64.rpm
    就会出现下面的提示
        xx packages excluded due to repository priority protections
    并且找不到所需要的包,这是因为在高优先级源中存在的包,会将其他低优先级中的包屏蔽掉,因此无法从低优先级的源中安装所需要的包。

    解决办法是禁用yum-plugin-priorities插件,将/etc/yum/pluginconf.d/priorities.conf文件中的enabled=1改称enabled=0
    默认是1;设置enabled = 0,这样就可以禁用priorities插件。从而能够安装任意源上的包。

    或者把高优先级的软件源关闭,就是在对应源文件的源位置后面添加enabled=0,有的就将enabled=1改为enabled=0
    例如关闭epel源
    [root@CentOS yum.repos.d]# vi epel.repo

    [epel]
    name=Extra Packages for Enterprise Linux 6 - $basearch
    baseurl=http://mirrors.aliyun.com/epel/6/$basearch
            http://mirrors.aliyuncs.com/epel/6/$basearch
    #mirrorlist=https://mirrors.fedoraproject.org/metalink?repo=epel-6&arch=$basearch
    failovermethod=priority
    enabled=1                        #将enabled=1改为enabled=0关闭 [epel]源
    gpgcheck=0
    gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6
    ......   
                
    十一、显示当前可用源列表

    [root@CentOS yum.repos.d]# yum repolist
    已加载插件:fastestmirror, priorities, refresh-packagekit, security
    Loading mirror speeds from cached hostfile
     * base: mirrors.aliyun.com
     * epel: mirrors.aliyun.com
     * extras: mirrors.aliyun.com
     * updates: mirrors.aliyun.com
    106 packages excluded due to repository priority protections
    仓库标识                                          仓库名称                                                                                 状态
    base                                              CentOS-6 - Base - mirrors.aliyun.com                                                          6,706
    epel                                              Extra Packages for Enterprise Linux 6 - x86_64                                           12,391+106
    extras                                            CentOS-6 - Extras - mirrors.aliyun.com                                                           53
    updates                                           CentOS-6 - Updates - mirrors.aliyun.com                                                       1,185
    repolist: 20,335
    [root@CentOS yum.repos.d]#

    所然上面添加了很多源,但是我把现在暂时不用的源都通过enabled=0关闭了,只留下一个EPEL第三方源,这样可以减少软件的冲突和软件搜索的速度。































  • 相关阅读:
    【转】QT创建子对话框的方法
    IplImage转为Mat的方法
    浅谈Android选项卡(二)
    浅谈Android选项卡(一)
    Android来电、去电监听
    文件加密
    Java实现文件重命名
    使用单个httpclient实例请求数据。
    获取Android状态栏的高度
    [置顶] 微软翻译接口
  • 原文地址:https://www.cnblogs.com/pipci/p/8882868.html
Copyright © 2011-2022 走看看