nexus3作为yum私服的使用

Yum(全称为 Yellow dog Updater, Modified)是一个软件包管理器。Yum基于RPM包管理,能够从指定的服务器自动下载RPM包并且安装,可以自动处理依赖性关系,并且一次安装所有依赖的软件包,无须繁琐地一次次下载、安装。

在开始之前,我先说说自己之前是怎么在不能上网的服务器上安装软件的:
1)本地新安装一台和目标服务器系统一样的虚拟机,在/etc/yum.conf中将“keepcache=0”改成keepcache=1(为了保存安装的rpm包)
2)在本地虚拟机上用yum安装需要的软件
3)把本地虚拟机/var/cache/下的rpm包都拷贝到目标服务器上的一个目录下,并用createrepo进行创建yum源仓库
4)配置目标服务器上的repo源地址
这个过程光看看就非常繁琐,而且yum源中的rpm包是固定死的,不能更新。在了解到了nexus这个大神器之后,我觉得之前的自己真是蠢的有点可爱,哈哈!

用nexus来作为yum私服的好处:
1.节省公网带宽,这个是私服的共有特征。
2.由于权限、配额等原因,公司中有些服务器无法上网,那这些不能上网的服务器怎么安装软件包啊?nexus可以完美的解决这个问题。

概述

1)Nexus3 提供了的3种类型的Docker仓库,前两者都可以创建多个仓库,最后一个则可以将他们全部聚合到一个URL来访问。
docker (hosted): 自托管
docker (proxy): 代理
docker (group): 聚合
建议为你想要创建的每个新仓库创建一个新的blob store。这样,每个仓库的数据都将位于/nexus-data中的不同文件夹中(在Docker容器内)

2)下面打算创建三个仓库 docker-hub-hosted, docker-hub-proxy, docker-hub-group
分别创建三个blobs: docker-hub-hosted, docker-hub-proxy, docker-hub-group
group类型的docker仓库,是一个聚合类型的仓库。它能够仓库聚合成一个URL对外提供服务,可以屏蔽后端的差异性,实现类似透明代理的功能。

一、创建Blob Stores

新建一个blob store专门作为的存储。

1)Type
选择"File"。
2)Name
就叫yum-blob吧。
3)Enable Soft Quota
限制目录的大小。我这边就不限制了。如果要限制的话,就勾选上,并填上限制的条件和限制的值就OK了。
4)Path
在填入Name之后,path会自动生成。
在这里插入图片描述

二、创建一个hosted类型的仓库

用户可以把一些自己的构件手动上传至宿主仓库(Hosted Repository)中。
点击"Repository"–>“Repositories”–>“Create repository”,选择yum(hosted)。

在这里插入图片描述

1)Name
就叫yum-hosted-my吧。

2)Online
勾选,可以设置这个仓库是在线还是离线。

3)Yum
Repodata Depth:指定创建repodata文件夹的存储库深度,这里选择"2"。
Deploy Policy:布局策略
Strict:严格
Permissive:宽松
这里选择默认的Strict。

4)Storang
Blob store:选择此仓库使用的Blob存储,这里选择之前创建的yum-blob。
Strict Content Type Validation:验证上传内容格式,这里就用默认的勾选。

5)Hosted
Deployment Policy:部署策略,有三个选项,分别是:
Allow Redeploy:允许重新部署
Disable Redeploy:禁止重新部署
Read-Only:只读

我这里使用默认的"Disable Redeploy",如果是开发环境,可以选择"Allow Redeploy"。

6)Cleanup
Cleanup Policies:清除策略,这个是新增的功能,这里先不进行设置。

配置完成后如下图

在这里插入图片描述在这里插入图片描述

三、创建一个proxy类型的仓库

代理仓库(Proxy Repository)是远程仓库的代理,当用户向这个代理仓库请求一个依赖包时,这个代理仓库会先在本地查找,如果存在,会直接提供给用户进行下载;如果在代理仓库本地查找不到,就会从配置的远程中央仓库中进行下载,下载到私服上之后再提供给用户下载。所以一般我们把私服架设在内网之中,这样可以节省外网带宽,并且大大提高了用户下载依赖的速度。
点击"Repository"–>“Repositories”–>“Create repository”,选择yum(proxy)。

