如何搭建 yum 源私服及配置使用私服
2021年01月11日 23:30:55 Linux ⁄ 共 2423字 评论数 1 ⁄ 被围观 2,733次

这篇简单记录下如何搭建 yum 源私服,以及常见的 yum 安装软件命令,纯属笔记,仅供参考。

1. yum 源私服搭建步骤

第一步,安装 nginx 或 apache

这里以安装 apache 为例,nginx同理,请自行尝试。

命令:yum install httpd

安装后启动 httpd 服务。

命令:service httpd start

另外,便于以后启动机器时自动启动服务,配置服务自启动。

命令:chkconfig httpd on

安装 apache 后,访问目录默认为 /var/www/html,可以通过访问 http://机器IP 测试是否能够访问,正常情况下默认打开 apache 测试页面。

第二步,安装 createrepo 和 reposync

命令:yum install createrepo reposync

注意:如果是在安装过程中,可能会有如下提示:

No package reposync available.
Nothing to do

解决方法为:安装 yum-utils,命令如下:

命令:yum install yum-utils

第三步,下载 rpm 包

下载 base 目录包,命令如下:

命令:reposync --repoid=base

同理,下载 updates,extras 和 epel 目录的包,替换 base 即可。由于包的数量巨大,下载与网速有关,慢慢等待吧~

第四步,生成包对应的源数据

对下载的各个目录,需要生成包的源数据,比如 base 目录源数据生成命令如下:

命令:createrepo --update /var/www/html/base/

第五步,测试配置结果

对下载的包和源数据,通过访问代理页面,可以看到如下结果。

其它目录测试同理,换掉 IP 地址后的目录名即可。

2. yum 源私服配置使用

第六步,修改操作机器的 yum 源为该私服

比如,另外找一台测试机器,修改 yum 源为以上搭建的 yum 私服。

命令:cd /etc/yum.repos.d/

命令:vi CentOS-Base.repo

注释掉原有的配置,添加私服配置,参考如下:

[base]
name=CentOS-$releasever - Base - mirrors.aliyun.com
failovermethod=priority
baseurl=http://192.168.220.100/base/
#baseurl=http://mirrors.aliyun.com/centos/$releasever/os/$basearch/
#        http://mirrors.aliyuncs.com/centos/$releasever/os/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-6
 
#released updates 
[updates]
name=CentOS-$releasever - Updates - mirrors.aliyun.com
failovermethod=priority
baseurl=http://192.168.220.100/updates/
#baseurl=http://mirrors.aliyun.com/centos/$releasever/updates/$basearch/
#        http://mirrors.aliyuncs.com/centos/$releasever/updates/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-6
 
#additional packages that may be useful
[extras]
name=CentOS-$releasever - Extras - mirrors.aliyun.com
failovermethod=priority
baseurl=http://192.168.220.100/extras/
#baseurl=http://mirrors.aliyun.com/centos/$releasever/extras/$basearch/
#        http://mirrors.aliyuncs.com/centos/$releasever/extras/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-6

第七步,重新生成测试机 yum 缓存配置

在测试机器上,先清理已有缓存,再重新生成 yum 源缓存配置,将软件包信息缓存本机,提高搜索安装效率。

命令:yum clean all

命令:yum makecache

然后用 yum install xxx 来安装包,及时机器没有外网,下载安装包也是嗖嗖的。

附录1:其它一些常用的三方软件源

阿里云:https://developer.aliyun.com/mirror/

网易:http://mirrors.163.com/

腾讯:https://mirrors.cloud.tencent.com/

。。。

原文链接:https://blog.csdn.net/tzhuwb/article/details/112499430

目前有 1 条留言 其中:访客:0 条, 博主:0 条

  1. Avatar photo Aniyah Ava Ariana Huber : 2024年02月29日16:46:39  -9楼 @回复 回复
    Keep up the amazing work!

给我留言

留言无头像?