Linux

关注公众号 jb51net

关闭
首页 > 网站技巧 > 服务器 > Linux > Linux配置本地yum源

Linux如何配置本地yum源(光盘镜像挂载)

作者:slyybw

这篇文章主要介绍了Linux如何配置本地yum源(光盘镜像挂载),具有很好的参考价值,希望对大家有所帮助。如有错误或未考虑完全的地方,望不吝赐教

光盘镜像挂载

上传或者从其它服务器scp传输镜像CentOS-7-x86_64-DVD-1908.iso到目标服务器/mnt目录下(我这里从集群中别的服务器scp过来的):

scp传输命令(1024是服务器端口,需要改成你自己的,IP地址也是同样的需要修改):

如果服务器上有镜像就不用管下面这条命令

scp -P 1024 -r CentOS-7-x86_64-DVD-1908.iso root@192.168.67.200:/mnt/

登录到目标服务器查看镜像

[root@localhost mnt]# ll
total 4554750
-rw-r--r-- 8 root root 4664066080    Dec  5  2016 CentOS-7-x86_64-DVD-1908.iso

创建挂载目录

[root@localhost mnt]# mkdir /mnt/iso
[root@localhost mnt]# ls
4554752
-rw-r--r-- 8 root root 4664066080    Dec  5  2016 CentOS-7-x86_64-DVD-1908.iso
drwxr-xr-x 8 root root 2048          Dec  5  2016 iso

挂载镜像

[root@localhost mnt]# mount CentOS-7-x86_64-DVD-1908.iso /mnt/iso/
mount: /dev/sr0 is write-protected, mounting read-only

有的系统会提示错误需要使用mount -o loop -t iso9660

则将上面的mount语句换成下面语句:(如果你执行上面的mount语句不报错就跳过下面这条命令)

mount -o loop -t iso9660 CentOS-7-x86_64-DVD-1908.iso  /mnt/iso

挂载完毕进入挂载目录查看

[root@localhost mnt]# cd iso/
[root@localhost iso]# ll
total 654
-rw-r--r-- 1 root root     14 Dec  5  2016 CentOS_BuildTag
drwxr-xr-x 3 root root   2048 Dec  5  2016 EFI
-rw-r--r-- 1 root root    215 Dec 10  2015 EULA
-rw-r--r-- 1 root root  18009 Dec 10  2015 GPL
drwxr-xr-x 3 root root   2048 Dec  5  2016 images
drwxr-xr-x 2 root root   2048 Dec  5  2016 isolinux
drwxr-xr-x 2 root root   2048 Dec  5  2016 LiveOS
drwxrwxr-x 2 root root 630784 Dec  5  2016 Packages
drwxrwxr-x 2 root root   4096 Dec  5  2016 repodata
-rw-r--r-- 1 root root   1690 Dec 10  2015 RPM-GPG-KEY-CentOS-7
-rw-r--r-- 1 root root   1690 Dec 10  2015 RPM-GPG-KEY-CentOS-Testing-7
-r--r--r-- 1 root root   2883 Dec  5  2016 TRANS.TBL

镜像已经被解压到挂载目录。

备份原始repo文件

创建备份目录

mkdir  /etc/yum.repos.d/bak

移动文件

mv    /etc/yum.repos.d/*.repo /etc/yum.repos.d/bak/

创建新的repo文件

新建Centos-CDROM.repo文件

vi /etc/yum.repos.d/Centos-CDROM.repo
[CDROM]
name=CentOS-$releasever - CDROM
baseurl=file:///mnt/iso
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

刷新repo信息

[root@localhost ~]# yum clean all
Loaded plugins: fastestmirror, langpacks
Cleaning repos: CDROM
Cleaning up everything
Cleaning up list of fastest mirrors
[root@localhost ~]# yum makecache
Loaded plugins: fastestmirror, langpacks
CDROM                                                                                                                                                           | 3.6 kB  00:00:00     
(1/4): CDROM/group_gz                                                                                                                                           | 155 kB  00:00:00     
(2/4): CDROM/primary_db                                                                                                                                         | 3.0 MB  00:00:00     
(3/4): CDROM/filelists_db                                                                                                                                       | 3.0 MB  00:00:00     
(4/4): CDROM/other_db                                                                                                                                           | 1.3 MB  00:00:00     
Determining fastest mirrors
Metadata Cache Created

验证一下

[root@localhost ~]# yum -y install mariadb
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
Resolving Dependencies
--> Running transaction check
---> Package mariadb.x86_64 1:5.5.52-1.el7 will be installed
--> Processing Dependency: mariadb-libs(x86-64) = 1:5.5.52-1.el7 for package: 1:mariadb-5.5.52-1.el7.x86_64
--> Running transaction check
---> Package mariadb-libs.x86_64 1:5.5.52-1.el7 will be installed
Removing mariadb-libs.x86_64 1:5.5.52-1.el7 - u due to obsoletes from installed mysql-community-libs-5.6.37-2.el7.x86_64
Removing mariadb.x86_64 1:5.5.52-1.el7 - u due to obsoletes from installed mysql-community-client-5.6.37-2.el7.x86_64
--> Restarting Dependency Resolution with new changes.
--> Running transaction check
---> Package mariadb.x86_64 1:5.5.52-1.el7 will be installed
---> Package mariadb-libs.x86_64 1:5.5.52-1.el7 will be installed
--> Finished Dependency Resolution

总结

可以看到没问题了,本地yum源已经可以使用了。

以上为个人经验,希望能给大家一个参考,也希望大家多多支持脚本之家。

您可能感兴趣的文章:
阅读全文