1)Name
因为我要代理阿里云的yum仓库,所以就叫"yum-proxy-aliyun"。

2)Online
勾选,设置成在线。

3)Proxy
Remote storage:设置远程中央仓库的地址,我这里设置成阿里云的yum仓库地址—http://mirrors.aliyun.com/centos/

其他的用默认值即可。

4)Storage
Blob store:选择yum-blob
Strict Content Type Validation:验证上传内容格式,这里就用默认的勾选。

5)Routing,Negative Cache,Cleanup,HTTP
都使用默认配置。
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

四、创建一个group类型的仓库
仓库组(Repository Group)的目的是将多个仓库(代理仓库和宿主仓库)聚合,对用户暴露统一的地址。当用户需要获取某一个依赖包时,请求的是仓库组的地址,系统将会根据仓库组配置的仓库顺序依次查找。
点击"Repository"–>“Repositories”–>“Create repository”,选择yum(gruop)。

1)Name
yum-group-my

2)Online
勾选,设置成在线

3)Storage
Blob store:选择yum-blob
Strict Content Type Validation:使用默认的勾选

4)Group
将左侧的Available中的仓库列表添加到右侧的Members中。
在这里插入图片描述
在这里插入图片描述

五、验证测试

测试很简单,找一台不能上网的服务器或者把服务器中的其他yum源配置删除。为了方便,我这里直接把服务器中的其他yum源配置文件删除。

1、客户端配置
先备份原始repo文件

[root@localhost ~]# cd /etc/yum.repos.d/
[root@localhost yum.repos.d]# ls
Centos-7.repo  CentOS-Base.repo  CentOS-CR.repo  CentOS-Debuginfo.repo  CentOS-fasttrack.repo  CentOS-Media.repo  CentOS-Sources.repo  CentOS-Vault.repo
[root@localhost yum.repos.d]# mkdir repo_bak
[root@localhost yum.repos.d]# mv *.repo repo_bak/

再创建nexus.repo

[root@localhost yum.repos.d]# vim nexus.repo
[nexusrepo]
name=Nexus Repository
baseurl=http://192.168.0.125:9081/repository/yum-group-my/$releasever/os/$basearch/
enabled=1
gpgcheck=0
[root@localhost yum.repos.d]# ls
nexus.repo  repo_bak

2、更新客户端的yum源
用yum celan all和yum makecache命令来更新客户端yum源

[root@localhost yum.repos.d]# yum clean all
Loaded plugins: fastestmirror
Cleaning repos: nexusrepo
Cleaning up everything
Maybe you want: rm -rf /var/cache/yum, to also free up space taken by orphaned data from disabled or removed repos
Cleaning up list of fastest mirrors
[root@localhost yum.repos.d]# yum makecache
Loaded plugins: fastestmirror
nexusrepo                                                                                                                            | 1.8 kB  00:00:00     
(1/4): nexusrepo/7/x86_64/group_gz                                                                                                   | 167 kB  00:00:00     
(2/4): nexusrepo/7/x86_64/filelists                                                                                                  | 7.6 MB  00:00:00     
(3/4): nexusrepo/7/x86_64/primary                                                                                                    | 2.9 MB  00:00:00     
(4/4): nexusrepo/7/x86_64/other                                                                                                      | 1.6 MB  00:00:00     
Determining fastest mirrors
nexusrepo                                                                                                                                       10097/10097
nexusrepo                                                                                                                                       10097/10097
nexusrepo                                                                                                                                       10097/10097
Metadata Cache Created

3、验证从私服下载
客户端的yum配置已经完成,这里用yum安装gcc来做测试。

安装之前,先看一眼现在私服上的yum-group-my仓库是没有任何的构件的。
在这里插入图片描述

好了,万事具备,开始安装gcc吧

