<六>企业级开源仓库nexus3实战应用–使用nexus3配置yum私有仓库

一两个星期之前,你如果在我跟前说起私服的事情,我大概会绕着你走,因为我对这个东西真的一窍不通。事实上也正如此,开发同学曾不止一次的跟我说公司的私服版本太旧了,许多新的依赖编译之后不会从远程仓库自动缓存下来,然后每次就需要手动的上传,不方便极了。我听了之后,一方面确实因为各种忙碌没有抽开时间,但另一方面,则是每当打开私服面对着满屏的英文时,我都觉得眼前私服毕竟还能用,就不折腾了。

直到偶然一个契机,在网上看到一篇介绍nexus3.x的文章,文章写得也比较清晰,我也有兴致细读下去,就这样,开启了我的nexus3私服之旅。

开始我以为这个只是针对maven私服而存在的工具,后来才发现它所支持的,竟然将运维日常所面临的各种私服都包括了,这就极大的引发了我的钻研兴致,从maven私服的研究开始,一发不可收拾的,就又写出了一个nexus3系列教程,涵盖了安装,配置,maven私服,maven私服从2.x到3.x的迁移,docker私服,npm私服,yum私服,纵观全网络,大概也找不到一个人如此这般的,倾尽所有的,知无不言的,言无不尽的将nexus3作为一个系列写成文章的了。而现在,如果再有人与我说起私服的事情,至少我不会跑了,或许更想停下来了,,,哈哈。这就是付出学习所给人带来的心境上的转化!

前言啰嗦几句,愿您在这个小系列中,学习愉快!

想要查看本系列其他文章:请点此处跳转

希望正在读这段话的你能够在这个小系列中获得自信以及喜悦!

yum相较于rpm,能够更好地解决安装软件时的依赖包问题,使用yum安装更简单更方便。搭建本地YUM源服务器,可以避免升级安装软件时占用公网带宽;有了本地YUM源服务器,可以解决无法连接Internet的其他YUM客户端的软件升级和安装。

搭建yum私服,我们依旧使用nexus3,这个强大的让人忍不住想保住它亲一亲的优秀开源工具,再增添多少的赞美也不为过。

与其他私服一样的,yum私服同样有三种类型:

  • hosted : 本地存储,即同 yum 官方仓库一样提供本地私服功能
  • proxy : 提供代理其他仓库的类型,如我们常用的163仓库
  • group : 组类型,实质作用是组合多个仓库为一个地址,相当于一个透明代理。

那么就来一个一个创建。

1,创建blob存储。

为其创建一个单独的存储空间,命名为yum-hub

2,创建hosted类型的yum库。

后来才发现,其实每次创建的这个hosted类型的,并没有什么用。不过照例创建一波吧。

  • Name::定义一个名称local-yum
  • Storage:Blob store,我们下拉选择前面创建好的专用blob:yum-hub。
  • Hosted:开发环境,我们运行重复发布,因此Delpoyment policy 我们选择Allow redeploy。这个很重要!

整体配置截图如下:

3,创建一个proxy类型的yum仓库。

其他的均是默认。

这里就先创建一个代理163的仓库,其实还可以多创建几个,诸如阿里云的,搜狐的,等等,这个根据个人需求来定义。

整体配置截图如下:

4,创建一个group类型的yum仓库。

  • Name:group-yum
  • Storage:选择专用的blob存储yum-hub。
  • group : 将左边可选的2个仓库,添加到右边的members下。

整体配置截图如下:

这些配置完成之后,就可以使用了。

5,构建缓存。

新建一台环境干净的主机,此时需要保证这台主机能够上网,因为私服当中还没有进行初始化。

先简单配置一下,将yum源指向到私服中来。

