Maven 私服搭建
1. 下载Nexus
登录https://www.sonatype.com/download-oss-sonatype,下载最新的Nexus版本。 我这里使用的是nexus-3.16.1-02版本;
SRE实战 互联网时代守护先锋,助力企业售后服务体系运筹帷幄!一键直达领取阿里云限量特价优惠。
2. 将tar包上传到服务器/usr/local/目录下解压, 这个时候会出现 nexus-3.16.1-02、sonatype-work 两个文件夹
tar -zxvf nexus-3.16.1-02-unix.tar.gz
3. 修改配置文件(修改端口号)
cd /usr/local/nexus-3.16.1-02/etc vim nexus-default.properties
4. 启动Nexus
cd /usr/local/nexus-3.16.1-02/bin ./nexus start --后台启动
./nexus run --前台启动,显示日志
启动用户是root的时候会出现下面的警告,可以通过修改/usr/local/nexus-3.16.1-02/bin/nexus.rc文件解决;
#run_as_user="root"
vim nexus.rc
5. 服务启动完以后,输入Ip地址+端口访问(8081),Nexus默认的账户名和密码是是 admin/admin123
6. 配置私有库,将私有库添加到http://192.168.209.128:8081/repository/maven-public/中。
7. 一般私服都是存在内网环境,Nexus3.0以后需要通过命令命令将具体的jar包打到私服中;
#将下面的脚本丢到需要上传jar包的文件目录下
chmod u+x mavenimport.sh
./mavenimport.sh -u admin -p admin123 -r http://192.168.209.128:8081/repository/lingan/
#!/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}/{} ;
8. 设置登录用户权限,建议将admin注销,重新定义一个登录用户。在Nexus 3.0 这个版本中我直接删除admin会报错,但是设置为不可用没有问题;
9. 配置Maven,修改Maven中的Setting文件
<server> <id>release</id> <username>******</username> <password>******</password> </server> <server> <id>snapshot</id> <username>******</username> <password>******</password> </server> <mirror> <id>nexus-public</id> <mirrorOf>*</mirrorOf> <url>http://192.168.209.128:8081/repository/maven-public/</url> </mirror>

更多精彩