centos安装nexus搭建mvn私服与配置
官网下载
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
wget http://tar.matosiki.site/tar/nexus-3.13.0-01.tar.gz
tar -vxzf nexus-3.13.0-01.tar.gz
mv nexus-3.13.0-01 /opt/
mv nexus-3.13.0-01 nexus
# 运行前更改端口和启动路径
vim /opt/nexus/etc/nexus-default.properties
application-port=5566
application-host=0.0.0.0
nexus-context-path=/nexus
# 运行 首次启动用run命令 之后使用start
./opt/nexus/bin/nexus run
# 测试 默认用户名admin 密码admin123
curl localhost:5566
|
启动生成后默认会在opt目录下生成sonatype-work文件夹,进入文件夹配置nexus
1
2
3
4
5
6
7
|
# 运行后再更改配置方式 默认端口8081
# 简单配置nexus 更改端口
cd /opt/sonatype-work/nexus3/etc/
vim nexus.properties
application-port=5566
application-host=0.0.0.0
nexus-context-path=/nexus
|
将nexus作为服务
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
|
vi /etc/profile
export NEXUS_HOME="/opt/nexus"
source /etc/profile
# 添加nexus用户
groupadd nexus
useradd -g nexus nexus
chown -R nexus:nexus
vi /opt/nexus/bin/nexus.rc
run_as_user="nexus"
# 建立软连接
sudo ln -s $NEXUS_HOME/bin/nexus /etc/init.d/nexus
cd /etc/init.d
sudo chkconfig --add nexus
sudo chkconfig --levels 345 nexus on
sudo service nexus start
cd /etc/init.d
sudo update-rc.d nexus defaults
sudo service nexus start
sudo systemctl daemon-reload
sudo systemctl enable nexus.service
sudo systemctl start nexus.service
|
如果不能启动试试删除
1
2
|
rm -rf tmp/
rm -rf cache/
|
查看日志
1
|
tail -f /opt/sonatype-work/nexus3/log/nexus.log
|
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
39
40
41
42
43
44
45
46
|
<settings>
<mirrors>
<mirror>
<!--This sends everything else to /public -->
<id>nexus</id>
<mirrorOf>*</mirrorOf>
<url>http://localhost:8081/repository/maven-public/</url>
</mirror>
</mirrors>
<profiles>
<profile>
<id>nexus</id>
<!--Enable snapshots for the built in central repo to direct -->
<!--all requests to nexus via the mirror -->
<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>
</profiles>
<activeProfiles>
<!--make the profile active all the time -->
<activeProfile>nexus</activeProfile>
</activeProfiles>
<servers>
<server>
<id>nexus</id>
<username>admin</username>
<password>admin123</password>
</server>
</servers>
</settings>
|
pom.xml配置 以便发布jar到仓库
1
2
3
4
5
6
7
8
9
10
11
12
|
<distributionManagement>
<repository>
<id>nexus</id>
<name>Releases</name>
<url>http://{your-nexus-ip}/repository/maven-releases</url>
</repository>
<snapshotRepository>
<id>nexus</id>
<name>Snapshot</name>
<url>http://{your-nexus-ip}/repository/maven-snapshots</url>
</snapshotRepository>
</distributionManagement>
|
发布命令
上传第三方jar包到nexus
发布不带pom文件的独立jar包:
-DrepositoryId的值即为在setttings.xml里面配置的server id。
1
2
3
4
5
6
7
8
|
mvn deploy:deploy-file -DgroupId=<group-id> \
-DartifactId=<artifact-id> \
-Dversion=<version> \
-Dpackaging=<type-of-packaging> \
-Dfile=<path-to-file> \
-DrepositoryId=<id-to-map-on-server-section-of-settings.xml> \
-Durl=<url-of-the-repository-to-deploy>
|
发布带有pom的jar包
1
2
3
4
|
mvn deploy:deploy-file -DpomFile=<path-to-pom> \
-Dfile=<path-to-file> \
-DrepositoryId=<id-to-map-on-server-section-of-settings.xml> \
-Durl=<url-of-the-repository-to-deploy>
|