1,将原有的移走。

  1. [root@7-3 ~]$cd /etc/yum.repos.d/
  2. [root@7-3 yum.repos.d]$ls
  3. CentOS-Base.repo CentOS-CR.repo CentOS-Debuginfo.repo CentOS-fasttrack.repo CentOS-Media.repo CentOS-Sources.repo CentOS-Vault.repo
  4. [root@7-3 yum.repos.d]$mkdir bak
  5. [root@7-3 yum.repos.d]$mv * bak
  6. mv: cannot move bak to a subdirectory of itself, bak/bak
  7. [root@7-3 yum.repos.d]$ls
  8. bak

2,创建一个新的源。

  1. [root@7-3 yum.repos.d]$vim nexus.repo

添加如下内容:

其中的url就是私服当中创建的group的对外地址,后面的$releasever/os/$basearch/不要漏掉了。

  1. [nexus]
  2. name=Nexus Repository
  3. baseurl=http://192.168.106.65:8081/repository/group-yum/$releasever/os/$basearch/
  4. enabled=1
  5. gpgcheck=0
注意这还不是完整内容,我第一次构建的时候只写了这些内容,以求私服自己能够通过刚刚配置的proxy将远程的包拉下来,最后发现这种方式,死活都是无法成功的。

因此,这里还应该将163的源配置添加进来。

完整内容应该如下:

  1. [root@7-3 yum.repos.d]$cat nexus.repo
  2. [nexus]
  3. name=Nexus Repository
  4. baseurl=http://192.168.106.65:8081/repository/group-yum/$releasever/os/$basearch/
  5. enabled=1
  6. gpgcheck=0
  7.  
  8. #released updates
  9. [updates]
  10. name=CentOS-$releasever-Updates-163.com
  11. #mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates
  12. baseurl=http://mirrors.163.com/centos/$releasever/updates/$basearch/
  13. gpgcheck=1
  14. gpgkey=http://mirrors.163.com/centos/RPM-GPG-KEY-CentOS-7
  15.  
  16. #additional packages that may be useful
  17. [extras]
  18. name=CentOS-$releasever-Extras-163.com
  19. #mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras
  20. baseurl=http://mirrors.163.com/centos/$releasever/extras/$basearch/
  21. gpgcheck=1
  22. gpgkey=http://mirrors.163.com/centos/RPM-GPG-KEY-CentOS-7
  23.  
  24. #additional packages that extend functionality of existing packages
  25. [centosplus]
  26. name=CentOS-$releasever-Plus-163.com
  27. baseurl=http://mirrors.163.com/centos/$releasever/centosplus/$basearch/
  28. gpgcheck=1
  29. enabled=0
  30. gpgkey=http://mirrors.163.com/centos/RPM-GPG-KEY-CentOS-7

3,构建缓存。

现在,就可以通过makecache将远程的包拉到内部私服当中了。

操作之前,就像古代变戏法一般的,依旧先去私服看一眼group-yum当中是否有包存在,这是一个固定流程哈。

可以看到空空如也,那么通过如下三步操作创建缓存。

  1. [root@7-3 yum.repos.d]$yum clean all
  2. Loaded plugins: fastestmirror
  3. Cleaning repos: extras nexus updates
  4. Cleaning up everything
  5. Cleaning up list of fastest mirrors
  6. [root@7-3 yum.repos.d]$yum makecache
  7. Loaded plugins: fastestmirror
  8. extras | 3.4 kB 00:00:00
  9. nexus | 1.8 kB 00:00:00
  10. updates | 3.4 kB 00:00:00
  11. (1/12): extras/7/x86_64/prestodelta | 100 kB 00:00:00
  12. (2/12): extras/7/x86_64/primary_db | 204 kB 00:00:00
  13. (3/12): extras/7/x86_64/other_db | 126 kB 00:00:00
  14. (4/12): extras/7/x86_64/filelists_db | 604 kB 00:00:00
  15. (5/12): nexus/7/x86_64/group_gz | 167 kB 00:00:00
  16. (6/12): nexus/7/x86_64/primary | 2.9 MB 00:00:00
  17. (7/12): nexus/7/x86_64/other | 1.6 MB 00:00:00
  18. (8/12): nexus/7/x86_64/filelists | 7.1 MB 00:00:00
  19. (9/12): updates/7/x86_64/prestodelta | 679 kB 00:00:00
  20. (10/12): updates/7/x86_64/filelists_db | 3.4 MB 00:00:00
  21. (11/12): updates/7/x86_64/other_db | 578 kB 00:00:00
  22. (12/12): updates/7/x86_64/primary_db | 6.0 MB 00:00:01
  23. Determining fastest mirrors
  24. nexus 9911/9911
  25. nexus 9911/9911
  26. nexus 9911/9911
  27. Metadata Cache Created
  28.  
  29. [root@7-3 yum.repos.d]$yum update -y #这个过程比较长,内容比较多,不完全复制了。

