CentOS 使用光盘ISO镜像搭建本地源实现离线/无网络yum安装软件
在没有网络的情况下,我们可以通过制作CentOS的光盘ISO镜像来实现离线/无网络yum安装软件,本文将详细介绍如何使用CentOS光盘ISO镜像搭建本地源,以及如何在离线状态下进行yum安装。
1、准备工作
我们需要准备一张CentOS光盘ISO镜像,可以从官方网站下载,需要一台光驱或者U盘,用于刻录光盘,还需要一个可以挂载光盘的目录,mnt/cdrom。
2、挂载光盘ISO镜像
将光盘ISO镜像挂载到指定目录,可以使用以下命令:
sudo mount -o loop /path/to/your/iso /mnt/cdrom
/path/to/your/iso为光盘ISO镜像的路径,/mnt/cdrom为挂载目录。
3、创建本地源目录
在挂载的光盘ISO镜像目录下,创建一个名为localrepo的目录,用于存放本地源文件:
sudo mkdir -p /mnt/cdrom/localrepo
4、将CentOS光盘ISO镜像中的文件复制到本地源目录
将光盘ISO镜像中的所有文件复制到刚刚创建的localrepo目录中:
sudo cp -r /mnt/cdrom/* /mnt/cdrom/localrepo/
5、配置本地源文件
编辑localrepo目录下的repodata文件夹中的centos.repo文件,添加以下内容:
[base] name=CentOS-$releasever Base baseurl=file:///mnt/cdrom/localrepo gpgcheck=0 enabled=1 gpgkey=file:///mnt/cdrom/RPM-GPG-KEY-CentOS-6
6、生成yum缓存文件
运行以下命令生成yum缓存文件:
sudo yum makecache --downloadonly --destdir=/tmp/yum_cache
7、将yum缓存文件复制到目标机器上并挂载
将生成的yum缓存文件(位于/tmp/yum_cache目录下)复制到目标机器上,然后挂载该目录:
sudo mkdir -p /mnt/cache sudo mount --bind /tmp/yum_cache /mnt/cache
8、在目标机器上配置yum源
编辑目标机器上的/etc/yum.repos.d/CentOS-Base.repo文件,添加以下内容:
[base] name=CentOS-$releasever Base – Base OSes and applications in Red Hat Enterprise Linux 6 and later using systemd from ELRepo.org repository. [notable for its long list of additional packages]. ($releasever) [notable for its long list of additional packages] baseurl=http://mirror.centos.org/centos6/$releasever/os/$basearch/Packages/centos-$releasever-os.$basearch.rpm http://mirror.centos.org/centos6/$releasever/os/$basearch/Packages/centos-$releasever-os-noarch.rpm http://mirror.centos.org/centos6/$releasever/extras/x86_64/Packages/centos-$releasever-extras-x86_64.rpm http://mirror.centos.org/centos6/$releasever/epel6/Packages/centos-$releasever-epel-6.noarch.rpm http://mirror.centos.org/centos6/$releasever/epel6/Extras/x86_64/Packages/centos-$releasever-epel-6-x86_64.rpm http://mirror.centos.org/centos6//os/\$basearch//Packages/@core\@.xml http://mirror.centos.org/centos6//os/\$basearch//Packages/\@updates@.xml http://mirror.centos.org/centos6//extras/\@appstream\@.xml http://mirror.centos.org/centos6//extras/\@remi\@.xml http://mirror.centos.org/centos6//extras/\@testing\@.xml http://mirror.centos.org/$releasever/\i386/\Packages/\centos-$releasever-libgcc.i686.rpm http://mirror.centos.org/\$releasever/\amd64/\Packages/\centos-$releasever-libgcc.x86_64.rpm http://mirror.centos.org/\$releasever/\i386/\Packages/\wget * https://rpmfindplus.net //linux/i386 $basearch $(basename \$srcdir) main restricted optional multiverse lownormal devel floppy src $readonly $(basename \$rpmdir)" read only rpm baseurl mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os&infra=$infra include=(OS)\%{nil} filehash=sha256 checksumtype=md5 gpgcheck=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6 CC=$cc CFLAGS="\"%{?_smp_mflags}\"" %{?sysroot} kernel=\$\(uname -r\) preinstall postinstall preuninstall postuninstall checksumdir=sha256 > 8bit > md5 > lzma2 > xz > bzip2 > rawhide > upx > pgpcheck > nogpgcheck > notest > noclean > noautoremove > noconfig > nobisect > nosourceextraction > nochecksumdiff > nosigndiff > novendorchange > nopatch > noprogressbar >> 8bit >> md5 >> lzma2 >> xz >> bzip2 >> rawhide >> upx >> pgpcheck >> notest >> noclean >> noautoremove >> noconfig >> nobisect >> nosourceextraction >> nochecksumdiff >> nosigndiff >> novendorchange >> nopatch >> noprogressbar 2>&1 && echo "done!" || echo "failed!" exit $?;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;" read only rpm baseurl mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os&infra=$infra include=(OS)\%{nil} filehash=sha256 checksumtype=md5 gpgcheck=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6 CC=$cc CFLAGS="\"%{?_smp_mflags}\"" %{?sysroot} kernel=\$(uname -r\) preinstall postinstall preuninstall postuninstall checksumdir=sha25� > 8bit > md5 > lzma2 > xz > bzip2 > rawhide > upx > pgpcheck > notest > noclean > noautoremove > noconfig > nobisect > nosourceextraction > nochecksumdiff > nosigndiff > novendorchange > nopatch > noprogressbar &>> ""%{LOGNAME}""_CentOS_""%{HOSTNAME}""_postinst_errors &>> ""%{LOGNAME}""_CentOS_""%{HOSTNAME}""_postinst_errors &>> ""%{LOGNAME}""_CentOS_""%{HOSTNAME}""_postrm_errors &>> ""%{LOGNAME}""_CentOS_""%{HOSTNAME}""_postrm_errors &>> ""%{LOGNAME}""_CentOS_""%{HOSTNAME}""_prerm_errors &>> ""%{LOGNAME}""_CentOS_""%{HOSTNAME}""_prerm_errors &>> ""%{LOGNAME}""_CentOS_""%{HOSTNAME}"", installkernel = yes, installheaders = yes, installman = man $(basename \$rpmdir)", setup = yes, sizelimit = 1G, skipifexists = true, exclude = file:[^(\t]*doc|contrib|nonfree|outoftree), downloadonly = false,
原创文章,作者:K-seo,如若转载,请注明出处:https://www.kdun.cn/ask/273940.html