Skip to content

Commit b921bce

Browse files
committed
📝 Writing docs.
1 parent ad48adc commit b921bce

1 file changed

Lines changed: 191 additions & 0 deletions

File tree

Lines changed: 191 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,191 @@
1+
# Nexus 安装
2+
3+
> 关键词:maven, nexus
4+
>
5+
> 部署环境
6+
>
7+
> - Nexus 3.13.0
8+
> - JDK 1.8
9+
> - Maven 3.5.4
10+
>
11+
12+
## 下载安装 Nexus
13+
14+
进入[官方下载地址](https://www.sonatype.com/download-oss-sonatype),选择合适版本下载。
15+
16+
![](http://oyz7npk35.bkt.clouddn.com/images/20180920180929160614.png)
17+
18+
本人希望将 Nexus 部署在 Linux 机器,所以选用的是 Unix 版本。
19+
20+
这里,如果想通过命令方式直接下载(比如用脚本安装),可以在[官方历史发布版本页面](https://help.sonatype.com/repomanager3/download/download-archives---repository-manager-3)中找到合适版本,然后执行以下命令:
21+
22+
```sh
23+
wget -O /opt/maven/nexus-unix.tar.gz http://download.sonatype.com/nexus/3/nexus-3.13.0-01-unix.tar.gz
24+
tar -zxf nexus-unix.tar.gz
25+
```
26+
27+
解压后,有两个目录:
28+
29+
- nexus-3.13.0-01 - 包含了 Nexus 运行所需要的文件。是 Nexus 运行必须的。
30+
- sonatype-work - 包含了 Nexus 生成的配置文件、日志文件、仓库文件等。当我们需要备份 Nexus 的时候默认备份此目录即可。
31+
32+
## 启动停止 Nexus
33+
34+
进入 nexus-3.13.0-01/bin 目录,有一个可执行脚本 nexus。
35+
36+
执行 `./nexus`,可以查看允许执行的参数,如下所示,含义可谓一目了然:
37+
38+
```sh
39+
$ ./nexus
40+
Usage: ./nexus {start|stop|run|run-redirect|status|restart|force-reload}
41+
```
42+
43+
- 启动 nexus - `./nexus start`
44+
- 停止 nexus -
45+
46+
启动成功后,在浏览器中访问 `http://<ip>:8081`,欢迎页面如下图所示:
47+
48+
![](http://oyz7npk35.bkt.clouddn.com/images/20180920180929164140.png)
49+
50+
点击右上角 Sign in 登录,默认用户名/密码为:admin/admin123。
51+
52+
有必要提一下的是,在 Nexus 的 Repositories 管理页面,展示了可用的 maven 仓库,如下图所示:
53+
54+
![](http://oyz7npk35.bkt.clouddn.com/images/20180920180929170924.png)
55+
56+
> 说明:
57+
>
58+
> - maven-central - maven 中央库(如果没有配置 mirror,默认就从这里下载 jar 包),从 https://repo1.maven.org/maven2/ 获取资源
59+
> - maven-releases - 存储私有仓库的发行版 jar 包
60+
> - maven-snapshots - 存储私有仓库的快照版(调试版本) jar 包
61+
> - maven-public - 私有仓库的公共空间,把上面三个仓库组合在一起对外提供服务,在本地 maven 基础配置 settings.xml 中使用。
62+
>
63+
64+
## 使用 Nexus
65+
66+
如果要使用 Nexus,还必须在 settings.xml 和 pom.xml 中配置认证信息。
67+
68+
### 配置 settings.xml
69+
70+
一份完整的 `settings.xml`
71+
72+
```xml
73+
<?xml version="1.0" encoding="UTF-8"?>
74+
75+
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
76+
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">
77+
<pluginGroups>
78+
<pluginGroup>org.sonatype.plugins</pluginGroup>
79+
</pluginGroups>
80+
81+
<!-- Maven 私服账号信息 -->
82+
<servers>
83+
<server>
84+
<id>releases</id>
85+
<username>admin</username>
86+
<password>admin123</password>
87+
</server>
88+
<server>
89+
<id>snapshots</id>
90+
<username>admin</username>
91+
<password>admin123</password>
92+
</server>
93+
</servers>
94+
95+
<!-- jar 包下载地址 -->
96+
<mirrors>
97+
<mirror>
98+
<id>public</id>
99+
<mirrorOf>*</mirrorOf>
100+
<url>http://10.255.255.224:8081/repository/maven-public/</url>
101+
</mirror>
102+
<!-- 国内建议使用 aliyun 作为中央仓库以加速下载 -->
103+
<mirror>
104+
<id>aliyun</id>
105+
<mirrorOf>central</mirrorOf>
106+
<name>Aliyun Mirror</name>
107+
<url>http://maven.aliyun.com/nexus/content/groups/public/ </url>
108+
</mirror>
109+
</mirrors>
110+
111+
<profiles>
112+
<profile>
113+
<id>zp</id>
114+
<repositories>
115+
<repository>
116+
<id>central</id>
117+
<url>http://central</url>
118+
<releases>
119+
<enabled>true</enabled>
120+
</releases>
121+
<snapshots>
122+
<enabled>true</enabled>
123+
</snapshots>
124+
</repository>
125+
</repositories>
126+
<pluginRepositories>
127+
<pluginRepository>
128+
<id>central</id>
129+
<url>http://central</url>
130+
<releases>
131+
<enabled>true</enabled>
132+
</releases>
133+
<snapshots>
134+
<enabled>true</enabled>
135+
<updatePolicy>always</updatePolicy>
136+
</snapshots>
137+
</pluginRepository>
138+
</pluginRepositories>
139+
</profile>
140+
</profiles>
141+
142+
<activeProfiles>
143+
<activeProfile>zp</activeProfile>
144+
</activeProfiles>
145+
</settings>
146+
```
147+
148+
### 配置 pom.xml
149+
150+
在 pom.xml 中添加如下配置:
151+
152+
```xml
153+
<distributionManagement>
154+
<repository>
155+
<id>releases</id>
156+
<name>Releases</name>
157+
<url>http://10.255.255.224:8081/repository/maven-releases</url>
158+
</repository>
159+
<snapshotRepository>
160+
<id>snapshots</id>
161+
<name>Snapshot</name>
162+
<url>http://10.255.255.224:8081/repository/maven-snapshots</url>
163+
</snapshotRepository>
164+
</distributionManagement>
165+
```
166+
167+
> 注意:
168+
>
169+
> - `<repository>``<snapshotRepository>` 的 id 必须和 `settings.xml` 配置文件中的 `<server>` 标签中的 id 匹配。
170+
> - `<url>` 标签的地址需要和 maven 私服的地址匹配。
171+
>
172+
173+
### 执行 maven 构建
174+
175+
如果要使用 settings.xml 中的私服配置,必须通过指定 `-P zp` 来激活 profile。
176+
177+
示例:
178+
179+
```sh
180+
# 编译并打包 maven 项目
181+
$ mvn clean package -Dmaven.skip.test=true -P zp
182+
183+
# 编译并上传 maven 交付件(jar 包)
184+
$ mvn clean deploy -Dmaven.skip.test=true -P zp
185+
```
186+
187+
## 参考资料
188+
189+
- https://www.cnblogs.com/hoobey/p/6102382.html
190+
- https://blog.csdn.net/wzygis/article/details/49276779
191+
- https://blog.csdn.net/clj198606061111/article/details/52200928

0 commit comments

Comments
 (0)