原文:https://yq.aliyun.com/articles/5981

第8章 私服nexus

本章详细介绍了nexus的安装过程,设置maven从私服下载构件,以及发布构件至nexus。

8.1 什么是nexus

nexus是一个web版的仓库管理软件

8.2 nexus安装

nexus安装非常简单。
下载地址:http://www.sonatype.org/nexus/go

本文以Linux环境为例,安装nexus:
1. 首先在/usr/local下建nexus目录
2. 将下载的zip包解压,将其中的nexus-2.11.4-01解压至nexus如图:

  1. 进入bin目录,将nexus设置为可执行权限:

cd bin

chmod +x nexus

  1. 设置root可执行nexus
    默认的nexus是不让root用户直接启动的,会报出如下错误

    `WARNING - NOT RECOMMENDED TO RUN AS ROOT`
    `If you insist running as root, then set the environment variable RUN_AS_USER=root before running this script.`

需要设置root执行权限
export set RUN_AS_USER=root
此语句仅临时设置root变量,重启linux后会无效,如需持久设置,需要修改环境变量,见以下步骤。

  1. 此时执行./nexus start即可启动nexus。

  1. 停止nexus

./nexus stop

  1. 配置环境变量,设置开机启动

    • 设置环境变量:

vim /etc/profile

在最后一行添加export set RUN_AS_USER=root

  • 设置开机启动
    进入到配置目录:

cd /etc/init.d

复制脚本cp /usr/local/nexus/bin/nexus nexus

添加系统服务:chkconfig --add nexus

设置启动级别为345:chkconfig --levels 345 nexus on

查看是否添加成功:chkconfig --list|grep nexus,如图

  • 修改脚本

vim /etc/init.d/nexus

第一行添加:
RUN_AS_USER="root"

然后,将NEXUS_HOME=".."修改为NEXUS_HOME="/usr/local/nexus"

如图:

  • 重启Linux
    reboot
  • 访问地址:http://<LinuxIP>:8081/nexus/#welcome

注意:重启Linux需要一段时间,不断刷新此地址即可。

查看nexus是否启动,`ps –ef|grep nexus`。

