Nexus搭建开发组的私有仓库

转自:cnblogs;https://www.cnblogs.com/fanzhenyong/p/7709434.html

一、私有仓库的价值

  开发Java应用系统,用到Maven、sbt和 Gradle等构建工具,在构建过程中一般需要从互联网下载依赖库,构建私有仓库就是为了在开发组或者部门内共用,从而节省整体的下载成本和构建成本。下面先以Maven为例说明。  

  Maven是一个强大的构建工具,一般用于Java项目。Maven项目基于对象模型(POM),可以通过一小段描述信息来管理项目的构建,报告和文档的软件项目管理工具。Maven 除了以程序构建能力为特色之外,还提供高级项目管理工具。由于 Maven 的缺省构建规则有较高的可重用性,所以常常用两三行 Maven 构建脚本就可以构建简单的项目。

Maven的Java项目一般需要下载第三方组件,下载后构成本地仓库,为了减少网络对构建项目的影响,一般会构建私服仓库,代理第三方库。Nexus就是构建私服仓库的优秀软件。

 

 

三层仓库架构
 

图 1 三层仓库架构

 

二、准备工作

2.1、安装Java编译环境

Java编译环境包括核心的JDK和编译工具,因为Java的编译工具有很多种,而开源项目作者的随意性很高,常用的工具有maven,gradle,sbt,ant等等,本文关注Maven。

因为Oracle不再维护Java1.7,所以采用Java 1.8作为编译核心.

2.1.1、安装

操作系统采用Centos7.4

yum install java-1.8.0-openjdk-devel java-1.8.0-openjdk java-1.8.0-openjdk-headless -y

2.1.2、验证

查看jdk版本号

 

java -version

java version "1.8.0_162"
Java(TM) SE Runtime Environment (build 1.8.0_162-b12)
Java HotSpot(TM) 64-Bit Server VM (build 25.162-b12, mixed mode)

 

2.1.3、设置环境变量

vi /etc/profile

export JAVA_HOME=/ms/java/jdk1.8.0_181
export JRE_HOME=${JAVA_HOME}/jre
export CLASSPATH=.:${JAVA_HOME}/lib:${JRE_HOME}/lib
export PATH=${JAVA_HOME}/bin:$PATH

source /etc/profile

 

三、安装Nexus

3.1、下载nexus

从官方网站现在最新3.X版

https://www.sonatype.com/download-oss-sonatype

下载(2018年3月)最新版nexus-3.9.0-01-unix.tar.gz ()

3.2、部署

以/opt为存储私有仓库的目录为例

cd /opt/scm
tar -xf ~/download/nexus-3.9.0-01-unix.tar.gz -C .

生成两个目录

nexus-3.9.0-01
sonatype-work

3.3、系统服务

3.3.1、编辑系统服务文件

vi /etc/systemd/system/nexus.service

[Unit]
Description=nexus service
After=network.target

[Service]
Type=forking
LimitNOFILE=65536
ExecStart=/opt/scm/nexus-3.9.0-01/bin/nexus start
ExecStop=/opt/scm/nexus-3.9.0-01/bin/nexus stop
User=ansible
Restart=on-abort

[Install]
WantedBy=multi-user.target

3.3.2、设置为自启动服务

sudo systemctl  daemon-reload
sudo systemctl start nexus.service
sudo systemctl status nexus.service
sudo systemctl enable nexus.service

 

四、设置Nexus

4.1、浏览器登录

http://10.0.0.11:8081/

sign in

用户名的密码为:admin admin123

4.2、进入管理界面

 manager 1

 

4.3、增加新的代理源

 manager 2

 

设置名称和URL

 manager 3

 

Cache统一设置为200天 288000

 manager 4

 逐个增加常用代理

