前置条件要求存在jdk1.8的环境
这里之所以要特地提下下载是因为这个东西是真难下,我的电脑本身一直没有安装过专门的下载工具(度盘不算),一般下载都是走网盘或者浏览器直接下载,这次无论度盘的离线下载还是浏览器下载都非常慢甚至下载失败(100M光纤),在服务器上使用wget同样很慢,最后安装了迅雷使用迅雷下载后速度快很多,看来下载确实需要专业的下载工具,下载完成后上传到服务器上即可,当然也可以直接在服务器上使用wget下载,如果不嫌弃下载的慢的话:
官方下载页:https://www.sonatype.com/download-oss-sonatype
实际资源地址
wget https://sonatype-download.global.ssl.fastly.net/repository/repositoryManager/3/nexus-3.10.0-04-unix.tar.gz
#解压
tar -zvxf nexus-3.10.0-04-unix.tar.gz
#解压的文件夹移到nexus(自动创建)
mv nexus-3.10.0-04/ /usr/local/nexus
#防火墙开启8081端口,该端口是nexus的默认端口(在/usr/local/nexus/etc/nexus-default.properties文件中)
vi /etc/sysconfig/iptables
# 在打开的文件中加入如下内容
-A INPUT -p tcp -m state --state NEW -m tcp --dport 8081 -j ACCEPT
#启动 ps 我安装时第一次启动使用./nexus start 访问不到web页面,使用run命令可以,之后使用start也可以了
./nexus run &
#启动成功会有如下信息
WARNING: ************************************************************
WARNING: Detected execution as "root" user. This is NOT recommended!
WARNING: ************************************************************
Starting nexus
上面启动成功后会警告不要使用root用户启动,这里可以新建一个用户,也可以指定root用户启动,使他不出现警告,下面配置指定root用户启动
#该文件在bin目录下和启动程序nexus同级 vi nexus.rc
run_as_user=root
我这里没有下载索引,以前配置过nenus2.x时下载过全部索引,很大很慢,下载了一晚上,不下载索引并不影响使用,这里会同步当前项目使用的依赖到私服的索引中,有新的依赖从私服中获取也会更新对应的索引,下面介绍一种离线安装的方式
在maven的setting.xml文件中配置私服配置,这种方式配置后所有本地使用该配置的maven项目的pom文件都无需配置私服下载相关配置
<profiles>
<profile>
<id>mycof</id>
<repositories>
<!-- 私有库地址-->
<repository>
<id>nexus</id>
<url>http://192.168.16.30:8081/repository/maven-public/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
<pluginRepositories>
<!--插件库地址-->
<pluginRepository>
<id>nexus</id>
<url>http://192.168.16.30:8081/repository/maven-public/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>
</profile>
激活使用上面的配置
<!--激活profile-->
<activeProfiles>
<activeProfile>mycof</activeProfile>
</activeProfiles>
指定镜像代理为我们的私服
<mirror>
<id>nexus-myself</id>
<!--*指的是访问任何仓库都使用我们的私服-->
<mirrorOf>*</mirrorOf>
<name>Nexus myself</name>
<url>http://192.168.16.30:8081/repository/maven-public/</url>
</mirror>
这种配置是修改单个项目的pom文件,无需修改maven的setting配置
<repositories>
<repository>
<id>nexus</id>
<url>http://192.168.16.30:8081/repository/maven-public/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
建议使用全局的setting配置,一个项目组共用一个maven的setting配置,项目中就无需配置下载相关的私服仓库配置
对于中央仓库没有的jar包,需要我们自己将jar包发布到私服中去,其中jar包主要分为两类,一类是本地自己开发供给项目组其余同事使用,这种直接配置项目的pom文件和maven的setting文件,之后deploy发布即可发布到,另一类是第三方jar包,可以直接使用web页面上传并设置对应GAV即可
出现uploading信息并且没报错说明上传成功
到对应仓库查看
注意:
对于第三方jar包的上传采用nenus提供的web界面上传,上传成功后需要使用该jar包的话,依赖中填写自定义的GAV即可
本博客所有文章如无特别注明均为原创。作者:陌晴
版权所有:《电光石火》 => Nexus3.x安装及配置
本文地址:https://cloud.tencent.com/developer/article/1147232
欢迎转载!复制或转载请以超链接形式注明,文章为 陌晴 原创,并注明原文地址 Nexus3.x安装及配置,谢谢。