maven 安装
下载
wget https://mirrors.bfsu.edu.cn/apache/maven/maven-3/3.6.3/binaries/apache-maven-3.6.3-bin.tar.gz
安装
tar -zxvf apache-maven-3.6.3-bin.tar.gz -C /usr/local/
mv /usr/local/apache-maven-3.6.3/ /usr/local/maven/
mkdir /usr/local/maven/repo
配置
<!-- 配置本地仓库 -->
<localRepository>/usr/local/maven/repo</localRepository>
<!-- 配置阿里云镜像 -->
<mirror>
<id>nexus-aliyun</id>
<mirrorOf>central</mirrorOf>
<name>Nexus aliyun</name>
<url>http://maven.aliyun.com/nexus/content/groups/public</url>
</mirror>
环境变量
# 进入配置文件
vim /etc/profile
# 添加 maven 环境变量
MAVEN_HOME=/usr/local/maven
export PATH=${MAVEN_HOME}/bin:${PATH}
# 刷新配置
source /etc/profile
验证
mvn -v
nexus 安装
nexus 下载
wget https://download.sonatype.com/nexus/3/latest-unix.tar.gz
nexus 安装
mkdir /usr/local/nexus/
tar -zxvf latest-unix.tar.gz -C /usr/local/nexus/
修改环境变量
vim /etc/profile
export NEXUS_HOME=/usr/local/nexus/nexus-3.20.1-01
export PATH=$PATH:$NEXUS_HOME/bin
source /etc/profile
修改启动用户
vim /usr/local/nexus/nexus-3.20.1-01/bin/nexus
# 命令模式查找
/run_as_user
# 将 run_as_user=true 改为 false
修改端口
vim /usr/local/nexus/nexus-3.20.1-01/etc/nexus-default.properties
启动nexus
nexus start
nexus status
开机自启动
vim /etc/rc.d/rc.local
# 添加这一行内容
/usr/local/nexus/nexus-3.20.1-01/bin/nexus start
chmod 755 /etc/rc.d/rc.local
jdk 8
# 若 jdk 版本不为 8,nexus-3.x 报错
# 解决方案
# 下载 jdk1.8 并解压缩放在本地,不需要给它配置环境变量,将 Nexus 的启动 Jdk 改成本地的 jdk1.8 所在的位置
vim /usr/local/nexus/nexus-3.20.1-01/bin/nexus
# 查找 jdk 路径
/JAVA_HOME_OVERRIDE
# 更换对应的 jdk8 路径
# 重新启动
nexus start
启动后自动停止
# nexus 所需运行内存大于服务器,将运行内存改小即可
vim /usr/local/nexus/nexus-3.20.1-01/bin/nexus.vmoptions
# 修改运行内存
-Xms256m
-Xmx256m
-XX:MaxDirectMemorySize=512m
# 重启服务
nexus restart
nexus 测试
# nexus 地址 ip:port
http://127.0.0.1:8081
# 登录 admin
# 查看 admin 密码
more /usr/local/nexus/sonatype-work/nexus3/admin.password
# 按照提示执行即可
私服配置
nexus 添加仓库
asaawan-releases
asaawan-snapshots
maven 配置
<?xml version="1.0" encoding="UTF-8"?>
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
<!-- 配置本地仓库 -->
<localRepository>/usr/local/maven/repo</localRepository>
<pluginGroups></pluginGroups>
<proxies></proxies>
<servers>
<!-- 配置私服仓库与访问用户和密码 -->
<server>
<id>asaawan-releases</id>
<username>admin</username>
<password>admin</password>
</server>
<server>
<id>asaawan-snapshots</id>
<username>admin</username>
<password>admin</password>
</server>
</servers>
<mirrors>
<!-- 配置阿里云镜像 -->
<mirror>
<id>nexus-aliyun</id>
<mirrorOf>central</mirrorOf>
<name>Nexus aliyun</name>
<url>http://maven.aliyun.com/nexus/content/groups/public</url>
</mirror>
<!-- 配置私服 -->
<mirror>
<id>nexus-asaawan</id>
<mirrorOf>*</mirrorOf>
<url>http://42.193.49.173:8081/repository/maven-public/</url>
</mirror>
</mirrors>
<profiles></profiles>
</settings>
pom.xml 配置
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.asaawan</groupId>
<artifactId>nexus-demo</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>pom</packaging><!-- pom 根目录 -->
<properties>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
<spring.version>5.1.9.RELEASE</spring.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencyManagement>
<dependencies>
<!--spring环境-->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>${spring.version}</version>
</dependency>
</dependencies>
</dependencyManagement>
<build>
<!--插件-->
<pluginManagement>
<plugins>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.21.0</version>
</plugin>
</plugins>
</pluginManagement>
</build>
<!--私服配置-->
<distributionManagement>
<repository>
<id>asaawan-releases</id>
<url>http://42.193.49.173:8081/repository/asaawan-releases/</url>
</repository>
<snapshotRepository>
<id>asaawan-snapshots</id>
<url>http://42.193.49.173:8081/repository/asaawan-snapshots/</url>
</snapshotRepository>
</distributionManagement>
</project>
发布资源到私服
mvn deploy
私服查看上传资源
http://127.0.0.1:8081