In java development, the use of maven is essential. For our locally configured settings.xml file, we usually configure a foreign warehouse or Alibaba Cloud warehouse. If you are using a foreign warehouse, download The speed is relatively slow. If you use the Alibaba Cloud warehouse, the download speed is relatively impressive, but if the Internet speed is not good, or if there is no Internet, it will be even more difficult to download. So this time reflects the importance of our private server.
When we need a jar package for a certain maven project, for example: spring-web.jar
first check whether there is such a jar package in the local warehouse (the version also needs to be judged). If there is, you don’t need to download it. If not, download it. And save it in the local warehouse, and then if you need it later, you don’t need to download it.
Private server download address: download link
If you can't download it, you can use the command:
wget http://sonatype-download.global.ssl.fastly.net/nexus/oss/nexus-2.11.4-01-bundle.tar.gz
Or Baidu Cloud
链接: https://pan.baidu.com/s/1YvdbLU3vesImq06EYABXrw 提取码: fhnv 复制这段内容后打开百度网盘手机App,操作更方便哦
Unzip after uploading to the server
tar -zxvf nexus-2.11.4-01-bundle.tar.gz
Then move the decompressed file to usr/local
mv nexus-2.11.4-01 /usr/local
If you are running as a root user, it is recommended to add this configuration in the /etc/profile folder
export RUN_AS_USER=root
Then turn off the firewall
systemctl stop firewalld.service
After the setting is complete, we start to start the private server
. There is a nexus command in the bin directory to
start
./nexus start
After startup, let’s test it. The default port is 8081. When the following interface appears, the access is successful.
Access to the nexus server, and you can log in.
The default user name is admin, the password is admin123, and
click repositories for warehouse management
The first public Repositories, the type is group, which is simply understood as a collection of warehouses. The following warehouses are the elements that can be added to this collection.
Only a single url can be provided externally, as shown in the figure above: http://127.0.0.1:8081/nexus/content/groups/public/
Most end users only need to configure the above single aggregated url , Instead of configuring multiple warehouses separately. Users also don't need to know that a certain jar package comes from the maven central repository, or Apache Snapshots, or other repositories added by ourselves.
The advantage of this is that if we want to add a new warehouse (such as Open Source China, Alibaba Cloud), the client does not need to make any changes, just add the new warehouse on nexus to the warehouse group that provides external services. can.
The second 3rd party, like the last and second warehouses, Releases and Snapshots, is of the type hosted, meaning a warehouse managed locally by nexus. This repository is used for commercial, non-open source dependent repositories provided by third parties, such as oracle jdbc driver.
The penultimate Releases is used to store the dependencies of the official version used by the development team.
The penultimate Snapshots are used to store the frequently updated dependency packages built daily by the development team.
Both Apache Snapshots and Central types are proxy, which means a proxy for remote warehouses. The former includes the snapshot version released by the Apache Software Foundation (so the translation is not correct), and the latter is the Maven central warehouse. Maven usually connects to the warehouse by default.
The Central M1 Shadow type is virtual. According to the official document, it is just a mapping of a different presentation method of an existing warehouse. If necessary, please refer to section 6.2.3 of the official manual.
If you want to modify the default port number, you can go to /usr/local/nexus-2.11.4-01/conf
vi nexus.properties
After the modification is complete, remember to restart nexus
to the bin directory
./nexus restart
Add a remote warehouse
Click add to add, select proxy Repository (remote warehouse, proxy warehouse)
and then fill in, the key is the address.
Then we go to the configuration under public Repositories to configure.
If you want to use it, drag it to the left, the
higher the priority The higher
upload the jar package
Configure in settings.xml
After opening, find the servers node and add the following content
<server>
<id>releases</id>
<username>admin</username>
<password>admin123</password>
</server>
<server>
<id>snapshots</id>
<username>admin</username>
<password>admin123</password>
</server>
Add the following configuration to the pom of the project that needs to be uploaded
Note: The id in the server node corresponds to the id of the repository node below, and the address corresponding to the warehouse Allow Redeploy
option needs to be enabled in nexus
<distributionManagement>
<repository>
<id>releases</id>
<name>Nexus Release Repository</name>
<url>http://192.168.92.11:9999/nexus/content/repositories/releases</url>
</repository>
<snapshotRepository>
<id>snapshots</id>
<name>Nexus Snapshot Repository</name>
<url>http://192.168.92.11:9999/nexus/content/repositories/snapshots</url>
</snapshotRepository>
</distributionManagement>
In idea,
I clean and install the project that uploaded the jar package. I used the install command to
refresh the nexus using deploy if it didn’t work. I saw that it was uploaded. I
used the private server locally and added it in settings.xml
<mirror>
<id>nexus</id>
<mirrorOf>*</mirrorOf>
<name>nexus</name>
<url>http://192.168.92.11:9999/nexus/content/groups/public/</url>
</mirror>
If the corresponding jar package is not found in the private server, it will look for it in Alibaba Cloud, because we have configured the corresponding Alibaba Cloud image in the server