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
sudo apt update
sudo apt upgradeInstall Java 17
sudo apt install -y fontconfig openjdk-17-jdk
sudo update-alternatives --config javaDownload and extract Nexus3
wget https://download.sonatype.com/nexus/3/nexus-3.71.0-06-unix.tar.gzsudo tar -xzvf nexus-3.71.0-06-unix.tar.gz -C /opt
sudo mv /opt/nexus-3.71.0-06 /opt/nexusCreate Nexus user
sudo adduser nexusUpdate permissions for Nexus
sudo chown -R nexus:nexus /opt/nexus
sudo chown -R nexus:nexus /opt/sonatype-workConfigure Nexus to run as a service
sudo vim /opt/nexus/bin/nexus.rcUncomment and set:
run_as_user="nexus"Create Nexus Service
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
EOFStart and enable Nexus
sudo systemctl enable nexus
sudo systemctl start nexus
sudo systemctl status nexusLow Memory fix
sudo fallocate -l 2G /swapfile
sudo chmod 600 /swapfile
sudo mkswap /swapfile
sudo swapon /swapfileecho '/swapfile none swap sw 0 0' | sudo tee -a /etc/fstabOptimize Nexus Memory Settings
sudo vim /opt/nexus/bin/nexus.vmoptionsReduce the -Xms and -Xmx to these values
-Xms512m
-Xmx512mRestart Nexus
sudo systemctl enable nexus.service
sudo systemctl start nexus.service
sudo systemctl status nexus.serviceEnable TLS
TLS Configuration
Install Nginx:
sudo apt install -y nginxStart Nginx:
sudo systemctl enable nginx
sudo systemctl start nginx
sudo systemctl status nginxConfigure Nginx proxy for Nexus:
sudo vim /etc/nginx/sites-available/nexus.devopsfoundry.comPaste the following contents:
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;
}
}sudo ln -s /etc/nginx/sites-available/nexus.devopsfoundry.com /etc/nginx/sites-enabled/sudo nginx -t
sudo systemctl restart nginxInstall Certbot and obtain TLS certificate:
sudo apt install -y python3-certbot-nginxsudo certbot --nginx -d nexus.devopsfoundry.comHow is this guide?