wget https://sonatype-download.global.ssl.fastly.net/nexus/3/nexus-3.6.0-02-unix.tar.gz tar xzvf nexus-3.6.0-02-unix.tar.gz
cd nexus-3.6.0-02/bin #前台启动服务 ./nexus run #在后台启动服务,不在界面上打印任何启动或者运行时信息 ./nexus start #关闭服务 ./nexus stop #查看nexus运行状态 ./nexus status #重启服务 ./nexus restart #强制重载一遍配置文件,而后重启服务 ./nexus force-reload
默认用户admin,密码admin123html
咱们能够在项目的POM中配置仓库和插件仓库,固然若是咱们想要全部的Maven项目都使用私服,能够在settings.xml中配置,可是settings.xml并不直接支持配置repositories和pluginRepositories,可是Maven提供了profiles下的profile可让咱们定义一系列的配置信息,而后指定其激活条件,可以定义在settings.xml中的信息有<repositories>、<pluginRepositories>和<properties>。定义在<properties>里面的键值对能够在pom.xml中使用,这里咱们配置远程仓库的地址和插件仓库。缓存
<profiles> <profile> <id>gpcmarket</id> <repositories> <repository> <id>gpcmarket</id> <name>gpcmarket private nexus</name> <url>http://ip:port/repository/maven-public/</url> <releases> <enabled>true</enabled> </releases> <snapshots> <enabled>true</enabled> </snapshots> </repository> </repositories> <pluginRepositories> <pluginRepository> <id>gpcmarket</id> <name>gpcmarket private nexus</name> <url>http://ip:port/repository/maven-public/</url> <releases> <enabled>true</enabled> </releases> <snapshots> <enabled>true</enabled> </snapshots> </pluginRepository> </pluginRepositories> </profile> <profile> <id>jdk-1.8</id> <activation> <activeByDefault>true</activeByDefault> <jdk>1.8</jdk> </activation> <properties> <maven.compiler.source>1.8</maven.compiler.source> <maven.compiler.target>1.8</maven.compiler.target> <maven.compiler.compilerVersion>1.8</maven.compiler.compilerVersion> </properties> </profile> </profiles> <activeProfiles> <activeProfile>gpcmarket</activeProfile> </activeProfiles>
可是Maven除了从Nexus上下载构件以外,还会时不时从中央仓库下载构件,然而这应该是Nexus的工做,因此咱们须要配置一个镜像,用<mirrorof>*</mirrorof>将Maven任何构件下载的请求都转发到私服中。安全
<mirrors> <mirror> <id>gpcmarket-public</id> <name>gpcmarket-public</name> <url>http://ip:port/repository/maven-public/</url> <mirrorOf>*</mirrorOf> </mirror> </mirrors>
这里就有一个问题,在这里配置了镜像,那在<profiles>里配置的远程仓库不是没有用了吗?当Maven须要下载发布版或者快照版构件的时候,他会首先检查咱们配置的远程仓库中的<releases>和<snapshots>元素,看该类型的构件是否能够下载,若是能够下载,就转到镜像地址去下载。因此咱们配置的远程仓库中的<url>失效了,有效的是<releases>和<snapshots>元素。bash
在项目正常开发中,快照版本的构件能够部署到Nexus中策略为Snapshot的例如:maven-snapshots宿主仓库中,发布版本能够部署到Nexus中策略为Release的例如:maven-releases宿主仓库中,项目的POM文件配置以下:网络
<distributionManagement> <repository> <id>gpcmarket-releases</id> <url>http://ip:port/nexus/repositories/releases/</url> </repository> <snapshotRepository> <id>gpcmarket-snapshots</id> <url>http://ip:port/nexus/repositories/snapshots/</url> </snapshotRepository> </distributionManagement>
可是Nexus仓库对于匿名用户是只读的,因此为了可以部署构件,还须要在settings.xml文件中配置认证信息。eclipse
<servers> <server> <id>gpcmarket-releases</id> <username>user</username> <password>pwd</password> </server> <server> <id>gpcmarket-snapshots</id> <username>user</username> <password>pwd</password> </server> </servers>
固然对于一些因为许可证因素等没法发布到公共仓库的构件,咱们只能本身下载而后经过Nexus的界面手动上传到私服中。
到此为止,Nexus私服的搭建与配置基本完毕,下面是关于权限管理的问题。
出于安全性考虑、须要对Nexus仓库进行权限管理、好比只有管理员才能配置Nexus、某个项目组有特定的仓库、等等。maven
Nexus是基于权限(Privilege)作访问控制的。一个用户能够被赋予一个或者多个角色、一个角色能够包含一个或者多个权限、还能够包含一个或者多个角色。用户必须拥有相应的角色继而拥有相应权限、才能作相应操做,可是有一点要注意这里的权限都是基于仓库的,即对仓库的增删改查权限。ui
在3.x版本中, Nexus只预约义了两个重要的角色:url
Nexus提供了一系列可配置的调度任务来方便用户管理系统。用户能够设定这些任务运行的方式,例如天天、每周等。调度任务会在适当的时候在后台运行。
要创建一个调度任务,单击左边导航菜单中的“Scheduled Tasks”,而后再右边的界面上单击Add按钮,按照页面上的提示填写相关内容。Nexus包含了如下几种类型的调度任务:spa