background
I am a Java engineer. Desktops, laptops, and virtual machines may be used to compile and build maven projects when I am at home. When I have a maven private server at home, the effect of building speed is obvious;
Tangled
After preparing a computer to deploy the private server, is it 24 hours to boot? It seems a bit wasteful, so turn it on when you use it, and turn it off when you are done? Slightly troublesome (Do you want to scold me for being lazy? You scolded right ...)
Synology DS218 +
There is a Synology DS218 + at home. For a long time, it has been turned on for 24 hours to serve the whole family. If you can bring private clothing here, it seems that the previous tangle is gone;
- The picture below is what DS218 + just bought. Two NAS hard drives have been in stable service:
- The following picture is a memory stick purchased online. Now a total of 2 + 8 = 10G memory, sufficient memory is the guts to dare toss:
Ideas
In fact, the operation is very simple: Synology has a docker service, you can use docker to deploy nexus, so this article is actually the basic operation record of Synology docker, the following are the points to note:
- Container port
- Container data volume
- File Permissions
- Login container operation
Environmental information
- Synology System: DSM 6.2.2-24922 Update 4
- Resources of Synology before deploying nexus:
- Open Docker, search for nexus on the registry page , find sonatype / nexus3 , select the label 3.19.1 , as shown below:
- After the image is downloaded, select the image on the image page and click the start button:
- Click Advanced Settings on the startup page :
- Allow the container to restart automatically and create a desktop shortcut:
- For data volume mapping, create a new folder named nexus3 on the host machine according to the following diagram :
- Then map the container's / nexus-data directory to the host's nexus3, so that all the data of the container can be saved:
- Port mapping, if the 8081 port of the host is not occupied, map it directly to 8081, otherwise change to an unoccupied one:
- After the setting is completed, run the container after checking the wizard , and then click Apply to create the nexus3 container:
- I thought it was done like this, but I didn't expect many error messages to pop up:
- As shown below, view the container log:
- I quickly found the problem: the host mapped to the container's directory, and the container process failed to write due to permissions:
- Think about it too. For security reasons, the host's nexus3 directory and containers cannot be manipulated at will. Here we will let go of the write permission of this directory, as shown in the following figure, use File Station to set this directory:
- Increase write permissions:
- After the above operation is completed, it starts to wait, because the container will automatically restart after each unexpected exit, and finally, I see the log of the successful startup:
Operation nexus3
- My intranet IP of Synology is 192.168.50.42 , so the browser access address: http://192.168.50.42:8081, the familiar page comes out:
- The next question to face is how to obtain the login password. The default password of nexus is stored in the /nexus-data/admin.password file of the container, so there are two methods to obtain it.
- The / nexus-data directory of the container has been mapped to the docker / nexus3 directory of the host machine , so use File Statiion to open the directory, download the admin.password file, and then open it with a text editor:
- Another method is to enter the container to view the file, the operation is as follows, select the container to add a command:
- Enter / bin / bash in the input box that pops up , so that a new bash process is created under the container's namespace. This process can see all files under the same namespace, including /nexus-data/admin.password, and then use the cat command Just check the contents of the file:
- After getting the password, you can log in to nexus on the page, the account is admin :
- After successful login, follow the prompts to set a new password:
- Next is the normal operation of nexus. I wo n’t say more here. Let ’s focus on it. Create a new account bolingcavalry with administrator rights and set the password to 123456 :
- Obtain the address of the central warehouse of the private server:
- At this point, the deployment is successful. Next, verify whether the private server is easy to use.
Prepare two computers to verify Nexus service
The following figure is the architecture diagram after deploying the private server:
prepare two computers, computer A and computer B, to verify that the newly deployed Nexus3 can cache the jar package of the central warehouse (you can also create two computers with a virtual machine);
- Both computers A and B have JDK8 and Maven3 installed;
- The conf / settings.xml files in the maven directory on both computers A and B must be modified as follows;
- Find the servers node and add the following:
<server>
<id>maven-central</id>
<username>bolingcavalry</username>
<password>123456</password>
</server>
- Find the mirrors node and add the following content, where the content of the url is the maven-central warehouse address obtained earlier :
<mirror>
<id>maven-central</id>
<mirrorOf>*</mirrorOf>
<url>http://192.168.50.42:8081/repository/maven-central/</url>
</mirror>
Compile the build project on computer A (should be slow)
Compile the open source project spring-cloud-alibaba on the A computer. At this time, there is no jar package cached on the Nexus, so the compilation speed will be very slow, because all dependent jars must be downloaded from the central warehouse, let's try:
- Log in to computer A and download the 2.1.1.RELEASE archive package of spring-cloud-alibaba:
wget https://github.com/alibaba/spring-cloud-alibaba/archive/v2.1.1.RELEASE.tar.gz
- Unzip the downloaded file:
tar -zxvf v2.1.1.RELEASE.tar.gz
- Enter the unzipped directory:
cd spring-cloud-alibaba-2.1.1.RELEASE/
- Compile:
mvn clean compile -U -DskipTests
- Compilation is complete, as shown in the red box below, this compilation takes 7 minutes and 32 seconds :
- Take a look on the Nexus webpage, as shown below, at this time, a lot of jars have been cached:
Compile the build project on B computer (should be soon)
- Do the same operation on the B computer. At this time, the jar package required for compilation has been cached on the Nexus. The compilation process is significantly faster. The final operation result is as shown in the figure below, which takes only 1 minute and 8 seconds :
- Looking at the resources occupied by the nexus service, a lot of memory is used. If no memory stick is added, it is estimated that the use of its own 2G memory will drag down the entire Synology. Although the container can limit the memory, it will also cause frequent GC of the nexus process. It's still very card, so it is necessary to ensure sufficient memory: So
far, the actual combat of deploying maven private server for Synology DS218 + is completed. From now on, the code at home can be regarded as a stable private server, no need to care, and it is available at any time.