![Alt text](https://img.alicdn.com/imgextra/i2/653726111/TB2Kpa_hXXXXXXRXFXXXXXXXXXX_!!653726111.png)

8.3 nexus仓库设置

8.3.1 登录系统,修改密码

nexus默认的管理员密码是admin/admin123,为了安全起见,第一件事就是上来修改管理员密码。

8.3.2 nexus内置仓库介绍

1、 仓库类型介绍

仓库类型 介绍
group 仓库组
hosted 宿主仓库
proxy 代理仓库
virtual 虚拟仓库

2、 仓库介绍

仓库 介绍
3rd party 这是一个策略为Releases的宿主仓库,用来部署无法从公共仓库获得的第三方发布版本构件
Apache Snapshots 这是一个策略为Snapshots的代理仓库,用来代理ApacheMaven仓库的快照版本构件
Central 这是一个策略为Releases的代理仓库,用来代理maven中央仓库中发布的版本构件
Central M1 shadow 这是一个策略为Releases的虚拟仓库,用来提供中央仓库中M1格式的发布版本的构件
Codehaus Snapshots 这是一个策略为Snapshots的代理仓库,用来代理Codehaus Snapshots仓库的快照版本构件的仓库
Releases 这是一个策略为Releases的宿主仓库,用来部署管理内部的发布版本构件
Snapshots 这是一个策略为Snapshots的宿主仓库,用来部署管理内部的快照版本构件

8.3.3 索引

  • 开启远程索引
    一个新搭建的nexus,是一个空的仓库,nexus默认是关闭远程索引下载,打开步骤如图:

    注意:3个proxy类型的远程索引都需要打开

    然后在3个proxy类型的仓库上,点击右键,Repair Index,nexus就会去下载远程的索引文件。

    测试

    在Browse Remote 中搜索任意jar

8.3.4 创建宿主仓库

8.3.5 仓库组设置

  • 什么是仓库组?

仓库组是将多个仓库聚合成一个仓库地址,为maven提供服务。maven配置中,只需要配置仓库组的链接,即可同时得到多个仓库的构件。
仓库组中仓库的顺序决定了仓库组遍历其所含仓库的次序,所以应该将常用的仓库放在前面。

仓库组设置很简单:
点击type为group类型的仓库,configuration标签页中Ordered Group Repositories为当前组包含仓库,available repositories为可继续添加的仓库。

8.4 配置maven从私服下载构件

前面安装了nexus,目的就是让开发人员的maven链接私服下载构件。

修改maven配置文件setting.xml

找到profiles标签,设置代码:

<profiles>
<profile>
<id>nexus</id>
<repositories>
<repository>
<id>nexus</id>
<name>crop-nexus</name>
<url>http://你的NexusIP:8081/nexus/content/groups/public/</url>
<releases>
<!-- true表示开启仓库发布版本下载,false表示禁止 -->
<enabled>true</enabled> </releases>
<snapshots>
<!-- true表示开启仓库快照版本下载,false表示禁止 -->
<enabled>true</enabled> </snapshots>
</repository>
</repositories> <pluginRepositories>
<pluginRepository>
<id>nexus</id>
<url> http://你的NexusIP:8081/nexus/content/groups/public/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<!-- 禁止快照版本,防止不稳定的插件影响项目构建 -->
<enabled>false</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>
</profile>
</profiles>
<!-- 激活nexus私服 -->
<activeProfiles>
<activeProfile>nexus</activeProfile>
</activeProfiles>

这样配置,maven就可以从私服下载构件了,但是会有个问题,他还会时不时的请求中央仓库,如果想完全让maven访问nexus私服,需要设置镜像mirrors来支持。

8.5 maven的镜像配置

maven配置镜像后,所有的构件都只会从镜像服务器下载。

<mirrors>
<mirror>
<id>nexus</id>
<mirrorOf>*</mirrorOf>
<name>crop-nexus</name>
<url>http://你的nexusIP:8081/nexus/content/groups/public/</url>
</mirror>
</mirrors>

8.6 发布构件至nexus

8.6.1 配置distributionManagement

发布仓库一般分为Releases版和snapshot版,所以要配置2个仓库地址
注意:这个是在项目的pom.xml中配置的

<!-- 发布构件至私服nexus -->
<distributionManagement>
<repository>
<id>nexus-releases</id>
<name>corp nexus-releases</name>
<url>http://你的nexusIP:8081/nexus/content/repositories/releases/</url>
</repository>
<snapshotRepository>
<id>nexus-snapshot</id>
<name>corp nexus-snapshot</name>
<url>http://你的nexusIP:8081/nexus/content/repositories/snapshots/</url>
</snapshotRepository>
</distributionManagement>

8.6.2 设置用户

配置好pom.xml后,需要指定发布用户,在setting.xml中设置:


<servers> <!-- 发布Releases版的账号,ID要与distributionManagement中的Releases ID一致 -->
<server>
<id>nexus-releases</id>
<username>admin</username>
<password>******</password>
</server>
<!-- 发布snapshot版的账号,ID要与distributionManagement中的snapshot ID一致 -->
<server>
<id>nexus-snapshot</id>
<username>admin</username>
<password>******</password>
</server> </servers>

设置完成,使用命令发布至nexus

mvn deploy

在nexus中查看

Linux 搭建 nexus 私服【转】的更多相关文章

  1. linux 搭建 nexus 私服及配置

    安装篇 1.tar -zxvf nexus-latest-bundle.tar.gz 2.cd nexus-2.13.0-01/bin 3../nexus start 这时可能提示 ********* ...

  2. Linux安装配置maven以及搭建nexus私服(编写启动脚本)

    2011年07月12日16:32  下面介绍在Linux操作系统下安装配置maven和搭建nexus私服. 一.安装前的准备 下载 jdk http://www.oracle.com/technetw ...

  3. Linux 安装配置maven3.0 以及搭建nexus私服

    http://carvin.iteye.com/blog/785365 一.软件准备 1.apache-maven-3.0-bin.tar.gz 下载地址:http://www.apache.org/ ...

  4. Linux 搭建Nexus

    Linux 安装Maven和nexus代理仓库 1    说明 环境:redhat Enterprise Linux Server5.3-x64. 版本:Maven 3.0.5 ,Nexus-2.5. ...

  5. Linux_Centos中搭建nexus私服

    1.在Linux下搭建Nexus私服 1).下载并且解压      下载  nexus-2.11.2-03-bundle.zip      unzip nexus-2.11.2-03-bundle.z ...

  6. 搭建nexus私服,无法下载相关jar包,报错Repository proxy-mode is BLOCKED_AUTO

    在搭建nexus私服的时候,之前没直接用来下载maven的相关插件jar包,一直可以使用, 结果今天要编译hadoop的时候,在linux上新用maven就报错了,无法下载maven的相关插件(如下) ...

  7. 搭建nexus私服(maven)

    这里提供nexus的直接下载页面的链接: https://www.sonatype.com/download-oss-sonatype maven获取依赖jar包是从中央仓库获取,但很莫名的出现jar ...

  8. Linux搭建Nexus仓库+高可用方案

    Linux搭建nexus仓库 1.安装jdk 1.1 获取安装包,解压到指定目录: tar xf jdk.tar.gz -C /opt/export 1.2 配置环境变量: # vim /etc/pr ...

  9. 搭建nexus私服

    一.安装 1.从网上下载nexus软件https://www.sonatype.com/download-oss-sonatype  下载Nexus Repository Manager OSS软件包 ...

