一、什么是Maven私服
私服是指私有服务器,是架设在局域网的一种特殊的远程仓库,目的是代理远程仓库及部署第三方构建。有了私服之后,当 Maven 需要下载构件时,直接请求私服,私服上存在则下载到本地仓库;否则,私服请求外部的远程仓库,将构件下载到私服,再提供给本地仓库下载
二、Maven安装
1.下载地址
http://maven.apache.org/download.cgi
2. 服务器安装jdk环境
一定要按照Jdk而不是jre
yum install java-1.8.0-openjdk-devel.x86_64
参考:https://www.cnblogs.com/yaun1498078591/p/10368884.html
3.安装Maven
3.安装Maven
[root@localhost ~]# cd /data/tools/maven
[root@localhost src]# wget https://mirrors.tuna.tsinghua.edu.cn/apache/maven/maven-3/3.8.1/binaries/apache-maven-3.8.1-bin.tar.gz
[root@localhost src]# tar -zxvf apache-maven-3.8.1-bin.tar.gz
4.配置系统环境变量
[root@localhost jvm]# vim /etc/profile
export JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.292.b10-2.el8.x86_64
export CLASSPATH=.:$JAVA_HOME/jre/lib/rt.jar:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
export PATH=$PATH:$JAVA_HOME/bin
export MAVEN_HOME=/data/tools/maven/apache-maven-3.8.1
export PATH=$PATH:$MAVEN_HOME/bin
[root@localhost jvm]# source /etc/profile
5.验证Maven是否安装成功
执行命令:mvn -v
Apache Maven 3.8.1 (05c21c65bdfed0f71a2f2ada8b84da59348c4c5d)
Maven home: /data/tools/maven/apache-maven-3.8.1
Java version: 1.8.0_292, vendor: Red Hat, Inc., runtime: /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.292.b10-2.el8.x86_64/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "4.18.0-301.1.el8.x86_64", arch: "amd64", family: "unix"
三、安装Nexus
1.下载地址
https://www.sonatype.com/download-oss-sonatype
2. 源码安装
[root@localhost jvm]# cd /data/tools/maven/
[root@localhost src]# wget https://sonatype-download.global.ssl.fastly.net/nexus/3/nexus-3.11.0-01-unix.tar.gz
[root@localhost src]# tar -zxvf nexus-3.11.0-01-unix.tar.gz
[root@localhost src]# mv nexus-3.11.0-01 /usr/local/nexus
3. 启动nexus
默认端口8081,如果要修改端口可以在etc/nexus-default.properties配置中修改
启动:
[root@localhost src]# /data/tools/maven/nexus-3.11.0-01/bin/nexus start
WARNING: ************************************************************
WARNING: Detected execution as "root" user. This is NOT recommended!
WARNING: ************************************************************
Starting nexus
上面在启动过程中出现警告:不推荐使用root用户启动,创个新用户就行。这个警告不影响nexus的正常访问和使用。
4. 开放8081端口
[root@localhost src]# firewall-cmd --add-port=8081/tcp --permanent
success
[root@localhost src]# firewall-cmd --reload
success
5. 浏览器访问
这就把nexus服务搭建好了,默认管理员账号密码是admin/admin123
参考链接:https://my.oschina.net/u/2963821/blog/1806035
三、项目中配置使用
1.在开发代码电脑配置maven
本地写代码电脑的maven配置settings.xml 配置如下:
usr-releases
admin
admin123
usr-snapshots
admin
admin123
......
usr-private-repo
usr-releases
http://192.168.0.80:9001/repository/maven-releases/
true
false
usr-snapshots
http://192.168.0.80:9001/repository/maven-snapshots/
false
true
always
......
usr-private-repo
2.在项目的Pom文件配置distributionManagement,deploy时这样才能将打的jar包上传到私服
usr-releases
http://192.168.0.80:9001/repository/maven-releases/
usr-snapshots
http://192.168.0.80:9001/repository/maven-snapshots/