搭建nexus私服部署项目

1 nexus 安装与配置

1.1 安装 nexus

访问官网: https://help.sonatype.com/repomanager3/product-information/download

下载最新即可
在 linux 中找地方上传安装包
我放在 /usr/local/softwares/nexus
解压文件

tar -zxvf **.tar.gz
1.2 nexus 配置

进入 bin 文件夹

cd /usr/local/softwares/nexus/nexus-3.61.0-02/bin
vim nexus.vmoptions 

根据自己电脑配置适当调节第一、二、三的大小

配置端口
默认端口为 8081,如果需要在要在文件中配置端口。(如果不需改端口,此处可以忽略)

cd ..
cd etc
 nano nexus-default.properties


开启防火墙

[root@localhost etc]# firewall-cmd --add-port=8081/tcp --permanent 
success
[root@localhost etc]# firewall-cmd --reload
success
1.3 运行 nexus

返回 bin 文件夹

./nexus start

1.4 查看 nexus 的运行状态

如图则成功访问

1.5 修改管理员密码

点击右上角 sign in
首先我们要去 linux 中查看初始密码

cd /usr/local/softwares/nexus/sonatype-work/nexus3
cat admin.password

可以看到初始密码
初始账户为 admin, 首次登录后会让你修改密码

2 创建私有仓库

  • 创建 private-repository

maven-releases (Version policy=Release)默认只允许上传不带 SNAPSHOT 版本尾缀的包, 默认部署策略是 Disable redeploy 不允许重复上传相同版本号信息的 jar, 避免包版本更新以后使用方无法获取到最新的包。

maven-snapshots (Version policy=Snapshot)只允许上传带 SNAPSHOT 版本尾缀的包, 默认部署策略是 Allow redeploy, 允许重复上传相同版本号信息的 jar, 每次上传的时候会在 jar 的版本号上面增加时间后缀信息。

maven-central 中央仓库的拷贝, 如果环境可以访问中央仓库, 则可以获取到相关的包, 否则没用

maven-public 仓库组, 不是实际个一个仓库地址, 只是将现有的组合到一次, 可以通过它看到所属组内全部仓库的 jar 信息

设置如图, 其中 name 自定义, 其余几项请保持一致

  • 创建 private-releases 和 private-snapshots


    这三个仓库的区别只有version policy不同
    创建完毕后返回,点击 maven-public

    将这三个包导入右边

    保存即可

3 上传本地文件到自定义仓库中

在 nexus 目录下新建 repo 文件夹, 将本地仓库内容上传, 本地仓库位置见 1.3
在本地仓库上传的文件夹 repo 下创建一个 shell 脚本,命名 localrepository.Sh

nano localrepository.sh
#!/bin/bash
while getopts ":r:u:p:" opt; do
    case $opt in
        r) REPO_URL="$OPTARG"
        ;;
        u) USERNAME="$OPTARG"
        ;;
        p) PASSWORD="$OPTARG"
        ;;
    esac
done

find . -type f -not -path './mavenimport\.sh*' -not -path '*/\.*' -not -path '*/\^archetype\-catalog\.xml*' -not -path '*/\^maven\-metadata\-local*\.xml' -not -path '*/\^maven\-metadata\-deployment*\.xml' | sed "s|^\./||" | xargs -I '{}' curl -u "$USERNAME:$PASSWORD" -X PUT -v -T {} ${REPO_URL}/{} ;

添加权限

chmod +x localrepository.sh

执行以下命令

localrepository.sh -u nexus用户名 -p nexus密码 -r 仓库地址

4 修改 IDEA 配置


始终更新快照 打勾

同时对新项目也进行同样操作

在 maven 的 conf/settings. Xml 中配置 server

  • 此处设置服务信息,id 和上文设置的仓库名相同,账号密码即 nexus 的账号密码
