目录
1.安装maven仓库依赖
安装maven:
2.安装nexus
3.批量上传jar
nexus仓库依赖jdk,maven,我用的版本如下:
jdk8
maven 3.6.3
nexus 3.37.1
jdk本机已安装,没有安装的可以自己参考linux安装jdk的方法
可以yum安装也可以通过包安装,我这里通过包安装,使用的3.6.3版本
官网下载版本:
Index of /dist/maven/maven-3
下载对应的bin文件压缩包上传到/usr/local文件夹下,解压文件
[root@bd local]# tar -zxvf apache-maven-3.6.3-bin.tar.gz
配置环境变量
[root@bd local]# vi /etc/profile
#添加如下内容
export MAVEN_HOME=/usr/local/apache-maven-3.6.3
export PATH=$MAVEN_HOME/bin:$PATH
#保存
:wq
刷新环境变量
[root@bd local]# source /etc/profile
检查maven版本,如下正确显示版本号则代表maven安装完成
[root@bd local]# mvn -v
Apache Maven 3.6.3 (cecedd343002696d0abb50b32b541b8a6ba2883f)
Maven home: /usr/local/apache-maven-3.6.3
Java version: 1.8.0_262, vendor: Oracle Corporation, runtime: /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.262.b10-1.el7.x86_64/jre
Default locale: zh_CN, platform encoding: UTF-8
OS name: "linux", version: "3.10.0-1160.el7.x86_64", arch: "amd64", family: "unix"
nexus官网下载地址:Download Archives - Repository Manager 3,下载OSS版本(免费)
上传到/usr/local文件夹下,解压
[root@bd local]# tar -zxvf nexus-3.37.1-01-unix.tar.gz
修改配置文件
[root@bd conf]# vim /usr/local/nexus-3.37.1-01/etc/nexus-default.properties
application-port= //你的端口号
application-host= //你的ip
进入bin目录下,启动服务:
[root@bd bin]# ./nexus start
****************************************
WARNING - NOT RECOMMENDED TO RUN AS ROOT
****************************************
If you insist running as root, then set the environment variable RUN_AS_USER=root before running this script.
报错,根据提示信息,修改系统配置
[root@bd bin]# vim /etc/profile
#添加
export RUN_AS_USER=root
[root@bd bin]# source /etc/profile
再次启动
[root@bd bin]# ./nexus start
****************************************
WARNING - NOT RECOMMENDED TO RUN AS ROOT
****************************************
Starting Nexus OSS...
Started Nexus OSS.
根据配置的ip+port,浏览器打开,点击右上角sign in登陆
会提示admin初始密码位于/usr/local/sonatype-work/nexus3/admin.password下
cat /usr/local/sonatype-work/nexus3/admin.password
找到密码登陆后需重置密码,设置为自己的密码
首先新建仓库,点击create repository,类型选择maven2 (hosted)
仓库名随便起
在服务器上新建一个文件夹,导入本地maven仓库的jar包,我这是在/home文件夹下
在新文件夹下创建一个 shell 脚本:
[root@bd bd-repo]# touch mavenimport.sh
#赋予权限
[root@bd bd-repo]# chmod +x mavenimport.sh
[root@bd bd-repo]# vim 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}/{} ;
执行shell脚本(根据自己仓库配置修改)
./mavenimport.sh -u admin -p admin -r http://xxxxx:8081/repository/bd_repo/
耐心等待执行完毕,登陆对应仓库查看: