Redhat 8.8 创建本地 yum 源服务器

系统环境:Redhat 8.8

yum镜像:Redhat 8.8

Apache(httpd):

一、系统挂载镜像

[root@localhost ~]# lsblk

[root@localhost ~]# mkdir /tmp/cdrom
[root@localhost ~]# mount /dev/sr0 /tmp/cdrom/

[root@localhost ~]# df -h

 将镜像中文件复制到 /iso/rhel-8.8-x86_64下。

[root@localhost ~]#mkdir -p /iso/rhel-8.8-x86_64

[root@localhost ~]#cp -R /tmp/cdrom/* /iso/rhel-8.8-x86_64/

 二、服务器自身配置yum源

[root@localhost ~]#cd /etc/yum.repos.d/

[root@localhost yum.repos.d]# touch redhat.repo

[root@localhost yum.repos.d]# vim redhat.repo

[base]
name=BaseOS
baseurl=file:///iso/rhel-8.8-x86_64/BaseOS
enable=1
gpgcheck=0

[AppStream]
name=AppStream
baseurl=file:///iso/rhel-8.8-x86_64/AppStream
enable=1
gpgcheck=0

[root@localhost yum.repos.d]# yum clean all 

[root@localhost yum.repos.d]# yum makecache

三、安装配置 httpd 

[root@localhost yum.repos.d]# yum install -y httpd

已更新安装的产品。

已安装:
  apr-1.6.3-12.el8.x86_64                                                                      
  apr-util-1.6.1-6.el8.x86_64                                                                  
  apr-util-bdb-1.6.1-6.el8.x86_64                                                              
  apr-util-openssl-1.6.1-6.el8.x86_64                                                          
  httpd-2.4.37-56.module+el8.8.0+18556+a66138c1.4.x86_64                                       
  httpd-filesystem-2.4.37-56.module+el8.8.0+18556+a66138c1.4.noarch                            
  httpd-tools-2.4.37-56.module+el8.8.0+18556+a66138c1.4.x86_64                                 
  mod_http2-1.15.7-8.module+el8.8.0+18556+a66138c1.3.x86_64                                    
  redhat-logos-httpd-84.5-1.el8.noarch                                                         

完毕!

 编辑http的配置文件,修改默认目录为要发布镜像的目录 /iso。

[root@localhost conf]# cp /etc/httpd/conf/httpd.conf /etc/httpd/conf/httpd.conf.bak

[root@localhost conf]# vim httpd.conf

 删除 httpd 的默认主页(此处为将默认主页改名))

[root@localhost conf]# mv /etc/httpd/conf.d/welcome.conf /etc/httpd/conf.d/welcome.conf.bak

 修改 /iso 目录归属为 apache

[root@localhost /]# chown -R apache.apache iso

 四、关闭防火墙

[root@localhost /]#systemctl stop firewalld

[root@localhost /]#systemctl disable firewalld

[root@localhost /]#setenforce 0

五、重启 httpd 服务后访问 

[root@localhost /]# systemctl restart httpd

六、客户端配置 

在客户端编辑 repo 文件,指向镜像源位置。

注意:repo 文件中位置为网页能访问到的位置:http://ip/rhel-8.8-x86_64/。而不是系统中实际位置:http://ip/iso/rhel-8.8-x86_64/。切记,否则会报错。

 [root@localhost /]#yum makecache

 附录:第6步配置路径错误时报错信息:

BaseOS                                                                          31 kB/s | 196  B     00:00    
Errors during downloading metadata for repository 'BaseOS':
  - Status code: 404 for http://10.x.x.x/iso/rhel-8.8-x86_64/BaseOS/repodata/repomd.xml (IP: 10.1.81.194)
错误:为仓库 'BaseOS' 下载元数据失败 : Cannot download repomd.xml: Cannot download repodata/repomd.xml: All mirrors were tried 

### 更改 RHEL 8.8 软件源为浙江大学镜像站 对于 RHEL 8.8 的用户来说,如果希望将默认的软件源更改为浙江大学镜像站,则可以按照如下方法操作: #### 安装 EPEL 源并修改其配置指向新的镜像站点 首先需要安装 `epel-release` 包来启用额外的第三方仓库支持。这可以通过下面命令完成: ```bash yum install -y https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm ``` 接着通过编辑 `/etc/yum.repos.d/epel.repo` 文件内的 URL 地址实现对 EPEL 库中资源位置变更的目的。具体做法是在终端里输入以下指令以批量替换文件中的原有链接至目标服务器路径: ```bash sed -i 's|^#baseurl=https://download.example.com|baseurl=http://mirrors.zju.edu.cn|' /etc/yum.repos.d/epel* sed -i 's|^metalink=|#metalink=|' /etc/yum.repos.d/epel* ``` 上述命令会把所有匹配到的基础URL前缀由原来的示例网址变更为浙江大学提供的HTTP服务地址,并注释掉原有的 metalink 行[^1]。 #### 修改 BaseOS 和 AppStream 默认库设置 为了确保系统能够顺利获取官方发布的安全补丁和其他重要更新,在此之后还需要调整两个主要存储库——BaseOS 及 AppStream 中所使用的下载渠道。同样利用 sed 工具来进行全局性的字符串替换工作即可达成目的: ```bash for REPO in $(find /etc/yum.repos.d/ -name "*rhel*.repo"); do \ sudo sed -i 's|^mirrorlist=|#mirrorlist=|g' $REPO ;\ sudo sed -i 's|^#baseurl=http://cdn.redhat.com/baseurl=http://mirrors.zju.edu.cn/rhel|$' $REPO;\ done; ``` 这段脚本遍历了位于 `/etc/yum.repos.d/` 下面所有的 `.repo` 类型文档,针对每一个符合条件的对象分别执行两次不同的正则表达式查找与替换动作:一次用于禁用 mirrorlist 方式的索引机制;另一次则是直接指定固定的 baseurl 值给定于 ZJU 提供的服务端口上。 最后一步就是运行 `yum clean all && yum makecache` 来清除缓存数据以及重新构建元数据库以便立即生效新设定好的参数环境。 ```python import os def change_repo_to_zju(): """Change the repository to Zhejiang University Mirror""" commands = [ "yum install -y https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm", r"sed -i 's|^#baseurl=https://download\.example\.com|baseurl=http://mirrors\.zju\.edu\.cn|' /etc/yum.repos.d/epel*", r"sed -i 's|^metalink=|#metalink=|' /etc/yum.repos.d/epel*" ] for cmd in commands: os.system(cmd) change_repo_to_zju() ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值