Your private Maven artifacts repository: install Sonatype Nexus OSS on AWS EC2 Amazon Linux

Nexus OSS from Sonatype is a artifacts repository.
I currently use Nexus to store the Maven artifacts of my Java projects that need to be imported by other Maven projects.

I had some headache setting up Nexus OSS on the Amazon cloud so I though of posting the steps to have your own private artifact repository on the cloud.

The following steps will help you to install Sonatype Nexus OSS on a EC2 instance on AWS.
We’ll be using a EC2 micro. Micro instances are the cheapest EC2 instances but they do still costs money. You might get one for free for a while with the free tier.

Login into the AWS Management Console and go to EC2 
https://console.aws.amazon.com/ec2/v2/home

Create a new Security Group called ContinuosIntegration
allow the following inbound services
22 (SSH) 0.0.0.0/0
80 (HTTP) 0.0.0.0/0
443 (HTTPS) 0.0.0.0/0
4000 0.0.0.0/0
8080 (HTTP*) 0.0.0.0/0
8081 0.0.0.0/0 (Nexus OSS)
9000 0.0.0.0/0 (Jenkins)

Launch a new EC2 instance
Amazon Machine Image: Amazon Linux AMI – 64 bit
Instance Type: t1.micro (so far t1.micro was good enough for my 5 Java projects)
Security Group: ContinuosIntegration (previously created)

Download KeyPair into SSH folder and change KeyPair Access Permnission

You haven’ t done already so. Download the KeyPair for this instance into ~/.ssh/YOUR_KEY_PAIR.pem.
Limit the .pem file permission to avoid ssh to complain:

$ chmod 400 ~/.ssh/YOUR_KEY_PAIR.pem

Connect with SSH to your EC2 instance
Find the address of your EC2 instance by selecting it in the Managament Console (something like ec2-XX-XXX-XXX-XXX.compute-1.amazonaws.com)
Adapt the following bash command to your KEY_PAIR filename and EC2 instance address:

$ ssh -i ~/.ssh/YOUR_KEY_PAIR.pem ec2-user@ec2-XX-XXX-XXX-XXX.compute-1.amazonaws.com

Download and unzip Nexus OSS

$ cd /usr/local
$ sudo wget http://www.sonatype.org/downloads/nexus-latest-bundle.tar.gz
$ sudo tar -xvzf nexus-latest-bundle.tar.gz
$ sudo rm nexus-latest-bundle.tar.gz

Create a link to the actual nexus-VERSION folder (replace nexus-2.5.1-01 with your nexus installed version)

$ sudo ln -s nexus-2.5.1-01/ nexus

Create NEXUS_HOME environment variable

$ export NEXUS_HOME=/usr/local/nexus

Create nexus user with restricted permissions

$ sudo useradd -m nexus

Change ownership of nexus folder to the nexus user and nexus group

$ sudo chown -R nexus:nexus /usr/local/nexus-2.5.1-01/
sudo chown -R nexus:nexus /usr/local/sonatype-work

Edit the nexus executable (necessary for the nexus user and to run nexus as a service)
I’m using the vi editor since it’s already installed on Amazon Linux.

$ sudo vi /usr/local/nexus/bin/nexus

PRESS i to enter in insert mode

change the following lines:
NEXUS_HOME=”/usr/local/nexus” #(necessary to run nexus as a service)
RUN_AS_USER=nexus #(remove the #comment in front and set the RUN_AS_USER to “”"”"”"nexus)
PIDDIR”"”"”"” =”/home/nexus” #(necessary to run nexus as the nexus user)

PRESS esc to exit the insert mode

PRESS : and type :wq and then press enter to save and quit

Launch Nexus

$ cd /usr/local/nexus/bin
$ sudo ./nexus console
$ tail -f /usr/local/nexus/logs/wrapper.log

Stop Nexus

$ cd /usr/local/nexus/bin
$ sudo ./nexus stop

Start nexus as a service
Copy the nexus starting script to /etc/init.d

$ sudo cp $NEXUS_HOME/bin/nexus /etc/init.d/nexus

Make the nexus script executable

$ sudo chmod 755 /etc/init.d/nexus

Make effective this nexus service settings

$ cd /etc/init.d
$ chkconfig --add nexus
$ sudo chkconfig --levels 345 nexus on

now you nexus should start automatically at each OS startup.

You can still start/stop nexus as a service manually:

$ sudo service nexus start

Access nexus web dashboard
Once nexus is running should be able to connect to the Nexus Dashboard using the EC2 address followed by the 8081 port and /nexus path:

http://ec2-XX-XXX-XXX-XXX.com:8081/nexus

login in nexus and change default credentials

login using the default credentials username: admin password: admin123
Once you are logged in create a new admin account and delete the default admin credentials using the Security -> Users screen accessible through the menu on the left.

Also read...

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>