Centos7配置yum源(本地yum源和阿里网络yum源)

一、centos7配置yum源

yum源分为本地yum源和网络yum源

1、配置本地yum源

步骤一:在centos虚拟机中挂载光盘

1.创建挂载点目录

[root@localhost ~]# mkdir /mnt/cdrom
[root@localhost ~]# df /mnt/cdrom
文件系统          1K-块    已用     可用 已用% 挂载点
/dev/sda3      39517336 7718416 31798920   20% /

2.挂载光盘

[root@localhost ~]# mount /dev/cdrom /mnt/cdrom
mount: /dev/sr0 写保护,将以只读方式挂载

3.查看挂载记录

[root@localhost ~]# df -hT /mnt/cdrom
文件系统       类型     容量  已用  可用 已用% 挂载点
/dev/sr0       iso9660  4.3G  4.3G     0  100% /mnt/cdrom

步骤二:更改配置文件

1.进入/etc/yum.repos.d/中查看文件

[root@localhost ~]# cd /etc/yum.repos.d/
[root@localhost yum.repos.d]# ll
总用量 28
-rw-r--r--. 1 root root 1664 830 2017 CentOS-Base.repo
-rw-r--r--. 1 root root 1309 830 2017 CentOS-CR.repo
-rw-r--r--. 1 root root  649 830 2017 CentOS-Debuginfo.repo
-rw-r--r--. 1 root root  314 830 2017 CentOS-fasttrack.repo
-rw-r--r--. 1 root root  630 830 2017 CentOS-Media.repo
-rw-r--r--. 1 root root 1331 830 2017 CentOS-Sources.repo
-rw-r--r--. 1 root root 3830 830 2017 CentOS-Vault.repo

2.将CentOS-Base.repo和CentOS-Debuginfo.repo改名或者移动,绕过网络安装,以便使用本地安装

#本次使用改名 方便作为备份文件
[root@localhost yum.repos.d]# mv CentOS-Debuginfo.repo CentOS-Debuginfo.repo.bak
[root@localhost yum.repos.d]# mv CentOS-Base.repo CentOS-Base.repo.bak

3.编辑文件CentOS-Media.repo(使用vim编辑器)

[root@localhost yum.repos.d]# vim CentOS-Media.repo
# CentOS-Media.repo
#
#  This repo can be used with mounted DVD media, verify the mount point for
#  CentOS-7.  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=c7-media [command]
#  
# or for ONLY the media repo, do this:
#
#  yum --disablerepo=\* --enablerepo=c7-media [command]

[c7-media]
name=CentOS-$releasever - Media
baseurl=file:///mnt/cdrom
gpgcheck=0		#用来检查GPG-KEY,0为不检查,1为检查
enabled=1		#是否用该yum源,0为禁用,1为使用
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

~                                                                               
~                                                                               
~                                                                               
"CentOS-Media.repo" 20L, 563C                                 17,1         全部

4.清除yum缓存,测试yum源配置

清除yum缓存

[root@localhost yum.repos.d]# yum clean all
已加载插件:fastestmirror, langpacks
正在清理软件源: c7-media
Cleaning up everything
Maybe you want: rm -rf /var/cache/yum, to also free up space taken by orphaned data from disabled or removed repos
Cleaning up list of fastest mirrors

测试

[root@localhost yum.repos.d]# yum list
已加载插件:fastestmirror, langpacks
c7-media                                                 | 3.6 kB     00:00     
(1/2): c7-media/group_gz                                   | 156 kB   00:00     
(2/2): c7-media/primary_db                                 | 3.1 MB   00:00     
Determining fastest mirrors
已安装的软件包
GConf2.x86_64                           3.2.6-8.el7                    @anaconda
GeoIP.x86_64                            1.5.0-11.el7                   @anaconda
ModemManager.x86_64                     1.6.0-2.el7                    @anaconda
ModemManager-glib.x86_64                1.6.0-2.el7                    @anaconda
NetworkManager.x86_64                   1:1.8.0-9.el7                  @anaconda
NetworkManager-adsl.x86_64              1:1.8.0-9.el7                  @anaconda
NetworkManager-glib.x86_64              1:1.8.0-9.el7                  @anaconda
NetworkManager-libnm.x86_64             1:1.8.0-9.el7                  @anaconda
NetworkManager-libreswan.x86_64         1.2.4-2.el7                    @anaconda
NetworkManager-libreswan-gnome.x86_64   1.2.4-2.el7                    @anaconda
NetworkManager-ppp.x86_64               1:1.8.0-9.el7                  @anaconda

出现已安装的软件包时,便成功配置了

2、配置网络yum源

步骤一:备份

1)进入/etc/yum.repos.d 查看目录下文件

[root@localhost yum.repos.d]# ll
总用量 28
-rw-r--r--. 1 root root 1664 830 2017 CentOS-Base.repo.bak
-rw-r--r--. 1 root root 1309 830 2017 CentOS-CR.repo
-rw-r--r--. 1 root root  649 830 2017 CentOS-Debuginfo.repo.bak
-rw-r--r--. 1 root root  314 830 2017 CentOS-fasttrack.repo
-rw-r--r--. 1 root root  563 318 19:37 CentOS-Media.repo
-rw-r--r--. 1 root root 1331 830 2017 CentOS-Sources.repo
-rw-r--r--. 1 root root 
1.查看系统本身存在的版本 rpm -qa | grep yum 2.卸载centos7上存在的yum安装包 rpm -e 包 --nodeps 3.下载yum包(http://mirrors.163.com/centos/7/os/x86_64/Packages/) yum-metadata-parser-1.1.4-10.el7.x86_64 PackageKit-yum-1.0.7-6.el7.centos.x86_64 yum-utils-1.1.31-40.el7.noarch 下方两个一起装 yum-plugin-fastestmirror-1.1.31-40.el7.noarch yum-langpacks-0.4.2-7.el7.noarch yum-3.4.3-150.el7.centos.noarch yum-rhn-plugin-2.0.1-6.el7.noarch 4.安装yum包 rpm -ivh yum* 5.创建配置文件(/etc/yum.repos.d/CentOS-Base.repo) vi /etc/yum.repos.d/CentOS-Base.repo [base] name=CentOS-$releasever - Base - 163.com #mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch;=$basearch&repo=os baseurl=http://mirrors.163.com/centos/(系统版本号)7/os/$basearch/ gpgcheck=1 gpgkey=http://mirrors.163.com/centos/RPM-GPG-KEY-CentOS-7 #released updates [updates] name=CentOS-$releasever - Updates - 163.com #mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch;=$basearch&repo=updates baseurl=http://mirrors.163.com/centos/7/updates/$basearch/ gpgcheck=1 gpgkey=http://mirrors.163.com/centos/RPM-GPG-KEY-CentOS-7 #additional packages that may be useful [extras] name=CentOS-$releasever - Extras - 163.com #mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch;=$basearch&repo=extras baseurl=http://mirrors.163.com/centos/7/extras/$basearch/ gpgcheck=1 gpgkey=http://mirrors.163.com/centos/RPM-GPG-KEY-CentOS-7 #additional packages that extend functionality of existing packages [centosplus] name=$releasever - Plus - 163.com baseurl=http://mirrors.163.com/centos/7/centosplus/$basearch/ gpgcheck=1 enabled=0 gpgkey=http://mirrors.163.com/centos/RPM-GPG-KEY-CentOS-7 每一个baseurl的centos后都改成自己系统的版本号 6.执行命令 yum clean all yum makecache yum install telnet
评论 36
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

跑不完的脚本

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值