CentOS7光盘挂载以及更换YUM源

CentOS7光盘挂载以及更换YUM源

1、光盘挂载

1) 设置镜像连接

在这里插入图片描述

2)执行挂载操作

[root@centos7 ~]# mount /dev/cdrom /mnt/dvd/
mount: /dev/sr0 写保护,将以只读方式挂载
[root@centos7 ~]# 
[root@centos7 ~]# df -hT /mnt/dvd/		//检查目录对应的挂载设备
文件系统       类型     容量  已用  可用 已用% 挂载点
/dev/sr0       iso9660  4.5G  4.5G     0  100% /mnt/dvd
[root@centos7 ~]#

3)撤销挂载

[root@centos7 ~]# umount /mnt/dvd

4)配置开机挂载光盘

上述的挂在操作一次性有效,重启系统后不再有效。

[root@centos7 ~]# vim /etc/fstab 		//编辑fastab文件,在文本末行加入以下参数,'ro'为只读。
   /dev/cdrom              /mnt/dvd                iso9660 ro              0 0

在这里插入图片描述

2、更换YUM源

2.1 使用本机目录作为软件源

1)清理旧的配置(mv移走或者rm删除都行),或者不可用/不使用的配置,避免干扰。

[root@centos7 ~]# mkdir  /etc/yum.repos.d/repobak
[root@centos7 ~]# mv  /etc/yum.repos.d/*.repo  /etc/yum.repos.d/repobak/

2)手动添加新的软件源,指向前一步准备的本地软件仓库

[root@centos7 ~]# vim /etc/yum.repos.d/sss.repo 	//自行创建源文件
*****添加以下内容后,保存退出:*****
	[sss]							//sss为名称可自定义
	name=sss						//sss为名称可自定义
	baseurl=file:///mnt/dvd/		//软件源为本地挂载点
	enabled=1
	gpgcheck=0						//不检查签名
============================================================================
也可以执行以下命令自动生成软件源文件:
[root@centos7 ~]# yum-config-manager  --add-repo  file:///mnt/dvd/
[root@svr7 ~]# vim /etc/yum.conf
[main]
cachedir=/var/cache/yum/$basearch/$releasever
keepcache=0
.. ..  
gpgcheck = 0 	//不检查签名

3)清理yum缓存数据(更正错误配置时可能需要,但不是必需的)

[root@centos7 ~]# yum clean all
已加载插件:fastestmirror, langpacks
正在清理软件源: sss
Cleaning up list of fastest mirrors
Other repos take up 744 M of disk space (use --verbose for details)
[root@centos7 ~]#

4)列出软件仓库列表,确认配置结果

[root@centos7 ~]# yum repolist 
已加载插件:fastestmirror, langpacks
Determining fastest mirrors
sss                                                   | 3.6 kB   00:00     
(1/2): sss/group_gz                                   | 153 kB   00:00     
(2/2): sss/primary_db                                 | 3.3 MB   00:00     
源标识                   源名称                                    状态
sss                      sss from: file:///mnt/dvd/               4,071
repolist: 4,071
[root@centos7 ~]#

2.2 更换软件源链接地址

这里将源改为清华大学的。

1)备份源文件

[root@centos7 ~]#cp /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.bak

2)替换源

编辑 /etc/yum.repos.d/CentOS-Base.repo 文件,将文本中开头为mirrorlist的行前面加#注释掉;并将开头为baseurl的行取消注释(如果被注释的话),把该行内的域名(例如)替换为 。mirror.centos.orgmirrors.tuna.tsinghua.edu.cn

# 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
baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos/$releasever/os/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-7

#released updates
[updates]
name=CentOS-$releasever - Updates
baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos/$releasever/updates/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-7

#additional packages that may be useful
[extras]
name=CentOS-$releasever - Extras
baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos/$releasever/extras/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-7

#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-$releasever - Plus
baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos/$releasever/centosplus/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=centosplus
gpgcheck=1
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-7

3)确认配置

[root@centos7 ~]# yum clean all
已加载插件:fastestmirror, langpacks
正在清理软件源: base extras updates
Cleaning up list of fastest mirrors
Other repos take up 19 M of disk space (use --verbose for details)
[root@centos7 ~]# 
[root@centos7 ~]# yum repolist 
已加载插件:fastestmirror, langpacks
Determining fastest mirrors
base                                                   | 3.6 kB     00:00     
extras                                                 | 2.9 kB     00:00     
updates                                                | 2.9 kB     00:00     
(1/4): extras/7/x86_64/primary_db                      | 222 kB     00:06     
(2/4): updates/7/x86_64/primary_db                     | 3.7 MB     00:05     
(3/4): base/7/x86_64/group_gz                          | 153 kB     00:08     
(4/4): base/7/x86_64/primary_db                        | 6.1 MB     00:00:18     
源标识                            源名称                            状态
base/7/x86_64                     CentOS-7 - Base                   10,072
extras/7/x86_64                   CentOS-7 - Extras                 448
updates/7/x86_64                  CentOS-7 - Updates                773
repolist: 11,293
[root@centos7 ~]#

猜你喜欢

转载自blog.csdn.net/Sakura0156/article/details/110229544
今日推荐