CentOS6 搭建网络yum源

  • 环境
    • 虚拟机:VMware® Workstation 12 Pro (12.1.0 build-3272444)
    • Linux系统:CentOS 6.8
    • 远程工具:Xshell 6 (Build 0197)

CentOS6 搭建网络yum源

目录

CentOS6 搭建网络yum源

一、为什么要搭建网络yum源?

二、网络yum源配置步骤

第一步、虚拟机必须能ping通外网,确保网络畅通

第二步、备份配置文件

第三步、下载yum源

第四步、修改yum源地址 

第五步、 释放yum源缓存

第六步、重新建立yum缓存

第七步、建立缓存成功后,查看yum源列表

三、小结


一、为什么要搭建网络yum源?

        为安装虚拟机用中文插件 zhcon,经过网络一番狠狠查找后,有网友推荐用yum安装,所以就配置了网络yum源。下面将详细配置步骤记录下来。

二、网络yum源配置步骤

第一步、虚拟机必须能ping通外网,确保网络畅通

[root@localhost ~]# ping 114.114.114.114    <--能ping通代表网络畅通
PING 114.114.114.114 (114.114.114.114) 56(84) bytes of data.
64 bytes from 114.114.114.114: icmp_seq=1 ttl=128 time=28.6 ms
64 bytes from 114.114.114.114: icmp_seq=2 ttl=128 time=29.4 ms
64 bytes from 114.114.114.114: icmp_seq=3 ttl=128 time=35.9 ms
64 bytes from 114.114.114.114: icmp_seq=4 ttl=128 time=28.6 ms
64 bytes from 114.114.114.114: icmp_seq=5 ttl=128 time=28.1 ms
64 bytes from 114.114.114.114: icmp_seq=6 ttl=128 time=51.2 ms

第二步、备份配置文件

[root@localhost ~]# cd /etc/yum.repos.d/            <--进入配置目录
[root@localhost yum.repos.d]# ls                    <--查看配置文件
CentOS-Base.repo  CentOS-Debuginfo.repo  CentOS-fasttrack.repo  CentOS-Media.repo  CentOS-Vault.repo
[root@localhost yum.repos.d]# cp -a /etc/yum.repos.d/* /tmp/    <--所有配置文件拷贝到 /tmp/ 目录下
[root@localhost yum.repos.d]# ls /tmp                           <--拷贝成功
CentOS-Base.repo       CentOS-fasttrack.repo  yum.log                                   yum_save_tx-2022-04-24-19-04oHS63a.yumtx
CentOS-Base.repo.bak   CentOS-Media.repo      yum_save_tx-2022-04-24-19-017v8IEc.yumtx
CentOS-Debuginfo.repo  CentOS-Vault.repo      yum_save_tx-2022-04-24-19-03R5u8X8.yumtx
[root@localhost yum.repos.d]# 

第三步、下载yum源

[root@localhost yum.repos.d]# wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repo

第四步、修改yum源地址 

  1. http://mirrors.aliyun.com/centos/ 修改成 https://vault.centos.org/6.8/os/x86_64/

  2. http://mirrors.aliyun.com/ 修改成 http://vault.centos.org/

  3. 修改结果如下面代码

[root@localhost yum.repos.d]# vi CentOS-Base.repo 

  1 # CentOS-Base.repo
  2 #
  3 # The mirror system uses the connecting IP address of the client and the
  4 # update status of each mirror to pick mirrors that are updated to and
  5 # geographically close to the client.  You should use this for CentOS updates
  6 # unless you are manually picking other mirrors.
  7 #
  8 # If the mirrorlist= does not work for you, as a fall back you can try the 
  9 # remarked out baseurl= line instead.
 10 #
 11 #
 12 
 13 [base]
 14 name=CentOS-$releasever - Base - mirrors.aliyun.com
 15 failovermethod=priority
 16 baseurl=http://vault.centos.org/centos/$releasever/os/$basearch/
 17         https://vault.centos.org/6.8/os/x86_64/$releasever/os/$basearch/
 18         http://mirrors.cloud.aliyuncs.com/centos/$releasever/os/$basearch/
 19 gpgcheck=1
 20 gpgkey=https://vault.centos.org/6.8/os/x86_64/RPM-GPG-KEY-CentOS-$releasever
 21 
 22 #released updates 
 23 [updates]
 24 name=CentOS-$releasever - Updates - mirrors.aliyun.com
 25 failovermethod=priority
 26 baseurl=http://vault.centos.org/centos/$releasever/updates/$basearch/
 27         https://vault.centos.org/6.8/os/x86_64/$releasever/updates/$basearch/
 28         http://mirrors.cloud.aliyuncs.com/centos/$releasever/updates/$basearch/
 29 gpgcheck=1
 30 gpgkey=https://vault.centos.org/6.8/os/x86_64/RPM-GPG-KEY-CentOS-$releasever
 31 
 32 #additional packages that may be useful
 33 [extras]
 34 name=CentOS-$releasever - Extras - mirrors.aliyun.com
 35 failovermethod=priority
 36 baseurl=http://vault.centos.org/centos/$releasever/extras/$basearch/
 37         https://vault.centos.org/6.8/os/x86_64/$releasever/extras/$basearch/
 38         http://mirrors.cloud.aliyuncs.com/centos/$releasever/extras/$basearch/
 39 gpgcheck=1
 40 gpgkey=https://vault.centos.org/6.8/os/x86_64/RPM-GPG-KEY-CentOS-$releasever
 41 
 42 #additional packages that extend functionality of existing packages
 43 [centosplus]
 44 name=CentOS-$releasever - Plus - mirrors.aliyun.com
 45 failovermethod=priority
 46 baseurl=http://vault.centos.org/centos/$releasever/centosplus/$basearch/
 47         https://vault.centos.org/6.8/os/x86_64/$releasever/centosplus/$basearch/
 48         http://mirrors.cloud.aliyuncs.com/centos/$releasever/centosplus/$basearch/
 49 gpgcheck=1
 50 enabled=0
 51 gpgkey=https://vault.centos.org/6.8/os/x86_64/RPM-GPG-KEY-CentOS-$releasever
 52 
 53 #contrib - packages by Centos Users
 54 [contrib]
 55 name=CentOS-$releasever - Contrib - mirrors.aliyun.com
 56 failovermethod=priority
 57 baseurl=http://vault.centos.org/centos/$releasever/contrib/$basearch/
 58         https://vault.centos.org/6.8/os/x86_64/$releasever/contrib/$basearch/
 59         http://mirrors.cloud.aliyuncs.com/centos/$releasever/contrib/$basearch/
 60 gpgcheck=1
 61 enabled=0
 62 gpgkey=https://vault.centos.org/6.8/os/x86_64/RPM-GPG-KEY-CentOS-$releasever

第五步、 释放yum源缓存

yum clean all

第六步、重新建立yum缓存

yum makecache

第七步、建立缓存成功后,查看yum源列表

yum list

        至此,出现yum列表即证明网络yum源配置成功。

三、小结

  • 知识点总结
    • 网络yum源配置全过程
    • 使用阿里yum源下载repo文件
    • 用清华网址代替阿里网址

你可能感兴趣的:(Linux系统管理,CentOS6,Linux基础知识,linux,centos,服务器)