LogoDocumentation

Nexus

Learn how to install and configure Nexus Repository Manager for artifact storage and dependency management

What is Nexus?

Nexus is a repository manager designed to store, manage, and distribute components, binaries, and build artifacts across your entire software supply chain. It helps developers streamline dependency management, version control, and artifact storage, ensuring a smooth and efficient software development lifecycle.

By integrating Nexus into your DevOps workflow, teams can securely manage open-source and proprietary dependencies while improving build performance and reliability.

Prerequisites

  • Virtual Machine running Ubuntu 22.04 or newer

Update Package Repository and Packages

Bash
sudo apt update
sudo apt upgrade

Install Java 17

Bash
sudo apt install -y fontconfig openjdk-17-jdk
sudo update-alternatives --config java

Download and extract Nexus3

Bash
wget https://download.sonatype.com/nexus/3/nexus-3.71.0-06-unix.tar.gz
Bash
sudo tar -xzvf nexus-3.71.0-06-unix.tar.gz -C /opt
sudo mv /opt/nexus-3.71.0-06 /opt/nexus

Create Nexus user

Bash
sudo adduser nexus

Update permissions for Nexus

Bash
sudo chown -R nexus:nexus /opt/nexus
sudo chown -R nexus:nexus /opt/sonatype-work

Configure Nexus to run as a service

Bash
sudo vim /opt/nexus/bin/nexus.rc

Uncomment and set:

Bash
run_as_user="nexus"

Create Nexus Service

Bash
sudo tee /etc/systemd/system/nexus.service <<EOF
[Unit]
Description=nexus service
After=network.target
[Service]
Type=forking
LimitNOFILE=65536
User=nexus
Group=nexus
ExecStart=/opt/nexus/bin/nexus start
ExecStop=/opt/nexus/bin/nexus stop
Restart=on-abort
[Install]
WantedBy=multi-user.target
EOF

Start and enable Nexus

Bash
sudo systemctl enable nexus
sudo systemctl start nexus
sudo systemctl status nexus

Low Memory fix

Bash
sudo fallocate -l 2G /swapfile
sudo chmod 600 /swapfile
sudo mkswap /swapfile
sudo swapon /swapfile
Bash
echo '/swapfile none swap sw 0 0' | sudo tee -a /etc/fstab

Optimize Nexus Memory Settings

Bash
sudo vim /opt/nexus/bin/nexus.vmoptions

Reduce the -Xms and -Xmx to these values

Bash
-Xms512m
-Xmx512m

Restart Nexus

Bash
sudo systemctl enable nexus.service
sudo systemctl start nexus.service
sudo systemctl status nexus.service

Enable TLS

TLS Configuration

Install Nginx:

Bash
sudo apt install -y nginx

Start Nginx:

Bash
sudo systemctl enable nginx
sudo systemctl start nginx
sudo systemctl status nginx

Configure Nginx proxy for Nexus:

Bash
sudo vim /etc/nginx/sites-available/nexus.devopsfoundry.com

Paste the following contents:

NGINX
server {
    listen   *:80;
    server_name  nexus.devopsfoundry.com;
    client_max_body_size 1G;
    location / {
        proxy_pass http://127.0.0.1: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;
    }
    # Docker /v2 and /v1 (for search) requests
    location /v2 {
        proxy_set_header Host $host:$server_port;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_pass http://127.0.0.1:1111;
    }
    location /v1 {
        proxy_set_header Host $host:$server_port;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_pass http://127.0.0.1:1111;
    }
}
Bash
sudo ln -s /etc/nginx/sites-available/nexus.devopsfoundry.com /etc/nginx/sites-enabled/
Bash
sudo nginx -t
sudo systemctl restart nginx

Install Certbot and obtain TLS certificate:

Bash
sudo apt install -y python3-certbot-nginx
Bash
sudo certbot --nginx -d nexus.devopsfoundry.com

How is this guide?