1,使用 docker-compose 构建

1,创建一个目录,并创建配置文件,可以选择在自己有读写权限的任意目录下创建

cd /root
mkidr nexues
cd nexus
vi docker-compose.yml

2,docker-compose.yml 配置文件

version: '3.1'
services:
  nexus:
    restart: always
    image: sonatype/nexus3
    container_name: nexus
    ports:
      - 8081:8081
    volumes:
      - /usr/local/docker/nexus/data:/nexus-data

3,启动

docker-compose up -d   // 后台启动命令
docker logs -f nexus   // 监听容器日志

4,如果出现权限不足的情况,说明是数据卷的权限不够,我们需要将数据卷的权限设置为 777

chmod 777 /root/nexus/data

5,启动成功后,可以在浏览器中输入 http://ip:8081 访问窗口后台管理界面,出现如下画面为安装成功

2,登入

1,默认账号为:admin

2,获取自动生成的密码(第一次登入后会让你修改密码)

cd /root/neuxs/data
cat admin.password 

3,该镜像 需要的 cpu 和 内存较大,请选择性能较好的主机配置

4,在项目中使用

1,maven 配置文件的配置 setting.xml 加入两个 server

<server>
  <id>nexus-releases</id>
  <username>admin</username>
  <password>你的密码</password>
</server>
<server>
  <id>nexus-snapshots</id>
  <username>admin</username>
  <password>你的密码</password>
</server>
  1. nexus-releases: 用于发布 Release 版本
  2. nexus-snapshots: 用于发布 Snapshot 版本(快照版)
  3. 在项目 pom.xml 中设置的版本号添加 SNAPSHOT 标识的都会发布为 SNAPSHOT 版本,没有 SNAPSHOT 标识的都会发布为 RELEASE 版本
  4. SNAPSHOT 版本会自动加一个时间作为标识,如:1.0.0-SNAPSHOT 发布后为变成 1.0.0-SNAPSHOT-20180522.123456-1.jar

2,配置项目上传 jar 包 pom.xml 配置

<distributionManagement>  
  <repository>  
    <id>nexus-releases</id>  
    <name>Nexus Release Repository</name>  
    <url>http://192.168.200.100:8081/repository/maven-releases/</url>  
  </repository>  
  <snapshotRepository>  
    <id>nexus-snapshots</id>  
    <name>Nexus Snapshot Repository</name>  
    <url>http://192.168.200.100:8081/repository/maven-snapshots/</url>  
  </snapshotRepository>  
</distributionManagement> 
  1. ID 名称必须要与 settings.xml 中 Servers 配置的 ID 名称保持一致
  2. ip 地址是你安装的主机的 IP

3,上传到私服的 maven 命令

mvn deploy

4, 直接上传 jar 包的 maven 命令

mvn deploy:deploy-file          ^
  -DgroupId=坐标                ^
  -DartifactId=坐标             ^ 
  -Dversion=版本                ^
  -Dpackaging=jar               ^
  -Dfile=jar本地的物理地址       ^ 
  -Durl=http://192.168.200.100:8081/repository/maven-3rd/  ^ 
  -DrepositoryId=nexus-releases ^

3,拉取私有仓库的地址 pom.xml

<repositories>
    <repository>
        <id>nexus</id>
        <name>Nexus Repository</name>
        <url>http://192.168.200.100:8081/repository/maven-public/</url>
        <snapshots>
            <enabled>true</enabled>
        </snapshots>
        <releases>
            <enabled>true</enabled>
        </releases>
    </repository>
</repositories>
<pluginRepositories>
    <pluginRepository>
        <id>nexus</id>
        <name>Nexus Plugin Repository</name>
        <url>http://192.168.200.100:8081/repository/maven-public/</url>
        <snapshots>
            <enabled>true</enabled>
        </snapshots>
        <releases>
            <enabled>true</enabled>
        </releases>
    </pluginRepository>
</pluginRepositories>
posted on 2020-03-15 17:11  被遗忘的优雅  阅读(570)  评论(0编辑  收藏  举报