目录
1. 使用admin账户登录 , 然后点击齿轮(Configuration) > Repositories(仓库)
4. 私有仓库(hosted)不用创建 , 使用原有的 maven-releases 和 maven-snapshots即可
资源下载:评论区留下联系邮箱,阿里网盘暂不支持分享。
注意:安装nexus前,需要安装JDK
1. 安装启动Nexus
1.1 安装
1) 在usr/local目录下创建mysql安装目录:
cd /usr/local
mkdir soft/nexus
2) 将资源放在nexus文件下
3) 解压nexus文件
tar zxvf nexus-3.9.0-01-unix.tar.gz
4) 配置 nexus 环境变量
打开 etc/ 目录下的 profile 文件,命令如下
vim /etc/profile
把 nuxus 环境添加到 profile 尾部,环境代码如下
# nexus
export MAVEN_HOME=/usr/local/soft/nexus/nexus-3.9.0-01
export PATH=$PATH:$MAVEN_HOME/bin
注:/usr/local/nexus/nexus-3.9.0-01 为nexus的安装路径
5) 重新加载配置文件,让配置生效
# 重新加载profile文件,让配置生效
source profile
# 或者,这个命令在任何目录都可以操作
source /etc/profile
1.2 启动 nexus
1) 进入 nexus 根目录下的 bin 目录,启动 nexus 服务
nexus start
2) 更改端口
- nexus 默认端口是 8081 , 如果我们的端口被占用了,则需要重新为 nexus 指定端口,端口的配置文件在安装目录下的 etc 目录
- 进入 etc 目录,找到 nexus-default.properties 文件
- 用 vim 打开 nexus-default.properties 文件
把
# Jetty section
application-port=8081
application-host=0.0.0.0
改为
# Jetty section
application-port=8084
application-host=0.0.0.0
这样我们就把 nexus 的端口从 8081 改为 8084 , 还需要重启 nexus服务
# 重启服务
nexus restart
3) 开启端口
# 开启8084端口
firewall-cmd --zone=public --add-port=8084/tcp --permanent
# 重启
firewall-cmd --reload
默认用户名/密码为 : admin/admin123
1.3 其他命令
# 启动
nexus start
# 停止
nexus stop
# 重启
nexus restart
# 查看状态
nexus status
2. 配置Nexus
1. 使用admin账户登录 , 然后点击齿轮(Configuration) > Repositories(仓库)
仓库有3类 , proxy(代理仓库-也就是别人的仓库) hosted(私有仓库 - 也就是自己的仓库) group(聚合仓库 - 一般引用都是使用这个库)
2. 配置ali的maven镜像,提高速度 (代理库)
阿里rep地址 :
https://maven.aliyun.com/repository/public
1) 点击 Create repository
2) 选择maven2(proxy)
3) 点击 Create repository即可
3. 在group中加入ali镜像
找到maven-public的group仓库 , 点右边的>进入修改
在最下面 Group处 , 把ali的镜像加入
4. 私有仓库(hosted)不用创建 , 使用原有的 maven-releases 和 maven-snapshots即可
3. 配置Maven客户端和pom.xml实现发布
1. 配置setting.xml
<?xml version="1.0" encoding="UTF-8"?>
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
<!-- 配置本地jar包存放路径 -->
<localRepository>D:/repository</localRepository>
<pluginGroups></pluginGroups>
<proxies></proxies>
<servers>
<!-- 配置从nexus私服下载jar包所需要的账号密码 -->
<server>
<id>nexus</id>
<username>admin</username>
<password>admin123</password>
</server>
<!-- 配置往nexus私服上传jar包所需要的账号密码 -->
<server>
<!--注意这个id 需要和pom.xml的对应-->
<id>maven-releases</id>
<username>admin</username>
<password>admin123</password>
</server>
<!-- 配置往nexus私服上传jar包所需要的账号密码 -->
<server>
<!--注意这个id 需要和pom.xml的对应-->
<id>maven-snapshots</id>
<username>admin</username>
<password>admin123</password>
</server>
</servers>
<!-- 配置镜像代理 -->
<mirrors>
<mirror>
<id>nexus</id>
<mirrorOf>*</mirrorOf><!-- 配置为*的意思是将所有请求都转发到镜像仓库上 -->
<url>http://172.16.150.132:8084/repository/maven-public/</url>
</mirror>
<!--这2个备用 以免在外网环境连不上私服-->
<!-- <mirror>-->
<!-- <id>alimaven</id>-->
<!-- <mirrorOf>central</mirrorOf>-->
<!-- <url>https://maven.aliyun.com/repository/public/</url>-->
<!-- </mirror>-->
<!-- <mirror>-->
<!-- <id>alimaven_central</id>-->
<!-- <mirrorOf>central</mirrorOf>-->
<!-- <url>http://maven.aliyun.com/nexus/content/repositories/central/</url>-->
<!-- </mirror>-->
</mirrors>
<profiles>
<profile>
<id>nexus</id>
<!--Override the repository (and pluginRepository) "central" from the Maven Super POM
to activate snapshots for both! -->
<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>
<profile>
<id>jdk1.8</id>
<activation>
<activeByDefault>true</activeByDefault>
<jdk>1.8</jdk>
</activation>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<maven.compiler.compilerVersion>1.8</maven.compiler.compilerVersion>
</properties>
</profile>
</profiles>
<activeProfiles>
<activeProfile>nexus</activeProfile>
<activeProfile>jdk1.8</activeProfile>
</activeProfiles>
</settings>
2. pom.xml配置
在pom.xml中插入发布相关信息
<!-- 配置私服上传jar包地址 -->
<distributionManagement>
<repository>
<!-- release包上传地址 -->
<id>maven-releases</id>
<url>http://172.16.150.132:8084/repository/maven-releases/</url>
</repository>
<snapshotRepository>
<!-- snapshots包上传地址 -->
<id>maven-snapshots</id>
<url>http://172.16.150.132:8084/repository/maven-snapshots/</url>
</snapshotRepository>
</distributionManagement>
完成 , 可直接通过deploy发布到私服
查看私服是否有上传文件