Home > Archives > 在Centos7中安装Nexus实战

在Centos7中安装Nexus实战

Publish:

Download

Nexus下载nexus-2.14.2-01-bundle.tar.gz

安装步骤

1
copy nexus-2.14.2-01-bundle.tar.gz >> /tmp

Install

1
2
3
4
5
[root@localhost ~]# mkdir /opt/nexus
[root@localhost ~]# cd /opt/nexus
[root@localhost nexus]# tar -zxvf /tmp/nexus-2.14.2-01-bundle.tar.gz 
[root@localhost nexus]# ln -sf /opt/nexus/nexus-2.14.2-01 /opt/nexus/latest
[root@localhost nexus]# ln -sf /opt/nexus/latest /opt/nexus/default

New User

1
2
[root@localhost nexus]# useradd -r nexus --shell /	/false
[root@localhost nexus]# chown -hR nexus: /opt/nexus

开机启动

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
[root@localhost nexus]# vim /etc/init.d/nexus

#!/bin/sh

# chkconfig: - 80 20
# Description: Nexus OSS

NEXUS_HOME=/opt/nexus/default
RUN_AS_USER=nexus
JAVA_HOME=/usr/java/default

export NEXUS_HOME RUN_AS_USER JAVA_HOME

"$NEXUS_HOME/bin/nexus"\
$1
exit $?


[root@localhost nexus]# chmod +x /etc/init.d/nexus

设定

1
[root@localhost nexus]# vim /opt/nexus/default/conf/nexus.properties

[BEFORE]

1
2
3
4
5
6
7
8
9
10
11
12
# Jetty section
application-port=8081
application-host=0.0.0.0
nexus-webapp=${bundleBasedir}/nexus
nexus-webapp-context-path=/nexus

# Nexus section
nexus-work=${bundleBasedir}/../sonatype-work/nexus
runtime=${bundleBasedir}/nexus/WEB-INF

# orientdb buffer size in megabytes
storage.diskCache.bufferSize=4096

[AFTER]

1
2
3
4
application-port=9083
application-host=0.0.0.0
nexus-webapp=${bundleBasedir}/nexus
nexus-webapp-context-path=/

设置开机启动

1
[root@localhost nexus]# chkconfig nexus on

防火墙

1
2
3
4
[root@localhost nexus]# vim /etc/sysconfig/iptables
-A INPUT -p tcp -m state --state NEW -m tcp --dport 8081 -j ACCEPT

[root@localhost nexus]# service iptables restart

默认用户名密码

1
2
3
4
username-password:
admin-admin123

http://localhost:9083

Nexus、Setting.xml、pom.xml集成

在Nexus服务器上添加aliyun镜像

Views/Repositories » Repositories » Add » Proxy Repository

1
2
3
4
5
6
7
8
9
10
11
1. Repository ID: nexus-aliyun
2. Repository Name: Nexus aliyun
3. Repository Type: proxy
4. Provider: Maven2
5. Format: maven2
6. Repository Policy: Release
7. Remote Repository Access >>
	1)Remote Storage Location:http://maven.aliyun.com/nexus/content/groups/public/
	2)Download Remote Indexes:True
	3)Auto Blocking Enabled:True
	4)File Content Validation:True

Put out of service with Central

1
右击[Central],选择[Put out of service]。

更新 group [Public Repositories]

1
2
3
4
5
1. 选中[Public Repositories]。
2. 点击Tab [Configuration]。
	1)把Central 从[Ordered Group Repositories]移除。
	2)把[Nexus aliyun]添加到[Ordered Group Repositories]。
3. 点击保存。

更新Releases

1
2
3
4
1. 选中 [Releases].
2. 点击Tab [Configuration]
	1) Repository Policy: Release
	2) Deployment Policy: Allow Redeploy

更新Snapshots

1
2
3
4
1. 选中 [Releases].
2. 点击Tab [Configuration]
	1) Repository Policy: Snapshot
	2) Deployment Policy: Allow Redeploy

更新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
<?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">  
  <localRepository>D:/repo</localRepository>  
  <pluginGroups></pluginGroups>  
  <proxies></proxies>
  <servers>  
	  <server>
		<id>releases</id>
		<username>admin</username>
		<password>admin123</password>
	  </server>
	  <server>
		<id>snapshots</id>
		<username>admin</username>
		<password>admin123</password>
	  </server>
  </servers>  
  <mirrors>  
	<mirror>
		<id>localmaven</id>
		<name>local maven</name>
		<url>http://127.0.0.1:8081/nexus/content/groups/public/</url>
		<mirrorOf>*</mirrorOf>        
	</mirror>
  </mirrors>  
  <profiles></profiles>  
</settings>

更新项目的pom.xml

如果你发现,你需要提交你的本地jar到本地的Nexus仓库中,就需要更新你项目的pom.xml文件,可以直接添加到description标签的后面,或者其他位置。

1
2
3
4
5
6
7
8
9
10
11
12
13
<distributionManagement>
  <repository>
	<id>releases</id>
	<name>User Project Release</name>
	<url>http://127.0.0.1:8081/nexus/content/repositories/releases/</url>
  </repository>

  <snapshotRepository>
	<id>snapshots</id>
	<name>User Project SNAPSHOTS</name>
	<url>http://127.0.0.1:8081/nexus/content/repositories/snapshots/</url>
  </snapshotRepository>
</distributionManagement>

发布本地jar到Nexus仓库中

1
mvn clean deploy -X -Dmaven.test.skip=true

参考资料

  1. CentOS7 Nexus安装
  2. 用nexus搭建maven私服
  3. maven发布项目到私服-snapshot快照库和release发布库的区别和作用及maven常用命令

声明: 本文采用 BY-NC-SA 授权。转载请注明转自: Ding Bao Guo