Nexus是一个强大的仓库管理器,极大地简化了内部仓库的维护和外部仓库的访问。html
2016年4月6日Nexus 3.0版本发布,相较2.x版本有了很大的改变:java
对低层代码进行了大规模重构,提高性能,增长可扩展性以及改善用户体验。node
升级界面,极大的简化了用户界面的操做和管理。nginx
提供新的安装包,让部署更加简单。npm
增长对Docker, NeGet, npm, Bower的支持。ubuntu
提供新的管理接口,以及加强对自动任务的管理。vim
下载地址:http://www.sonatype.com/downl...浏览器
官方文档:http://books.sonatype.com/nex...oracle
PDF文档:http://books.sonatype.com/nex...app
Windows / Linux / Mac
Java JDK 8+
Apache Maven 3.0+
示例基于Ubuntu 16.04 LTS环境,安装前检查JDK:
nexus@ubuntu:~$ java -version java version "1.8.0_91" Java(TM) SE Runtime Environment (build 1.8.0_91-b14) Java HotSpot(TM) 64-Bit Server VM (build 25.91-b14, mixed mode)
该步骤不是必须的,但为了更好的管理和维护,建议建立一个管理用户。
# 使用root权限建立一个用户 root@ubuntu:~# adduser nexus ## 给nexus用户添加sudo权限 # 1. 给root写的权限 root@ubuntu:~# chmod u+w /etc/sudoers # 2. 编辑/etc/sudoers,在root下添加nexus用户权限 nexus ALL=(ALL) ALL # 3. 保存后撤回写的权限 root@ubuntu:~# chmod u-w /etc/sudoers
root@ubuntu:~# su nexus nexus@ubuntu:~$ wget https://sonatype-download.global.ssl.fastly.net/nexus/3/nexus-3.0.1-01-unix.tar.gz nexus@ubuntu:~$ ls nexus-3.0.1-01-unix.tar.gz
nexus@ubuntu:~$ tar -zxvf nexus-3.0.1-01-unix.tar.gz # 查看安装目录 nexus@ubuntu:~$ ls nexus-3.0.1-01/ bin data deploy etc lib LICENSE.txt NOTICE.txt public system # bin: 启动脚本和启动时的配置文件 # data: 数据存储目录 # etc: 配置文件 # lib: Apache Karaf的二进制包 # public: 公共资源 # system: 系统依赖的组件和插件 # 指定JDK版本(可选) nexus@ubuntu:~$ vim nexus-3.0.1-01/bin/nexus INSTALL4J_JAVA_HOME_OVERRIDE="/usr/lib/jvm/java-8-oracle" # 修改使用的用户(不建议使用root用户) nexus@ubuntu:~/nexus-3.0.1-01$ vim bin/nexus.rc run_as_user="nexus"
nexus@ubuntu:~$ ./nexus-3.0.1-01/bin/nexus start # 可选的命令:{start|stop|run|run-redirect|status|restart|force-reload}
打开浏览器输入:http://127.0.0.1:8081
如下配置均为可选,更详细的配置请查看官方文档
Nexus 3.0 的默认配置:
nexus@ubuntu:~$ cat nexus-3.0.1-01/bin/nexus.vmoptions -Xms1200M -Xmx1200M -XX:+UnlockDiagnosticVMOptions -XX:+UnsyncloadClass -Djava.net.preferIPv4Stack=true -Dkaraf.home=. -Dkaraf.base=. -Dkaraf.etc=etc -Djava.util.logging.config.file=etc/java.util.logging.properties -Dkaraf.data=data -Djava.io.tmpdir=data/tmp -Dkaraf.startLocalConsole=false
修改JVM配置:
请根据系统实际状况配置
其余的JVM参数也能够添加到这里
-Xms1500M -Xmx2G
nexus@ubuntu:~$ vim nexus-3.0.1-01/etc/org.sonatype.nexus.cfg application-port=9081
重启后访问:http://localhost:9081
nexus@ubuntu:~$ vim nexus-3.0.1-01/bin/nexus.vmoptions # 默认存储目录 -Dkaraf.data=data -Djava.io.tmpdir=data/tmp
Apache httpd.
ProxyRequests Off ProxyPreserveHost On <VirtualHost: *:80> ServerName www.example.com ServerAdmin admin@example.com ProxyPass /nexus http://localhost:8081/ ProxyPassReverse / http://localhost:8081/ ErrorLog logs/nexus/error.log CustomLog logs/nexus/access.log common </VirtualHost>
nginx.
http { proxy_send_timeout 120; roxy_read_timeout 300; proxy_buffering off; keepalive_timeout 5 5; tcp_nodelay on; server { listen *:80; server_name www.example.com; # allow large uploads of files - refer to nginx documentation client_max_body_size 1G # optimize downloading files larger than 1G - refer to nginx doc before adjusting # proxy_max_temp_file_size 2G location /nexus { proxy_pass http://localhost:8081/nexus; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } } }
Apache httpd. Ensure Apache httpd is loading mod_ssl.
Listen 443 ProxyRequests Off ProxyPreserveHost On <VirtualHost *:443> SSLEngine on SSLCertificateFile "example.pem" SSLCertificateKeyFile "example.key" ServerName repo.example.com ServerAdmin admin@example.com ProxyPass / http://localhost:8081/ ProxyPassReverse / http://localhost:8081/ RequestHeader set X-Forwarded-Proto "https" ErrorLog logs/repo.example.com/nexus/error.log CustomLog logs/repo.example.com/nexus/access.log common </VirtualHost>
nginx. Make sure nginx is compiled using the --with-http_ssl_module option.
http { proxy_send_timeout 120; proxy_read_timeout 300; proxy_buffering off; keepalive_timeout 5 5; tcp_nodelay on; server { listen *:443; server_name repo.example.com; # allow large uploads of files - refer to nginx documentation client_max_body_size 1G # optimize downloading files larger than 1G - refer to nginx doc before adjusting #proxy_max_temp_file_size 2G ssl on ssl_certificate example.pem; ssl_certificate_key example.key; location / { proxy_pass http://localhost:8081/; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For ←- $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto "https"; } } }
顾名思义是代理第三方仓库的,如:
maven-central
nuget.org-proxy
版本策略(Version Policy):
Release: 正式版本
Snapshot: 快照版本
Mixed: 混合模式
布局策略(Layout Policy):
Strict:严格
Permissive:宽松
存储本地上传的组件和资源的,如:
maven-releases
maven-snapshots
nuget-hosted
部署策略(Deployment Policy):
Allow Redeploy:容许从新部署
Disable Redeploy:禁止从新部署
Read-Only:只读
一般包含了多个代理仓库和宿主仓库,在项目中只要引入仓库组就能够下载到代理仓库和宿主仓库中的包,如:
maven-public
nuget-group
用户界面的操做和管理相对简单,请参考官方文档
在Maven settings.xml中添加Nexus认证信息:
<server> <id>nexus-releases</id> <username>admin</username> <password>admin123</password> </server> <server> <id>nexus-snapshots</id> <username>admin</username> <password>admin123</password> </server>
nexus-releases: 用于发布Release版本
nexus-snapshots: 用于发布Snapshot版本
Release版本与Snapshot版本的区分:
Release: 4.3.0 Snapshot: 4.3.0-SNAPSHOT
在项目POM.xml中设置的版本号添加SNAPSHOT标识的都会发布为SNAPSHOT版本,没有SNAPSHOT标识的都会发布为Release版本。
SNAPSHOT版本会自动加一个时间做为标识,如:4.3.0-SNAPSHOT
发布后为变成4.3.0-SNAPSHOT-20160712.114532-1.jar
在POM.xml中添加如下代码:
<distributionManagement> <repository> <id>nexus-releases</id> <name>Nexus Release Repository</name> <url>http://127.0.0.1:8081/repository/maven-releases/</url> </repository> <snapshotRepository> <id>nexus-snapshots</id> <name>Nexus Snapshot Repository</name> <url>http://127.0.0.1:8081/repository/maven-snapshots/</url> </snapshotRepository> </distributionManagement>
注意事项:
ID名称必需要与settings.xml中Servers配置的ID名称保持一致。
项目版本号中有SNAPSHOT标识的,会发布到Nexus Snapshots Repository, 不然发布到Nexus Release Repository,并根据ID去匹配受权帐号。
mvn deploy
Nexus 3.0不支持页面上传,可以使用maven命令:
# 如第三方JAR包:aliyun-sdk-oss-2.2.3.jar mvn deploy:deploy-file -DgroupId=com.aliyun.oss -DartifactId=aliyun-sdk-oss -Dversion=2.2.3 -Dpackaging=jar -Dfile=D:\aliyun-sdk-oss-2.2.3.jar -Durl=http://127.0.0.1:8081/repository/maven-3rd/ -DrepositoryId=nexus-releases
注意事项:
建议在上传第三方JAR包时,建立单独的第三方JAR包管理仓库,便于管理有维护。(maven-3rd)
-DrepositoryId=nexus-releases
对应的是settings.xml中Servers配置的ID名称。(受权)
<repositories> <repository> <id>nexus</id> <name>Nexus Repository</name> <url>http://127.0.0.1:8081/repository/maven-public/</url> <snapshots> <enabled>true</enabled> </snapshots> <releases> <enabled>true</enabled> </releases> </repository> </repositories> <pluginRepositories> <pluginRepository> <id>nexus</id> <name>Nexus Plugin Repository</name> <url>http://127.0.0.1:8081/repository/maven-public/</url> <snapshots> <enabled>true</enabled> </snapshots> <releases> <enabled>true</enabled> </releases> </pluginRepository> </pluginRepositories>
注意事项:
在开发中若是有严格的管理要求,可将SNAPSHOT和RELEASE单独配置。
有插件依赖时配置插件仓库,默认会使用Maven中央仓库。