在生產環境中,咱們總會遇到下載或更新rpm包的操做,可是每每咱們不可能全部的服務器都能鏈接外網(特別是一些zf單位)。因此理想的狀況下就是咱們有一臺linux服務器能夠連外網,其他的服務器經過它作代理來更新rpm包。java
有一些比較傳統的方法是把包下載到本地,經過createrepo命令生成本地倉庫,其他的服務器經過ftp/http的方式來訪問,可是有時候咱們會須要一些拓展的包,因此有沒有一種比較方便的方式讓咱們能夠代理到阿里或者163的yum源呢。linux
下面咱們就講一下使用Nexus代理,無論是你是centos6,centos7或者ubuntu,也無論你是rpm仍是pip或是yum,Nexus均可以知足你的需求。apache
安裝:ubuntu
操做系統:centos7centos
[root@yangdong ~]# cat /etc/redhat-release CentOS Linux release 7.2.1511 (Core)
nexusServer: 192.168.105.233緩存
安裝前的準備: 關閉selinux,安裝jdk,安裝maven服務器
# sed -i 's/^SELINUX=.*/SELINUX=permissive/g' /etc/selinux/configcurl
# java -version
java version "1.8.0_151"
Java(TM) SE Runtime Environment (build 1.8.0_151-b12)
Java HotSpot(TM) 64-Bit Server VM (build 25.151-b12, mixed mode)maven
# mvn -v
Apache Maven 3.6.1 (d66c9c0b3152b2e69ee9bac180bb8fcc8e6af555; 2019-04-05T03:00:29+08:00)
Maven home: /opt/apache-maven-3.6.1
Java version: 1.8.0_151, vendor: Oracle Corporation, runtime: /opt/jdk1.8.0_151/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "3.10.0-327.el7.x86_64", arch: "amd64", family: "unix"ui
環境配置:
export JAVA_HOME=/opt/jdk1.8.0_151 export PATH=$PATH:$JAVA_HOME/bin export PATH=$PATH:/opt/apache-maven-3.6.1/bin export MAVEN_HOME=/opt/apache-maven-3.6.1 export RUN_AS_USER=root
安裝包地址:
https://www.sonatype.com/nexus-repository-oss
百度網盤:
連接:https://pan.baidu.com/s/1v77nB57eiYOQxI5ZBvv87w
提取碼:cz79
安裝Nexus:
[root@yangdong opt]# tar xf latest-unix.tar.gz #會生成 nexus-3.18.1-01 sonatype-work兩個目錄 [root@yangdong opt]# ls apache-maven-3.6.1 jdk1.8.0_151 latest-unix.tar.gz sonatype-work apache-maven-3.6.1-bin.tar.gz jdk-8u151-linux-x64.tar.gz nexus-3.18.1-01
啓動Nexus:
[root@yangdong opt]# cd nexus-3.18.1-01/bin/ [root@yangdong bin]# ./nexus start WARNING: ************************************************************ WARNING: Detected execution as "root" user. This is NOT recommended! WARNING: ************************************************************ Starting nexus
[root@yangdong nexus-3.18.1-01]# ./bin/nexus status
WARNING: ************************************************************
WARNING: Detected execution as "root" user. This is NOT recommended!
WARNING: ************************************************************
nexus is running.
配置Nexus:
訪問地址:http://192.168.105.233:8081
初始用戶:admin 密碼:cat /opt/sonatype-work/nexus3/admin.password
創建倉庫:
這個時候咱們就已經部署好了,只須要在客戶端配置repo文件就能夠了。
#yum clean all #yum makecache [root@yangdong ~]# cd /etc/yum.repos.d/ [root@yangdong yum.repos.d]# ls nexus.repo repot [root@yangdong yum.repos.d]# cat nexus.repo [nexus] name=Nexus Yum Repository baseurl=http://192.168.105.233:8081/repository/yumGroup/$releasever/os/$basearch/ enabled=1 gpgcheck=0
這個時候你可能會報錯:
[root@yangdong yum.repos.d]# yum makecache Loaded plugins: fastestmirror Determining fastest mirrors http://192.168.105.233:8081/repository/yumGroup/7/os/x86_64/repodata/repomd.xml: [Errno 14] HTTP Error 401 - Unauthorized Trying other mirror.
是由於你是匿名用戶訪問Nexus,所以認證不經過。須要打開匿名用戶的權限。
這時候咱們下載一個包試試:
[root@yangdong yum.repos.d]# yum repolist Loaded plugins: fastestmirror Loading mirror speeds from cached hostfile repo id repo name status nexus/7/x86_64 Nexus Yum Repository 10,019 repolist: 10,019 [root@yangdong yum.repos.d]# yum -y install httpd Loaded plugins: fastestmirror Loading mirror speeds from cached hostfile Resolving Dependencies --> Running transaction check ---> Package httpd.x86_64 0:2.4.6-88.el7.centos will be installed --> Processing Dependency: httpd-tools = 2.4.6-88.el7.centos for package: httpd-2.4.6-88.el7.centos.x86_64 --> Processing Dependency: /etc/mime.types for package: httpd-2.4.6-88.el7.centos.x86_64 --> Running transaction check ---> Package httpd-tools.x86_64 0:2.4.6-88.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-88.el7.centos nexus 2.7 M Installing for dependencies: httpd-tools x86_64 2.4.6-88.el7.centos nexus 90 k mailcap noarch 2.1.41-2.el7 nexus 31 k Transaction Summary ======================================================================================================================================================================= Install 1 Package (+2 Dependent packages) Total download size: 2.8 M Installed size: 9.6 M Downloading packages: (1/3): httpd-tools-2.4.6-88.el7.centos.x86_64.rpm | 90 kB 00:00:00 (2/3): mailcap-2.1.41-2.el7.noarch.rpm | 31 kB 00:00:00 (3/3): httpd-2.4.6-88.el7.centos.x86_64.rpm | 2.7 MB 00:00:00 ----------------------------------------------------------------------------------------------------------------------------------------------------------------------- Total 2.7 MB/s | 2.8 MB 00:00:01 Running transaction check Running transaction test Transaction test succeeded Running transaction Installing : mailcap-2.1.41-2.el7.noarch 1/3 Installing : httpd-tools-2.4.6-88.el7.centos.x86_64 2/3 Installing : httpd-2.4.6-88.el7.centos.x86_64 3/3 Verifying : httpd-tools-2.4.6-88.el7.centos.x86_64 1/3 Verifying : mailcap-2.1.41-2.el7.noarch 2/3 Verifying : httpd-2.4.6-88.el7.centos.x86_64 3/3 Installed: httpd.x86_64 0:2.4.6-88.el7.centos Dependency Installed: httpd-tools.x86_64 0:2.4.6-88.el7.centos mailcap.noarch 0:2.1.41-2.el7 Complete!
能夠看到咱們的倉庫已經識別到了Nexus,同時咱們下載了httpd的包。這時候咱們去Nexus上看下是否緩存了。
能夠看到咱們的Nexus已經緩存到了本地,下載在有客戶端如今httpd就能夠直接從Nexus獲取了。
同時,Nexus也可作maven的緩存,這個後期有須要的時候會繼續更新!
#批量上傳本地的rpm包:
for i in `ls /var/centos6`; do curl -v --user 'admin:admin123' --upload-file $i http://192.168.105.233:8081/repository/yumDev/$i; done