Docker deployment Nexus Maven private server
1. Preface
Nexus is a powerful warehouse manager widely used to manage and organize dependencies and artifacts in software building processes. Deploying Nexus private servers with Docker simplifies installation and management processes and provides greater flexibility and scalability.
2. Environmental preparation
Before you begin your deployment, make sure your system meets the following requirements:
- Docker and Docker Compose installed
- Have basic Linux command line operation knowledge
- Have administrator privileges
3. Download Nexus Mirror
First, we need to download the Nexus image from Docker Hub. Execute the following command:
docker pull sonatype/nexus3
4. Create a persistent storage directory
To ensure the persistence of Nexus data, we need to create a directory on the host to store Nexus data. Execute the following command:
mkdir -p /usr/local/docker/nexus-data chmod 777 -R /usr/local/docker/nexus-data
5. Start the Nexus container
Run the Nexus container with Docker and mount the data directory into the container. Execute the following command:
docker run -d --name nexus3 -p 8081:8081 -v /usr/local/docker/nexus-data:/nexus-data -m 1024m sonatype/nexus3 docker logs -f nexus3
6. Access the Nexus management interface
After the container is started, the Nexus management interface can be accessed through the browser. Open the browser and enter the following address:
http://<your IP address>:8081
The default administrator username isadmin
, the password isadmin123
. If the password is wrong, you can enter the container to view the administrator password:
docker exec -it nexus3 cat /nexus-data/
7. Configure Nexus repository
7.1 Default warehouse description
Nexus provides the following repositories by default:
-
maven-central
:Maven Central Library -
maven-releases
: Private library distribution -
maven-snapshots
: Private library snapshot version -
maven-public
: Warehouse grouping, including the above three warehouses
7.2 Create Blob Stores
Before creating a repository, you need to specify the file storage directory. Blob Stores can be created in the Nexus management interface.
7.3 Creating a repository
Nexus supports three types of repositories:
-
hosted
: Local repository for storing local components -
proxy
: Agent repository, used to proxy remote public repository -
group
: Repository group, used to merge multiplehosted
andproxy
storehouse
7.3.1 Create a Hosted Repository
In the Nexus management interface, select Createhosted
storehouse. There are three options to choose:
-
Releases
: Released version -
Snapshot
: Unreleased version -
Mixed
: Hybrid version
7.3.2 Creating a Proxy repository
Select Createproxy
Repository and set the address of the agent remote repository. For example:
- JBoss Maven Central Warehouse Address: /maven2/
- Alibaba Cloud Maven Central Warehouse Address: /nexus/content/groups/public/
- Apache Maven Central Warehouse Address: /maven2/
7.3.3 Create a Group Repository
creategroup
The warehouse willhosted
andproxy
The warehouses are combined to provide a unified access portal.
8. Configure Docker to use Nexus private server
8.1 Configuring Docker Daemon
Edit Docker configuration file/etc/docker/
, add the Nexus private server address:
{ "registry-mirrors": ["http://<your IP address>:8081/repository/docker-group/"]}
Restart Docker service:
systemctl restart docker
8.2 Upload the mirror to the Nexus private server
Use the following command to upload the image to the Nexus private server:
docker tag <Your mirror> <yourIPaddress>:8081/repository/docker-hosted/<Your mirror> docker push <yourIPaddress>:8081/repository/docker-hosted/<Your mirror>
8.3 Pulling mirrors from Nexus private server
Use the following command to pull the image from the Nexus private server:
docker pull <yourIPaddress>:8081/repository/docker-hosted/<your镜像>
9. Configure permission management
In the Nexus management interface, users and roles can be configured to control access to the repository.
10. Monitoring and Maintenance
Regularly check Nexus logs and performance to ensure the system is running smoothly. You can view Nexus logs using the following command:
docker logs -f nexus3
11. Backup and Restore
To prevent data loss, it is recommended to back up the Nexus data directory regularly. You can back up your data using the following command:
tar -czvf /usr/local/docker/nexus-data
When recovering data, unzip the backup file and replace the original data directory:
tar -xzvf -C /usr/local/docker/nexus-data
12. Troubleshooting of FAQs
12.1 The Nexus management interface cannot be accessed
Check whether the container is running normally:
docker ps -a
Check whether the port is occupied:
netstat -tuln | grep 8081
12.2 Uploading the image failed
Check whether the Docker Daemon configuration is correct and make sure that the Nexus private server address has been added toregistry-mirrors
。
12.3 Failed to pull the image
Check Nexus warehouse configuration to ensure that the warehouse type and address are correct.
13. Advanced configuration
13.1 Configuring HTTPS
For increased security, HTTPS can be configured for Nexus. Here are the configuration steps:
- Generate a self-signed certificate or obtain a certificate from a certificate authority.
- Copy the certificate and key files into the Nexus container.
- Edit Nexus configuration file
, add the following:
application-port-ssl=8443 application-keystore=/path/to/ application-keystore-password=your_keystore_password
- Restart the Nexus container:
docker restart nexus3
13.2 Configuring the reverse proxy
To better manage traffic, Nginx or Apache can be used as the reverse proxy. Here is an example of Nginx configuration:
server { listen 80; server_name your_domain.com; location / { proxy_pass http://localhost:8081; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme; } }
Add the above configuration to the Nginx configuration file and restart the Nginx service:
systemctl restart nginx
13.3 Configuring LDAP Integration
Nexus supports integration with LDAP servers for unified user management. Here are the configuration steps:
- In the Nexus management interface, navigate to
Security
->LDAP
。 - Add a new LDAP server configuration and fill in the server address, port, binding DN and password information.
- Test the connection to make sure the configuration is correct.
- Save the configuration and sync the LDAP user to Nexus.
14. Performance optimization
14.1 Adjusting JVM parameters
To improve Nexus' performance, JVM parameters can be adjusted. Edit Nexus containerFile, add or modify the following parameters:
-Xms2g -Xmx2g -XX:MaxDirectMemorySize=2g -XX:+UnlockExperimentalVMOptions -XX:+UseCGroupMemoryLimitForHeap -XX:MaxRAMFraction=1
14.2 Configuration Cache
Nexus supports configuring caches to improve access speeds. You can navigate to the Nexus management interfaceRepository
-> Repositories
, select the repository to configure the cache, and set the cache policy and expiration time.
14.3 Regular cleaning
To maintain system performance, it is recommended to regularly clean up components and warehouses that are no longer needed. You can navigate to the Nexus management interfaceSystem
-> Tasks
, create regular cleaning tasks.
15. Log Management
15.1 Configuring the log level
You can navigate to the Nexus management interfaceAdministration
-> Support
-> Logging
, configure log level and log file location.
15.2 Integrated ELK
To better analyze and manage logs, Nexus logs can be integrated into the ELK (Elasticsearch, Logstash, Kibana) stack. Here are the configuration steps:
- Install and configure Filebeat to collect Nexus logs.
- Configure Logstash to parse and filter log data.
- Store log data into Elasticsearch and use Kibana for visual analysis.
16. Upgrade and migration
16.1 Upgrade Nexus
To maintain the security and stability of the system, it is recommended to upgrade Nexus regularly. Here are the upgrade steps:
- Stop the current Nexus container:
docker stop nexus3
- Backup Nexus data directory:
tar -czvf /usr/local/docker/nexus-data
- Download the latest Nexus image:
docker pull sonatype/nexus3
- Start a new Nexus container:
docker run -d --name nexus3 -p 8081:8081 -v /usr/local/docker/nexus-data:/nexus-data sonatype/nexus3
16.2 Migration of Nexus
If you need to migrate Nexus to a new server, you can follow these steps:
- Backup Nexus data directory:
tar -czvf /usr/local/docker/nexus-data
- Copy the backup file to the new server:
scp user@new_server:/path/to/backup
- Unzip the backup file on the new server:
tar -xzvf -C /usr/local/docker/nexus-data
- Start the Nexus container on the new server:
docker run -d --name nexus3 -p 8081:8081 -v /usr/local/docker/nexus-data:/nexus-data sonatype/nexus3
This is all about this article about Docker deployment of Nexus Maven private server. For more related content on Docker Nexus Maven private server, please search for my previous articles or continue browsing the related articles below. I hope everyone will support me in the future!