nexus3系列的安装与配置

本文档详细介绍了如何安装和配置Nexus3,包括下载最新版本、解压安装、修改配置文件、启动服务以及访问Nexus3仓库。默认端口为9000,初始用户名密码为admin/admin123。同时,文中提到了Nexus3中的仓库设置和如何在项目中配置部署。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

nexus系列教程

引言

nexus2.x版本的安装配置请参考我之前的博客: https://www.cnblogs.com/huhongy/protected/p/7181919.html

目前nexus的版本已经更新到3,下面让我们来看一下怎么来安装注册,服务。

​ 前面我介绍过nexus2系列的安装方式,随着几年的更新,现在maven的私服已经到nexus3,关于安装和启动都发生一些改变

官网 :https://help.sonatype.com/repomanager3/download/download-archives---repository-manager-3

在这我就不介绍nexus是干啥的了,因为前面说了好多了,本节只关注nexus3版本的安装。

下载

​ 选择自己喜欢的一版下载,我这演示的nexus3.22 最新版

解压安装

​ 将nexus-3.22.0-02-win64.zip解压到任意目录

解压后会出现两个目录
	nexus-3.22.0-02    安装目录
		..... 主要关注文件夹
		bin			命令文件目录
		etc			配置文件目录
	sonatype-work	   工作目录

配置文件

​ 在etc下有一个默认的配置文件 nexus-default.properties,内容如下

## DO NOT EDIT - CUSTOMIZATIONS BELONG IN $data-dir/etc/nexus.properties
##
# Jetty section
application-port=9000	  	Nexus服务监听的端口  默认是8081
application-host=0.0.0.0    Nexus服务监听的主机
nexus-args=${jetty.etc}/jetty.xml,${jetty.etc}/jetty-http.xml,${jetty.etc}/jetty-requestlog.xml
nexus-context-path=/		Nexus服务的上下文路径

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

nexus.hazelcast.discovery.isEnabled=true

​ 运行环境修改

在bin目录下有nexus.vmoptions配置文件,可以根据自己电脑修改,与配置jdk的Xms差不多

-Xms2703m
-Xmx2703m
-XX:MaxDirectMemorySize=2703m
-XX:+UnlockDiagnosticVMOptions
-XX:+LogVMOutput
-XX:LogFile=../sonatype-work/nexus3/log/jvm.log
-XX:-OmitStackTraceInFastThrow
-Djava.net.preferIPv4Stack=true
-Dkaraf.home=.
-Dkaraf.base=.
-Dkaraf.etc=etc/karaf
-Djava.util.logging.config.file=etc/karaf/java.util.logging.properties
-Dkaraf.data=../sonatype-work/nexus3
-Dkaraf.log=../sonatype-work/nexus3/log
-Djava.io.tmpdir=../sonatype-work/nexus3/tmp
-Dkaraf.startLocalConsole=false
#
# additional vmoptions needed for Java9+
#
# --add-reads=java.xml=java.logging
# --add-exports=java.base/org.apache.karaf.specs.locator=java.xml,ALL-UNNAMED
# --patch-module=java.base=lib/endorsed/org.apache.karaf.specs.locator-4.2.6.jar
# --patch-module=java.xml=lib/endorsed/org.apache.karaf.specs.java.xml-4.2.6.jar
# --add-opens=java.base/java.security=ALL-UNNAMED
# --add-opens=java.base/java.net=ALL-UNNAMED
# --add-opens=java.base/java.lang=ALL-UNNAMED
# --add-opens=java.base/java.util=ALL-UNNAMED
# --add-opens=java.naming/javax.naming.spi=ALL-UNNAMED
# --add-opens=java.rmi/sun.rmi.transport.tcp=ALL-UNNAMED
# --add-exports=java.base/sun.net.www.protocol.http=ALL-UNNAMED
# --add-exports=java.base/sun.net.www.protocol.https=ALL-UNNAMED
# --add-exports=java.base/sun.net.www.protocol.jar=ALL-UNNAMED
# --add-exports=jdk.xml.dom/org.w3c.dom.html=ALL-UNNAMED
# --add-exports=jdk.naming.rmi/com.sun.jndi.url.rmi=ALL-UNNAMED
#
# comment out this vmoption when using Java9+
#
-Djava.endorsed.dirs=lib/endorsed

启动 与注册服务

在neuxs-3.22.x/bin 目录下有nexus.exe的命令,可以通过其来启动nexus服务

参考官网:https://help.sonatype.com/repomanager3/installation/run-as-a-service

# 启动neuxs的集中方式
nexus.exe /run  
# neuxs注册成服务
nexus.exe /insall nexus3[服务名]
# 启动停止服务
nexus.exe /start nexus3
nexus.exe /stop nexus3

访问

安装配置完成后,服务启动,可以通过web方式进行访问,上面我配置的监听端口是9000,就是可以通过localhost:9000进行启动访问

默认用户名密码是admin/admin123 或者在第一次登陆时会提示在密码文件中存储,然后初始化进行登陆修改即可。

