Skip to content

Sonatype Nexus Server

Introduction

This describes on how to install a Sonatype Nexus server within an LXC-container.

Installation

Create an LXC-container

Presuming LXC is already installed.

Create a container type from a selection out of the list which is downloaded.

lxc-create -n nexus -t download
For this example debian, bookworm, amd64 is selected.

Start the container.

lxc-start -n nexus3

Make the LXC-container run at the start by changing or adding the following to the file /var/lib/lxc/nexus3/config.

# Enable auto start of this container.
lxc.start.auto = 1
# Delay start this container 30 seconds from when the host starts.
lxc.start.delay = 30

To get hold of the containers’ console (root), execute the following.

lxc-attach -n nexus3

Container Configuration

Install the needed packages for easy use of command line (bash-completion) and an editor (joe) or any other.

apt install bash-completion mc joe wget

Modifying the .bashrc for autocompletion.

if [ -f /etc/bash_completion ] && ! shopt -oq posix; then
    . /etc/bash_completion
fi

Create a System User & Group

The Nexus service is running under user nexus and a system user named nexus and with its primary group are created.

adduser --system nexus
addgroup --system nexus
usermod --gid nexus

Download & Install

Install required java version 17 runtime engine first.

apt install openjdk-17-jre-headless

Download the latest application using this download page to get a download link.

As of the date of writing the URL and command are as follows.

mkdir download && cd download
wget "https://download.sonatype.com/nexus/3/nexus-3.76.1-01-unix.tar.gz"

Install by unpacking the downloaded nexus-3.xx.x-xx.tar.gz file into the /opt directory.
Create the directory when it does not exist yet using mkdir -p /opt.

tar xf nexus-x.x.x-xx.tar.gz -C /opt

After this a /opt/nexus-x.x.x-xx directory and the /opt/sonatype-work directory are created.

Create a /opt/nexus symlink to the /opt/nexus-x.x.x-xx directory in order to upgrade more easily without changing the systemd to run the service.

ln -s /opt/nexus-x.x.x-xx /opt/nexus
Make nexus the owner of the /opt/sonatype-work and its content.

cown -R nexus:nexus /opt/sonatype-work

Create a Systemd Service

Create a file /etc/systemd/system/nexus.service containing the following content.

[Unit]
Description=nexus service
After=network.target

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

[Install]
WantedBy=multi-user.target

Run the following commands to enable and start this new service.

systemctl daemon-reload
systemctl enable nexus.service
systemctl start nexus.service

Check the service status to see if it is running.

systemctl --no-pager status nexus.service

Once the server is started it is started it can be accessed on port 8081. The initial admin password is found in file /opt/sonatype-work/nexus3/admin.password and is deleted by Nexus when the admin password is changed in the web-application.

cat /opt/sonatype-work/nexus3/admin.password

Upgrading

Download Application

A help page of Sonatype has a download link of the latest version in different Java version flavors.

Installation

Install the appropriate Java runtime engine needed.

To upgrade to a new version, unpack the downloaded .tar.gz file in a /tmp directory move only directory /tmp/nexus-3.69.0-02 to /opt/nexus-3.69.0-02.

tar -C /tmp -xf nexus-3.69.0-02-java11-unix.tar.gz
mv /tmp/nexus-3.69.0-02 /opt/

Stop the Nexus services and update the /opt/nexus symlink to the new version directory.
Finally start the service again.

systemctl stop nexus
ln -nrsf /opt/nexus-3.69.0-02 /opt/nexus
ls -l /opt
systemctl start nexus

The application wil take some time to update the content database.
This could be minutes before the web-application responds.

Check if the service is running errorless.

systemctl --no-pager status nexus