Installation and use of neven private service Nexus

Transferred from: https://blog.csdn.net/ThinkWon/article/details/94346681

Whenever and wherever possible, dry cargo is read more and technical resources are obtained. Source code and learning materials are collected. Please pay attention to source code community official account (ydmsq666) and Gabor WeChat (guyun297890152), and enter WeChat technology exchange group and QQ technology exchange group (183198395).

Introduction to Nexus
Nexus is the Maven warehouse manager. If you use maven, you can download the required artifact s from the Maven central warehouse, but this is usually not a good practice. You should set up a maven warehouse server locally to maintain the local warehouse while acting as a proxy for the remote warehouse, so as to save bandwidth and time. Nexus can meet such needs. In addition, it also provides a powerful warehouse management function, component search function, which is based on REST. The friendly UI is a REST client of extjs, which occupies less memory and is based on a simple file system rather than a database. These advantages make it increasingly the most popular Maven warehouse manager. In addition, nexus can manage Docker images.

Note: for Maven profile, please refer to Maven profile

Benefits of private service
When there is no private server: if there is no local warehouse, go to the central warehouse to download

After setting up the private server: no local warehouse, download from the private server again, no private server, download from the central warehouse again

  • Reduce network bandwidth traffic
  • Accelerate Maven build
  • Deploying third party artifacts
  • Improve stability and control
  • Reduce the load of central warehouse

Using Docker to install Nexus private server
Note: please install Docker yourself first

Find Nexus3 image

docker search nexus3

Pull Nexus3 image

docker pull sonatype/nexus3

Note: the latest version of Nexus 3.18 has some problems in downloading dependency. It is recommended to install Nexus 3.17

The specific error is as follows: Caused by: org.apache.maven.wagon.authorization.AuthorizationException: Not authorized

View image

docker images

Run Nexus container

#Enter / opt directory, create host mount directory and set permissions
cd /opt
mkdir nexus-data
chown -R 200 nexus-data
#Run nuxus private server
# -d: Background operation
# -p: The first parameter is the host port and the second parameter is the container port
# --Name: name the container
# --restart always restarts a container when it exits
# -v: Mount the configuration, log, data file and other folders in the container to the specified directory of the host
docker run -d --name nexus3 -p 8081:8081 --restart always -v /opt/nexus-data:/nexus-data sonatype/nexus3

If no permission is set, the following error will be reported when running nexus

Warning:  Cannot open log file: ../sonatype-work/nexus3/log/jvm.log
Warning:  Forcing option -XX:LogFile=/tmp/jvm.log
Unable to update instance pid: Unable to create directory /nexus-data/instances
/nexus-data/log/karaf.log (No such file or directory)
Unable to update instance pid: Unable to create directory /nexus-data/instances
mkdir: cannot create directory '../sonatype-work/nexus3/log': Permission denied
mkdir: cannot create directory '../sonatype-work/nexus3/tmp': Permission denied
OpenJDK 64-Bit Server VM warning: Cannot open file ../sonatype-work/nexus3/log/jvm.log due to No such file or directory

Login to Nexus

Access web address: http://ip:8081

Since version 3.17, the default password is no longer admin123, but randomly generated. The first login page will show the password of the admin user in / nexus data/ admin.password

Note: when we just installed the / nexus data directory, we attached it to the host's / opt / nexus data directory, so the password is in / opt / nexus data/ admin.password

Execute the command VIM / opt / nexus data/ admin.password , you can view the password such as 9c3ac7fb-4264-4457-8e48-4aa84c71e7ad, and then log in. User name: admin, password: / opt / nexus data/ admin.password The code inside

After logging in, the user will be asked to set a new password. Here, set the user name and password to admin/admin123

After login, the interface is as follows

Default warehouse description

Maven central: Maven Central Library, default from https://repo1.maven.org/maven2/ Pull jar
 Maven releases: private library release jar. Please set the Deployment policy to Allow redeploy for initial installation
 Maven snapshots: private library snapshot (debug version) jar
 Maven public: warehouse grouping, combining the above three warehouses to provide external services, and basic configuration in local maven settings.xml Or project pom.xml Used in

Warehouse type

Group: This is a concept of warehouse aggregation. Users can access the warehouse configured in the group by selecting the address of the group as their warehouse address, which is convenient for developers to set their own warehouse. Maven public is a group type warehouse. Multiple warehouses are set internally. The access order depends on the configuration order. 3.x default Releases, Snapshots, Central. Of course, you can also set them yourself.	
Hosted: private warehouse, internal project release warehouse, specially used to store jar files generated by ourselves
 Third party: third party jar not published to the public network (3. X removed)
Snapshots: snapshot repository for local projects
 Releases: official release of local project
 Proxy: the proxy type, to find the data warehouse from the remote central warehouse (you can click the value of the Remote Storage attribute in the Configuration tab of the corresponding warehouse to find the path of the remote warehouse being proxied). For example, you can configure the Alibaba cloud maven warehouse
 Central: central warehouse
 Apache Snapshots: Apache private snapshot repository (3.x removed)

Configure alicloud public warehouse

