一、實驗背景
? 在生產(chǎn)環(huán)境中,我們不可能所有的服務(wù)器都能連接外網(wǎng)更新rpm包,比較理想的環(huán)境是:有一臺Linux服務(wù)器可以連接外網(wǎng),剩余的服務(wù)器通過這臺yum服務(wù)器更新。
傳統(tǒng)的做法是先把包下載到內(nèi)網(wǎng)中的yum服務(wù)器上,然后通過createrepo命令生成本地倉庫,其余服務(wù)器通過HTTP/FTP訪問這個鏈接,這種做法比較費時費事。有沒有一種比較好的方式,讓我們直接通過這臺服務(wù)器代理連接到公網(wǎng)的163、阿里云yum倉庫呢?
這就是本次介紹的Nexus代理,無論你的客戶機(jī)是CentOS6還是CentOS7又或者是Ubuntu,不論你是想用yum還是pip又或者是npm包管理器,Nexus都能滿足你的需求。
你只需要將nexus放到能連外網(wǎng)的服務(wù)器上,通過nexus暴露服務(wù)就可以了。
二、實驗環(huán)境
操作系統(tǒng):CentOS7.5 Minimal
nexusServer: 192.168.1.107
yumClient:192.168.1.103
三、安裝nexus,創(chuàng)建yum私有倉庫
在nexusServer服務(wù)器
關(guān)閉selinux
# setenforce 0
# sed? -i? 's/^SELINUX=.*/SELINUX=permissive/g'? /etc/selinux/config
安裝docker
# yum -y install? yum-utils device-mapper-persistent-data lvm2
# yum-config-manager? --add-repo? ? https://download.docker.com/linux/centos/docker-ce.repo
# yum list docker-ce? --showduplicates | sort? -r

#? yum -y install docker-ce-18.06.0.ce?
# systemctl? start docker
# systemctl? status docker
# systemctl? enable? docker
# docker version


拉取鏡像,運行nexus服務(wù)
在nexusServer 服務(wù)器
# docker pull sonatype/nexus3:3.16.0
# docker images

#? mkdir /opt/nexus-data
# chown -R? 200 /opt/nexus-data
注:容器中nexus的默認(rèn)運行用戶是nexus,uid和gid為200
用命令行形式運行nexus容器
#? docker run -d? \
? --name nexus \
? --ulimit nofile=65536:65536 \
? -p 192.168.1.106:8081:8081 \
? -v /opt/nexus-data:/nexus-data \
? sonatype/nexus3:3.16.0

# docker logs? -f? nexus

# docker? ps? -a
# ss? -tan

瀏覽器訪問: http:192.168.1.107:8081


默認(rèn)登錄用戶名密碼:admin/admin123


創(chuàng)建yum私有倉庫
yum私服有三種類:

創(chuàng)建blob存儲,為其創(chuàng)建一個單獨的存儲空間,命名為yum


創(chuàng)建hosted類型的yum庫
Name::定義一個名稱yumDev
Storage:Blob store,我們下拉選擇前面創(chuàng)建好的專用blob:yum。
Hosted:開發(fā)環(huán)境,我們運行重復(fù)發(fā)布,因此Delpoyment policy 我們選擇Allow redeploy




創(chuàng)建一個proxy類型的yum倉庫
Name: yumProxy
Proxy:Remote Storage: 遠(yuǎn)程倉庫地址,寫: http://mirrors.163.com/centos
Storage: yum
其他設(shè)置,使用均是默認(rèn)。
這里就先創(chuàng)建一個代理163的倉庫,其實還可以多創(chuàng)建幾個,諸如阿里云,搜狐等等,這個根據(jù)個人需求來定義。



創(chuàng)建一個group類型的yum倉庫
Name:yumGroup
Storage:選擇專用的blob存儲yum
group : 將左邊可選的2個倉庫,添加到右邊的members


可以創(chuàng)建多個prxoy類型的yum倉庫,通過同一個group暴露給客戶端使用

構(gòu)建yum緩存
新建一臺環(huán)境干凈的主機(jī),此時需要保證這臺主機(jī)能夠上網(wǎng),因為私服當(dāng)中還沒有進(jìn)行初始化。
先簡單配置一下,將yum源指向到私服中來。
#? cd /etc/yum.repos.d
# mkdir repoBackup
# mv *.repo? repoBackup
# vim nexus.repo
####################################################################
[nexus]
name=Nexus Yum Repository
baseurl=http://192.168.1.107:8081/repository/yumGroup/$releasever/os/$basearch/
enabled=1
gpgcheck=0
#######################################################################


#? yum clean all
#? yum? makecache

現(xiàn)在,我們可以從頁面上看緩存包了



服務(wù)端啟動方式改進(jìn),將nexus注冊成系統(tǒng)服務(wù)
編寫unit文件
# vim /etc/systemd/system/nexus.service
####################################################
[Unit]
Description=Nexus
Documentation=https://www.sonatype.com
After=network-online.target firewalld.service docker.service
Requires=docker.service
[Service]
ExecStartPre=-/usr/bin/docker rm -f nexus
ExecStart=/usr/bin/docker run \
--name nexus \
--ulimit nofile=65536:65536 \
-p 192.168.1.107:8081:8081 \
-v /opt/nexus-data:/nexus-data \
sonatype/nexus3:3.16.0
ExecStop=/usr/bin/docker stop nexus
LimitNOFILE=65535
Restart=on-failure
StartLimitBurst=3
StartLimitInterval=60s
[Install]
WantedBy=multi-user.target
#####################################################

停止和刪除命令行啟動的nexus服務(wù)
# docker stop nexus
# docker rm nexus
用systemd啟動服務(wù)
# systemctl daemon-reload
#? systemctl start? nexus
#? systemctl enable nexus
#? systemctl status nexus

# docker logs? -f nexus

四、測試nexus的yum私服
在yumClient服務(wù)器
用一臺不能上網(wǎng)但是可以與剛剛私服通信的主機(jī),將其yum源指向的配置好的私服,或者是將其他的源都切斷,然后yum源僅僅指向私服,看看安裝是否順利。
#? cd /etc/yum.repos.d
# mkdir repoBackup
# mv *.repo? repoBackup
# vim nexus.repo
####################################################################
[nexus]
name=Nexus Yum Repository
baseurl=http://192.168.1.107:8081/repository/yumGroup//$releasever/os/$basearch/
enabled=1
gpgcheck=0
#######################################################################

#? yum clean all
# yumrepolist?
#? yum? -y? install? httpd


五、參考
nexus3搭建yum源
https://blog.51cto.com/daibaiyang119/2116205
http://limingming.org/index.php/2018/12/nexus3-yum-repo
企業(yè)級開源倉庫nexus3實戰(zhàn)應(yīng)用
http://www.eryajf.net/category/%E6%9C%AF%E4%B8%9A%E4%B8%93%E6%94%BB/%E6%9C%8D%E5%8A%A1%E7%B1%BB%E7%9B%B8%E5%85%B3/nexus
Nexus OSS配置yum代理
https://qgdlsj.com/nexus-oss-yum-proxy
Nexus Repository Manager 3.5: Yum Proxy Support Now Available
https://blog.sonatype.com/nexus-repository-manager-3.5
Nexus System Requirements
https://help.sonatype.com/repomanager3/system-requirements
國內(nèi)yum源列表記錄
http://limingming.org/index.php/2018/12/yum-repo-china
用nexus3.x 官方鏡像搭建docker私有鏡像倉庫
http://www.itdecent.cn/p/86e573f18df3