1. 安装jdk1.8
2. 下载nexus3包文件
下载地址:链接: https://pan.baidu.com/s/1q7wXzt60RDS_oxYXuCltlA 密码: qacr
3. 安装步骤
| 1. 解压压缩包:
#解压后又2个目录 #nexus-3.18.1-01:包含了 Nexus 运行所需要的文件。是 Nexus 运行必须的 #sonatype-work:包含了 Nexus 生成的配置文件、日志文件、仓库文件等。当我们需要备份 Nexus 的时候默认备份此目录即可 |
| 2. 配置nexus环境变量
#修改环境变量 vim /etc/profile export export NEXUS_HOME=/usr/local/nexus/nexus-3.25.0-03
#使配置生效 source /etc/profile
#修改启动用户 vim /usr/local/nexus/nexus-3.25.0-03/bin/nexus.rc #run_as_user="" #内容就这一行,放开注释,填写用户即可
#修改端口 vim /usr/local/nexus/nexus-3.25.0-03/etc/nexus-default.properties #默认是8081
#最后启动nexus cd /usr/local/nexus/nexus-3.25.0-03/bin ./nexus start的启动方式是后台启动 ./nexus run的启动方式是前台启动,显示日志。 ./nexus status
#访问http://ip:8081,
登陆用户admin 密码存放在:/usr/local/nexus/sonatype-work/nexus3/admin.password 目录 #修改成了admin ,admin123
#开机自启动 vim /etc/rc.d/rc.local
/usr/local/nexus/nexus-3.25.0-03/bin/nexus start #添加这一行内容
chmod 755 /etc/rc.d/rc.local |
| 如果不知道仓库的目录,可通过查询命令: [[email protected] repository]# find / -name 'maven-central' -type d
#目录地址如下
|
4. 批量导入本地仓库
如图点击顺序
选择maven2(hosted)
按照自身需求填写如下选项
点击Create repository
然后在页面上可以看到我们新建的仓库
点击进入,看到该仓库的URL,记下。192.168.174.129是我的Centos虚拟机的ip地址
创建TOUCH MAVENIMPORT.SH脚本,批量上传
1.先将本地maven/repository仓库打一个完整的zip压缩包
2.上传到linux目录,如:/opt
3.解压repository.zip
4.进入repository目录
5.创建touch mavenimport.sh脚本,写入以下内容;
#!/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}/{} ;
6.输入chmod a+x mavenimport.sh进行可执行授权
7.执行导入命令
./mavenimport.sh -u admin -p admin123 -r http://192.168.6.52:8081/repository/shwz-releases/
8.等待全部导入完毕后,在Nexus上刷新即可看到已导入的jar