0% found this document useful (0 votes)
58 views20 pages

Nexus Repository Manager Overview

The Nexus Repository Manager Guide provides comprehensive instructions on installing, configuring, and managing Nexus Repository Manager, including user management, repository types, and artifact uploading. It covers advanced topics such as integration with CI/CD tools, Kubernetes deployment, high availability, and performance tuning. Best practices for security and maintenance are also outlined to ensure optimal usage of the repository manager.

Uploaded by

BhavnaRani
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
58 views20 pages

Nexus Repository Manager Overview

The Nexus Repository Manager Guide provides comprehensive instructions on installing, configuring, and managing Nexus Repository Manager, including user management, repository types, and artifact uploading. It covers advanced topics such as integration with CI/CD tools, Kubernetes deployment, high availability, and performance tuning. Best practices for security and maintenance are also outlined to ensure optimal usage of the repository manager.

Uploaded by

BhavnaRani
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

DevOps Shack

Nexus Repository Manager Guide

1. Introduction to Nexus Repository Manager

Sonatype Nexus is a powerful repository manager that helps with artifact


management, proxying remote repositories, caching, and hosting internal
artifacts.

●​ Nexus Repository OSS – Free and open-source.


●​ Nexus Repository Pro – Paid version with advanced features.
●​ Supports: Maven, npm, PyPI, Docker, Helm, Raw, and more.

2. Installation & Setup

Installing Nexus on Linux


wget
[Link]
[Link]
tar -xvf [Link]
mv nexus-<version> nexus
cd nexus
./bin/nexus start

●​ Default web interface: [Link]




●​ Default admin login:


○​ Username: admin
○​ Password: Found in [Link]
(/sonatype-work/nexus3/[Link])

3. Nexus Directory Structure

●​ /nexus/bin – Start/Stop scripts.


●​ /nexus/etc – Configuration files.
●​ /nexus/sonatype-work – Repository storage and logs.
●​ /nexus/logs – Application logs.

4. Nexus User Management

Create a New User

1.​ Login as admin.


2.​ Go to Security → Users.
3.​ Click Create User.
4.​ Assign necessary roles.

Roles & Permissions

●​ nx-admin – Full access.


●​ nx-repository-view-<repo>-read – Read access to a specific
repository.
●​ nx-repository-view-<repo>-write – Write access.

5. Repository Types

1. Hosted Repository

●​ Used for internal artifacts storage.


●​ Example: Internal Maven or Docker registry.

2. Proxy Repository

●​ Caches external repositories like Maven Central, Docker Hub, etc.


●​ Speeds up builds by reducing external fetch requests.

3. Group Repository

●​ Aggregates multiple repositories under a single URL.

6. Configuring a Repository

Creating a Maven Hosted Repository

1.​ Go to Repositories → Create repository.


2.​ Select Maven (hosted).
3.​ Configure:
○​ Version Policy: Release/Snapshot/Mixed.
○​ Write Policy: Allow redeploy/Disable.
○​ Storage: Blob store.
4.​ Save & Deploy.

7. Uploading Artifacts to Nexus​




Upload via UI

1.​ Go to Repositories → Select Repository.


2.​ Click Upload.
3.​ Select the artifact and provide metadata.

Upload via Maven

Setting up [Link]
xml
<servers>
<server>
<id>nexus</id>
<username>admin</username>
<password>admin123</password>
</server>
</servers>

Deploying Artifact
mvn deploy -DrepositoryId=nexus
-Durl=[Link]
es/

8. Proxying Remote Repositories

Example: Proxying Maven Central

1.​ Go to: Repositories → Create Repository​




2.​ Select: Maven (proxy)


3.​ Enter Remote URL:
[Link]
4.​ Enable Caching: To store downloaded artifacts.
5.​ Save and Apply.

9. Configuring Nexus as a Docker Registry

Enable Docker Repository

1.​ Create a new Docker Hosted Repository


○​ Name: docker-internal
○​ HTTP Port: 8082
2.​ Enable HTTP Access
○​ Go to Repositories → docker-internal → HTTP
○​ Set Allow Anonymous Access (optional).

Push Docker Image


docker login -u admin -p admin123
[Link]
docker tag myimage localhost:8082/myrepo:latest
docker push localhost:8082/myrepo:latest

10. Cleanup Policies

●​ Go to Admin → Cleanup Policies​





