Nexus 3 : installation

Installing Nexus on Linux (without container)

Download the Nexus archive and uncompress it into a target folder.
The application consists of two folders :
– nexus-3.XX.X
– sonatype-work
The first one contains the nexus application and the second contains the data (repository, blob, … elements and downloaded artifacts too).

Helpful commands

nexus start : run nexus in background

nexus run : run nexus in foreground

nexus stop : stop nexus

Good practices : run as nexus and not root

To to run Nexus with the root user but a dedicated user such as a nexus user.
To achieve that :
1) we create the user and add it in its group : sudo adduser nexus nexus
2) we edit the nexus-3.XXX/bin/nexus.rc file in this way : run_as_user="nexus"
3) we change the owners of the directories where nexus is installed to make nexus the proprietary and the group too : sudo chown -R nexus:nexus nexus-root-folder
4) (optional) Change the home directory of the nexus user in the nexus directory installation : sudo usermod -d /opt/nexus nexus

Run Nexus as a service without container

1) follow the good practice of the previous point : run as nexus and not root.
….

Run Nexus as a service with a Docker container

Here is for systemd/ubuntu.

1) Follow the good practice of the previous point : run as nexus and not root.

2) Run docker with :
– a (n)amed container to be able to reference it in the service scripts
– the nexus (u)ser
– an external port that suits to your need (here 8072)
– a policy that tries to (restart) it unless the container was stopped
– a named (v)olume that stores application data beyond a container launch
The volume declared by the nexus image (/nexus-data) is about the sonatype-work directory present in the classical package.
– the nexus3 image

    docker run -d \
           --name nexus \
           -u nexus \
    	   -p 8072:8081 \
           --restart=unless-stopped \
	   -v nexus-data:/nexus-data \
    	   sonatype/nexus3

3) Edit the nexus.rc in the container to specify nexus as user (see the above best practice)

4) Declare the service in your systemd 

[Unit]
Description=Nexus repository
Requires=docker.service
After=docker.service
 
[Service]
Restart=on-abort
ExecStart=/usr/bin/docker start -a nexus
ExecStop=/usr/bin/docker stop -t 2 nexus
User=nexus
 
[Install]
WantedBy=default.target

5) Enable the service : sudo systemctl enable nexus

6) Reload the systemd manager configuration : sudo systemctl daemon-reload

Ce contenu a été publié dans Non classé. Vous pouvez le mettre en favoris avec ce permalien.

Laisser un commentaire

Votre adresse de messagerie ne sera pas publiée. Les champs obligatoires sont indiqués avec *