ManagedCloud Servers

High performance handled and monitored by us 24/7/365. A complete solution to provide you with our in house expertise 24/7 tailored to your specific needs. We'll setup a bespoke server for your site using the latest tehnologies so you can get the most out of your hardware and get your website loading quickly and reliably. Find out more..

cPanelCloud Servers

Recommended - High performance cloud servers with no technical knowledge required. If you're hosting multiple websites already and you're looking to consolidate, or if you're looking to isolate yourself from the shared hosting environment but you don't have the time or knoweldge to manage a server, then the Managed cPanel Servers are for you. Find out more..

UnmanagedCloud Servers

Our unmanaged range gives you complete control at rock bottom prices and our cloud platform boasts super fast multipath 40Gb/s network, the latest Intel Xeon V3 CPUs and enterprise grade redundant SSDs. If you're a sysadmin look no further, we offer some of the best specification to price ratio servers available. Find out more..

Want your very own server? Get our 1GB memory, Xeon V4, 20GB SSD VPS for £10.00 / month.

View Plans

How To Create a Repository Manager With Apache Archiva On Ubuntu 14.04

Introduction

When you are building a java application it's most likely you will use Maven Repository, whether local or from The Maven Central](). You might not want to host your library on maven central since anyone can download the build artifact from maven central. This is where you need your own artifact repository manager.

Repository Manager Alternatives There are several artifact repository manager that you can use.

  • JFrog provides open source version called Artifactory
  • Sonatype provides Nexus. Nexus available in two version, Open Source and professional
  • Apache Software Foundation have Apache Archiva.

Goals

In this tutorial we'll learn how to install Apache Archiva. We will use a standalone package instead of installing Apache Archiva as web application on Tomcat, this is only for the sake of simplicity. If you are familiar with Tomcat and have a standardized Tomcat installation you can choose to install Apache Archiva on Tomcat or another Java EE application server.

We will create a separate base application directory with data directory. This will make upgrade and backup easier. We will also put Nginx in front of Apache Archiva, Nginx will run on standard port for http and https and it will proxy the traffic to archiva that run on port 8080. SSL termination will be done on nginx. We will also use MySQL as database server instead of bundled Apache Derby. The reason for this is easier maintenace since most admins familiar with MySQL. You can skip steps for MySQL installation and configuration if you prefer using default Apache Derby Database.

Step 1 - Installing prerequisite applications

This tutorial assumes that the system you use is a fresh install with minimal installed packages. Before we install prerequisite packages we will update the system to latest packages.

Update repository metadata

$ sudo apt-get update

Update all packages

$ sudo apt-get upgrade

Now you have the latest update for the base image. Time to install pre-requisite software.

Step 2 - Install Nginx from nginx.org

We will install nginx from nginx.org repository. The reason is that the Ubuntu repo ships with an older version of nginx. While this is ok and there is no specific feature on new version that we really need, having the latest stable version will benefit us for having the latest features and bug fixes.

Add Nginx package signing key

$ wget -c -O- http://nginx.org/keys/nginx_signing.key | sudo apt-key add -

Add nginx.org Repository $ echo "deb http://nginx.org/packages/ubuntu/ trusty nginx" | sudo tee -a /etc/apt/sources.list > /dev/null $ echo "deb-src http://nginx.org/packages/ubuntu/ trusty nginx" | sudo tee -a /etc/apt/sources.list > /dev/null

Install Nginx

$ sudo apt-get update
$ sudo apt-get -y install nginx

Now we have nginx installed, we can check it by restarting the service :

$ sudo service nginx restart

Configure nginx

Create new configuration file on /etc/nginx/conf.d/archiva with the contents as below. There are two server blocks, one for http the other one is for https. You need to change server_name and ssl certificate.

