环境信息
centos7.2
安装目录
Nexus下载与安装
1. 安装前工作
下载与安装
下载
wget "https://sonatype-download.global.ssl.fastly.net/nexus/oss/nexus-2.14.3-02-bundle.tar.gz"
解压
[root@kunzai installPath]# tar -zxvf nexus-2.14.3-02-bundle.tar.gz
移动并且改名
[root@kunzai installPath]# mv nexus-2.14.3-02 ./../nexus-2.14.3
进入解压的文件并查看位置
[root@kunzai nexus-2.14.3]# pwd
/usr/local/java/nexus-2.14.3
基础的命令说明
进入bin目录执行以下命令
启动
[root@kunzai bin]# ./nexus start
关闭
[root@kunzai bin]# ./nexus stop
重启
[root@kunzai bin]# ./nexus restart
启动出现的问题
[root@kunzai bin]# ./nexus start
****************************************
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用户运行Nexus,可以修改bin/nexus中的配置跳过警告(修改RUN_AS_USER=root)
解决方案:
vi nexus
# NOTE - This will set the user which is used to run the Wrapper as well as
# the JVM and is not useful in situations where a privileged resource or
# port needs to be allocated prior to the user being changed.
#RUN_AS_USER=
修改为
# NOTE - This will set the user which is used to run the Wrapper as well as
# the JVM and is not useful in situations where a privileged resource or
# port needs to be allocated prior to the user being changed.
RUN_AS_USER=root
重新启动
修改端口
注:Nexus默认端口8081,如果想修改端口。修改/conf/nexus.properties文件
访问信息
端口默认为8081
http://ip:port/nexus/
账号-密码(默认)
admin/admin123
修改配置
1: 点击views/Repositories下面的Repositories,将列表中所有Type为proxy 的项目的 Configuration 中的 Download Remote Indexes 设置为True
2: 将Releases仓库项目中 Configuration的Deployment Policy设置为 Allow ReDeploy
3: 当然我们也避免不了会使用到一些第三方的 jar ,而这些jar包也不存在于互联网上的maven中央仓库中,这时我们可以手工添加jar 到我们的私服中。
添加第三方 jar 如下:
①:选择仓库-3rd party然后选择其下面的artifact upload选项,然后可以进行上传。
②:填写完必选字段,点击Upload Artifact(s)按钮即可
配置本地项目引用私服
自动发布构件到远程仓库,在工程pom.xml中添加(就是发布到中央仓库中)
<distributionManagement>
<repository>
<id>releases</id><!--这个ID需要与你的release仓库的Repository ID一致-->
<url>http://ip:port/nexus/content/repositories/releases</url>
</repository>
<snapshotRepository>
<id>snapshots</id><!--这个ID需要与你的snapshots仓库的Repository ID一致-->
<url>http://ip:port/nexus/content/repositories/snapshots</url>
</snapshotRepository>
</distributionManagement>
修改本地$MAVEN_HOME\conf目录下的settings.xml配置文件,添加如下配置(发布时候用到的账号密码)
可以有多个server项
<servers>
<server>
<!--这个要与distributionManagement中的repository的id相同(其实就是这个ID需要与你的release仓库的Repository ID一致),-->
<id>releases</id>
<username>xxx</username>
<password>xxxxx</password>
</server>
<server>
<!--这个要与distributionManagement中的repository的id相同(其实就是这个ID需要与你的release仓库的Repository ID一致),-->
<id>snapshots</id>
<username>xxx</username>
<password>xxxxx</password>
</server>
</servers>
在本地工程目录下执行以下命令进行发布
mvn deploy
配置Maven从Nexus下载构件
在POM中配置Nexus私服,这样的配置只对当前的Maven项目有效。
在settings.xml中配置profile元素,这样就能让本机所有的Maven项目都使用自己的Maven私服。
可以有多个profile项
<profiles>
<profile>
<!--这个无所谓,可以自定义,下面activeProfile选项可以激活此id-->
<id>nexus</id>
<repositories>
<repository>
<!--这个要与servlet上的id一致(其实就是这个ID需要与你的release仓库的Repository ID一致),-->
<id>snapshots</id>
<url>http://ip:port/nexus/content/groups/public/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
<!--指定Nexus的插件仓库-->
<pluginRepositories>
<pluginRepository>
<id>snapshots</id>
<url>http://ip:8081/nexus/content/groups/public/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>
</profile>
</profiles>
激活默认配置(settings.xml)
最下面激活要使用的项
<activeProfiles>
<activeProfile>nexus</activeProfile>
<activeProfile>aliyun</activeProfile>
</activeProfiles>
可以新增几个代理等仓库地址
点击新增仓库,选择proxy
①:新增1:aliyun
地址:http://maven.aliyun.com/nexus/content/groups/public
其他的默认即可
②:新增2:apache_release
地址:https://repository.apache.org/content/repositories/releases/
其他的默认即可
③:新增3:apache_snapshot
地址:https://repository.apache.org/content/repositories/snapshots/
其他的默认即可