DevOps KT

icon picker
Nexus Repo

SO
Security Operations
Last edited 169 days ago by Ram Kumar

Install Nexus Repository

Nexus Installation:

Prerequisites
A server running Ubuntu 20.04.
A root password is configured the server.

Getting Started

Before starting, you will need to update your system packages to the latest version. You can update them using the following command:
apt-get update -y
Once your server is updated, you can proceed to the next step.

Install Java

Nexus is based on Java so you will need to install Java version 8 in your system. You can install it with the following command:
apt-get install openjdk-8-jdk -y
Once Java is installed, you can verify the installed version of Java with the following command:
java -version
You should get the following output:
openjdk version "1.8.0_282"
OpenJDK Runtime Environment (build 1.8.0_282-8u282-b08-0ubuntu1~20.04-b08)
OpenJDK 64-Bit Server VM (build 25.282-b08, mixed mode)
Once the Java is installed, you can proceed to the next step.

Install Nexus

Before starting, you will need to create a separate user to run Nexus. You can create it by running the following command:
useradd -M -d /opt/nexus -s /bin/bash -r nexus
Next, allows nexus user to run all user with sudo without any password. You can do it with by running following command:
echo "nexus ALL=(ALL) NOPASSWD: ALL" > /etc/sudoers.d/nexus
Next, create a directory for Nexus and download the latest version of Nexus with the following command:
mkdir /opt/nexus
wget https://sonatype-download.global.ssl.fastly.net/repository/downloads-prod-group/3/nexus-3.29.2-02-unix.tar.gz
Once the download is completed, extract the downloaded file to the /opt/nexus directory by running the following command:
tar xzf nexus-3.29.2-02-unix.tar.gz -C /opt/nexus --strip-components=1
Next, set proper ownership to the nexus directory by running the following command:
chown -R nexus:nexus /opt/nexus
Next, edit the nexus.vmoptions configuration file and define max memory size:
vim /opt/nexus/bin/nexus.vmoptions
Set Java max memory size and replaced "../sonatype-work" with "./sonatype-work":
-Xms1024m
-Xmx1024m
-XX:MaxDirectMemorySize=1024m


-XX:LogFile=/opt/nexus/sonatype-work/nexus3/log/jvm.log
-XX:-OmitStackTraceInFastThrow
-Djava.net.preferIPv4Stack=true
-Dkaraf.home=.
-Dkaraf.base=.
-Dkaraf.etc=etc/karaf
-Djava.util.logging.config.file=/etc/karaf/java.util.logging.properties
-Dkaraf.data=/opt/nexus/sonatype-work/nexus3
-Dkaraf.log=/opt/nexus/sonatype-work/nexus3/log
-Djava.io.tmpdir=/opt/nexus/sonatype-work/nexus3/tmp
Save and close the file then edit the nexus.rc file and define the run as user:
vim /opt/nexus/bin/nexus.rc
Uncomment and change the following line with nexus user:
run_as_user="nexus"
Save and close the file then start the Nexxus service with the following command:
sudo -u nexus /opt/nexus/bin/nexus start
Next, verify the Nexus with the following command:
tail -f /opt/nexus/sonatype-work/nexus3/log/nexus.log
You should get the following output:
2021-02-23 12:20:51,839+0000 INFO [jetty-main-1] *SYSTEM com.softwarementors.extjs.djn.servlet.DirectJNgineServlet - Servlet GLOBAL configuration: registryConfiguratorClass=
2021-02-23 12:20:51,853+0000 INFO [jetty-main-1] *SYSTEM com.softwarementors.extjs.djn.jscodegen.CodeFileGenerator - Creating source files for APIs...
2021-02-23 12:20:52,582+0000 INFO [jetty-main-1] *SYSTEM org.sonatype.nexus.siesta.SiestaServlet - JAX-RS RuntimeDelegate: org.sonatype.nexus.siesta.internal.resteasy.SisuResteasyProviderFactory@649a69ca
2021-02-23 12:20:52,611+0000 INFO [jetty-main-1] *SYSTEM org.jboss.resteasy.plugins.validation.i18n - RESTEASY008550: Unable to find CDI supporting ValidatorFactory. Using default ValidatorFactory
2021-02-23 12:20:53,811+0000 INFO [jetty-main-1] *SYSTEM org.sonatype.nexus.siesta.SiestaServlet - Initialized
2021-02-23 12:20:53,817+0000 INFO [jetty-main-1] *SYSTEM org.sonatype.nexus.repository.httpbridge.internal.ViewServlet - Initialized
2021-02-23 12:20:53,852+0000 INFO [jetty-main-1] *SYSTEM org.eclipse.jetty.server.handler.ContextHandler - Started o.e.j.w.WebAppContext@7a65358d{Sonatype Nexus,/,file:///opt/nexus/public/,AVAILABLE}
2021-02-23 12:20:53,883+0000 INFO [jetty-main-1] *SYSTEM org.eclipse.jetty.server.AbstractConnector - Started ServerConnector@764a4935{HTTP/1.1, (http/1.1)}{0.0.0.0:8081}
2021-02-23 12:20:53,884+0000 INFO [jetty-main-1] *SYSTEM org.eclipse.jetty.server.Server - Started @37529ms
2021-02-23 12:20:53,884+0000 INFO [jetty-main-1] *SYSTEM org.sonatype.nexus.bootstrap.jetty.JettyServer -
-------------------------------------------------

Started Sonatype Nexus OSS 3.29.2-02

-------------------------------------------------
At this point, Nexus is started and listening on port 8081. You can check it with the following command:
ss -altnp | grep 8081
You should get the following output:
LISTEN 0 50 0.0.0.0:8081 0.0.0.0:* users:(("java",pid=5548,fd=795))
Next, stop the Nexus service with the following command:
/opt/nexus/bin/nexus stop

Create a Systemd Service File for Nexus

Next, you will need to create a systemd service file to manage the Nexus service. You can create it with the following command:
vim /etc/systemd/system/nexus.service
Add the following lines:
[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
Want to print your doc?
This is not the way.
Try clicking the ⋯ next to your doc name or using a keyboard shortcut (
CtrlP
) instead.