●​ Create Policy: Define conditions to remove old or unused artifacts.


●​ Apply Policy to repositories.

11. Backup & Restore

Backup
tar -czvf [Link] /path/to/nexus

Restore
tar -xzvf [Link] -C /path/to/nexus

12. Logs & Monitoring

Viewing Logs
tail -f sonatype-work/nexus3/logs/[Link]

Health Check

●​ Go to System → Health Check


●​ Monitor repository performance and security.

13. Security Hardening

●​ Change Default Admin Password after installation.


●​ Disable Anonymous Access unless required.
●​ Use HTTPS for secured communication.
●​ Restrict User Permissions based on the principle of least privilege.

14. Upgrading Nexus


systemctl stop nexus
mv nexus nexus-old
wget [Link]
tar -xvf [Link]
mv nexus-new nexus
systemctl start nexus

15. Troubleshooting

Common Issues & Fixes


Nexus not starting?​
cat sonatype-work/nexus3/logs/[Link]

●​ Check for missing dependencies or incorrect configurations.

Out of Memory Errors? Edit [Link]:​


diff​
-Xms2g
-Xmx4g

●​ Authentication Issues?

Reset Admin Password:​



rm -rf sonatype-work/nexus3/[Link]

16. Nexus REST API

List Repositories
curl -u admin:admin123 -X GET
"[Link]
"

Create Repository
curl -u admin:admin123 -X POST
"[Link]
" -H "Content-Type: application/json" -d
@[Link]

17. Integrating Nexus with CI/CD

Using Jenkins

1.​ Install Nexus Artifact Uploader Plugin


2.​ Configure Nexus Credentials
3.​ Upload Artifacts as Post Build Action

18. Best Practices

●​ Use Blob Stores for efficient storage.


●​ Enable Content Cleanup for unused artifacts.
●​ Monitor Disk Usage regularly.​



●​ Automate Backups with cron jobs.


●​ Enforce Role-Based Access Control (RBAC).

19. Advanced Configuration and Customization

Configuring Reverse Proxy (Nginx) for Nexus

Using Nginx as a reverse proxy allows secure access to Nexus via HTTPS.

1. Install Nginx
sudo apt update && sudo apt install nginx -y

2. Configure Nginx for Nexus

Create a new configuration file:

sudo nano /etc/nginx/sites-available/nexus

Add the following content:

nginx
server {
listen 80;
server_name [Link];
location / {
proxy_pass [Link]
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;
}
}

3. Enable Configuration

sudo ln -s /etc/nginx/sites-available/nexus
/etc/nginx/sites-enabled/
sudo systemctl restart nginx

Now, Nexus will be accessible at [Link]

Enabling HTTPS with Let’s Encrypt

1. Install Certbot
sudo apt install certbot python3-certbot-nginx -y

2. Generate SSL Certificate


sudo certbot --nginx -d [Link]

This enables HTTPS and automatically configures Nginx.

20. Managing Nexus Storage

Nexus stores artifacts in Blob Stores. Proper configuration ensures optimal ​







performance.

Create a Custom Blob Store

1.​ Navigate to Administration → Blob Stores.


2.​ Click Create Blob Store.
3.​ Choose File or S3 (Pro version).
4.​ Set the storage path.
5.​ Assign the blob store to a repository.

Automated Storage Cleanup

●​ Set up Cleanup Policies for removing unused artifacts.


●​ Enable Compact Blob Store for better storage efficiency.

21. Running Nexus as a Systemd Service

By default, Nexus runs as a foreground process. To run it as a background


service:

1. Create a Service File


sudo nano /etc/systemd/system/[Link]

Add the following:

ini

[Unit]​



Description=Nexus Repository Manager


After=[Link]

[Service]
Type=forking
User=nexus
Group=nexus
ExecStart=/opt/nexus/bin/nexus start
ExecStop=/opt/nexus/bin/nexus stop
Restart=on-abort

[Install]
WantedBy=[Link]

2. Enable and Start Service


sudo systemctl daemon-reload
sudo systemctl enable nexus
sudo systemctl start nexus

Check status:

sudo systemctl status nexus

22. Integrating Nexus with Kubernetes

Deploying Nexus in Kubernetes​




1. Create a Persistent Volume


yaml
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
name: nexus-pvc
spec:
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 50Gi

2. Deploy Nexus Pod