upstream archiva {
``` language-bash
    server 127.0.0.1:8080;
</code></pre>

}

server {

<pre><code class="language-bash"> listen 80; server_name archiva.example.com; client_max_body_size 20M; rewrite ^ https://$server_name$request_uri? permanent;

access_log /var/archiva/logs/access.log; error_log /var/archiva/logs/error.log; root /opt/archiva; index index.html;

proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header Host $host; proxy_set_header X-Forwarded-Proto $scheme;

keepalive_timeout 10 10; keepalive_requests 1500;

location / { proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header Host $http_host; proxy_redirect off; try_files /system/maintenance.html $uri $uri/index.html $uri.html @archiva; }

location @archiva { proxy_pass http://archiva; } </code></pre>

}

server {

<pre><code class="language-bash"> listen 443 ssl spdy; server_name archiva.example.com; client_max_body_size 20M;

access_log /var/log/nginx/archiva.example.com-access.log; error_log /var/log/nginx/archiva.example.com-error.log; root /opt/archiva; index index.html;

server_name_in_redirect off;

ssl_certificate /etc/nginx/ssl/archiva.example.com.crt; ssl_certificate_key /etc/nginx/ssl/archiva.example.com.key;

ssl_ciphers "EECDH+ECDSA+AESGCM EECDH+aRSA+AESGCM EECDH+ECDSA+SHA384 EECDH+ECDSA+SHA256 EECDH+aRSA+SHA384 EECDH+aRSA+SHA256 EECDH+aRSA+RC4 EECDH EDH+aRSA RC4 !aNULL !eNULL !LOW !3DES !MD5 !EXP !PSK !SRP !DSS"; ssl_prefer_server_ciphers on; ssl_protocols TLSv1 TLSv1.1 TLSv1.2;

ssl_session_cache shared:SSL:30m; ssl_session_timeout 10m;

proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header Host $host; proxy_set_header X-Forwarded-Proto $scheme;

keepalive_timeout 10 10; keepalive_requests 1500;

location / { proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header Host $host; proxy_redirect off; #try_files /system/maintenance.html $uri $uri/index.html $uri.html @archiva; proxy_pass http://127.0.0.1:8080; proxy_redirect http:// https://; } </code></pre>

}

<pre><code><br />### Restart nginx We need to restart nginx to reload the new configuration. </code></pre>

$ sudo service nginx restart

<pre><code><br />## Step 3 - Install MySQL We will use MySQL 5.6 for this installation. To install MySQL 5.6 you can run command below : </code></pre>

$ sudo apt-get install mysql-server-5.6

<pre><code>I recommend setting up the root password for your database server

### Secure MySQL Installation I recommend running /usr/bin/mysql_secure_installation to secure your MySQL installation. The wizard will ask you to delete default user, test database and only allow root access from localhost.

### Create MySQL user for Archiva In this step we will create archiva database and user that only has privileges to this database instead of using the MySQL root account which is not secure. </code></pre>

$ mysql -u root -p mysql > create database archiva; mysql > GRANT ALL PRIVILEGES on archiva.* to archiva@'localhost' IDENTIFIED BY ''; mysql > FLUSH PRIVILEGES;

<pre><code><br />### Step 4 - Install Oracle JDK Next, we'll install Oracle JDK 8 on the server. We will use webupd8team ppa repo instead of manually installing JDK 8 </code></pre>

$ sudo add-apt-repository ppa:webupd8team/java $ sudo apt-get update $ sudo apt-get install oracle-java8-installer

<pre><code>The installer will ask you to accept the License Agreement.

## Step 5 - Install Apache Archiva

### Download Apache Archiva 2.1.1 Download Apache Archiva 2.1.1 and it's MD5 signature ```` $ wget -c http://apache.osuosl.org/archiva/2.1.1/binaries/apache-archiva-2.1.1-bin.tar.gz $ wget -c http://www.apache.org/dist/archiva/2.1.1/binaries/apache-archiva-2.1.1-bin.tar.gz.md5

Check the integrity of package that we just downloaded.

$ md5sum apache-archiva-2.1.1-bin.tar.gz
18b7124e6f0a2c8f7db8167c6946d762  apache-archiva-2.1.1-bin.tar.gz

$ cat apache-archiva-2.1.1-bin.tar.gz.md5 18b7124e6f0a2c8f7db8167c6946d762

Make sure that hash output for two command below is the same. If don't redownload apache-archiva

Extract Archiva File

Extract Apache Archiva file that we just downloaded and move the file to /opt directory.

$ tar xzvf apache-archiva-2.1.1-bin.tar.gz
$ mv apache-archiva-2.1.1 /opt
$ sudo chown -R ubuntu:ubuntu /opt/apache-archiva-2.1.1
````

Separate the base installation with data directory. We'll put data directory on /var/archiva. We need logs, data, temp and conf directory under /var/archiva

$ sudo mkdir -p /var/archiva/{logs,data,temp,conf} $ sudo chown -R ubuntu:ubuntu /var/archiva


### Download MySQL JDBC Driver We need the MySQL JDBC Driver so that Archiva can use MySQL database. You can Download MySQL Connector/K from [http://dev.mysql.com/downloads/connector/j/](http://dev.mysql.com/downloads/connector/j/). Select **Platform Independent**.

$ cd ~ $ wget -c http://cdn.mysql.com/Downloads/Connector-J/mysql-connector-java-5.1.35.tar.gz



### Extract MySQL JDBC Driver Extract MySQL JDBC Driver before moving the content to archiva lib directory.

$ tar xzf mysql-connector-java-5.1.35.tar.gz


### Copy MySQL JDBC Driver to Archiva directory After extracting MySQL JDBC Driver we copy the library to apache archiva lib directory

cp mysql-connector-java-5.1.35/mysql-connector-java-5.1.35-bin.jar /opt/apache-archiva-2.1.1/lib


### Change Archiva Configuration edit /opt/apache-archiva-2.1.1/conf/jetty.xml to add MySQL configuration
    jdbc/users

com.mysql.jdbc.Driver jdbc:mysql://localhost/archiva

15 <!-- depends on your concurrent users numbers --> 30 10000 true true 10000 true <!-- very rigourous sql query validation --> select 1


You need to put MySQL username and pasword that you already created for archiva on these lines



### Set ARCHIVA_BASE environment variable Edit /etc/bash.bashrc with your favorite editor, add lines below at the bottom of the configuration

export ARCHIVA_BASE=/var/archiva



### Register Archiva as a Service We need to create symbolic link for bin/archiva on archiva directory to /etc/init.d

$ sudo ln -sf /opt/apache-archiva-2.1.1/bin/archiva /etc/init.d/archiva


Register archiva service to start on boot

$ update-rc.d archiva defaults 80


### Managing Archiva Service To start apache archiva you can use command below

$ sudo service archiva start


To stop apache archiva you can use command below

$ sudo service archiva stop


To restart apache archiva you can use command below

$ sudo service archiva restart ```

Summary

In this tutorial we learned how to install and configure Apache Archiva using nginx as reverse proxy. We also use MySQL as database server instead of bundled Apache Derby.

Want your very own server? Get our 1GB memory, Xeon V4, 20GB SSD VPS for £10.00 / month.

View Plans