The default search method of Nexus's Maven group is Maven releases > Maven snapshots > Maven central. We add an Alibaba cloud warehouse in the middle to speed up the access.

Select proxy type

 

Fill in the following information

Warehouse Name: maven aliyun
Alibaba cloud remote Maven warehouse address: http://maven.aliyun.com/nexus/content/groups/public/
Other options: default is OK

 

Modify the warehouse reference and order in Maven public:

 

At this point, the configuration is complete! When maven uses the maven public warehouse address, we will access it in the following order: local warehouse > private maven releases > private maven snapshots > remote Alibaba cloud maven warehouse > remote central warehouse.

Maven configuration uses Nexus private server
Maven configuration private server download dependency mode
There are two ways for maven to configure private server download

  • setting.xml : this file is configured for global mode

  • pom.xml : this file is configured for project exclusive mode

If pom.xml and setting.xml Also configured to pom.xml Subject to

setting.xml File configuration

There is no need to configure it at this time pom.xml File, you can use private server to download jar dependency package

Configure private server image

<mirrors>   
    <mirror>
      <!--Unique identifier of the mirror. id To distinguish between different mirror Element. -->
      <id>nexus-releases</id>
      <!--*It refers to using our private server when visiting any warehouse-->
      <mirrorOf>*</mirrorOf>    
      <!--The URL. Building the system will give priority to using this URL,Instead of using the default server URL.  -->
      <url>http://10.172.0.201:8081/repository/maven-public/</url>     
    </mirror>    
    <mirror>     
      <id>nexus-snapshots</id>     
      <mirrorOf>*</mirrorOf>     
      <url>http://10.172.0.201:8081/repository/maven-snapshots/</url>     
    </mirror>  
</mirrors>

The URL of the image can be copied directly from the copy button on the page

Configure to download jar package from private server

<profiles>

    <profile>
        <!--profile Of id-->
        <id>nexus</id>
        <repositories>
            <repository>
                <!--Warehouse id,repositories Multiple warehouses can be configured to ensure id No repetition-->
                <id>nexus-releases</id>
                <!--Warehouse address, i.e nexus Address of the warehouse group-->
                <url>http://nexus-releases</url>
                <releases>
                    <!--Download or not releases component-->
                    <enabled>true</enabled>
                </releases>
                <snapshots>
                    <enabled>true</enabled>
                </snapshots>
            </repository>
            <repository>
                <id>nexus-snapshots</id>
                <url>http://nexus-snapshots</url>
                <releases>
                    <enabled>true</enabled>
                </releases>
                <snapshots>
                    <enabled>true</enabled>
                </snapshots>
            </repository>
        </repositories>
        <pluginRepositories>
            <!-- Plug in repository, maven You need to download the plug-in from the private server -->
            <pluginRepository>
                <!-- Plug in repository id Repeat is not allowed. If repeat the back configuration, the front will be overwritten -->
                <id>nexus-releases</id>
                <url>http://nexus-releases</url>
                <releases>
                    <enabled>true</enabled>
                </releases>
                <snapshots>
                    <enabled>true</enabled>
                </snapshots>
            </pluginRepository>
            <pluginRepository>
                <id>nexus-snapshots</id>
                <url>http://nexus-snapshots</url>
                <releases>
                    <enabled>true</enabled>
                </releases>
                <snapshots>
                    <enabled>true</enabled>
                </snapshots>
            </pluginRepository>
        </pluginRepositories>
    </profile>  

</profiles>

<!--activation profile-->
<activeProfiles>    
    <activeProfile>nexus</activeProfile>    
</activeProfiles>

 

pom.xml File configuration

If you configure pom.xml , then pom.xml Subject to

<repositories>
	<repository>
		<id>maven-nexus</id>
		<name>maven-nexus</name>
		<url>http://10.172.0.201:8081/repository/maven-public/</url>
		<releases>
			<enabled>true</enabled>
		</releases>
		<snapshots>
			<enabled>true</enabled>
		</snapshots>
	</repository>
</repositories>

Configure Maven connection Private Server package upload project

Step 1, modify setting.xml File, specifying the user name and password of releases and snapshots server

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

The second step, in the project's pom.xml Add the distribution management node to the file

Note: the id in the repository needs to be consistent with the server id name in step 1

<distributionManagement>
	<repository>
		<id>releases</id>
		<name>Releases</name>
		<url>http://10.172.0.201:8081/repository/maven-releases/</url>
	</repository>
	<snapshotRepository>
		<id>snapshots</id>
		<name>Snapshot</name>
		<url>http://10.172.0.201:8081/repository/maven-snapshots/</url>
	</snapshotRepository>
</distributionManagement>

Step 3: release

mvn deploy

Log in to Nexus and check that there are related dependent packages in the corresponding warehouse.

Note the following:

  • If the project version number ends with - SNAPSHOT, it will be published to the snapshots SNAPSHOT version warehouse
  • If the project version number ends with - releases or nothing, it will be released to the releases official version warehouse

Upload the third-party jar package

 

Tags: Maven nexus xml Docker

Posted on Sun, 28 Jun 2020 23:34:32 -0400 by error_22