一.简介
Nexus是Maven的私有仓库管理器,用来管理项目依赖,自定义仓库,并且提供高级功能,如持续集成和部署。maven编译---本地私服nexus----本地私服nexus(无)---阿里云maven源
二.nexus安装部署
下载地址https://help.sonatype.com/en/download.html
0.安装jdk
#关闭防火墙和selinux
systemctl stop firewalld
systemctl disable firewalld
sed -i 's/^SELINUX=enforcing$/SELINUX=disabled/' /etc/selinux/config
setenforce 0
#安装openjdk8
yum -y install java-8
#或rpm包安装
rpm -ivh jdk-8u351-linux-x64.rpm
#修改文件描述符
ulimit -n 131072
echo "* - nofile 131072" >>/etc/security/limits.conf
1.安装nexus
#上传安装包到任意目录
rz nexus-3.13.0-01-unix.tar.gz
#解压到指定目录
mkdir -p /app/tools/
tar xf nexus-3.13.0-01-unix.tar.gz -C /app/tools/
#创建软连接
ln -s /app/tools/nexus-3.13.0-01 /app/tools/nexus
#配置环境变量
echo "export PATH=/app/tools/nexus/bin:$PATH" >>/etc/profile
source /etc/profile
#启动服务
nexus start
#查看端口
netstat -tlunp | grep 8081
#服务管理
/app/tools/nexus/bin/nexus {start|stop|run|run-redirect|status|restart|force-reload}
2.web登录
http://192.168.77.152:8081 账号和口令是admin/admin123
3.配置 私服nexus连接阿里云maven源
设置---Pepositories---maven-central---Proxy---填写阿里云maven代理地址---save
#仓库类型
maven-central:maven中央库
maven-releases:私库发行版jar
maven-snapshots:私库快照
maven-public:以上三个仓库组合对外提供服务,在本地maven基础配置settings.xml或项目pom.xml中使用
#代理
http://maven.aliyun.com/nexus/content/group/public/
三.kenkins上安装的maven配置
1.配置 jenkins上maven连接私服nexus
#修改maven配置文件
cd /app/tools/maven/conf/
cp settings.xml settings.xml.bak
cat >settings.xml<<'EOF'
<?xml version="1.0" encoding="UTF-8"?>
<settings xmlns="http://maven.apache.org/SETTINGS/1.2.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.2.0 https://maven.apache.org/xsd/settings-1.2.0.xsd">
<pluginGroups>
</pluginGroups>
<proxies>
</proxies>
<servers>
<server>
<id>my-nexus-releases</id>
<username>admin</username>
<password>admin123</password>
</server>
<server>
<id>my-nexus-snapshot</id>
<username>admin</username>
<password>admin123</password>
</server>
</servers>
<mirrors>
<mirror>
<id>nexus</id>
<mirrorOf>*</mirrorOf>
<url>http://192.168.77.152:8081/repository/maven-public</url>
</mirror>
</mirrors>
<profiles>
<profile>
<id>nexus</id>
<repositories>
<repository>
<id>central</id>
<url>http://192.168.77.152:8081/repository/maven-public</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>central</id>
<url>http://192.168.77.152:8081/repository/maven-public</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>
</profile>
</profiles>
<activeProfiles>
<activeProfile>nexus</activeProfile>
</activeProfiles>
</settings>
EOF
四.编译测试
1.下载一个带pom.xml的源码
2.编译测试
#解压
tar xf hello-word-war-master.tar.gz
cd hello-word-war-master
#maven编译
mvn clean package
编译过程