linux下搭建本地yum源
1.首先让镜像被系统识别
[root@localhost Desktop]# df //首先查看已存在的挂载项
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/vda1 10473900 6971760 3502140 67% /
devtmpfs 469332 0 469332 0% /dev
tmpfs 484920 140 484780 1% /dev/shm
tmpfs 484920 12784 472136 3% /run
tmpfs 484920 0 484920 0% /sys/fs/cgroup
/dev/mapper/vg0-vo 483670 2339 451840 1% /home
现在我把镜像挂载到/mnt目录上
[root@localhost Desktop]# mount -t iso9660 -o loop /dev/cdrom /mnt/cdrom //镜像挂载到/mnt目录上
mount: /dev/loop0 is write-protected, mounting read-only
[root@localhost Desktop]# df
Filesystem 1K-blocks Used Available Use% Mounted on
...
/dev/loop0 3654720 3654720 0 100% /mnt //挂载镜像成功
2.查看/mnt下的镜像文件
[root@localhost Desktop]# cd /mnt
[root@localhost mnt]# ls
addons images Packages RPM-GPG-KEY-redhat-release
EFI isolinux release-notes TRANS.TBL
EULA LiveOS repodata
GPL media.repo RPM-GPG-KEY-redhat-beta
有这些文件说明挂载成功了。
3.配置本地yum源
[root@localhost etc]# cd /etc/yum.repos.d/
[root@localhost etc]#rm -rf *
[root@localhost yum.repos.d]# vim yum.repo //文件名称一定以.repo为后缀
[rhel7.0] //仓库描述
name=rhel7.0 server //对软件源的描述
baseurl=file:///mnt //镜像的挂载入地址 file:// --格式 /mnt--指定目录
gpgcheck=0 //不检查gpgkey
enabled=1 //此yum源语句块立即生效
4.测试
[root@localhost yum.repos.d]# yum clear all //清空之前的yum源信息
Loaded plugins: langpacks
No such command: clear. Please use /usr/bin/yum --help
[root@localhost yum.repos.d]# yum repolist //列出yum的信息
Loaded plugins: langpacks
repo id repo name status
rhel7.0 rhel7.0 server 4,305
repolist: 4,305
[root@localhost yum.repos.d]# yum install gcc -y //下载gcc
5.设置开机自动挂载
系统reboot后,镜像不会自动挂载到/mnt目录上,我们需要修改系统启动文件。
[root@localhost Desktop]# vim /etc/rc.d/rc.local
最后一行添加
mount /root/Desktop/rhel-server-7.0-x86_64-dvd.iso /mnt //mount 镜像的绝对路径 要挂载的目录
[root@localhost Desktop]# chmod 755 /etc/rc.d/rc.local //系统开机时自动执行此脚本
测试
[root@localhost Desktop]# reboot
[root@foundation36 kiosk]# ssh 172.25.254.136
root@172.25.254.136's password:
Last login: Thu Jan 17 22:50:16 2019 from 172.25.254.36
[root@localhost ~]# df
Filesystem 1K-blocks Used Available Use% Mounted on
...
/dev/loop0 3654720 3654720 0 100% /mnt //开机被自动挂载上
The Internet is big, really big, like bigger than you thought big.