Maven私有库的安装,私有库和本地库配置(Sonatype Nexus + Maven)(五)

持续集成之 nexus 私有库安装与配置
maven 本地库配置连接 nexus 私有库

1、下载最新版 Nexus

1
# wget http://tt123-1251278568.cossh.myqcloud.com/software/nexus-2.14.8-01-bundle.tar.gz

2、解压

1
2
3
4
# mkdir nexus
# tar -zxvf nexus-2.14.8-01-bundle.tar.gz -C nexus
# cd nexus
# ls

控制台输出:

1
2
nexus-2.14.8-01:nexus服务
sonatype-work:私有库目录

3、编辑 Nexusnexus.properties 文件,配置端口和 nexus-work 目录信息(保留默认)

1
2
# cd nexus-2.14.8-01/conf/
# vi nexus.properties

控制台输出:

1
2
3
4
5
6
7
8
9
# Jetty section
application-port=8081
application-host=0.0.0.0
nexus-webapp=${bundleBasedir}/nexus
nexus-webapp-context-path=/nexus

# Nexus section
nexus-work=${bundleBasedir}/../sonatype-work/nexus
runtime=${bundleBasedir}/nexus/WEB-INF

4、编辑 nexus 脚本,配置 RUN_AS_USER
#RUN_AS_USER=
改为
#RUN_AS_USER=root
环境变量中配置 export RUN_AS_USER=root

1
# vi /etc/profile

加入

1
2
#set nexus
export RUN_AS_USER=root

5、防火墙开启8081端口

1
2
# firewall-cmd --add-port=8081/tcp --permanent
# firewall-cmd --reload

6、启动 nexus 服务

1
# /root/nexus/nexus-2.14.8-01/bin/nexus start

7、设置开机启动

1
# vi /etc/rc.d/rc.local

添加:

1
2
# nexus:8081 开机启动
/root/nexus/nexus-2.14.8-01/bin/nexus start

修改如下:

1
2
3
4
5
6
7
8
9
10
11
12
touch /var/lock/subsys/local

export JAVA_HOME=/root/jdk1.8.0_74

# base-tomcat:8080 开机启动
/root/base-tomcat/bin/startup.sh

# svnadmin-tomcat:9000 开机启动
/root/svnadmin-tomcat/bin/startup.sh

# nexus:8081 开机启动
/root/nexus/nexus-2.14.8-01/bin/nexus start

开机启动报异常:wrapper | Unable to start JVM: No such file or directory (2)
修改 /root/nexus/nexus-2.14.8-01/bin/jsw/conf/wrapper.conf

1
# vi /root/nexus/nexus-2.14.8-01/bin/jsw/conf/wrapper.conf

修改如下:

1
2
3
4
5
6
#开机启动没有环境变量,改为绝对路径  
#原本
#wrapper.java.command=java

#改为
wrapper.java.command=/root/jdk1.8.0_74/bin/java

8、浏览器访问 http://localhost:8081/nexus/

9、登陆,默认用户 admin 密码 admin123

nexus登陆后界面

10、Administrator –> server 配置邮箱服务地址,方便通过邮箱找回密码

配置SMTP服务

11、测试邮箱能否发送

测试发送邮件

12、给用户设置邮箱,方便找回密码

用户设置邮箱

13、仓库类型

Repositories 界面

  • group 仓库组:Nexus 通过仓库组的概念统一管理多个仓库,这样我们在项目中直接请求仓库组即可请求到仓库组管理的多个仓库;
  • hosted 宿主仓库:主要用于发布内部项目构件或第三方的项目构件(如购买商业的构件) 以及无法从公共仓库获取的构件(如 oracle 的 JDBC 驱动)
    • releases 内部的模块中 RELEASES 模块的发布仓库
    • snapshots 发布内部的 SNAPSHOT 模块的仓库
    • 3rd party 第三方依赖的仓库,这个数据通常是由内部人员自行下载之后发布上去
  • proxy 代理仓库:代理公共的远程仓库;
  • virtual 虚拟仓库:用于适配 Maven 1
  • 一般用到的仓库种类是 hostedproxy

==如果构建的 Maven 项目本地仓库没有对应的依赖包,那么就会去 Nexus 私服去下载, 如果Nexus私服也没有此依赖包,就回去远程中央仓库下载依赖,这些中央仓库就是proxy。
Nexus 私服下载成功后再下载至本地 Maven 库供项目引用。==

14、设置 proxy 代理仓库(Apache Snapshots/Central/Codehaus Snapshots)准许远程下载

开启远程索引下载

15、配置本地 maven 配置文件:settings-nexus.xml

16、idea 项目中 pom.xml 文件修改,添加以下内容

1
2
3
4
5
6
7
8
9
10
11
12
13
<!-- 配置远程发布到私服 -->
<distributionManagement>
<repository>
<id>nexus-releases</id>
<name>Nesux Releases Repository</name>
<url>http://120.27.225.66:8081/nexus/content/repositories/releases/</url>
</repository>
<snapshotRepository>
<id>nexus-snapshots</id>
<name>Nesux Snapshots Repository</name>
<url>http://120.27.225.66:8081/nexus/content/repositories/snapshots/</url>
</snapshotRepository>
</distributionManagement>

17、发布到私有库 Run –> Configurations –> + –> Maven

创建运行配置,必须按此步骤,否则报权限不足错误

运行,部署到 nexus 私服