当上边的第三步执行完成之后,此时我们可以回到刚刚那个空白的页面,看看内容是否上来了。

就是这么神奇。

6,验证一下效果。

验证的方式其实也很简单,找一台不能上网但是可以与刚刚私服通信的主机,将其yum源指向的配置好的私服,看看安装软件什么的是否可以so easy。

或者是将其他的源都切断,然后yum源仅仅指向私服,看看安装是否顺利。

这里采用第二种方式简单试验一下。

1,将原有的移走。

  1. [root@7-2 ~]$cd /etc/yum.repos.d/
  2. [root@7-2 yum.repos.d]$ls
  3. CentOS-Base.repo CentOS-CR.repo CentOS-Debuginfo.repo CentOS-fasttrack.repo CentOS-Media.repo CentOS-Sources.repo CentOS-Vault.repo
  4. [root@7-2 yum.repos.d]$mkdir bak
  5. [root@7-2 yum.repos.d]$mv * bak
  6. mv: cannot move bak to a subdirectory of itself, bak/bak
  7. [root@7-2 yum.repos.d]$ls
  8. bak

此时尝试一下安装。

  1. [root@7-2 yum.repos.d]$yum -y install httpd
  2.  
  3. Loaded plugins: fastestmirror
  4.  
  5. Determining fastest mirrors
  6. There are no enabled repos.
  7. Run "yum repolist all" to see the repos you have.
  8. To enable Red Hat Subscription Management repositories:
  9. subscription-manager repos --enable <repo>
  10. To enable custom repositories:
  11. yum-config-manager --enable <repo>

2,创建一个新的源。

  1. [root@7-2 yum.repos.d]$cat nexus.repo
  2. [nexus]
  3. name=Nexus Repository
  4. baseurl=http://192.168.106.65:8081/repository/group-yum/$releasever/os/$basearch/
  5. enabled=1
  6. gpgcheck=0

