mount挂载与本地yum源设置

mount挂载

在 linux 操作系统中,挂载是指将一个设备挂接到一个已存在的目录上。要 访问设备中的文件,通过访问这个挂载目录来访问。

命令格式:

mount [-t vfstype] [-o options] device dir
参数 解释
-t 指定文件系统的类型,mount会自动选择正确的类型。常用类型有:光盘镜像iso9660、linux文件网络共享 nfs等等。
-o 主要用来描述设备或档案的挂载方式
device 要挂接(mount)的设备
dir 设备在系统上的挂接点(mount point)

挂载方式:

参数 解释
loop 用来把一个文件当成硬盘分区挂接上系统
ro 采用只读方式挂接设备
rw 采用读写方式挂接设备

挂载光驱

[root@centos6-1 /]# mkdir -p /mount/cdrom
[root@centos6-1 /]# cd /mount/cdrom/
[root@centos6-1 cdrom]# ls
[root@centos6-1 cdrom]#  mount -t iso9660 -o ro /dev/cdrom /mount/cdrom/
[root@centos6-1 cdrom]# cd
[root@centos6-1 ~]# cd /mount/cdrom/
[root@centos6-1 cdrom]# ls
CentOS_BuildTag  isolinux                  RPM-GPG-KEY-CentOS-Debug-6
EFI              Packages                  RPM-GPG-KEY-CentOS-Security-6
EULA             RELEASE-NOTES-en-US.html  RPM-GPG-KEY-CentOS-Testing-6
GPL              repodata                  TRANS.TBL
images           RPM-GPG-KEY-CentOS-6
[root@centos6-1 cdrom]# 

卸载

[root@centos6-1 cdrom]# umount /mount/cdrom/
umount: /mount/cdrom: device is busy.
        (In some cases useful info about processes that use
         the device is found by lsof(8) or fuser(1))
[root@centos6-1 cdrom]# cd
[root@centos6-1 ~]# umount /mount/cdrom/
[root@centos6-1 ~]# ls /mount/cdrom/
[root@centos6-1 ~]# 

不要在挂载的目录卸载,否则会失败先退出挂载的目录再卸载

yum

yum(Yellow dog Updater, Modified)是一个在 Fedora 和 RedHat 以及 CentOS 中的 Shell 前端软件包管理器。基于 RPM 包管理,能够从指定的服务器 自动下载 RPM 包并且安装,可以自动处理依赖性关系,并且一次安装所有依赖的 软件包,无须繁琐地一次次下载、安装。
yum 机制的强大之处在于 yum 源。yum 源相当是一个目录项,当我们使用 yum 机制安装软件时,若需要安装依赖软件,则 yum 机制就会根据在 yum 源中定义好 的路径查找依赖软件,并将依赖软件安装好。

本地yum源

yum 源分为网络 yum 源和本地 yum 源。
yum 源配置文件有两个。一是直接配置在/etc/yum.conf 中,其中包含一些 主要的配置信息。另外就是/etc/yum.repos.d/下的 xx.repo 后缀文件, 默认都会被加载进来。

设置本地yum源

这里我们使用CentOS镜像提供的yum源
1.创建挂载镜像目录和本地yum源目录

[root@centos6-1 /]# mkdir -p /dev/centios /mount/local_yum

