docker安装maven私服

一、nexus3安装

1、安装镜像

docker pull sonatype/nexus3:3.32.0

2、新建目录

mkdir -p /home/apps/nexus/data

3、创建并启动

docker run \
-d \
--name nexus \
--restart=always \
--privileged=true \
-p 6006:8081 \
-v /home/apps/nexus/data:/var/nexus-data \
sonatype/nexus3:3.32.0

4、查nexus日志

docker logs nexus

5、开放6006端口

firewall-cmd --zone=public --add-port=6006/tcp --permanent

# 重新载入
firewall-cmd --reload

6、查看默认密码

# 进入容器
docker exec -it nexus /bin/bash

# 查看默认密码
vi /opt/sonatype/sonatype-work/nexus3/admin.password

7、登录网页

  • 登录:ip地址:6006
  • 帐号:admin,密码:从上面复制

二、创建私服仓库

1、修改中央仓库地址为阿里云

  • 点击设置->Repositories->maven-central->Remote storage,修改为阿里云仓库地址http://maven.aliyun.com/nexus/content/groups/public

2、创建仓库

  • 创建二个仓库,类型为maven2(hosted),名称为rapid-releases、rapid-snapshots

3、创建用户

  • 选择Users,创建用户,注意为用户选择相应的权限

三、nginx域名配置

server{
    listen 80;
    server_name nexus.abc.com;

    location / {
        proxy_pass http://127.0.0.1:6014;
        proxy_set_header Host $host;
        proxy_connect_timeout 3600;
        proxy_send_timeout 3600;
        proxy_read_timeout 3600;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_buffering off;
        proxy_request_buffering off;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto http;
    }
}

四、发布jar包到私服

1、修改maven配置文件settings.xml

    <server>
      <id>rapid-releases</id>
      <username>admin</username>
      <password>123456</password>
    </server>
    <server>
      <id>rapid-snapshots</id>
      <username>admin</username>
      <password>123456</password>
    </server>

2、修改项目的pom文件

  • 修改项目版本为SNAPSHOT/RELEASE,并发布到指定maven私服地址
    <groupId>com.cloud</groupId>
    <artifactId>rapid-common</artifactId>
    <version>1.0.1-SNAPSHOT</version>
    <name>rapid-common</name>

    <distributionManagement>
        <repository>
            <!--此名称要和.m2/settings.xml中设置的ID一致 -->
            <id>rapid-releases</id>
            <url>http://192.168.3.12:6006/repository/rapid-releases/</url>
        </repository>
        <snapshotRepository>
            <!--此名称要和.m2/settings.xml中设置的ID一致 -->
            <id>rapid-snapshots</id>
            <url>http://192.168.3.12:6006/repository/rapid-snapshots/</url>
        </snapshotRepository>
    </distributionManagement>

3、上传项目jar包到maven私服(IDEA)

  • 点击右侧MAVEN->项目->Lifecycle->deploy

image

五、引用maven私服jar包

<dependencies>
    <dependency>
        <groupId>com.cloud</groupId>
        <artifactId>rapid-common</artifactId>
        <version>1.0.1-SNAPSHOT</version>
    </dependency>
</dependencies>

<repositories>
    <repository>
        <id>rapid-releases</id>
        <url>http://192.168.3.12:6006/repository/rapid-releases/</url>
    </repository>
    <repository>
        <id>rapid-snapshots</id>
        <url>http://192.168.3.12:6006/repository/rapid-snapshots/</url>
    </repository>
</repositories>

六、参考

posted @ 2021-08-24 16:01  吕林光  阅读(506)  评论(0编辑  收藏  举报