直到偶然一個契機,在網上看到一篇介紹nexus3.x的文章,文章寫得也比較清晰,我也有興致細讀下去,就這樣,開啟了我的nexus3私服之旅。
開始我以為這個只是針對maven私服而存在的工具,后來才發現它所支持的,竟然將運維日常所面臨的各種私服都包括了,這就極大的引發了我的鑽研興致,從maven私服的研究開始,一發不可收拾的,就又寫出了一個nexus3系列教程,涵蓋了安裝,配置,maven私服,maven私服從2.x到3.x的遷移,docker私服,npm私服,yum私服,縱觀全網絡,大概也找不到一個人如此這般的,傾盡所有的,知無不言的,言無不盡的將nexus3作為一個系列寫成文章的了。而現在,如果再有人與我說起私服的事情,至少我不會跑了,或許更想停下來了,,,哈哈。這就是付出學習所給人帶來的心境上的轉化!
前言啰嗦幾句,願您在這個小系列中,學習愉快!
想要查看本系列其他文章:請點此處跳轉。
希望正在讀這段話的你能夠在這個小系列中獲得自信以及喜悅!
yum相較於rpm,能夠更好地解決安裝軟件時的依賴包問題,使用yum安裝更簡單更方便。搭建本地YUM源服務器,可以避免升級安裝軟件時占用公網帶寬;有了本地YUM源服務器,可以解決無法連接Internet的其他YUM客戶端的軟件升級和安裝。
與其他私服一樣的,yum私服同樣有三種類型:
hosted
: 本地存儲,即同 yum 官方倉庫一樣提供本地私服功能proxy
: 提供代理其他倉庫的類型,如我們常用的163倉庫group
: 組類型,實質作用是組合多個倉庫為一個地址,相當於一個透明代理。
那么就來一個一個創建。
1,創建blob存儲。
為其創建一個單獨的存儲空間,命名為yum-hub
。
2,創建hosted類型的yum庫。
后來才發現,其實每次創建的這個hosted類型的,並沒有什么用。不過照例創建一波吧。
Name
::定義一個名稱local-yumStorage
:Blob store,我們下拉選擇前面創建好的專用blob:yum-hub。Hosted
:開發環境,我們運行重復發布,因此Delpoyment policy 我們選擇Allow redeploy。這個很重要!
整體配置截圖如下:
3,創建一個proxy類型的yum倉庫。
Name
: proxy-163-yumProxy
:Remote Storage: 遠程倉庫地址,這里填寫: http://mirrors.163.com/centos/Storage
: yum-hub
其他的均是默認。
這里就先創建一個代理163的倉庫,其實還可以多創建幾個,諸如阿里雲的,搜狐的,等等,這個根據個人需求來定義。
整體配置截圖如下:
4,創建一個group類型的yum倉庫。
Name
:group-yumStorage
:選擇專用的blob存儲yum-hub。group
: 將左邊可選的2個倉庫,添加到右邊的members下。
整體配置截圖如下:
這些配置完成之后,就可以使用了。
5,構建緩存。
新建一台環境干凈的主機,此時需要保證這台主機能夠上網,因為私服當中還沒有進行初始化。
先簡單配置一下,將yum源指向到私服中來。
1,將原有的移走。
- [root@7-3 ~]$cd /etc/yum.repos.d/
- [root@7-3 yum.repos.d]$ls
- CentOS-Base.repo CentOS-CR.repo CentOS-Debuginfo.repo CentOS-fasttrack.repo CentOS-Media.repo CentOS-Sources.repo CentOS-Vault.repo
- [root@7-3 yum.repos.d]$mkdir bak
- [root@7-3 yum.repos.d]$mv * bak
- mv: cannot move ‘bak’ to a subdirectory of itself, ‘bak/bak’
- [root@7-3 yum.repos.d]$ls
- bak
2,創建一個新的源。
- [root@7-3 yum.repos.d]$vim nexus.repo
添加如下內容:
其中的url就是私服當中創建的group的對外地址,后面的$releasever/os/$basearch/
不要漏掉了。
- [nexus]
- name=Nexus Repository
- baseurl=http://192.168.106.65:8081/repository/group-yum/$releasever/os/$basearch/
- enabled=1
- gpgcheck=0
因此,這里還應該將163的源配置添加進來。
完整內容應該如下:
- [root@7-3 yum.repos.d]$cat nexus.repo
- [nexus]
- name=Nexus Repository
- baseurl=http://192.168.106.65:8081/repository/group-yum/$releasever/os/$basearch/
- enabled=1
- gpgcheck=0
- #released updates
- [updates]
- name=CentOS-$releasever-Updates-163.com
- #mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates
- baseurl=http://mirrors.163.com/centos/$releasever/updates/$basearch/
- gpgcheck=1
- gpgkey=http://mirrors.163.com/centos/RPM-GPG-KEY-CentOS-7
- #additional packages that may be useful
- [extras]
- name=CentOS-$releasever-Extras-163.com
- #mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras
- baseurl=http://mirrors.163.com/centos/$releasever/extras/$basearch/
- gpgcheck=1
- gpgkey=http://mirrors.163.com/centos/RPM-GPG-KEY-CentOS-7
- #additional packages that extend functionality of existing packages
- [centosplus]
- name=CentOS-$releasever-Plus-163.com
- baseurl=http://mirrors.163.com/centos/$releasever/centosplus/$basearch/
- gpgcheck=1
- enabled=0
- gpgkey=http://mirrors.163.com/centos/RPM-GPG-KEY-CentOS-7
3,構建緩存。
現在,就可以通過makecache將遠程的包拉到內部私服當中了。
操作之前,就像古代變戲法一般的,依舊先去私服看一眼group-yum
當中是否有包存在,這是一個固定流程哈。
可以看到空空如也,那么通過如下三步操作創建緩存。
- [root@7-3 yum.repos.d]$yum clean all
- Loaded plugins: fastestmirror
- Cleaning repos: extras nexus updates
- Cleaning up everything
- Cleaning up list of fastest mirrors
- [root@7-3 yum.repos.d]$yum makecache
- Loaded plugins: fastestmirror
- extras | 3.4 kB 00:00:00
- nexus | 1.8 kB 00:00:00
- updates | 3.4 kB 00:00:00
- (1/12): extras/7/x86_64/prestodelta | 100 kB 00:00:00
- (2/12): extras/7/x86_64/primary_db | 204 kB 00:00:00
- (3/12): extras/7/x86_64/other_db | 126 kB 00:00:00
- (4/12): extras/7/x86_64/filelists_db | 604 kB 00:00:00
- (5/12): nexus/7/x86_64/group_gz | 167 kB 00:00:00
- (6/12): nexus/7/x86_64/primary | 2.9 MB 00:00:00
- (7/12): nexus/7/x86_64/other | 1.6 MB 00:00:00
- (8/12): nexus/7/x86_64/filelists | 7.1 MB 00:00:00
- (9/12): updates/7/x86_64/prestodelta | 679 kB 00:00:00
- (10/12): updates/7/x86_64/filelists_db | 3.4 MB 00:00:00
- (11/12): updates/7/x86_64/other_db | 578 kB 00:00:00
- (12/12): updates/7/x86_64/primary_db | 6.0 MB 00:00:01
- Determining fastest mirrors
- nexus 9911/9911
- nexus 9911/9911
- nexus 9911/9911
- Metadata Cache Created
- [root@7-3 yum.repos.d]$yum update -y #這個過程比較長,內容比較多,不完全復制了。
當上邊的第三步執行完成之后,此時我們可以回到剛剛那個空白的頁面,看看內容是否上來了。
就是這么神奇。
6,驗證一下效果。
驗證的方式其實也很簡單,找一台不能上網但是可以與剛剛私服通信的主機,將其yum源指向的配置好的私服,看看安裝軟件什么的是否可以so easy。
或者是將其他的源都切斷,然后yum源僅僅指向私服,看看安裝是否順利。
這里采用第二種方式簡單試驗一下。
1,將原有的移走。
- [root@7-2 ~]$cd /etc/yum.repos.d/
- [root@7-2 yum.repos.d]$ls
- CentOS-Base.repo CentOS-CR.repo CentOS-Debuginfo.repo CentOS-fasttrack.repo CentOS-Media.repo CentOS-Sources.repo CentOS-Vault.repo
- [root@7-2 yum.repos.d]$mkdir bak
- [root@7-2 yum.repos.d]$mv * bak
- mv: cannot move ‘bak’ to a subdirectory of itself, ‘bak/bak’
- [root@7-2 yum.repos.d]$ls
- bak
此時嘗試一下安裝。
- [root@7-2 yum.repos.d]$yum -y install httpd
- Loaded plugins: fastestmirror
- Determining fastest mirrors
- There are no enabled repos.
- Run "yum repolist all" to see the repos you have.
- To enable Red Hat Subscription Management repositories:
- subscription-manager repos --enable <repo>
- To enable custom repositories:
- yum-config-manager --enable <repo>
2,創建一個新的源。
- [root@7-2 yum.repos.d]$cat nexus.repo
- [nexus]
- name=Nexus Repository
- baseurl=http://192.168.106.65:8081/repository/group-yum/$releasever/os/$basearch/
- enabled=1
- gpgcheck=0
再嘗試安裝:
- [root@7-2 yum.repos.d]$yum -y install httpd
- Loaded plugins: fastestmirror
- nexus | 1.8 kB 00:00:00
- (1/2): nexus/7/x86_64/group_gz | 167 kB 00:00:00
- (2/2): nexus/7/x86_64/primary | 2.9 MB 00:00:00
- Loading mirror speeds from cached hostfile
- nexus 9911/9911
- Resolving Dependencies
- --> Running transaction check
- ---> Package httpd.x86_64 0:2.4.6-80.el7.centos will be installed
- --> Processing Dependency: httpd-tools = 2.4.6-80.el7.centos for package: httpd-2.4.6-80.el7.centos.x86_64
- --> Processing Dependency: /etc/mime.types for package: httpd-2.4.6-80.el7.centos.x86_64
- --> Processing Dependency: libaprutil-1.so.0()(64bit) for package: httpd-2.4.6-80.el7.centos.x86_64
- --> Processing Dependency: libapr-1.so.0()(64bit) for package: httpd-2.4.6-80.el7.centos.x86_64
- --> Running transaction check
- ---> Package apr.x86_64 0:1.4.8-3.el7_4.1 will be installed
- ---> Package apr-util.x86_64 0:1.5.2-6.el7 will be installed
- ---> Package httpd-tools.x86_64 0:2.4.6-80.el7.centos will be installed
- ---> Package mailcap.noarch 0:2.1.41-2.el7 will be installed
- --> Finished Dependency Resolution
- Dependencies Resolved
- ==========================================================================================================================================================================================
- Package Arch Version Repository Size
- ==========================================================================================================================================================================================
- Installing:
- httpd x86_64 2.4.6-80.el7.centos nexus 2.7 M
- Installing for dependencies:
- apr x86_64 1.4.8-3.el7_4.1 nexus 103 k
- apr-util x86_64 1.5.2-6.el7 nexus 92 k
- httpd-tools x86_64 2.4.6-80.el7.centos nexus 89 k
- mailcap noarch 2.1.41-2.el7 nexus 31 k
- Transaction Summary
- ==========================================================================================================================================================================================
- Install 1 Package (+4 Dependent packages)
- Total download size: 3.0 M
- Installed size: 10 M
- Downloading packages:
- (1/5): apr-1.4.8-3.el7_4.1.x86_64.rpm | 103 kB 00:00:00
- (2/5): apr-util-1.5.2-6.el7.x86_64.rpm | 92 kB 00:00:00
- (3/5): httpd-tools-2.4.6-80.el7.centos.x86_64.rpm | 89 kB 00:00:00
- (4/5): mailcap-2.1.41-2.el7.noarch.rpm | 31 kB 00:00:00
- (5/5): httpd-2.4.6-80.el7.centos.x86_64.rpm | 2.7 MB 00:00:03
- ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
- Total 880 kB/s | 3.0 MB 00:00:03
- Running transaction check
- Running transaction test
- Transaction test succeeded
- Running transaction
- Installing : apr-1.4.8-3.el7_4.1.x86_64 1/5
- Installing : apr-util-1.5.2-6.el7.x86_64 2/5
- Installing : httpd-tools-2.4.6-80.el7.centos.x86_64 3/5
- Installing : mailcap-2.1.41-2.el7.noarch 4/5
- Installing : httpd-2.4.6-80.el7.centos.x86_64 5/5
- Verifying : httpd-tools-2.4.6-80.el7.centos.x86_64 1/5
- Verifying : apr-1.4.8-3.el7_4.1.x86_64 2/5
- Verifying : mailcap-2.1.41-2.el7.noarch 3/5
- Verifying : httpd-2.4.6-80.el7.centos.x86_64 4/5
- Verifying : apr-util-1.5.2-6.el7.x86_64 5/5
- Installed:
- httpd.x86_64 0:2.4.6-80.el7.centos
- Dependency Installed:
- 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
- Complete!
就是這個feel,爽爽爽。
到此地,關於nexus3所支持的私服類型,基本上生產中常用的,都一一介紹過了,到目前為止,我也沒有在網上看到過任何一個寫,針對nexus寫一個系列的教程並分享出來的,啥也不說了,鄉親們吶,我心情激動,我驕傲!