Linux【环境部署 02】yum源镜像下载+挂载镜像+本地yum源配置+局域网yum源服务搭建+局域网yum源使用(一篇学会离线yum源配置)

简介: Linux【环境部署 02】yum源镜像下载+挂载镜像+本地yum源配置+局域网yum源服务搭建+局域网yum源使用(一篇学会离线yum源配置)

1.yum源下载

1.1 国内镜像源列表

# 网易开源镜像站 
http://mirrors.163.com
# 阿里云开源镜像站
https://mirrors.aliyun.com
# 华为开源镜像站
http://mirrors.huaweicloud.com
# 中国科学技术大学开源软件镜像站
http://mirrors.ustc.edu.cn
# 上海交通大学镜像站
http://ftp.sjtu.edu.cn
# 北京外国语大学开源软件镜像站
http://mirrors.bfsu.edu.cn
# 清华大学开源软件镜像站
http://mirrors.tuna.tsinghua.edu.cn
# 南京大学开源镜像站
http://mirrors.nju.edu.cn
# 重庆大学开源软件镜像站
http://mirrors.cqu.edu.cn
# 南京邮电大学开源软件镜像站
http://mirrors.njupt.edu.cn
# 山东大学镜像站(似乎没有CentOS)
https://mirrors.sdu.edu.cn

1.2 下载对应版本的镜像文件

# 1.版本信息查询
cat /etc/centos-release
# 版本信息
CentOS Linux release 7.9.2009 (Core) 
# 2.版本信息查询
rpm -qi centos-release
# 版本信息
Name        : centos-release
Version     : 7
Release     : 9.2009.1.el7.centos
Architecture: x86_64
Install Date: Tue 08 Feb 2022 02:59:59 PM CST
Group       : System Environment/Base
Size        : 44787
License     : GPLv2
Signature   : RSA/SHA256, Thu 03 Dec 2020 12:35:28 AM CST, Key ID 24c6a8a7f4a80eb5
Source RPM  : centos-release-7-9.2009.1.el7.centos.src.rpm
Build Date  : Mon 23 Nov 2020 11:08:41 PM CST
Build Host  : x86-01.bsys.centos.org
Relocations : (not relocatable)
Packager    : CentOS BuildSystem <http://bugs.centos.org>
Vendor      : CentOS
Summary     : CentOS Linux release file
Description :
CentOS Linux release files

国内镜像源只有一个最新版本,比如 CentOS 7,只有 7.9.2009 版本,没有 7.8.2003 或 7.7.1908 等旧版本,非最新版本需要到 CentOS 官网下载。本次下载使用 网易开源镜像站 根据版本及分支信息找到要下载的文件。

isos目录是镜像文件。

镜像版本说明:

  • DVD:标准安装盘,里面包含大量的常用软件,大部分情况下安装时无需再在线下载;
  • Everything:对标准安装盘的软件进行补充,包含所有软件组件,体积最大;
  • Minimal:精简版本,包含核心组件;
  • NetInstall:网络安装镜像。

os目录是镜像解压文件。

本次以 Minimal 版本进行说明,镜像文件为CentOS-7-x86_64-Minimal-2009.iso

2.挂载镜像

# 1.新建目录 /mnt/iso 放置原始镜像文件 /mnt/cdrom 用于挂载镜像
mkdir -p /mnt/iso
mkdir -p /mnt/cdrom
# 2.上传 CentOS-7-x86_64-Minimal-2009.iso 文件到 /mnt/iso 文件夹下
# 3.挂载镜像 -o loop 用来把一个文件当成硬盘分区挂接上系统
mount -o loop /mnt/iso/CentOS-7-x86_64-Minimal-2009.iso  /mnt/cdrom
# 取消挂载
umount /mnt/cdrom

/mnt/cdrom 和 os 路径下的文件是一致的。

[root@aliyun cdrom]# ll
total 110
-rw-r--r--  2 root root    14 Oct 30  2020 CentOS_BuildTag
drwxr-xr-x  3 root root  2048 Oct 27  2020 EFI
-rw-rw-r-- 15 root root   227 Aug 30  2017 EULA
-rw-rw-r-- 15 root root 18009 Dec 10  2015 GPL
drwxr-xr-x  3 root root  2048 Oct 27  2020 images
drwxr-xr-x  2 root root  2048 Nov  3  2020 isolinux
drwxr-xr-x  2 root root  2048 Oct 27  2020 LiveOS
drwxr-xr-x  2 root root 73728 Nov  3  2020 Packages
drwxr-xr-x  2 root root  4096 Nov  3  2020 repodata
-rw-rw-r-- 15 root root  1690 Dec 10  2015 RPM-GPG-KEY-CentOS-7
-rw-rw-r-- 15 root root  1690 Dec 10  2015 RPM-GPG-KEY-CentOS-Testing-7
-r--r--r--  1 root root  2883 Nov  3  2020 TRANS.TBL

3.修改yum源配置