2.使用lrzsz上传CentOS-6.7-x86_64-bin-DVD1.iso镜像至虚拟机(irzsz使用见此:https://blog.csdn.net/weixin_37490221/article/details/80844825)上传需要一些时间

[root@centos6-1 /]# cd
[root@centos6-1 ~]# rz
rz waiting to receive.
Starting zmodem transfer.  Press Ctrl+C to cancel.
Transferring CentOS-6.7-x86_64-bin-DVD1.iso...
  100% 3804160 KB    17611 KB/sec    00:03:36       0 Errors  
[root@centos6-1 ~]#

3.挂载上传的镜像

[root@centos6-1 ~]# mount -o loop /root/CentOS-6.7-x86_64-bin-DVD1.iso /dev/centios
[root@centos6-1 ~]# cd /dev/centios/
[root@centos6-1 centios]# ls
CentOS_BuildTag  isolinux                  RPM-GPG-KEY-CentOS-Debug-6
EFI              Packages                  RPM-GPG-KEY-CentOS-Security-6
EULA             RELEASE-NOTES-en-US.html  RPM-GPG-KEY-CentOS-Testing-6
GPL              repodata                  TRANS.TBL
images           RPM-GPG-KEY-CentOS-6
[root@centos6-1 centios]# 

3.拷贝挂载的文件所有内容至local_yu目录(拷贝需要一些时间)

[root@centos6-1 centios]# cp -r /dev/centios/* /mount/local_yum/
[root@centos6-1 centios]# 

4.备份原yum源配置

[root@centos6-1 yum.repos.d]# ll
total 24
-rw-r--r--. 1 root root 1991 Aug  4  2015 CentOS-Base.repo
-rw-r--r--. 1 root root  647 Aug  4  2015 CentOS-Debuginfo.repo
-rw-r--r--. 1 root root  289 Aug  4  2015 CentOS-fasttrack.repo
-rw-r--r--. 1 root root  630 Aug  4  2015 CentOS-Media.repo
-rw-r--r--. 1 root root 6259 Aug  4  2015 CentOS-Vault.repo
[root@centos6-1 yum.repos.d]# rename .repo .repo.bak *.repo
[root@centos6-1 yum.repos.d]# ls
CentOS-Base.repo.bak       CentOS-fasttrack.repo.bak  CentOS-Vault.repo.bak
CentOS-Debuginfo.repo.bak  CentOS-Media.repo.bak
[root@centos6-1 yum.repos.d]# ll
total 24
-rw-r--r--. 1 root root 1991 Aug  4  2015 CentOS-Base.repo.bak
-rw-r--r--. 1 root root  647 Aug  4  2015 CentOS-Debuginfo.repo.bak
-rw-r--r--. 1 root root  289 Aug  4  2015 CentOS-fasttrack.repo.bak
-rw-r--r--. 1 root root  630 Aug  4  2015 CentOS-Media.repo.bak
-rw-r--r--. 1 root root 6259 Aug  4  2015 CentOS-Vault.repo.bak
[root@centos6-1 yum.repos.d]# 

上面备份的命令从后往前解读:把所有以repo结尾的文件的文件后缀由.repo修改为.repo.bak

5.清理yum源,让刚才修改生效

[root@centos6-1 yum.repos.d]# yum clear all
Loaded plugins: fastestmirror, security
No such command: clear. Please use /usr/bin/yum --help
[root@centos6-1 yum.repos.d]# yum clean all
Loaded plugins: fastestmirror, security
Cleaning repos: 
Cleaning up Everything
Cleaning up list of fastest mirrors
[root@centos6-1 yum.repos.d]# yum repolist all
Loaded plugins: fastestmirror, security
Determining fastest mirrors
repolist: 0
[root@centos6-1 yum.repos.d]# 

显示repolist: 0,修改生效

6.生成和修改本地yum源配置文件

[root@centos6-1 yum.repos.d]# cp CentOS-Base.repo.bak CentOS-Local.repo
[root@centos6-1 yum.repos.d]# vi CentOS-Local.repo

将文件内容修改为

[zaomianbao]
name=this is zaomianbao's local yum repo
baseurl=file:///mount/local_yum
gpgcheck=1
enable=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6

查看是否修改成功

[root@centos6-1 yum.repos.d]# yum repolist all
Loaded plugins: fastestmirror, security
Loading mirror speeds from cached hostfile
zaomianbao                                                         | 4.0 kB     00:00 ... 
zaomianbao/primary_db                                              | 4.6 MB     00:00 ... 
repo id                  repo name                                          status
zaomianbao               this is zaomianbao's local yum repo                enabled: 6,575
repolist: 6,575
[root@centos6-1 yum.repos.d]# 

显示yum源已经修改为刚刚设置而成的本地源,后面就开始断网模式下的快速yum吧

安装httpd

[root@centos6-1 ~]# yum install httpd
[root@centos6-1 ~]# httpd
[root@centos6-1 ~]# netstat -lnp|grep 80
tcp        0      0 :::80                       :::*                        LISTEN      29056/httpd         
unix  2      [ ACC ]     STREAM     LISTENING     14080  1594/cupsd          /var/run/cups/cups.sock
[root@centos6-1 ~]# 

安装成功,且启动成功(启动的时候有可能需要修改httpd的配置文件)

总结

本地yum源可以解决网络不好的情况下,yum时间过长的问题,但是本地yum源也有其明显的弊端,就是yum源的版本过旧不能随时更新。如果你想换回以前的yum源,将之前备份的repo文件恢复过来,再执行yum clean all和yum repolist all查看一下是否改变

猜你喜欢

转载自blog.csdn.net/weixin_37490221/article/details/80848564