Nexus 配置yum私库

本文介绍了如何配置私有的YUM仓库,包括从阿里源获取基础库并替换为私库地址,以及设置EPEL和其他开源软件的私有仓库。详细步骤包括修改repo文件,清理yum缓存,使私库下载rpm包的索引,并处理http方式私库的gpg验证问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

前序

原来的文章已经记录过如何创建私库等操作,这篇文章直接讲重点。有需要的可以参考:

base

base库我使用的是阿里源

在这里插入图片描述
可以看到remote-storage是: http://mirrors.aliyun.com/centos

这个可以去先在下载镜像源,在xxx.repo里的baseurl字段中可以看到。

私库地址的配置规则

配置了私库之后,将xx.repo放到你的/etc/yum.repo.d/xx.repo中。下载某个rpm库之后,比如阿里的镜像私库。

可以使用下面命令下载:

wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo

你可以看到baseurl这种类型的字段,将baseurl中第一变量(在这个例子里是$releasever)之前的地址全部替换掉。当然,注意除了[base]部分,其他的如[updates],[extras]等也要替换掉。

[base] # 其他的如`[updates]`,`[extras]`等也要替换掉。
name=CentOS-$releasever - Base - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/$releasever/os/$basearch/
        http://mirrors.aliyuncs.com/centos/$releasever/os/$basearch/
        http://mirrors.cloud.aliyuncs.com/centos/$releasever/os/$basearch/
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7

替换为:

[base]
name=CentOS-$releasever - Base - mirrors.aliyun.com
failovermethod=priority
# 其中http://192.168.10.3:8080/repository/rpm-x86就是上图中私库的URL地址。
baseurl=http://192.168.10.3:8080/repository/rpm-x86/$releasever/os/$basearch/
        http://192.168.10.3:8080/repository/rpm-x86/$releasever/os/$basearch/
        http://192.168.10.3:8080/repository/rpm-x86/$releasever/os/$basearch/
gpgcheck=1
gpgkey=http://172.16.15.240:65432/repository/rpm-x86/RPM-GPG-KEY-CentOS-7

epel-release

如果你有多个远程yum源,比如除了base还有epel-release,有的开源软件如gitlab,mysql都有自己的私库。拿你要配置多个yum私库,当然替换规则也是一样的,如下给出epel的repo

online

[epel]
name=Extra Packages for Enterprise Linux 7 - $basearch
baseurl=https://mirrors.tuna.tsinghua.edu.cn/epel/7/$basearch
#mirrorlist=https://mirrors.fedoraproject.org/metalink?repo=epel-7&arch=$basearch
failovermethod=priority
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7

[epel-debuginfo]
name=Extra Packages for Enterprise Linux 7 - $basearch - Debug
baseurl=https://mirrors.tuna.tsinghua.edu.cn/epel/7/$basearch/debug
#mirrorlist=https://mirrors.fedoraproject.org/metalink?repo=epel-debug-7&arch=$basearch
failovermethod=priority
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7
gpgcheck=1

[epel-source]
name=Extra Packages for Enterprise Linux 7 - $basearch - Source
baseurl=https://mirrors.tuna.tsinghua.edu.cn/epel/7/SRPMS
#mirrorlist=https://mirrors.fedoraproject.org/metalink?repo=epel-source-7&arch=$basearch
failovermethod=priority
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7
gpgcheck=1

local

那么这种情况下,就替换$basearch之前的字符串就可以了。

[epel]
name=Extra Packages for Enterprise Linux 7 - $basearch
baseurl=http://xxx.xxx.xxx.xxx:8080/repository/rpm-epel-release-x86/$basearch
#mirrorlist=https://mirrors.fedoraproject.org/metalink?repo=epel-7&arch=$basearch
failovermethod=priority
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7

[epel-debuginfo]
name=Extra Packages for Enterprise Linux 7 - $basearch - Debug
baseurl=http://xxx.xxx.xxx.xxx:8080/repository/rpm-epel-release-x86/$basearch/debug
#mirrorlist=https://mirrors.fedoraproject.org/metalink?repo=epel-debug-7&arch=$basearch
failovermethod=priority
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7
gpgcheck=1

[epel-source]
name=Extra Packages for Enterprise Linux 7 - $basearch - Source
baseurl=http://xxx.xxx.xxx.xxx:8080/repository/rpm-epel-release-x86/SRPMS
#mirrorlist=https://mirrors.fedoraproject.org/metalink?repo=epel-source-7&arch=$basearch
failovermethod=priority
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7
gpgcheck=1

让nexus私库缓存你的rpm包

第一步是将上面改好的repo放到/etc/yum.repo.d/$repo-name.repo,其中/$repo-name.repo就是远程仓库的名字(不是nexus私库的名字),比如CentOS-Base.repo,epel.repo,最好远程仓库的repo文件下载下来时文件名叫什么就叫什么。

第二步当然是将本地缓存都清了,然后让私库把rpm包的索引库(元数据)下载下来:

yum clean all
yum makecache

第三步就是把一些常用的包缓存起来

yum -y install xxxx

如果安装过了,可能不会走nexus,可以先卸载:

yum -y remove xxxx

然后你可以在私库中看到:
在这里插入图片描述

repomd.xml signature could not be verified for gitlab_gitlab-ee

这是因为它会进行文件完整性,如果你的私库时http方式的可能会引起这个错误。

[gitlab_gitlab-ee]
name=gitlab_gitlab-ee
baseurl=http://xxx.xxx.xxx.xxx:8080/repository/rpm-gitlab-x86/$basearch
repo_gpgcheck=0   # 这里会进行gpg签名验证,把1改成0,就不会出错了
gpgcheck=1
enabled=1
gpgkey=https://packages.gitlab.com/gitlab/gitlab-ee/gpgkey
       https://packages.gitlab.com/gitlab/gitlab-ee/gpgkey/gitlab-gitlab-ee-3D645A26AB9FBD22.pub.gpg
sslverify=0    # 把1改成0,如果私库不是https
sslcacert=/etc/pki/tls/certs/ca-bundle.crt
metadata_expire=300

常用私库

x86

  • http://mirrors.aliyun.com/centos

arm64

  • http://mirrors.ustc.edu.cn/centos-altarch
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值