一. 下载安装
nexus版本:nexus-3.20.1-01-win64
二. 运行
-
解压后的目录
-
启动
前台启动:nexus.exe /run 服务启动: 安装nexus服务:管理员身份运行cmd–>执行nexus.exe /install 服务名 卸载nexus服务:管理员身份运行cmd–>执行nexus.exe /uninstall 服务名 启动nexus服务:管理员身份运行cmd–>执行nexus.exe /start 服务名 停止nexus服务:管理员身份运行cmd–>执行nexus.exe /stop 服务名 查看nexus服务:管理员身份运行cmd–>执行nexus.exe /status 服务名 注意:后台运行这种方式,nexus服务只要安装一次,安装后默认操作系统启动而启动,无需执行每次运行启动命令
-
访问
初始访问地址:
http://localhost:8081
初始访问用户:
admin
初始访问密码: 存在
nexus-3.20.1-01-win64\sonatype-work\nexus3\admin.password
文件里当你登录后admin.password修改密码后会自动删除
三.配置参数
系统配置文件: nexus-3.20.1-01-win64\nexus-3.20.1-01\etc\nexus-default.properties
四.仓库类别
以maven仓库为例, 初始会创建四种仓库
其中又有三种Type
- group: 表示分组仓库,默认将
maven-central
、maven-releases
和maven-snapshots
三个仓库组合在一起对外提供服务,简化了maven客户端在settings.xml或pom.xml中的配置 - proxy: 表示代理仓库,用来代理远程仓库–下载组件时,如果代理仓库搜索不到,则把请求转发到远程仓库(默认为 https://repo1.maven.org/maven2/),并从远程仓库下载,然后将该组件缓存到代理仓库,当再次请求该组件时,则直接到代理仓库下载,不会再次请求远程仓库
- hosted: 表示宿主仓库,主要用来部署团队内部使用的内部组件,其中maven-releases用来部署团队内部的发布版本组件
maven-snapshots
用来部署团队内部的快照版组件
五.新增仓库并暴露出服务
点击后输入仓库名创建, 完成后将新创建的仓库加入group
中暴露出去
六.上传本地jar包至私服
-
新增shell脚本
mavenimport.sh
, 将其放至需要上传jar包的根目录#!/bin/bash # copy and run this script to the root of the repository directory containing files # this script attempts to exclude uploading itself explicitly so the script name is important # Get command line params while getopts ":r:u:p:" opt; do case $opt in r) REPO_URL="$OPTARG" ;; u) USERNAME="$OPTARG" ;; p) PASSWORD="$OPTARG" ;; esac done find . -type f -not -path './mavenimport\.sh*' -not -path '*/\.*' -not -path '*/\^archetype\-catalog\.xml*' -not -path '*/\^maven\-metadata\-local*\.xml' -not -path '*/\^maven\-metadata\-deployment*\.xml' | sed "s|^\./||" | xargs -I '{}' curl -u "$USERNAME:$PASSWORD" -X PUT -v -T {} ${REPO_URL}/{} ;
-
执行脚本
./mavenimport.sh -u username -p pass -r http://ip:port/repository/your_repositor_name/
注意此脚本需在Linux环境执行, 如在Windows环境, 需要借助Git的
Git Bash
工具 -
当上传完成后, 可修改Maven的settings.xml使用私服
<mirror> <id>imoveMirror</id> <mirrorOf>external:*</mirrorOf> <name>Thtf Maven mirror Nexus</name> <url>http://nexus.svr:8081/repository/maven-public/</url> </mirror>