Nexus部署本地yum源

在生产环境中,咱们总会遇到下载或更新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

 

 

 

 

参考:https://www.jianshu.com/p/0255cd957e15

相关文章
相关标签/搜索