neuxs仓库

neuxs在搭建好之后,有几个默认的仓库,大致说一下

仓库名作用
hosted 宿主仓库要用于部署无法从公共仓库获取的构件以及自己或第三方的项目构件(存放本公司开发的jar包(正式版本、测试版本))
proxy 代理仓库代理公共的远程仓库
group 仓库组Nexus 通过仓库组统一管理多个仓库,这样我们在项目中直接请求仓库组即可请求到仓库组管理的多个仓库(使用时连接组仓库,包含Hosted(宿主仓库)和Proxy(代理仓库))
release仓库内部的模块中release模块的发布仓库
snapshots发布那些非release版本, 非稳定版本

setting配置私服

1. 配置认证信息
2. 完善远程仓库  我采用阿里云  也可以配置的私服,然后拿私服的代理地址
3. 配置仓库与仓库插件地址   
4. 配置本地发布,默认id是配置认证信息的id  ---这步不是必须的,可以在项目的pom文件中配置
<?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
   | The path to the local repository maven will use to store artifacts.
   |
   | Default: ${user.home}/.m2/repository
  <localRepository>/path/to/local/repo</localRepository>
  -->
   <!--本地仓库 --> 
<localRepository>E:\workSoft\maven\maven_repository</localRepository>
  <!-- interactiveMode
   | This will determine whether maven prompts you when it needs input. If set to false,
   | maven will use a sensible default value, perhaps based on some other setting, for
   | the parameter in question.
   |
   | Default: true
  <interactiveMode>true</interactiveMode>
  -->

  <!-- offline
   | Determines whether maven should attempt to connect to the network when executing a build.
   | This will have an effect on artifact downloads, artifact deployment, and others.
   |
   | Default: false
  <offline>false</offline>
  -->

  <!-- pluginGroups
   | This is a list of additional group identifiers that will be searched when resolving plugins by their prefix, i.e.
   | when invoking a command line like "mvn prefix:goal". Maven will automatically add the group identifiers
   | "org.apache.maven.plugins" and "org.codehaus.mojo" if these are not already contained in the list.
   |-->
  <pluginGroups>
    <!-- pluginGroup
     | Specifies a further group identifier to use for plugin lookup.
    <pluginGroup>com.your.plugins</pluginGroup>
    -->
  </pluginGroups>

  <!-- proxies
   | This is a list of proxies which can be used on this machine to connect to the network.
   | Unless otherwise specified (by system property or command-line switch), the first proxy
   | specification in this list marked as active will be used.
   |-->
  <proxies>
  
  </proxies>

  <!-- servers
   | This is a list of authentication profiles, keyed by the server-id used within the system.
   | Authentication profiles can be used whenever maven must make a connection to a remote server.
   |-->
  <servers>
    <!-- server
     | Specifies the authentication information to use when connecting to a particular server, identified by
     | a unique name within the system (referred to by the 'id' attribute below).
     |
     | NOTE: You should either specify username/password OR privateKey/passphrase, since these pairings are
     |       used together.
     |
    <server>
      <id>deploymentRepo</id>
      <username>repouser</username>
      <password>repopwd</password>
    </server>
    -->

    <!-- Another sample, using keys to authenticate.
    <server>
      <id>siteServer</id>
      <privateKey>/path/to/private/key</privateKey>
      <passphrase>optional; leave empty if not used.</passphrase>
    </server>
    -->
    <!-- 配置私服认证信息 -->
    <server>
      <id>huhy-releases</id>
      <username>huhy</username>
      <password>123456</password>
    </server>
    <server>
      <id>huhy-snapshots</id>
      <username>huhy</username>
      <password>123456</password>
    </server>
  

  </servers>

  <!-- mirrors
   | This is a list of mirrors to be used in downloading artifacts from remote repositories.
   |
   | It works like this: a POM may declare a repository to use in resolving certain artifacts.
   | However, this repository may have problems with heavy traffic at times, so people have mirrored
   | it to several places.
   |
   | That repository definition will have a unique id, so we can create a mirror reference for that
   | repository, to be used as an alternate download site. The mirror site will be the preferred
   | server for that repository.
   |-->
  <mirrors>
    <!-- mirror
     | Specifies a repository mirror site to use instead of a given repository. The repository that
     | this mirror serves has an ID that matches the mirrorOf element of this mirror. IDs are used
     | for inheritance and direct lookup purposes, and must be unique across the set of mirrors.
     |
    <mirror>
      <id>mirrorId</id>
      <mirrorOf>repositoryId</mirrorOf>
      <name>Human Readable Name for this Mirror.</name>
      <url>http://my.repository.com/repo/path</url>
    </mirror>
     -->
      <mirror>
        <id>nexus-aliyun</id>
        <mirrorOf>central</mirrorOf>
        <name>Nexus aliyun</name>
        <url>http://maven.aliyun.com/nexus/content/groups/public</url>
      </mirror>
  </mirrors>

  <!-- profiles
   | This is a list of profiles which can be activated in a variety of ways, and which can modify
   | the build process. Profiles provided in the settings.xml are intended to provide local machine-
   | specific paths and repository locations which allow the build to work in the local environment.
   |
   | For example, if you have an integration testing plugin - like cactus - that needs to know where
   | your Tomcat instance is installed, you can provide a variable here such that the variable is
   | dereferenced during the build process to configure the cactus plugin.
   |
   | As noted above, profiles can be activated in a variety of ways. One way - the activeProfiles
   | section of this document (settings.xml) - will be discussed later. Another way essentially
   | relies on the detection of a system property, either matching a particular value for the property,
   | or merely testing its existence. Profiles can also be activated by JDK version prefix, where a
   | value of '1.4' might activate a profile when the build is executed on a JDK version of '1.4.2_07'.
   | Finally, the list of active profiles can be specified directly from the command line.
   |
   | NOTE: For profiles defined in the settings.xml, you are restricted to specifying only artifact
   |       repositories, plugin repositories, and free-form properties to be used as configuration
   |       variables for plugins in the POM.
   |
   |-->
  <profiles>
    <!-- profile
     | Specifies a set of introductions to the build process, to be activated using one or more of the
     | mechanisms described above. For inheritance purposes, and to activate profiles via <activatedProfiles/>
     | or the command line, profiles have to have an ID that is unique.
     |
     | An encouraged best practice for profile identification is to use a consistent naming convention
     | for profiles, such as 'env-dev', 'env-test', 'env-production', 'user-jdcasey', 'user-brett', etc.
     | This will make it more intuitive to understand what the set of introduced profiles is attempting
     | to accomplish, particularly when you only have a list of profile id's for debug.
     |
     | This profile example uses the JDK version to trigger activation, and provides a JDK-specific repo.
    <profile>
      <id>jdk-1.4</id>

      <activation>
        <jdk>1.4</jdk>
      </activation>

      <repositories>
        <repository>
          <id>jdk14</id>
          <name>Repository for JDK 1.4 builds</name>
          <url>http://www.myhost.com/maven/jdk14</url>
          <layout>default</layout>
          <snapshotPolicy>always</snapshotPolicy>
        </repository>
      </repositories>
    </profile>
    -->

    <!--
     | Here is another profile, activated by the system property 'target-env' with a value of 'dev',
     | which provides a specific path to the Tomcat instance. To use this, your plugin configuration
     | might hypothetically look like:
     |
     | ...
     | <plugin>
     |   <groupId>org.myco.myplugins</groupId>
     |   <artifactId>myplugin</artifactId>
     |
     |   <configuration>
     |     <tomcatLocation>${tomcatPath}</tomcatLocation>
     |   </configuration>
     | </plugin>
     | ...
     |
     | NOTE: If you just wanted to inject this configuration whenever someone set 'target-env' to
     |       anything, you could just leave off the <value/> inside the activation-property.
     |
    <profile>
      <id>env-dev</id>

      <activation>
        <property>
          <name>target-env</name>
          <value>dev</value>
        </property>
      </activation>

      <properties>
        <tomcatPath>/path/to/tomcat/instance</tomcatPath>
      </properties>
    </profile>
    -->
    <profile>
      <id>huhy</id>
      <!-- 指定仓库 -->
      <repositories>
		    <repository>
					<id>huhy-nexus</id>
					<url>http://localhost:9000/repository/maven-public/</url>
					<releases><enabled>true</enabled></releases>
					<snapshots><enabled>true</enabled></snapshots> 
		    </repository>  
      </repositories>
      <!-- 指定插件仓库 -->
      <pluginRepositories>  
				<pluginRepository>  
					<id>huhy-nexus</id>
					<url>http://localhost:9000/repository/maven-public/</url>
					<releases><enabled>true</enabled></releases>
					<snapshots><enabled>true</enabled></snapshots> 
				</pluginRepository>  
				
			</pluginRepositories>
    </profile>
  </profiles>
  

  <!-- activeProfiles
   | List of profiles that are active for all builds.
   |
  <activeProfiles>
    <activeProfile>alwaysActiveProfile</activeProfile>
    <activeProfile>anotherAlwaysActiveProfile</activeProfile>
  </activeProfiles>
  -->
  <!--激活配置-->
  <activeProfiles>
  	<!--profile下的id-->
    <activeProfile>huhy</activeProfile>
  </activeProfiles>
</settings>


注意: 关于配置deploy配置,需要在项目的配置文件中配置

<!-- 配置部署的远程仓库 -->
    <distributionManagement>
        <snapshotRepository>
            <id>huhy-snapshots</id>  与setting的认证信息的id一致即可
            <name>Nexus Snapshot Repository</name>
            <url>http://localhost:9000/repository/maven-snapshots/</url>
        </snapshotRepository>
        <repository>
            <id>huhy-releases</id>
            <name>Nexus Release Repository</name>
            <url>http://localhost:9000/repository/huhy-nexus/</url>
        </repository>
    </distributionManagement>

关于nexus的web端的操作,后面会有一篇博客重点讨论。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值