nexus的官方下载地址 https://www.sonatype.com/products/repository-oss-download

步骤1: Nexus本身是一个服务,将下载好的压缩包解压之后会看到俩个文件夹

centos nexus启动失败原因_maven

步骤2:打开命令行,切换到nexus-3.20.1-01/bin目录下,会看到Nexus的启动文件nexus.exe

centos nexus启动失败原因_maven_02

步骤3:输入命令nexus.exe/run,并回车启动nexus服务,出现以下信息表示启动成功

centos nexus启动失败原因_生产环境_03

可以修改nexus的一些配置,有两个配置文件:

  • nexus-3.20.1-01/bin目录下面的nexus.vmoptions,
  • nexus-3.20.1-01/etc目录下面的nexus-default.properties,里面可以修改端口号(默认是8081)
## DO NOT EDIT - CUSTOMIZATIONS BELONG IN $data-dir/etc/nexus.properties
##
# Jetty section
application-port=8081
application-host=0.0.0.0
nexus-args=${jetty.etc}/jetty.xml,${jetty.etc}/jetty-http.xml,${jetty.etc}/jetty-requestlog.xml
nexus-context-path=/

# Nexus section
nexus-edition=nexus-pro-edition
nexus-features=\
 nexus-pro-feature

nexus.hazelcast.discovery.isEnabled=true

步骤4:访问浏览器地址 localhost:8081就会看到nexus的欢迎页,如果时第一次进入会提示登录

centos nexus启动失败原因_生产环境_04

步骤5:登录以后点击Browse菜单,会看到nexus默认的仓库

centos nexus启动失败原因_maven_05

nexus四种仓库类型:

  • hosted :宿主仓库,这个仓库,是用来把公司内部的发布包部署到这个仓库里面来,然后公司内的其他人就可以从这个宿主仓库里去下载依赖使用
  • proxy:代理仓库,这个仓库不是用来给公司内部的发布部署的,是代理了公司外部的各种仓库,例如java.net,codehaus,jboss等等,最重要就是它代理了公司外部的中央仓库,但是这里也可以修改nexus连接为阿里云镜像仓库,阿里云去连接中央仓库。
  • group:仓库组,其实就是将各种宿主仓库、代理仓库全部组成一个虚拟的仓库组,然后我们的项目只要配置依赖一个仓库组,相当于就是可以自动连接仓库组对应的各种仓库。
  • virtual:虚拟仓库

nexus默认的仓库解释:

  • maven-central:这是代理仓库,代理maven中央仓库
  • maven-releases:该仓库是个宿主仓库,用于部署公司内部的release版本的发布包(类似于1.0.0,,release的意思就是你的工程已经经过了完善的测试,单元测试,集成测试,QA测试,上生产环境使用了)到这个仓库里面,供其他同事在生产环境依赖和使用
  • maven-snapshots:该仓库是个宿主仓库,用于部署公司内部的snapshot版本的发布包到这个仓库里(如果你的某个工程还在开发过程中,测试还没结束,但是,此时公司里其他同事也在开发一些工程,需要依赖你的包进行开发和测试,联调,此时你的工程的版本就是类似1.0.0-SNAPSHOT这样的版本),供其他同事在开发和测试的时候使用
  • maven-public:仓库组,上面所有release仓库都在这个仓库组内

步骤6:点击仓库后的cpoy按钮可以查看仓库的url,这个在maven配置仓库时使用

centos nexus启动失败原因_centos nexus启动失败原因_06

步骤7:点击网站上方的配置按钮,可以进行新建、修改、管理仓库,管理用户等操作,例如可以将maven-central仓库的代理仓库换成阿里云仓库

centos nexus启动失败原因_生产环境_07

步骤8:基本的私服就搭建好了,如果需要其他配置可以根据需求自行配置。可以进行本地配置私服测试,在settings.xml中配置

<!--指定连接到特定服务器时要使用的身份验证信息 注意server的id 要与mirror的id, repository的id一致-->
<!--此处的用户名和密码可以在nexus用户管理中新建以及赋予权限,默认有俩个用户amdin anonymous-->
<servers>
    <server>
        <id>nexusmy</id>
        <username>admin</username>
        <password>admin123456</password>
    </server>
</servers>
<!--配置镜像 用我们的私服代理所有的远程仓库-->
<mirrors>
    <mirror>
		<id>nexusmy</id>
		<mirrorOf>*</mirrorOf>
		<name>nexus-public</name>
		<url>http://localhost:8081/repository/maven-public/</url>    
    </mirror> 
</mirrors>

<!--配置私服仓库-->
<profiles>
    <profile>
		<id>alwaysActiveProfile</id>    
		<repositories>
			<repository>
				<id>nexusmy</id>
				<name>Team Maven Repository</name>
				<url>http://localhost:8081/repository/maven-public/</url>
				<releases>
					<enabled>true</enabled>
				</releases>
				<snapshots>
					<enabled>true</enabled>
				</snapshots>
			</repository>
		</repositories>
		<pluginRepositories>
			<pluginRepository>
				<id>nexusmy</id>
				<name>Team Maven Repository</name>
				<url>http://localhost:8081/repository/maven-public/</url>
				<releases>
					<enabled>true</enabled>
				</releases>
				<snapshots>
					<enabled>true</enabled>
				</snapshots>
			</pluginRepository>
		</pluginRepositories>
    </profile>
  </profiles>
  <activeProfiles>
    <activeProfile>alwaysActiveProfile</activeProfile>
  </activeProfiles>

步骤9:执行mvn命令就可以看到插件从私服下载,例如mvn clean

centos nexus启动失败原因_生产环境_08

步骤10:测试maven部署操作

  1. 在pom.xml中增加以下配置
<distributionManagement>
    <snapshotRepository>
        <id>snapshots</id>
        <name>Central snapshots Repository</name>
        <url>http://localhost:8081/repository/maven-snapshots/</url>
    </snapshotRepository>
    <repository>
        <id>releases</id>
        <name>Central-releases Repository</name>
        <url>http://localhost:8081/repository/maven-releases/</url>
    </repository>
</distributionManagement>
  1. 在settings.xml中增加以下配置
<servers>
    <server>
      <id>releases</id>
      <username>admin</username>
      <password>admin123456</password>
    </server>
	<server>
      <id>snapshots</id>
      <username>admin</username>
      <password>admin123456</password>
    </server>
</servers>
  1. 执行 mvn deploy,可以看到我们snapshots版本jar包已经上传到私服的maven-snapshots仓库

centos nexus启动失败原因_maven_09

centos nexus启动失败原因_生产环境_10