再尝试安装:

  1. [root@7-2 yum.repos.d]$yum -y install httpd
  2. Loaded plugins: fastestmirror
  3. nexus | 1.8 kB 00:00:00
  4. (1/2): nexus/7/x86_64/group_gz | 167 kB 00:00:00
  5. (2/2): nexus/7/x86_64/primary | 2.9 MB 00:00:00
  6. Loading mirror speeds from cached hostfile
  7. nexus 9911/9911
  8. Resolving Dependencies
  9. --> Running transaction check
  10. ---> Package httpd.x86_64 0:2.4.6-80.el7.centos will be installed
  11. --> Processing Dependency: httpd-tools = 2.4.6-80.el7.centos for package: httpd-2.4.6-80.el7.centos.x86_64
  12. --> Processing Dependency: /etc/mime.types for package: httpd-2.4.6-80.el7.centos.x86_64
  13. --> Processing Dependency: libaprutil-1.so.0()(64bit) for package: httpd-2.4.6-80.el7.centos.x86_64
  14. --> Processing Dependency: libapr-1.so.0()(64bit) for package: httpd-2.4.6-80.el7.centos.x86_64
  15. --> Running transaction check
  16. ---> Package apr.x86_64 0:1.4.8-3.el7_4.1 will be installed
  17. ---> Package apr-util.x86_64 0:1.5.2-6.el7 will be installed
  18. ---> Package httpd-tools.x86_64 0:2.4.6-80.el7.centos will be installed
  19. ---> Package mailcap.noarch 0:2.1.41-2.el7 will be installed
  20. --> Finished Dependency Resolution
  21.  
  22. Dependencies Resolved
  23.  
  24. ==========================================================================================================================================================================================
  25. Package Arch Version Repository Size
  26. ==========================================================================================================================================================================================
  27. Installing:
  28. httpd x86_64 2.4.6-80.el7.centos nexus 2.7 M
  29. Installing for dependencies:
  30. apr x86_64 1.4.8-3.el7_4.1 nexus 103 k
  31. apr-util x86_64 1.5.2-6.el7 nexus 92 k
  32. httpd-tools x86_64 2.4.6-80.el7.centos nexus 89 k
  33. mailcap noarch 2.1.41-2.el7 nexus 31 k
  34.  
  35. Transaction Summary
  36. ==========================================================================================================================================================================================
  37. Install 1 Package (+4 Dependent packages)
  38.  
  39. Total download size: 3.0 M
  40. Installed size: 10 M
  41. Downloading packages:
  42. (1/5): apr-1.4.8-3.el7_4.1.x86_64.rpm | 103 kB 00:00:00
  43. (2/5): apr-util-1.5.2-6.el7.x86_64.rpm | 92 kB 00:00:00
  44. (3/5): httpd-tools-2.4.6-80.el7.centos.x86_64.rpm | 89 kB 00:00:00
  45. (4/5): mailcap-2.1.41-2.el7.noarch.rpm | 31 kB 00:00:00
  46. (5/5): httpd-2.4.6-80.el7.centos.x86_64.rpm | 2.7 MB 00:00:03
  47. ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
  48. Total 880 kB/s | 3.0 MB 00:00:03
  49. Running transaction check
  50. Running transaction test
  51. Transaction test succeeded
  52. Running transaction
  53. Installing : apr-1.4.8-3.el7_4.1.x86_64 1/5
  54. Installing : apr-util-1.5.2-6.el7.x86_64 2/5
  55. Installing : httpd-tools-2.4.6-80.el7.centos.x86_64 3/5
  56. Installing : mailcap-2.1.41-2.el7.noarch 4/5
  57. Installing : httpd-2.4.6-80.el7.centos.x86_64 5/5
  58. Verifying : httpd-tools-2.4.6-80.el7.centos.x86_64 1/5
  59. Verifying : apr-1.4.8-3.el7_4.1.x86_64 2/5
  60. Verifying : mailcap-2.1.41-2.el7.noarch 3/5
  61. Verifying : httpd-2.4.6-80.el7.centos.x86_64 4/5
  62. Verifying : apr-util-1.5.2-6.el7.x86_64 5/5
  63.  
  64. Installed:
  65. httpd.x86_64 0:2.4.6-80.el7.centos
  66.  
  67. Dependency Installed:
  68. apr.x86_64 0:1.4.8-3.el7_4.1 apr-util.x86_64 0:1.5.2-6.el7 httpd-tools.x86_64 0:2.4.6-80.el7.centos mailcap.noarch 0:2.1.41-2.el7
  69.  
  70. Complete!

就是这个feel,爽爽爽。

到此地,关于nexus3所支持的私服类型,基本上生产中常用的,都一一介绍过了,到目前为止,我也没有在网上看到过任何一个写,针对nexus写一个系列的教程并分享出来的,啥也不说了,乡亲们呐,我心情激动,我骄傲!

猜你喜欢

转载自www.cnblogs.com/cheyunhua/p/10763360.html