centos7安装Nexus(Maven私服)与配置使用教程

之前有位大佬问我,他说有个第三方的Jar包,在idea导出库中使用,现在要部署上线测试,要如何导进去打包。

我说,不用那么麻烦,搞个Nexus私服,将Jar上传上去,然后配置Maven的setting文件指向私服就可以了。

下面介绍Nexus的安装和配置使用。

环境:

bash 复制代码
[root@localhost bin]# java -version
openjdk version "1.8.0_382"
OpenJDK Runtime Environment (build 1.8.0_382-b05)
OpenJDK 64-Bit Server VM (build 25.382-b05, mixed mode)
bash 复制代码
[root@localhost bin]# cat /proc/version
Linux version 3.10.0-1160.71.1.el7.x86_64 (mockbuild@kbuilder.bsys.centos.org) (gcc version 4.8.5 20150623 (Red Hat 4.8.5-44) (GCC) ) #1 SMP Tue Jun 28 15:37:28 UTC 2022
1、安装

下载安装包:

下载地址

创建目录:

bash 复制代码
 mkdir nexus

移动压缩包:

bash 复制代码
mv nexus-3.62.0-01-unix.tar.gz  ./nexus

解压:

bash 复制代码
tar -xvf nexus-3.62.0-01-unix.tar.gz

创建目录:

bash 复制代码
mkdir /usr/local/nexus

移动解压后的文件到新建的目录:

bash 复制代码
mv nexus-3.62.0-01 /usr/local/nexus/

切换到bin目录:

bash 复制代码
/usr/local/nexus/nexus-3.62.0-01/bin

编辑配置文件nexus.rc:

powershell 复制代码
run_as_user="root"

启动nexus:

bash 复制代码
./nexus run &

访问:http://192.168.213.5:8081/

登录:

提示登录密码在:/usr/local/nexus/sonatype-work/nexus3/admin.password

点击左侧的browse,有各种repository的type:

  • Group:这是一个仓库聚合的概念,用户仓库地址选择Group的地址,即可访问Group中配置的所有仓库资源,访问顺序取决于配置顺序3.x默认Releases,Snapshots,Central,可在web页面配置在web界面点开
  • Hosted:私有仓库,专门用来存储我们自己生成的jar文件
  • Snapshots:本地项目的快照仓库
  • Releases: 本地项目发布的正式版本
  • Proxy:公网上发布的jar 例如:spring
  • Central:中央仓库

配置maven的setting.xml:

xml 复制代码
在maven的setting.xml文件中配置私服配置,这种方式配置后所有本地使用该配置的maven项目的pom文件都无需配置私服下载相关配置
<?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">

    
    <servers>
        <server>
            <id>nexus-releases</id>
            <username>deployment</username>
            <password>deployment123</password>
        </server>
        <server>
            <id>nexus-snapshots</id>
            <username>deployment</username>
            <password>deployment123</password>
        </server>
    </servers>
    
    <mirrors>
        
        <mirror>
            <id>nexus-releases</id>
            <mirrorOf>*</mirrorOf>
            <url>http://192.168.213.5:8081/content/groups/public/</url>
            <!-- <url>http://repo1.maven.org/maven2/</url> -->
        </mirror>
        <mirror>
            <id>nexus-snapshots</id>
            <mirrorOf>*</mirrorOf>
            <url>http://192.168.213.5:8081/content/repositories/snapshots/</url> 
            <!-- <url>http://repo1.maven.org/maven2/</url> -->
        </mirror>

    </mirrors>

    <profiles>
        <profile>
            <id>nexus</id>
            <repositories>                            
                <repository>
                    <id>nexus-releases</id>
                    <url>http://192.168.213.5:8081/content/groups/public/</url> 
                    <!-- <url>http://repo1.maven.org/maven2/</url> -->
                    <releases>
                        <enabled>true</enabled>
                    </releases>
                    <snapshots>
                        <enabled>true</enabled>
                        <updatePolicy>always</updatePolicy>
                    </snapshots>
                </repository>
                <repository>
                    <id>nexus-snapshots</id>
                    <url>http://192.168.213.5:8081/content/repositories/snapshots/</url> 
                    <!-- <url>http://repo1.maven.org/maven2/</url> -->
                    <releases>
                        <enabled>true</enabled>
                    </releases>
                    <snapshots>
                        <enabled>true</enabled>
                        <updatePolicy>always</updatePolicy>
                    </snapshots>
                </repository>
            </repositories>
            <pluginRepositories>
                <pluginRepository>
                    <id>nexus-releases</id>
                    <url>http://192.168.213.5:8081/content/groups/public/</url> 
                    <!-- <url>http://repo1.maven.org/maven2/</url> -->
                    <releases>
                        <enabled>true</enabled>
                    </releases>
                    <snapshots>
                        <enabled>true</enabled>
                        <updatePolicy>always</updatePolicy>
                    </snapshots>
                </pluginRepository>
                <pluginRepository>
                    <id>nexus-snapshots</id>
                <url>http://192.168.213.5:8081/content/repositories/snapshots/</url> 
                    <!-- <url>http://repo1.maven.org/maven2/</url> -->
                    <releases>
                        <enabled>true</enabled>
                    </releases>
                    <snapshots>
                        <enabled>true</enabled>
                        <updatePolicy>always</updatePolicy>
                    </snapshots>
                </pluginRepository>				
            </pluginRepositories>
        </profile>
    </profiles>

    <activeProfiles>
        <activeProfile>nexus</activeProfile>
        <!--<activeProfile>dev</activeProfile>-->
    </activeProfiles>

</settings>
相关推荐
羱滒几秒前
sql调优之数据库开发规范
java·数据库·数据库开发
Forget the Dream29 分钟前
设计模式之责任链模式
java·c++·设计模式·责任链模式
jonyleek32 分钟前
「JVS更新日志」低代码、企业会议、智能BI、智能排产2.26更新说明
java·大数据·低代码·数据分析·软件需求
计算机小白一个1 小时前
蓝桥杯 Java B 组之最短路径算法(Dijkstra、Floyd-Warshall)
java·数据结构·算法·蓝桥杯
曼岛_1 小时前
[密码学实战]Java实现SM4加解密(ecb,cbc)及工具验证
java·密码学
Forget the Dream1 小时前
设计模式之代理模式
java·c++·设计模式·代理模式
帅的飞起来1 小时前
设计模式--spring中用到的设计模式
java·spring·设计模式
張葒兵3 小时前
记一次命令行启动springboot项目的问题 java -jar的问题
java·spring boot·jar
zr想努力3 小时前
Lua的table类型的增删改查操作
java·开发语言·lua
Forget the Dream4 小时前
设计模式之享元模式
java·c++·设计模式·享元模式