Docker build Nexus private server-build Nexus private server

Maven private server construction

1. What is nexus?

  • Nexus is a powerful Maven warehouse manager, which greatly simplifies the maintenance of its own internal warehouses and the access to external warehouses
  • Nexus is not the core concept of Maven, it is just a special Maven repository derived from it. For Maven, there are only two types of warehouses: local warehouses and remote warehouses.
  • Nexus is just one of the Maven repositories
  • Maven workflow

img

2. Why use nexus?

  • We can store the jar package we made in nexus for other friends to use
  • He provides powerful warehouse management functions
  • Speeding up Maven Build When building projects, Maven will keep requesting external repositories, which is very time-consuming. Use private server: Maven only checks the data in the local area network to improve the build speed

Three, build Nexus in Docker

Environmental requirements

  • There is an dockerenvironment

  • There is an docker-composeenvironment

1. Find a suitable place to store nexus

root@yufire:/usr/local/docker# mkdir nexus
root@yufire:/usr/local/docker/nexus# ls
root@yufire:/usr/local/docker/nexus# 

2. Write docker-compose file

vi docker-compose.yml

docker-compose.yml

version: '3.5'
services:
  nexus:
    restart: always 
    image: sonatype/nexus3:3.23.0 # nexus版本
    container_name: nexus # 容器名称
    environment:  # 环境变量
      INSTALL4J_ADD_VM_PARAMS: -XX:ActiveProcessorCount=4
    ports: # 映射的端口  
      - 80:8081
    volumes:  # 数据卷
      - ./data:/nexus-data
  • The set environment variable means the number of CPU cores of the machine. If the number of CPU cores of the machine where Nexus is deployed is less than 4 cores, Nexus will have a warning.

Create data folder

mkdir data  # data要与 volumes里的data对应
chmod 777 data # 赋予权限 否则nexus启动可能报错

Run docker-compose

docker-compose up -d  # -d 为守护态运行(后台运行)
Creating network "nexus_default" with the default driver # 创建了一个名称为 nexus_default的网络
Pulling nexus (sonatype/nexus3:3.23.0)... # 拉取 nexus镜像
3.23.0: Pulling from sonatype/nexus3
78afc5364ad2: Pull complete
58e1deb9693d: Pull complete
138a5c9bc330: Pull complete
a9af31a2240a: Pull complete
Digest: sha256:cb51454c5951f1330bfc6a8315b6a2b332f6292dbecee67b3e5a6d9ea4945ee9
Status: Downloaded newer image for sonatype/nexus3:3.23.0
Creating nexus ... done # 创建容器完成
  • Wait for the docker image to be downloaded

After the above is successful, check the docker running status

docker ps 
CONTAINER ID        IMAGE                    COMMAND                  CREATED              STATUS              PORTS                  NAMES
68609501ea22        sonatype/nexus3:3.23.0   "sh -c ${SONATYPE_DI…"   About a minute ago   Up About a minute   0.0.0.0:80->8081/tcp   nexus

After confirming that the startup is successful, visit the address of nexus

Fourth, build Nexus in Windows

  • pending upgrade

Five, configure Nexus private server

http://ip

img

Docker view Nexus initial password

Open the admin.password file in the data folder to view the password

root@yufire:/usr/local/docker/nexus# pwd
/usr/local/docker/nexus 
root@yufire:/usr/local/docker/nexus# ls
data  docker-compose.yml
root@yufire:/usr/local/docker/nexus# cd data/  # 进入data目录
root@yufire:/usr/local/docker/nexus/data# ls  查看data中的文件
admin.password  blobs  cache  db  elasticsearch  etc  generated-bundles  instances  karaf.pid  keystores  lock  log  orient  port  restore-from-backup  tmp
root@yufire:/usr/local/docker/nexus/data# cat admin.password   查看 初始密码
d85f05a9-861f-4b60-b7ee-5e7d9f83e9f6 # 复制初始密码 登陆

Windows view Nexus initial password

After the first successful login

  1. Click Next
  2. Reset password

img

  1. Configure anonymous access

img

Anonymous access

  • That is, a password must be set when accessing the warehouse, otherwise access is prohibited
  • The configuration password can be configured in the Maven configuration file

Configure warehouse

Settings -> Repositories -> Create repository

img

Find maven2(proxy)

img

Fill in warehouse information

img

  1. Set the warehouse name
  2. Set the warehouse path
  3. otherdefaultJust fine
  4. Find the drop-down Create repositorybutton to click to complete the creation

After creation, return to the warehouse list

img

Configure aliyun warehouse in maven-public

img

img

  • Drag aliyun-nexus directly to the first position on the right

img

  • Pay attention to the order!

Click the Save button to save

6. Use Nexus in the project

**Find the servers node of the Maven configuration file and configure authentication information**

<servers>
    <server>
        <id>releases</id>
        <username>admin</username>
        <password>123123</password>
    </server>
    <server>
        <id>snapshots</id>
        <username>admin</username>
        <password>123123</password>
    </server>
</servers>

The difference between Snapshots and Releases

  • nexus-releases: used to release the Release version
  • nexus-snapshots: Used to release Snapshot version (snapshot version)

Configuration in the project

Open pom.xml and add the following information

<distributionManagement>  
  <repository>  
    <id>releases</id>  
    <name>Nexus Release Repository</name>  
    <url>http://127.0.0.1:8081/repository/maven-releases/</url>  
  </repository>  
  <snapshotRepository>  
    <id>snapshots</id>  
    <name>Nexus Snapshot Repository</name>  
    <url>http://127.0.0.1:8081/repository/maven-snapshots/</url>  
  </snapshotRepository>  
</distributionManagement> 
  • Hereid Must be consistent with the id of the Nexus authentication information in the Maven configuration file
  • Revision of the project has SNAPSHOTidentified, will be posted to the Nexus Snapshots Repository, or posted to the Nexus Release Repository, and to match the authorized account according to ID.

Publish project to Nexus private server

maven deploy

Seven, attached

1. Upload a third-party JAR package

Nexus 3.0 does not support page upload, you can use the maven command:

# 如第三方JAR包:aliyun-sdk-oss-2.2.3.jar
mvn deploy:deploy-file 
  -DgroupId=com.aliyun.oss 
  -DartifactId=aliyun-sdk-oss 
  -Dversion=2.2.3 
  -Dpackaging=jar 
  -Dfile=D:\aliyun-sdk-oss-2.2.3.jar 
  -Durl=http://127.0.0.1:8081/repository/maven-3rd/ 
  -DrepositoryId=nexus-releases
  • -DrepositoryId=nexus-releasesCorresponds to the settings.xmlID name Servers configuration. (Authorization)

2. Maven configuration

Portal Maven configuration

end

Author: yufire © [email protected]

Guess you like

Origin blog.csdn.net/weixin_43420255/article/details/106414133