tonglin0325的个人主页

Centos7.0下Nexus私服搭建

1.下载nexus

1
2
wget https://sonatype-download.global.ssl.fastly.net/nexus/oss/nexus-2.11.2-03-bundle.tar.gz

2.解压,会出现两个目录,nexus-2.11.2-03是服务
  sonatype-work是私有库目录

1
2
3
mkdir nexus
tar -zxvf nexus-2.11.2-03-bundle.tar.gz -C ./nexus

3.修改配置,在nexus-2.11.2-03/bin目录下修改nexus文件

1
2
3
NEXUS_HOME=“安装目录”
RUN_AS_USER=xxx

4.修改端口,nexus-2.11.2-03/conf修改nexus.properties文件

1
2
application-port=XXX

5.启动

1
2
3
4
./bin/nexus start
Starting Nexus OSS...
Started Nexus OSS.

6.修改密码

1
2
3
4
admin:该用户拥有Nexus的全部权限,默认密码为admin123。
deployment:该用户能够访问Nexus,浏览仓库内容、搜索、上传部署构件,但是不能对Nexus进行任何配置,默认密码为deployment123。
anonymous:该用户对应了所有未登录的匿名用户,它们可以浏览仓库并进行搜索。

7.上传Jar包

参考:上传jar包到nexus私服

登录之后可以看到如下仓库

 

<1>如果上传的是第三方的jar包

在图中填入相应的jar包的信息就可以了

同时在maven的setting.xml文件中配置

1
2
3
4
5
6
7
8
9
10
11
12
13
 <servers>
<server>
<id>nexus-releases</id>
<username>admin</username>
<password>xxxx</password>
</server>
<server>
<id>nexus-snapshots</id>
<username>admin</username>
<password>xxxx</password>
</server>
</servers>

 以及

1
2
3
4
5
6
7
<mirror>
<id>mynexus</id>
<mirrorOf>central</mirrorOf>
<name>My Nexus</name>
<url>http://XXX/nexus/content/repositories/thirdparty/</url>
</mirror>

 <2>上传snapshot包

在工程的pom文件中配置

1
2
3
4
5
6
7
8
9
10
11
12
13
<distributionManagement>
<repository>
<id>nexus-releases</id>
<name>Nexus Release Repository</name>
<url>http://XXX/nexus/content/repositories/releases/</url>
</repository>
<snapshotRepository>
<id>nexus-snapshots</id>
<name>Nexus Snapshot Repository</name>
<url>http://XXX/nexus/content/repositories/snapshots/</url>
</snapshotRepository>
</distributionManagement>

 

 同时在maven的setting.xml文件中配置

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
   </profiles>
<profile>
<id>nexus</id>
<repositories>
<repository>
<id>nexus-releases</id>
<url>http://nexus-releases</url>
<releases><enabled>true</enabled></releases>
<snapshots><enabled>true</enabled></snapshots>
</repository>
<repository>
<id>nexus-snapshots</id>
<url>http://nexus-snapshots</url>
<releases><enabled>true</enabled></releases>
<snapshots><enabled>true</enabled></snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>nexus-releases</id>
<url>http://nexus-releases</url>
<releases><enabled>true</enabled></releases>
<snapshots><enabled>true</enabled></snapshots>
</pluginRepository>
<pluginRepository>
<id>nexus-snapshots</id>
<url>http://nexus-snapshots</url>
<releases><enabled>true</enabled></releases>
<snapshots><enabled>true</enabled></snapshots>
</pluginRepository>
</pluginRepositories>
</profile>
</profiles>

<activeProfiles>
<activeProfile>nexus</activeProfile>
</activeProfiles>

 然后在项目下运行,就会生成snapshot包

1
2
mvn deploy