yaml

apiVersion: apps/v1
kind: Deployment
metadata:
name: nexus
spec:
replicas: 1
selector:
matchLabels:​


app: nexus
template:
metadata:
labels:
app: nexus
spec:
containers:
- name: nexus
image: sonatype/nexus3:latest
ports:
- containerPort: 8081
volumeMounts:
- name: nexus-storage
mountPath: /nexus-data
volumes:
- name: nexus-storage
persistentVolumeClaim:
claimName: nexus-pvc

3. Expose as a Service
yaml

apiVersion: v1
kind: Service​



metadata:
name: nexus-service
spec:
selector:
app: nexus
ports:
- protocol: TCP
port: 8081
targetPort: 8081
type: LoadBalancer

Apply the configurations:

kubectl apply -f [Link]

23. Configuring Nexus for High Availability (HA)

High Availability (HA) ensures that Nexus remains available even in case of
failures.

1. Use External Database (Pro Version)

●​ Configure PostgreSQL as an external database.


●​ Edit [Link] to use an external database.

2. Set Up Load Balancer

Use HAProxy or Nginx to distribute load among multiple Nexus instances.


24. Automating Nexus with Ansible

Installing Nexus using Ansible

Create an Ansible playbook:

yaml
- name: Install Nexus
hosts: nexus_servers
become: yes
tasks:
- name: Download Nexus
get_url:
url:
[Link]
[Link]
dest: /opt/[Link]

- name: Extract Nexus


unarchive:
src: /opt/[Link]
dest: /opt/
remote_src: yes

- name: Start Nexus


command: "/opt/nexus/bin/nexus start"​

Run the playbook:

ansible-playbook [Link] -i inventory

25. Performance Tuning

Optimizing JVM Memory

Edit [Link]:

diff
-Xms4g
-Xmx8g

Increase Thread Pool Size

Edit [Link]:

ini
[Link]=200

Restart Nexus:

systemctl restart nexus

26. Monitoring Nexus with Prometheus & Grafana

1. Enable Metrics Endpoint​





In Nexus Pro, navigate to Administration → System → Metrics and enable


Prometheus metrics.

2. Scrape Metrics with Prometheus


yaml

scrape_configs:
- job_name: 'nexus'
static_configs:
- targets: ['[Link]']

3. Visualize in Grafana

●​ Import a Nexus Dashboard in Grafana.


●​ Connect to Prometheus as a data source.

27. Migrating from Nexus 2 to Nexus 3

Steps to Migrate
Backup Nexus 2 Data​

tar -czvf [Link] /opt/nexus2

1.​ Install Nexus 3 on a new server.


2.​ Use Nexus Migration Tool (Pro feature).

Manually Transfer Artifacts if using the OSS version:​






rsync -av /opt/nexus2/storage/
/opt/nexus3/sonatype-work/

3.​ Reconfigure Repositories & Permissions.

28. Nexus Best Security Practices

●​ Use RBAC (Role-Based Access Control).


●​ Enforce HTTPS.
●​ Enable IP Whitelisting.
●​ Regularly update Nexus and plugins.
●​ Set password expiration policies.

29. Troubleshooting & Common Errors

Issue: Login Fails After Reset

Solution: Reset admin password:

rm -rf sonatype-work/nexus3/[Link]

Issue: Nexus Crashes on Large Artifact Uploads

Solution: Increase heap size:

export INSTALL4J_ADD_VM_PARAMS="-Xms4g -Xmx8g"

Issue: Slow Response Time

Solution: Enable Blob Store Compression.



30. Final Tips

●​ Use CI/CD pipelines to automate artifact deployment.


●​ Enable geo-replication for multi-region teams.
●​ Monitor storage usage and apply cleanup policies.
●​ Integrate Sonatype Lifecycle for security scanning.

Common questions

Powered by AI

To use Nexus as a Docker registry, first create a Docker Hosted Repository and assign a name, such as 'docker-internal', and specify an HTTP Port, like 8082. To allow image pushing and pulling, configure HTTP access, optionally enabling anonymous access . When it comes to security, important considerations include whether to allow anonymous access, which can simplify interaction but reduce security, and whether to enforce HTTPS for encrypted communications, as HTTP traffic is susceptible to eavesdropping . Moreover, using Role-Based Access Control (RBAC) and ensuring that user permissions are restricted to the least privilege necessary enhances security.