# 1.备份原yum源配置
cp -r /etc/yum.repos.d /etc/yum.repos.d.bak
# 2.查看是否备份成功
ll  /etc/yum.repos.d.bak
# 3.删除原yum源配置
rm -rf /etc/yum.repos.d/*
# 4.新建本地yum离线源配置
vim /etc/yum.repos.d/local.repo

/etc/yum.repos.d/local.repo 内容如下:

[local]
name=local
baseurl=file:///mnt/cdrom   
enabled=1           
gpgcheck=0
gpgkey=file:///mnt/cdrom/RPM-GPG-KEY-CentOS-7
# 5.清除缓存启用本地yum源
yum clean all
  # 返回信息 已启用 local
  Loaded plugins: fastestmirror
  Cleaning repos: local
  Cleaning up list of fastest mirrors
  Other repos take up 168 M of disk space (use --verbose for details)

4. 局域网yum源

4.1 局域网yum源服务搭建

# 安装并启动 apache http 服务
yum -y install httpd
systemctl start httpd

apache http 服务测试 http://aliyun 默认是80端口。

apache http 服务的文件目录为 /var/www/html,所以需要建立快捷方式指向本地yum源:

# 创建软链接
ln -s /mnt/cdrom/ /var/www/html/centos7

访问测试 http://aliyun/centos7/

至此局域网yum源服务搭建完成。

4.2 局域网yum源应用

# 备份删除原 yum 源配置并添加远程源配置
cp -r /etc/yum.repos.d /etc/yum.repos.d.bak
rm -rf /etc/yum.repos.d/*
vim /etc/yum.repos.d/remote.repo
# remote.repo 内容如下
[remote]
name=remote
baseurl=http://aliyun/centos7/ 
enabled=1           
gpgcheck=0
gpgkey=http://192.168.0.174/centos7/RPM-GPG-KEY-CentOS-7
# 清除缓存启用远程yum源
yum clean all
  # 返回信息 
  Loaded plugins: fastestmirror, langpacks
  Cleaning repos: remote
  Cleaning up list of fastest mirrors
  Other repos take up 30 M of disk space (use --verbose for details)
目录
相关文章
|
4月前
|
存储 Linux 开发工具
Linux环境下使用Buildroot配置软件包
使用Buildroot可以大大简化嵌入式Linux系统的开发和维护工作,但它需要对Linux系统和交叉编译有深入的理解。通过上述步骤,可以有效地配置和定制软件包,为特定的嵌入式应用构建高效、稳定的系统。
549 11
|
6月前
|
存储 监控 Linux
Linux环境锁定关键文件防止误删操作流程。
总结以上内容,在Linux环境下锁定重要文档避免误删涉及到多种技术手段与策略组合运作, 包括但不限于利用chatter指挥官固化文档状态至只读模式、运作ACL精准调整访问权利列表、编排自动化流程简
265 20
|
6月前
|
Linux
Linux环境下的UDEV机制及其与守护进程的关联
实际使用时管理员需要熟悉编写合适udev rules去满足特殊需求;同时也需要注意避免编写过度复杂导致无法预料结果rules.UDEVD虽然稳健但错误配置可能导致无法预料问题因此需谨慎处理相关配置工作.
238 16
|
5月前
|
Linux 应用服务中间件 Shell
二、Linux文本处理与文件操作核心命令
熟悉了Linux的基本“行走”后,就该拿起真正的“工具”干活了。用grep这个“放大镜”在文件里搜索内容,用find这个“探测器”在系统中寻找文件,再用tar把东西打包带走。最关键的是要学会使用管道符|,它像一条流水线,能把这些命令串联起来,让简单工具组合出强大的功能,比如 ps -ef | grep 'nginx' 就能快速找出nginx进程。
626 1
二、Linux文本处理与文件操作核心命令
|
5月前
|
Linux
linux命令—stat
`stat` 是 Linux 系统中用于查看文件或文件系统详细状态信息的命令。相比 `ls -l`,它提供更全面的信息,包括文件大小、权限、所有者、时间戳(最后访问、修改、状态变更时间)、inode 号、设备信息等。其常用选项包括 `-f` 查看文件系统状态、`-t` 以简洁格式输出、`-L` 跟踪符号链接,以及 `-c` 或 `--format` 自定义输出格式。通过这些选项,用户可以灵活获取所需信息,适用于系统调试、权限检查、磁盘管理等场景。
402 137
|
5月前
|
安全 Ubuntu Unix
一、初识 Linux 与基本命令
玩转Linux命令行,就像探索一座新城市。首先要熟悉它的“地图”,也就是/根目录下/etc(放配置)、/home(住家)这些核心区域。然后掌握几个“生存口令”:用ls看周围,cd去别处,mkdir建新房,cp/mv搬东西,再用cat或tail看文件内容。最后,别忘了随时按Tab键,它能帮你自动补全命令和路径,是提高效率的第一神器。
945 57
|
4月前
|
存储 安全 Linux
Linux卡在emergency mode怎么办?xfs_repair 命令轻松解决
Linux虚拟机遇紧急模式?别慌!多因磁盘挂载失败。本文教你通过日志定位问题,用`xfs_repair`等工具修复文件系统,三步快速恢复。掌握查日志、修磁盘、验重启,轻松应对紧急模式,保障系统稳定运行。
868 2