欢迎来访~

CentOS配置yum源

本文章介绍了linux 本地yum源和网络yum源的2种配置方法,供大家参考。

 

实验环境
CentOS 6.5
 
一、本地yum源配置
 
1.挂载
[root@hello2099 ~]# mount /dev/sr0 /mnt
2.设置自动挂载
[root@hello2099 ~]# echo "/dev/sr0 /mnt iso9660 defaults 0 0" >> /etc/fstab
 或者通过编辑 /etc/fstab 添加
# /etc/fstab
# Created by anaconda on Sat Jul 23 23:50:56 2016
#
# Accessible filesystems, by reference, are maintained under '/dev/disk'
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#
UUID=d1de03fc-0b6c-4049-842f-5674979708d3 /                       ext4    defaults        1 1
UUID=0c616650-9249-40e6-9c10-338541585485 /boot                   ext4    defaults        1 2
UUID=a3454e45-308e-422c-974c-b5b69949e9f8 swap                    swap    defaults        0 0
tmpfs                   /dev/shm                tmpfs   defaults        0 0
devpts                  /dev/pts                devpts  gid=5,mode=620  0 0
sysfs                   /sys                    sysfs   defaults        0 0
proc                    /proc                   proc    defaults        0 0
/dev/sr0               /mnt                     iso9660 defaults        0 0
~
 3.查看是否已挂载
[root@hello2099 ~]# df
Filesystem     1K-blocks    Used Available Use% Mounted on
/dev/sda2       10321208 4640508   5156412  48% /
tmpfs            1019324     144   1019180   1% /dev/shm
/dev/sda1         495844   39263    430981   9% /boot
/dev/sr0         4363088 4363088         0 100% /mnt
[root@hello2099 ~]#
 
4.查看现有yum源
[root@hello2099 ~]# ls /etc/yum.repos.d/
CentOS-Base.repo  CentOS-Debuginfo.repo  CentOS-Media.repo  CentOS-Vault.repo
[root@hello2099 ~]#
 
5.备份原yum源,我这里就直接删除原yum源
[root@hello2099 ~]# rm -rf /etc/yum.repos.d/*
 
6.配置yum源文件
[root@hello2099 ~]# cat > /etc/yum.repos.d/centos6.repo <<EOF
> [centos6-source]
> name=centos6-source
> baseurl=file:///mnt
> enable=1
> gpgcheck=0
> EOF
[root@hello2099 ~]#
 
7.查看配置文件是否生成
[root@hello2099 ~]# ls /etc/yum.repos.d/
centos6.repo
[root@hello2099 ~]#
 
8.验证yum源
用命令“yum clean all”清除缓存,再执行命令“yum list”能否正确列出yum源中的软件包。如果没有报错,则本地yum源配置成功.
[root@hello2099 ~]# yum clean all
[root@hello2099 ~]# yum list
.....
zlib-static.x86_64                    1.2.3-29.el6                centos6-source
zsh.x86_64                            4.3.10-7.el6                centos6-source
zsh-html.x86_64                       4.3.10-7.el6                centos6-source
[root@hello2099 ~]#

 

 
 
二、配置网络yum源
 
1. 先备份原yum源:
mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
 
2.下载新的 CentOS-Base.repo 到 /etc/yum.repos.d/
阿里云各版本yum源下载方式如下:
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@hello2099 ~]# wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repo
--2016-07-23 18:18:33-- &nbsp;http://mirrors.aliyun.com/repo/Centos-6.repo
Resolving mirrors.aliyun.com... 112.124.140.210, 115.28.122.210
Connecting to mirrors.aliyun.com|112.124.140.210|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 2572 (2.5K) [application/octet-stream]
Saving to: “/etc/yum.repos.d/CentOS-Base.repo”
&nbsp;
100%[======================================>] 2,572 &nbsp; &nbsp; &nbsp; --.-K/s &nbsp; in 0.002s
&nbsp;
2016-07-23 18:18:33 (1.24 MB/s) - “/etc/yum.repos.d/CentOS-Base.repo” saved [2572/2572]
 
3.
[root@hello2099 ~]# sed -i ‘s/$releasever/6.7/g’ /etc/yum.repos.d/CentOS-Base.repo   ???干嘛的,先写着吧。
 
4.清除缓存
yum clean all
[root@hello2099 ~]# yum clean all
Loaded plugins: fastestmirror, refresh-packagekit, security
Cleaning repos: base centos6-source extras updates
Cleaning up Everything
[root@hello2099 ~]#
 
5..运行yum makecache生成缓存
[root@hello2099 ~]# yum makecache
Loaded plugins: fastestmirror, refresh-packagekit, security
Determining fastest mirrors
 * base: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
base                                                     | 3.7 kB     00:00
base/group_gz                                            | 226 kB     00:00
base/filelists_db                                        | 6.4 MB     00:08
base/primary_db                                          | 4.7 MB     00:06
base/other_db                                            | 2.8 MB     00:03
centos6-source                                           | 4.0 kB     00:00 ...
centos6-source/group_gz                                  | 220 kB     00:00 ...
centos6-source/filelists_db                              | 5.8 MB     00:00 ...
centos6-source/primary_db                                | 4.4 MB     00:00 ...
centos6-source/other_db                                  | 2.7 MB     00:00 ...
extras                                                   | 3.4 kB     00:00
extras/filelists_db                                      |  38 kB     00:00
extras/prestodelta                                       | 1.3 kB     00:00
extras/primary_db                                        |  37 kB     00:00
extras/other_db                                          |  51 kB     00:00
updates                                                  | 3.4 kB     00:00
updates/filelists_db                                     | 1.1 MB     00:01
updates/prestodelta                                      |  91 kB     00:00
updates/primary_db                                       | 1.4 MB     00:01
updates/other_db                                         |  17 MB     00:22
Metadata Cache Created
 
6.执行命令“yum list”能否正确列出yum源中的软件包。如果没有报错,则网络yum源配置成功.
[root@hello2099 ~]# yum list
.....
zip.x86_64                             3.0-1.el6_7.1                     base
zlib.i686                              1.2.3-29.el6                      base
zlib-devel.i686                        1.2.3-29.el6                      base
zlib-static.x86_64                     1.2.3-29.el6                      base
zsh.x86_64                             4.3.11-4.el6.centos.2             base
zsh-html.x86_64                        4.3.11-4.el6.centos.2             base
[root@hello2099 ~]#
 
发现代码高亮用多了也好丑,等抽时间再改改。
 
 
 
赞(0)
可附来源转载:一只北极熊 » CentOS配置yum源

富强、民主、文明、和谐、自由、平等、公正、法治、爱国、敬业、诚信、友善