1.如果是VMware安装的虚拟机,首先确定是不是使用镜像文件创建的虚拟机,如果如图所示,那么镜像已经在安装的时候映射到Linux虚拟机/dev/sr0或/dev/sr1下面,此时需要将该镜像进行挂载
2创建挂载目录用于挂载镜像
[root@localhost media]# cd /mnt/
[root@localhost mnt]# ls
[root@localhost mnt]# mkdir cdrom
3.将镜像挂载到/mnt/cdrom
[root@localhost ~]# mount /dev/sr0 /mnt/cdrom
mount: no medium found on /dev/sr0
查看上图中设备状态是不是为【已连接】
[root@localhost mnt]# mount /dev/sr1 /mnt/cdrom
mount: /dev/sr1 is write-protected, mounting read-only
df -hT 可查看是否挂载成功,以及文件系统类型
[root@localhost mnt]# df -hT
Filesystem Type Size Used Avail Use% Mounted on
/dev/sda3 xfs 18G 3.0G 15G 17% /
devtmpfs devtmpfs 899M 0 899M 0% /dev
tmpfs tmpfs 913M 176K 913M 1% /dev/shm
tmpfs tmpfs 913M 8.9M 904M 1% /run
tmpfs tmpfs 913M 0 913M 0% /sys/fs/cgroup
/dev/sda1 xfs 297M 144M 154M 49% /boot
tmpfs tmpfs 183M 24K 183M 1% /run/user/0
/dev/sr1 iso9660 3.8G 3.8G 0 100% /mnt/cdrom ##镜像文件挂载成功
4.设置开机自动挂载,mount -a ##检测开机自动挂载过程
[root@localhost mnt]# vim /etc/fstab
#
#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=6fc260d0-c0df-43b3-a546-96f3083016ad / xfs defaults 0 0
UUID=c30558f8-f1d1-48d4-83bd-4aee54fb3d3e /boot xfs defaults 0 0
UUID=37045a03-e996-476e-af3c-f82cdb38ad88 swap swap defaults 0 0
/dev/sr1 /mnt/cdrom iso9660 defaults 0 0
[root@localhost mnt]# mount -a
5.编辑yum源,使其可以访问到本地yum源
[root@localhost mnt]# vim /etc/yum.repos.d/redhat.repo
[redhat7.2]
name=my local repo
baseurl=file:///mnt/cdrom
enable=1
gpgcheck=0
[root@localhost mnt]# yum clean all
Loaded plugins: langpacks, product-id, search-disabled-repos, subscription-
: manager
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
There are no enabled repos.
Run "yum repolist all" to see the repos you have.
You can enable repos with yum-config-manager --enable <repo>
[root@localhost mnt]# cd /etc/yum.repos.d/
此时发现写入的内容被清空;(如果enable为0,则会恢复为初始redhat.repo文件)
[root@localhost yum.repos.d]# cat redhat.repo
[root@localhost yum.repos.d]# vim redhat.repo
仔细观察发现,redhat系统yum配置中 subscription manager插件强制要求用户使用subscription-manager 去注册。在 /etc/yum/pluginconf.d/subscription-manager.conf 设置enabled=0,问题解决
[root@localhost yum.repos.d]# vim /etc/yum/pluginconf.d/
langpacks.conf search-disabled-repos.conf
product-id.conf subscription-manager.conf
rhnplugin.conf
[root@localhost yum.repos.d]# vim /etc/yum/pluginconf.d/subscription-manager.conf
[root@localhost yum.repos.d]# cat /etc/yum/pluginconf.d/subscription-manager.conf
[main]
enabled=0
[root@localhost yum.repos.d]# vim /etc/yum.repos.d/redhat.repo
[root@localhost yum.repos.d]# vim /etc/yum.repos.d/redhat.repo
[root@localhost yum.repos.d]# yum clean all
Loaded plugins: langpacks, product-id, search-disabled-repos
Cleaning repos: redhat7.2
Cleaning up everything
[root@localhost yum.repos.d]# yum repolist
Loaded plugins: langpacks, product-id, search-disabled-repos
redhat7.2 | 4.1 kB 00:00
(1/2): redhat7.2/group_gz | 136 kB 00:00
(2/2): redhat7.2/primary_db | 3.6 MB 00:00
repo id repo name status
redhat7.2 my local repo 4,620
repolist: 4,620
[root@localhost yum.repos.d]#
常见yum命令有:
####yum命令####
yum install softwarename ##安装
repolist ##列出设定yum源信息
remove softwarename ##卸载
list softwarename ##查看软件源中是否有次软件
list all ##列出所有软件名称
list installd ##列出已经安装的软件名称
list available ##列出可以用yum安装的软件名称
clean all ##清空yum缓存
search softwareinfo ##根据软件信息搜索软件名字
whatprovides filename ##在yum源中查找包含filename文件的软件包
update ##更新软件
history ##查看系统软件改变历史
reinstall softwarename ##重新安装
info softwarename ##查看软件信息
groups list ##查看软件组信息
groups info softwaregroup ##查看软件组内包含的软件
groups install softwaregroup ##安装组件
groups remove softwaregroup ##卸载组件
至此本地yum源搭建成功,当然如果你需要共享yum源,可以配置http共享你的yum源;另外,安装一些非系统内置软件,你会发现该yum源满足不了需求,此时可以下载安装包搭建第三方yum源或者使用公网yum源,如阿里,网易公司yum源等。