[root@localhost ~]# yum -y install gcc

然后再看一眼私服上的yum-group-my仓库。
在这里插入图片描述

和预期的一样,私服上已经从远程中央仓库下载了gcc的rpm和它的依赖包。

4、验证上传
yum客户端没有附带上传rpm包的方法。官网给出的例子是使用curl通过简单的http-put的方法将rpm包上传到私服的hosted仓库中。

我这里拿一个grafana的rpm进行上传测试

[root@localhost ~]# curl -v --user 'admin:Abc@123456' --upload-file ./grafana-4.4.3-1.x86_64.rpm http://192.168.0.125:9081/repository/yum-hosted-my/test/grafana-4.4.3-1.x86_64.rpm
* About to connect() to 192.168.0.125 port 9081 (#0)
*   Trying 192.168.0.125...
* Connected to 192.168.0.125 (192.168.0.125) port 9081 (#0)
* Server auth using Basic with user 'admin'
> PUT /repository/yum-hosted-my/test/grafana-4.4.3-1.x86_64.rpm HTTP/1.1
> Authorization: Basic YWRtaW46QWJjQDEyMzQ1Ng==
> User-Agent: curl/7.29.0
> Host: 192.168.0.125:9081
> Accept: */*
> Content-Length: 47258737
> Expect: 100-continue
> 
< HTTP/1.1 100 Continue
* We are completely uploaded and fine
< HTTP/1.1 400 Uploading RPMs above the configured depth is not allowed. Repodata depth set to 2, RPM depth is lower (1)
< Date: Mon, 14 Oct 2019 07:11:30 GMT
< Server: Nexus/3.19.0-01 (OSS)
< X-Content-Type-Options: nosniff
< Content-Security-Policy: sandbox allow-forms allow-modals allow-popups allow-presentation allow-scripts allow-top-navigation
< X-XSS-Protection: 1; mode=block
< Content-Length: 0
< 
* Connection #0 to host 192.168.0.125 left intact

可以看到上传并没有成功,报了400的错误,原因是"Uploading RPMs above the configured depth is not allowed. Repodata depth set to 2, RPM depth is lower (1)"。这是因为之前在创建yum-hosted-my仓库的时候,我设置了"Repodata Depth"的值为2,也就是rpm包的上传深度为2。但是我在用curl命令上传时的深度就只有test这么一级目录,所以我的实际上传是深度为1,小于设置的上传深度2才报的这个错。

解决方法:
用curl上传的时候将rpm包的上传深度大于等于2就行。

[root@localhost ~]# curl -v --user 'admin:Abc@123456' --upload-file ./grafana-4.4.3-1.x86_64.rpm http://192.168.0.125:9081/repository/yum-hosted-my/test/my/grafana-4.4.3-1.x86_64.rpm     
* About to connect() to 192.168.0.125 port 9081 (#0)
*   Trying 192.168.0.125...
* Connected to 192.168.0.125 (192.168.0.125) port 9081 (#0)
* Server auth using Basic with user 'admin'
> PUT /repository/yum-hosted-my/test/my/grafana-4.4.3-1.x86_64.rpm HTTP/1.1
> Authorization: Basic YWRtaW46QWJjQDEyMzQ1Ng==
> User-Agent: curl/7.29.0
> Host: 192.168.0.125:9081
> Accept: */*
> Content-Length: 47258737
> Expect: 100-continue
> 
< HTTP/1.1 100 Continue
* We are completely uploaded and fine
< HTTP/1.1 200 OK
< Date: Mon, 14 Oct 2019 07:21:04 GMT
< Server: Nexus/3.19.0-01 (OSS)
< X-Content-Type-Options: nosniff
< Content-Security-Policy: sandbox allow-forms allow-modals allow-popups allow-presentation allow-scripts allow-top-navigation
< X-XSS-Protection: 1; mode=block
< Content-Length: 0
< 
* Connection #0 to host 192.168.0.125 left intact

可以看到,返回200,这时候去私服看一下yum-group-my仓库。
在这里插入图片描述

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值