• Linux下配置yum源为阿里云或网易的详解


    一、yum源概述
      yum需要一个yum库,也就是yum源。默认情况下,CentOS就有一个yum源。在/etc/yum.repos.d/目录下有一些默认的配置文件(可以将这些文件移到/opt下,或者直接在yum.repos.d/下重命名)。首先要找一个yum库(源),然后确保本地有一个客户端(yum这个命令就是客户端),由yum程序去连接服务器。连接的方式是由配置文件决定的。通过编辑/etc/yum.repos.d/CentOS-Base.repo文件,可以修改设置。
    打开CentOS-Base.repo文件,可以看到url路径是CentOS的官网自身的yum源,
    http://mirrorlist.centos.org/?release=releasever&arch=basearch&repo=os。可以将这个mirrorlist注释掉,然后将baseurl设置成国内的阿里云源
    http://mirrors.aliyun.com/repo/Centos-6.repo或者http://mirrors.aliyun.com/repo/Centos-7.repo
    也可以在用于大量的rpm包的前提下设置成自己的本地文件系统(挂载目录),需要移除CentOS-Base.repo文件,并编辑CentOS-Media.repo文件。http://mirrors.aliyun.com/repo/Centos-6.repo或者Centos-7.repo

    name=Description              //一个描述,随意。
    baseurl=                     //设置资源库的地址,可以写阿里云也可以是自己的yum
        ftp://
        http://
        file:///
    enabled={1|0}                  //enabled=1开启本地更新模式
    gpgcheck={1|0}                //gpgcheck=1表示检查;可以不检查gpgcheck=0
    gpgkey=                       // 检查的key;如果上面不检查这一行可以不写。  
    

    二、YUM源配置方法  

    2.1、配置方法一(阿里云yum源)

    1)安装wget
    [root@localhost ~]# yum install -y wget
    2) 备份/etc/yum.repos.d/CentOS-Base.repo文件
    [root@localhost ~]# cd /etc/yum.repos.d/
    [root@localhost yum.repos.d]# mv CentOS-Base.repo CentOS-Base.repo.back20190401
    3) 下载阿里云的Centos-6.repo文件
    [root@localhost yum.repos.d]# wget -O CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repo
    [root@localhost yum.repos.d]# wget -O CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
    4) 重新加载yum
    [root@localhost yum.repos.d]# yum clean all
    Loaded plugins: fastestmirror, refresh-packagekit, security
    Cleaning repos: base extras updates
    Cleaning up Everything
    Cleaning up list of fastest mirrors
    [root@localhost yum.repos.d]# yum makecache
    Loaded plugins: fastestmirror, refresh-packagekit, security
    Determining fastest mirrors
     * base: mirrors.aliyun.com
     * extras: mirrors.aliyun.com
     * updates: mirrors.aliyun.com
    。。。。。。
    

    2.2、yum源配置方法二(本地挂载目录)  

    1) 下载iso文件
        从CentOS的官网下载CentOS的完整版iso文件,并上传到Linux文件系统中,例如/opt/tools/。
    
    2) 创建挂载目录
        为iso文件的挂载创建目录。
    [root@localhost ~]# mkdir /mnt/vcdrom
    
    3) 挂载
      将iso文件挂载到挂载目录。
    [root@localhost ~]# mount -o loop -t iso9660 /opt/tools/CentOS-6.7-x86_64-bin-DVD1.iso /mnt/vcdrom
    
    4) 移除或备份Centos-Base.repo文件
    [root@localhost ~]# cd /etc/yum.repos.d/
    [root@localhost ~]# mv Centos-Base.repo Centos-Base.repo.back
    5) 编辑Centos-Media.repo文件
    [root@localhost ~]# vim /etc/yum.repos.d/Centos-Media.repo
    
    ........
    name=CentOS-$releasever - Media
    baseurl=file:///mnt/vcdrom/                  //将baseurl修改为DVD的挂载目录
    gpgcheck=1
    enabled=1#开启本地更新模式
    ........
    
    6) 重新加载yum
    [root@localhost ~]# yum clean all
    [root@localhost ~]# yum makecache
    7) 编写脚本并开机自动挂载
      
    首先,编写脚本。
    [root@localhost ~]#vim /opt/shell/mymount.sh
    #!/bin/bash
    #
    mount -o loop -t iso9660 /opt/tools/CentOS-6.7-x86_64-bin-DVD1.iso /mnt/vcdrom
    :wq!
     
    其次,修改脚本执行权限。
    [root@localhost ~]#chmod 777 /opt/shell/mymount.sh
      
    再次,修改/etc/rc.local配置文件。
    [root@localhost ~]#vim /etc/rc.local
      
    在文件最后一行加上如下
    [root@localhost ~]# /opt/shell/mymount.sh
      
    最后,重启机器测试。
    [root@localhost ~]# init 6 
    

    2.3、yum源配置方法三(远程挂载目录)

    2.3.1、服务端配置

    第一,安装nfs-utils和rpcbind。
    
    [root@localhost ~]# yum -y install nfs-utils rpcbind
      
    第二,设置开机启动服务。
    
    [root@localhost ~]# chkconfig nfs on
    [root@localhost ~]# chkconfig rpcbind on 
      
    第三,启动相关服务。
    
    [root@localhost ~]# service rpcbind start             //需要先启动rpcbind
    [root@localhost ~]# service nfs start
    Starting NFS services:                                     [  OK  ]
    Starting NFS quotas:                                       [  OK  ]
    Starting NFS mountd:                                       [  OK  ]
    Starting NFS daemon:                                       [  OK  ]
    Starting RPC idmapd:                                       [  OK  ]
      
    第四,创建共享目录。
    
    [root@localhost ~]# mkdir -p /mnt/vcdrom/
      
    第五,编辑/etc/exports文件,添加如下内容。
    
    [root@localhost ~]# vim /etc/exports 
    添加如下内容:
    /mnt/vcdrom/ 192.168.94.5(rw,async,no_root_squash,no_subtree_check)   
    
    注:配置文件说明:/mnt/vcdrom/为共享的目录,使用绝路径。对172.16.24.8(rw,no_root_squash,no_all_squash,sync) 为客户端的地址及权限,地址可以是一个网段,一个IP地址或者是一个域名,域名支持通配符,如:*eason.com。
    
    权限说明:rw:read-write,可读写;ro:read-only,只读;sync:文件同时写入硬盘和内存;async:文件暂存于内存,而不是直接写入内存;no_root_squash:NFS客户端连接服务端时如果使用的是root的话,那么对服务端分享的目录来说,也拥有root权限。显然开启这项是不安全的。root_squash:NFS客户端连接服务端时如果使用的是root的话,那么对服务端分享的目录来说,拥有匿名用户权限,通常他将使用nobody或nfsnobody身份;all_squash:不论NFS客户端连接服务端时使用什么用户,对服务端分享的目录来说都是拥有匿名用户权限;anonuid:匿名用户的UID值,通常是nobody或nfsnobody,可以在此处自行设定;anongid:匿名用户的GID值。
    
    第六,参考yum源配置方法二,将/opt/tools/下的ios文件挂载到/mnt/vcdrom,需要设置开机自动挂载。
    

    2.3.2、客户端配置  

    第一,安装nfs-utils和rpcbind。
    
    [root@localhost ~]# yum install -y nfs-utils rpcbind
       
     第二,设置开机启动服务。
    
    [root@localhost ~]# chkconfig nfs on
    [root@localhost ~]# chkconfig rpcbind on
       
     第三,启动服务。
    
    [root@localhost ~]# service rpcbind start
    [root@localhost ~]# service nfs start
      
    第四,创建挂载点。
    
    [root@localhost ~]# mkdir -p /mnt/vcdrom/
       
     第五,挂载目录。
    
    [root@localhost ~]# mount -t nfs server_ip:/mnt/vcdrom /mnt/vcdrom
       
     第六,编辑/etc/fstab,配置开机自动挂载
    
     这里可以参考yum源配置方法二的介绍,编写脚本,使脚本开机运行。下面给出第二种方法:
    
    [root@localhost ~]# vim /etc/fstab 
    添加如下内容:
    server_ip:/mnt/vcdrom /mnt/vcdrom nfs rw,tcp,intr 0 1
      
    第七,修改yum源设置。
    
    参考yum源配置方法二。    

    三、yum配置常见问题汇总

    3.1、如果要想CentOS使用yum update更新时不升级内核,方法如下:

    [root@localhost ~]# cp /etc/yum.conf /etc/yum.confbak
    方法一)修改yum的配置文件
    [root@localhost ~]# vim /etc/yum.conf 
    在[main]的最后添加 exclude=kernel*
    
    方法二)直接在yum的命令后面加上如下的参数:
    [root@localhost ~]# yum --exclude=kernel* update
    

    3.2、yum安装的过程中经常会出现这种错误:  

    Loaded plugins: branch, fastestmirror, security
    Determining fastest mirrors
     * addons: mirrors.aliyun.com
     * base: mirrors.aliyun.com
     * extras: mirrors.aliyun.com
     * updates: mirrors.aliyun.com
    http://mirrors.aliyun.com/centos/6/addons/x86_64/repodata/repomd.xml: [Errno 14] PYCURL ERROR 22 - "The requested URL returned error: 404"
    Trying other mirror.
    http://mirrors.aliyuncs.com/centos/6/addons/x86_64/repodata/repomd.xml: [Errno 14] PYCURL ERROR 22 - "The requested URL returned error: 404"
    Trying other mirror.
    Error: Cannot retrieve repository metadata (repomd.xml) for repository: addons. Please verify its path and try again   

    常规处理:

    安装的过程中一直报这个错误,这是由于网络的问题,repomd.xml文件下载不来,大部分都是因为配置了代理或者其他网络原因导致的,而本次是因为没有配置host文件地址,导致的本次绑定一个ip地址172.16.50.96 yum.tbsite.net
    当然也有很多是其他问题,具体问题需要具体分析,但是这里挺常见一个场景。

    ---------------------------------------------书山有路勤为径,学海无涯苦作舟--------------------------------------------------------

  • 相关阅读:
    happens-before规则和指令重排
    如何利用Google API为WordPress网页添加二维码
    Hadoop全分布式安装
    Hadoop完全分布式安装设置ssh免密登陆遇到的错误问题
    hadoop环境搭建过程中遇到的问题
    使用python去除图片周围的白色边框(黑色边框)
    Pandas(python)数据处理:只对某一列DataFrame数据进行归一化
    VM安装Ubuntu问题合集(无法联网、中文界面设置、中文输入法etc)
    C 语言控制台实现五子棋项目
    利用位运算求一个月的天数
  • 原文地址:https://www.cnblogs.com/easonscx/p/10724718.html
Copyright © 2020-2023  润新知