随机推荐

  1. day31 configparser 配置文件模块

    #__author__: Administrator #__date__: 2018/8/8 # configparse 生成配置文件,配置文会以件.ini结尾 # 对于格式有要求 # 创建配置文档 ...

  2. get改post

    //原模式,get 入参只能小于260字符 location.href = hrefStr; localhost/getinfo/UUSDDJSKDJSJKJK 后台 getinfo(string i ...

  3. 【 Gym - 101138J 】Valentina and the Gift Tree(树链剖分)

    BUPT2017 wintertraining(15) 4 D Gym - 101138J 数据 题意 n个节点的一棵树,每个节点的权值为g,q个询问,树上的节点U-V,求U到V的路径的最大子段和. ...

  4. 洛谷 P1613 跑路 解题报告

    P1613 跑路 题目描述 小\(A\)的工作不仅繁琐,更有苛刻的规定,要求小\(A\)每天早上在\(6:00\)之前到达公司,否则这个月工资清零.可是小\(A\)偏偏又有赖床的坏毛病.于是为了保住自 ...

  5. py3+requests+re+urllib,爬取并下载不得姐视频

    实现原理及思路请参考我的另外几篇爬虫实践博客 py3+urllib+bs4+反爬,20+行代码教你爬取豆瓣妹子图:http://www.cnblogs.com/UncleYong/p/6892688. ...

  6. MySQL基本命令行

    登陆:mysql –h localhost –u 用户名 –p mysql –u 用户名 –p   (默认连接localhost服务器) 服务器中可以有多个库,库中可以有多个表.数据库的名字无法修改 ...

  7. 线程的加入.join()

    格式:以加入A线程为例 线程对象B.join()   无参数,则A线程一直暂停,直到B线程运行结束. 线程对象B.join(时间t)   有参数,则A线程每隔t时间暂停一次,直到B线程运行结束. 关于 ...

  8. LVS+Keepalived实现MySQL从库读操作负载均衡配置

    转载于osyunwei 说明: 操作系统:CentOS 5.X 64位 MySQL主服务器:192.168.21.126 MySQL从服务器:192.168.21.127,192.168.21.128 ...

  9. 理解 PHP 依赖注入

    Laravel框架的依赖注入确实很强大,并且通过容器实现依赖注入可以有选择性的加载需要的服务,减少初始化框架的开销,下面是我在网上看到的一个帖子,写的很好拿来与大家分享,文章从开始按照传统的类设计数据 ...

  10. 过时date.toLocaleString()的解决方法

    System.out.println(new java.util.Date()); 输出:Thu Jan 27 14:43:28 CST 2011 System.out.println(new jav ...