Today I wanted to share some simple installation steps on installing Nexus Repository OSS on CentOS 7.
Nexus Repository OSS is a free, open source artifact repository with universal format support provided by Sonatype. More information can be found here.
In my case I want to configure a Proxy Repository for Docker Container Images using Nexus Repository OSS. A Proxy Repository can be defined as follows:
A proxy repository is a repository that is linked to a remote repository, such as the Central Repository. When using a proxy, requests for components are verified against the cached components in your proxy repository. When you search for components, if the request isn’t found in your proxy repository, it is forwarded to the Central Repository. That component is then retrieved from Central and cached in the repository manager. If you search for that same component again, it will be found in local storage. This eliminates the need to go to the Central Repository and reduces bandwidth and time needed to retrieve the components you need.Source: Sonatype
CentOS 7 VM
I deployed a CentOS 7 Virtual Machine in my lab environment with the following specs:
- 4 vCPUs
- 4GB RAM
- 50GB Disk for root
- 50GB Disk for Docker Proxy Repository Data
The System Requirements for Nexus Repository OSS can be found here.
Useful tools for troubleshooting
The following tools can be useful for troubleshooting your setup:
yum install net-tools
This will give you netstat for example.
yum install telnet
This allows you to perform telnet commands on the VM.
Nexus Repository OSS Installation on CentOS 7
- Let’s start with installing the prerequisites:
yum install -y epel-release vim wget unzip
2. Nexus Repository OSS requires Java 8 Runtime Environment. Check if you have Java installed, if not, make sure to install it:
java -version yum -y install java-1.8.0-openjdk java-1.8.0-openjdk-devel
3. We will be installing Nexus Repository OSS in a specific folder and create another folder for Data & Log files
mkdir -p /data/nexus-data /opt/nexus
4. Download the latest version of Nexus Repository OSS:
wget -O /tmp/nexus.tar.gz http://download.sonatype.com/nexus/3/latest-unix.tar.gz
5. Extract it to our installation directory (/opt/nexus):
tar xvfz /tmp/nexus.tar.gz -C /opt/nexus --strip-components 1
6. Create a Service Account called ‘nexus’ to run the Nexus Repository OSS Application under:
sudo useradd --system --no-create-home nexus
7. Set the necessary permissions on the Nexus folders for the nexus Service Account:
chown -R nexus:nexus /opt/nexus chown -R nexus:nexus /data/nexus-data
8. Configure the Environment Variables:
# Make sure to select the default JDK, # in my case the correct one was already selected alternatives --config java # Setting up JAVA_HOME by adding the following line # at the bottom of /etc/bashrc export JAVA_HOME=$(dirname $(dirname $(readlink $(readlink $(which javac))))) # Setting up NEXUS_HOME by adding the following line # at the bottom of /etc/bashrc export NEXUS_HOME=/opt/nexus # Get the updated JAVA_HOME and NEXUS_HOME into current shell source /etc/bashrc # Check the JAVA version, should return 1.8.x java -version
9. I changed the following options in the $NEXUS_HOME/bin/nexus.vmoptions config file to make sure we are using the correct folders where the nexus Service Account has permissions on:
-XX:LogFile=/data/nexus-data/nexus3/log/jvm.log -Dkaraf.data=/data/nexus-data/nexus3 -Dkaraf.log=/data/nexus-data/nexus3/log -Djava.io.tmpdir=/data/nexus-data/nexus3/tmp
10. Configure the run_as_user option in the Nexus Repository OSS Configuration file $NEXUS_HOME/bin/nexus.rc :
11. Create a SystemD Service File in /etc/systemd/system/nexus.service
[Unit] Description=Nexus Server After=syslog.target network.target [Service] Type=forking LimitNOFILE=65536 ExecStart=/opt/nexus/bin/nexus start ExecStop=/opt/nexus/bin/nexus stop User=nexus Group=nexus Restart=on-failure [Install] WantedBy=multi-user.target
12. (Optionally – if not using a SystemD Service file) You can increase / decrease the Open File limit in this file /etc/security/limits.conf by adding the following line to it :
nexus - nofile 65536
See Sonatype Support article here.
13. (Optionally – if using a SystemD Service file like in point 11) You can increase / decrease the Open File limit in this file /etc/systemd/system/nexus.service by modifying the following line:
See Sonatype Support article here.
14. Enable & Start the Nexus Service:
sudo systemctl daemon-reload sudo systemctl start nexus.service sudo systemctl enable nexus.service
15. Nexus Repository OSS is running on port 8081, to check if it’s listening on that port run the following command:
netstat -an | grep 8081
16. Now make sure that the firewall allows connections on port 8081:
firewall-cmd --permanent --add-port=8081/tcp firewall-cmd --reload
17. Take your favourite Web Browser and browse to the following URL:
You should be greeted with the Welcome Page:
For a later blogpost I’m thinking to set this up behind an NGINX Proxy and then afterwards make sure my Repository is used. Stay tuned!