<servers>
    <!-- server
     | Specifies the authentication information to use when connecting to a particular server, identified by
     | a unique name within the system (referred to by the 'id' attribute below).
     |
     | NOTE: You should either specify username/password OR privateKey/passphrase, since these pairings are
     |       used together.
     |
     -->
    <server>
      <id>private-repository</id>
      <username>admin</username>
      <password>123456</password>
    </server>
	  <server>
		  <id>private-releases</id>
		  <username>admin</username>
		  <password>123456</password>
	  </server>
	  <server>
		  <id>private-snapshots</id>
		  <username>admin</username>
		  <password>123456</password>
	  </server>


	  <!-- Another sample, using keys to authenticate.
      <server>
        <id>siteServer</id>
        <privateKey>/path/to/private/key</privateKey>
        <passphrase>optional; leave empty if not used.</passphrase>
      </server>
      -->
  </servers>
  • 此处设置镜像信息,id 随意,name 随意,星号代表全部,url 地址从 nexus 中复制
<mirrors>
        <!-- mirror
         | Specifies a repository mirror site to use instead of a given repository. The repository that
         | this mirror serves has an ID that matches the mirrorOf element of this mirror. IDs are used
         | for inheritance and direct lookup purposes, and must be unique across the set of mirrors.
         |
        <mirror>
          <id>mirrorId</id>
          <mirrorOf>repositoryId</mirrorOf>
          <name>Human Readable Name for this Mirror.</name>
          <url>http://my.repository.com/repo/path</url>
        </mirror>
         -->
        <mirror>
            <id>aliyunmaven</id>
            <mirrorOf>central</mirrorOf>
            <name>阿里云公共仓库</name>
            <url>https://maven.aliyun.com/repository/public</url>
        </mirror>
        <mirror>
            <id>privatemaven</id>
            <mirrorOf>*</mirrorOf>
            <name>私人仓库</name>
            <url>http://192.168.188.128:8081/repository/maven-public/</url>
        </mirror>

    </mirrors>
  • 此处设置 profile
<profile>
            <id>jdk-1.8</id>
            <activation>
                <activeByDefault>true</activeByDefault>
                <jdk>1.8</jdk>
            </activation>

            <properties>
                <maven.compiler.source>1.8</maven.compiler.source>
                <maven.compiler.target>1.8</maven.compiler.target>
                <maven.compiler.compilerVersion>1.8</maven.compiler.compilerVersion>
            </properties>
        </profile>
        <profile>
            <!-- profile 的 id -->
            <id>nexus</id>
            <repositories>
                <repository>
                    <!-- 仓库 id,repositories 可以配置多个仓库,保证 id 不重复 -->
                    <id>nexus</id>
                    <!-- 仓库地址,即 nexus 仓库组的地址 -->
                    <url>http://192.168.188.128:8081/repository/maven-public/</url>
                    <!-- 是否下载 releases 构件 -->
                    <releases>
                        <enabled>true</enabled>
                    </releases>
                    <!-- 是否下载 snapshots 构件 -->
                    <snapshots>
                        <enabled>true</enabled>
                    </snapshots>
                </repository>
            </repositories>
            <pluginRepositories>
                <!--  插件仓库,maven 的运行依赖插件,也需要从私服下载插件  -->
                <pluginRepository>
                    <!--  插件仓库的 id 不允许重复,如果重复后边配置会覆盖前边  -->
                    <id>public</id>
                    <name>Public Repositories</name>
                    <url>http://192.168.188.128:8081/repository/maven-public/</url>
                    <!-- 是否下载 releases 构件 -->
                    <releases>
                        <enabled>true</enabled>
                    </releases>
                    <!-- 是否下载 snapshots 构件 -->
                    <snapshots>
                        <enabled>true</enabled>
                    </snapshots>
                </pluginRepository>
            </pluginRepositories>
        </profile>
    </profiles>
  • 最后,在结束标签前添加表示启用
<activeProfiles>
        <activeProfile>nexus</activeProfile>
    </activeProfiles>

5 导入依赖

在 maven 中配置镜像,在项目的 pom. Xml 文件中添加

<distributionManagement>
        <snapshotRepository>
            <id>private-snapshots</id>
            <url>http://192.168.188.128:8081/repository/private-snapshots/</url>
        </snapshotRepository>
        <repository>
            <id>private-releases</id>
            <url>http://192.168.188.128:8081/repository/private-releases/</url>
        </repository>
    </distributionManagement>
    <repositories>
        <repository>
            <id>nexus</id>
            <url>http://192.168.188.128:8081/repository/maven-public/</url>
            <releases>
                <enabled>true</enabled>
            </releases>
            <snapshots>
                <enabled>true</enabled>
            </snapshots>
        </repository>
    </repositories>

测试部署

部署成功

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值