1. aliyun
http://maven.aliyun.com/nexus/content/groups/public
2. apache_snapshot
https://repository.apache.org/content/repositories/snapshots/
3. apache_release
https://repository.apache.org/content/repositories/releases/
4. atlassian
https://maven.atlassian.com/content/repositories/atlassian-public/
5. central.maven.org
http://central.maven.org/maven2/
6. datanucleus
http://www.datanucleus.org/downloads/maven2
7. maven-central (安装后自带,仅需设置Cache有效期即可)
https://repo1.maven.org/maven2/
8. nexus.axiomalaska.com
http://nexus.axiomalaska.com/nexus/content/repositories/public
9. oss.sonatype.org
https://oss.sonatype.org/content/repositories/snapshots
10.pentaho
https://public.nexus.pentaho.org/content/groups/omni/
11. spring-snapshots
https://repo.spring.io/snapshot
//在配置这个代理源的时候,Version pollcy 要设置成 Snapshot,Layout pollcy 要设置成 Permissive.
12. spring-milestones
https://repo.spring.io/milestone

 

再次强调,在

How long (in minutes) to cache metadata before rechecking the remote repository.处

统一设置为

288000 即200天,当然可以设置为更长的时间

设置maven-public

将这些代理加入Group

 manager 5

 

4.3、设置私用仓库可重复发布

  Nexus安装后自带maven-releases,maven-snapshots两个仓库,用于将生成的jar包发布在这两个仓库中,在实际开发中需要将maven-releases设置为可以重复发布。

  maven-releases

  manager 6

  注:maven-snapshots缺省是可以重新部署的。

 

五、安装maven并设置私用仓库

5.1、下载安装

从maven官网下载3.5.0 http://maven.apache.org/download.cgi

cd tools
tar -xf ../download/apache-maven-3.5.0-bin.tar.gz –C .

5.2、设置环境变量

vi /etc/profile

export PATH=/home/tools/apache-maven-3.5.0/bin:$PATH

source /etc/profile

 

5.3、测试

mvn -version

Apache Maven 3.5.3 (3383c37e1f9e9b3bc3df5050c29c8aff9f295297; 2018-02-25T03:49:05+08:00)
Maven home: D:\DevTools\apache-maven-3.5.3\bin\..
Java version: 1.8.0_162, vendor: Oracle Corporation
Java home: D:\DevTools\Java\jdk1.8.0_162\jre
Default locale: zh_CN, platform encoding: GBK
OS name: "windows 10", version: "10.0", arch: "amd64", family: "windows"

(暂用windows版本的maven做演示)

5.4、配置

vi /home/tools/apache-maven-3.5.0/conf/settings.xml(本地服务器可以使用localhost,开发组其他服务器则修改为对应Nexus服务器的域名或者IP地址)

<settings>
  <pluginGroups>  
     <pluginGroup>org.sonatype.plugins</pluginGroup>  
  </pluginGroups> 
  <mirrors>
    <mirror>
      <id>nexus</id>
      <mirrorOf>*</mirrorOf>
      <url>http://localhost:8081/repository/maven-public/</url>
    </mirror>
  </mirrors>
  <profiles>
    <profile>
      <id>nexus</id>
      <!--Enable snapshots for the built in central repo to direct -->
      <!--all requests to nexus via the mirror -->
      <repositories>
        <repository>
          <id>central</id>
          <url>http://central</url>
          <releases><enabled>true</enabled></releases>
          <snapshots><enabled>true</enabled></snapshots>
        </repository>
      </repositories>
     <pluginRepositories>
        <pluginRepository>
          <id>central</id>
          <url>http://central</url>
          <releases><enabled>true</enabled></releases>
          <snapshots><enabled>true</enabled></snapshots>
        </pluginRepository>
      </pluginRepositories>
    </profile>
  </profiles>
  <activeProfiles>
    <!--make the profile active all the time -->
    <activeProfile>nexus</activeProfile>
  </activeProfiles>
  <servers>
    <server>
      <id>nexus</id>
      <username>admin</username>
      <password>admin123</password>
    </server>
  </servers>
</settings>
 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值