CentOS内网yum源构建&使用最佳实践

一、yum源构建(base源、updates源、epel源)

1. 找一台能连互联网的centos服务器,虚拟机也行。

2. 备份已有yum repo文件

cd /etc/yum.repo.d
mkdir bak
mv *.repo bak

3. 导入华为云yum repo

#导入华为yum源配置
cat > /etc/yum.repos.d/CentOS-Base.repo <<EOF
# CentOS-Base.repo
#
# The mirror system uses the connecting IP address of the client and the
# update status of each mirror to pick mirrors that are updated to and
# geographically close to the client.  You should use this for CentOS updates
# unless you are manually picking other mirrors.
#
# If the mirrorlist= does not work for you, as a fall back you can try the 
# remarked out baseurl= line instead.
#
#
 
[base]
name=CentOS-\$releasever - Base - repo.huaweicloud.com
baseurl=https://repo.huaweicloud.com/centos/\$releasever/os/\$basearch/
#mirrorlist=https://mirrorlist.centos.org/?release=\$releasever&arch=\$bas
### 配置CentOS 7内网YUM仓库 #### 准备工作 为了确保能够顺利配置本地镜像,在开始之前需要准备ISO镜像文件并挂载到指定目录。 ```bash sudo mount -o loop CentOS-7-x86_64-Everything-1908.iso /mnt/iso ``` 此命令会将ISO镜像以只读方式挂载至`/mnt/iso`路径下[^2]。 #### 创建备份 在修改任何现有配置前,建议先对原始配置进行备份以防万一出现问题可以恢复: ```bash cp -ar /etc/yum.repos.d /etc/yum.repos.d.bak ``` 这条指令用于复制整个yum配置文件夹的内容,并将其保存在一个新的名为`.bak`的子目录中作为备份副本[^1]。 #### 添加新仓库定义 接下来要编辑或新建一个repo文件来描述新增加的本地存储库位置。可以通过文本编辑器打开目标文件来进行操作: ```bash vi /etc/yum.repos.d/local.repo ``` 在此文件内部输入如下内容以建立名称为`local`的新资库条目: ```ini [local] name=CentOS Local Repository baseurl=file:///mnt/iso enabled=1 gpgcheck=0 ``` 上述片段指定了该仓库的基础URL指向已挂载好的ISO映射点;同时启用了这个仓库(`enabled=1`)并且关闭了GPG校验功能(`gpgcheck=0`)以便简化安装流程[^3]。 #### 更新缓存索引 完成以上步骤之后还需要刷新系统的包管理器元数据才能使改动生效: ```bash yum clean all &amp;&amp; yum makecache ``` 这两条命令分别用来清除旧有的缓存记录以及重新构建最新的可用软件列表。 通过执行这些操作就可以成功搭建起基于ISO镜像的离线环境下的yum服务端供其他机器访问使用了。
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值