If Nexus fails to start, reviewing the nexus.log file in sonatype-work/nexus3/logs can provide insight into what might be going wrong. Common issues include missing dependencies or incorrect configurations. Checking for such errors and resolving them, such as by adding necessary libraries or correcting configuration files, often rectifies the issue . Another step if struggling with memory-related issues is to adjust the JVM memory settings in nexus.vmoptions to allocate more heap memory . These actions target common problems that occur due to environment setup errors or insufficient resource allocation, allowing Nexus to start successfully.

Creating a Maven Hosted Repository in Nexus involves navigating to Repositories, selecting the option to create a new repository, and choosing 'Maven (hosted)'. During configuration, important options include the Version Policy and Write Policy. Version Policy can be set to Release, Snapshot, or Mixed, which dictates whether the repository will store released versions, snapshot versions, or both. The Write Policy has options like Allow redeploy or Disable, affecting whether artifacts can be overwritten once uploaded . Choosing different policies can influence how artifacts are managed. For instance, allowing snapshot versions is beneficial for ongoing development, while a release policy supports more stable, production-ready versions.

Optimizing Nexus repository performance can be significantly influenced by adjusting the JVM memory settings in the nexus.vmoptions file. By setting -Xms to 4g and -Xmx to 8g, the JVM is configured to use a starting heap size of 4 gigabytes and a maximum heap size of 8 gigabytes . These settings help manage memory more efficiently, particularly for larger Nexus deployments handling many artifacts. Proper memory allocation can prevent Out of Memory errors and improve response time by allowing more data to be held in memory, reducing garbage collection overhead, and enabling faster processing of repository requests . These improvements are crucial in maintaining repository performance and reliability under heavy workloads.

Automation tools like Ansible can manage Nexus installations by executing tasks such as downloading, extracting, and starting Nexus within a single playbook that can be run across multiple servers. By creating an Ansible playbook that includes steps for downloading the Nexus tarball, extracting it to a specified directory, and executing it using its start script, users can streamline deployments . The reliability gain from this approach lies in its repeatability and consistency, reducing human error and ensuring that environments are set up identically, thus preventing configuration drift and making it easier to maintain a desired state across environments .

Nexus Repository Manager is available in two versions: Nexus Repository OSS (open-source) and Nexus Repository Pro (paid). The open-source version offers basic features necessary for artifact management, such as supporting a variety of package formats (Maven, npm, PyPI, Docker, etc.). The paid version, Nexus Repository Pro, includes advanced features such as high availability configurations, access to professional technical support, and additional security features like repository health checks and analytics . These differences can impact an organization's artifact management strategy by determining the level of support and functionality available to them. Organizations needing advanced features, higher availability, and robust security might prefer the Pro version, while those with simpler needs might find the OSS version sufficient.

Using Cleanup Policies in Nexus is critical for effective repository storage management. They define conditions under which old or unused artifacts are automatically removed, which helps manage disk usage efficiently and ensures that storage does not become overwhelmed by obsolete data . This is especially important in environments with continuous integration flows, where numerous artifacts are produced regularly. By regularly cleaning up artifacts, organizations can maintain optimal repository performance, reduce storage costs, and minimize the potential burden on system resources .

Nginx serves as a reverse proxy for Nexus by handling incoming requests and forwarding them to the Nexus server. This setup not only facilitates better load management but also allows for the configuration of HTTPS to secure the traffic between clients and the server . To enable HTTPS with Nginx, Certbot can be used to generate an SSL certificate and automatically configure Nginx for SSL/TLS encryption, converting plain HTTP traffic to HTTPS . This enhances security by encrypting data in transit, preventing unauthorized access and data tampering, which is especially important when managing sensitive artifacts within the repository.

Integrating Nexus with a CI/CD pipeline using Jenkins involves several steps: Installing the Nexus Artifact Uploader Plugin in Jenkins, configuring credentials to allow Jenkins to authenticate with Nexus securely, and setting the pipeline to upload artifacts to Nexus as a post-build action . This integration benefits software development workflows by automating the process of artifact storage and retrieval, thereby reducing manual intervention and potential errors. It enables continuous delivery practices by ensuring that successful builds are immediately made available as artifacts in Nexus, which can then be used by other stages in the deployment pipeline, thereby accelerating software release cycles .

You might also like