Difference between revisions of "Nexus"

(Created page with "Category:Development Category:Linux This page explains how to setup and configure NEXUS Maven repositories. =Requirements= a) You need to setup Maven b) You need...")
 
Line 10: Line 10:
  
  
b) You need to create a root folder to host all the artifacts
+
b) Create user / group
 +
 
 +
<syntaxhighlight lang="bash">
 +
# Create group
 +
addgroup --system "nexus"
 +
 +
# Create Nexus user (home directory must be Nexus)
 +
adduser --home /opt/nexus --disabled-login --disabled-password nexus
 +
</syntaxhighlight>
 +
 
 +
 
 +
c) You need to create a root folder to host all the artifacts
  
 
<syntaxhighlight lang="bash">
 
<syntaxhighlight lang="bash">
 
mkdir -p /home/nexus
 
mkdir -p /home/nexus
 
chmod -R 777 /home/nexus
 
chmod -R 777 /home/nexus
 +
chown -R nexus:nexus /home/nexus
 
</syntaxhighlight>
 
</syntaxhighlight>
 +
  
  
Line 31: Line 44:
 
ln -s /opt/nexus-2.11.4-01/ /opt/nexus
 
ln -s /opt/nexus-2.11.4-01/ /opt/nexus
 
</syntaxhighlight>
 
</syntaxhighlight>
 +
 +
 +
Set rights
 +
 +
<syntaxhighlight lang="bash">
 +
chown -R nexus:nexus /opt/nexus
 +
chown -R nexus:nexus /opt/nexus-2.11.4-01
 +
</syntaxhighlight>
 +
  
  
 
=Configuration=
 
=Configuration=
 +
  
 
==Set nexus parameters==
 
==Set nexus parameters==
Line 47: Line 70:
 
<syntaxhighlight lang="apache">
 
<syntaxhighlight lang="apache">
 
application-port=9081
 
application-port=9081
 +
application-host=127.0.0.1
 
nexus-webapp-context-path=/nexus
 
nexus-webapp-context-path=/nexus
  
 
## Nexus section
 
## Nexus section
# nexus-work == folders where the artifacts are going to be saved. You must choose a folder with a lot of disk!
+
## nexus-work ==>> folders where the artifacts are going to be saved. You must choose a folder with a lot of disk!
nexus-work=${bundleBasedir}/../sonatype-work/nexus
+
nexus-work=/home/nexus
 
runtime=${bundleBasedir}/nexus/WEB-INF
 
runtime=${bundleBasedir}/nexus/WEB-INF
 
</syntaxhighlight>
 
</syntaxhighlight>
 +
 +
 +
==Log symlink==
 +
 +
<syntaxhighlight lang="bash">
 +
ln -s /opt/nexus/logs/wrapper.log /var/log/nexus.log
 +
</syntaxhighlight>
 +
 +
 +
 +
 +
==Set Nexus user and rights==
 +
 +
<syntaxhighlight lang="bash">
 +
vim /opt/nexus/bin/nexus
 +
</syntaxhighlight>
 +
 +
 +
<syntaxhighlight lang="apache">
 +
# Set the correct home
 +
NEXUS_HOME="/opt/nexus"
 +
 +
#uncomment and adjust
 +
RUN_AS_USER="nexus"
 +
#The PID directory must be a directory where you the runtime user can Read/Write
 +
PIDDIR="/opt/nexus"
 +
</syntaxhighlight>
 +
 +
 +
==ERROR Fix==
 +
 +
If you encounter the <code>Failed to start Nexus OSS</code> error, then you need to:
 +
 +
<syntaxhighlight lang="bash">
 +
chown -R nexus:nexus /opt/sonatype-work
 +
</syntaxhighlight>
 +
  
  
Line 69: Line 130:
  
 
<syntaxhighlight lang="bash">
 
<syntaxhighlight lang="bash">
NEXUS_HOME="/opt/nexus"
 
 
</syntaxhighlight>
 
</syntaxhighlight>
 +
 +
 +
 +
 +
 +
Congratulation! Now you’r Nexus installation is available on http://localhost:8081/nexus/. The default user and password are
 +
“admin” and “admin123“.
 +
Basic configuration of the maven clients
 +
 +
Login as admin, locate predefined repositories. All repositories of type “proxy” need to change “Download Remote Indexes” property  to true in the configuration tab.
 +
 +
As you see there are several types of repositories.
 +
 +
    proxy – acts as proxy for external repository.
 +
    hosted – repository that managed artifact produced by you
 +
    virtual – kind of adapter for e.g transforming maven1 to maven 2 format.
 +
    group – maybe not a repository in sonatyp’s terminology but behaves like one. A group groups several repositories to one exposing result as single URI.
 +
 +
Per default there is  a group “public” present. This group includes all the needed stuff, we just need to tell our maven clients to use this group. Maybe the easiest and flexiblest way to do so, is to use a mirror in settings.xml of your local maven.
 +
<mirrors>
 +
  <mirror>
 +
    <id>nexus</id>
 +
    <mirrorOf>*</mirrorOf>
 +
  <url>http://YOR_NEXUS_HOST:8081/nexus/content/groups/public</url>
 +
  </mirror>
 +
</mirrors>
 +
 +
Then we use a power of Maven Profiles and define new repositories they are magically (consider “*” in the mirror declaration) maps to the mirror.
 +
<profile>
 +
    <id>nexus</id>
 +
    <!--all requests to nexus via the mirror -->
 +
    <repositories>
 +
      <repository>
 +
        <id>central</id>
 +
        <url>http://central</url>
 +
        <releases><enabled>true</enabled></releases>
 +
        <snapshots><enabled>true</enabled></snapshots>
 +
      </repository>
 +
    </repositories>
 +
    <pluginRepositories>
 +
      <pluginRepository>
 +
        <id>central</id>
 +
        <url>http://central</url>
 +
        <releases><enabled>true</enabled></releases>
 +
        <snapshots><enabled>true</enabled></snapshots>
 +
      </pluginRepository>
 +
    </pluginRepositories>
 +
  </profile>
 +
 +
Do not forgete to activate thins new profile
 +
<activeProfiles>
 +
    <activeProfile>nexus</activeProfile>
 +
</activeProfiles>
 +
 +
Now your maven client knows only your nexus and everything it needs and how it gets it, should be controlled by nexus.
 +
 +
 +
=References=
 +
 +
* http://alexander.holbreich.org/2012/10/sonatype-nexus-setup/

Revision as of 00:05, 12 September 2015


This page explains how to setup and configure NEXUS Maven repositories.


Requirements

a) You need to setup Maven


b) Create user / group

# Create group
addgroup --system "nexus"
 
# Create Nexus user (home directory must be Nexus)
adduser --home /opt/nexus --disabled-login --disabled-password nexus


c) You need to create a root folder to host all the artifacts

mkdir -p /home/nexus
chmod -R 777 /home/nexus
chown -R nexus:nexus /home/nexus



Installation

Download Nexus OSS as Nexus Open-Source Server - take the ZIP format

cd /opt
wget http://www.sonatype.org/downloads/nexus-latest-bundle.tar.gz
tar xzvf nexus-latest-bundle.tar.gz
rm nexus-latest-bundle.tar.gz
ln -s /opt/nexus-2.11.4-01/ /opt/nexus


Set rights

chown -R nexus:nexus /opt/nexus
chown -R nexus:nexus /opt/nexus-2.11.4-01


Configuration

Set nexus parameters

Adjust the port number and root context path, if required

vim /opt/nexus/conf/nexus.properties


Set:

application-port=9081
application-host=127.0.0.1
nexus-webapp-context-path=/nexus

## Nexus section
## nexus-work ==>> folders where the artifacts are going to be saved. You must choose a folder with a lot of disk!
nexus-work=/home/nexus
runtime=${bundleBasedir}/nexus/WEB-INF


Log symlink

ln -s /opt/nexus/logs/wrapper.log /var/log/nexus.log



Set Nexus user and rights

vim /opt/nexus/bin/nexus


# Set the correct home
NEXUS_HOME="/opt/nexus"

#uncomment and adjust
RUN_AS_USER="nexus"
#The PID directory must be a directory where you the runtime user can Read/Write
PIDDIR="/opt/nexus"


ERROR Fix

If you encounter the Failed to start Nexus OSS error, then you need to:

chown -R nexus:nexus /opt/sonatype-work


Run Nexus from anywhere

Set the NEXUS_HOME into the start script. Without it you cannot run Nexus as a service!

ln -s /opt/nexus/bin/nexus /usr/bin/nexus
ln -s /opt/nexus/bin/nexus /etc/init.d/nexus

vim /opt/nexus/bin/nexus




Congratulation! Now you’r Nexus installation is available on http://localhost:8081/nexus/. The default user and password are “admin” and “admin123“. Basic configuration of the maven clients

Login as admin, locate predefined repositories. All repositories of type “proxy” need to change “Download Remote Indexes” property to true in the configuration tab.

As you see there are several types of repositories.

   proxy – acts as proxy for external repository.
   hosted – repository that managed artifact produced by you
   virtual – kind of adapter for e.g transforming maven1 to maven 2 format.
   group – maybe not a repository in sonatyp’s terminology but behaves like one. A group groups several repositories to one exposing result as single URI.

Per default there is a group “public” present. This group includes all the needed stuff, we just need to tell our maven clients to use this group. Maybe the easiest and flexiblest way to do so, is to use a mirror in settings.xml of your local maven. <mirrors>

 <mirror>
   <id>nexus</id>
   <mirrorOf>*</mirrorOf>
  <url>http://YOR_NEXUS_HOST:8081/nexus/content/groups/public</url>
 </mirror>

</mirrors>

Then we use a power of Maven Profiles and define new repositories they are magically (consider “*” in the mirror declaration) maps to the mirror. <profile>

    <id>nexus</id>
    <repositories>
      <repository>
        <id>central</id>
        <url>http://central</url>
        <releases><enabled>true</enabled></releases>
        <snapshots><enabled>true</enabled></snapshots>
      </repository>
    </repositories>
   <pluginRepositories>
      <pluginRepository>
        <id>central</id>
        <url>http://central</url>
        <releases><enabled>true</enabled></releases>
        <snapshots><enabled>true</enabled></snapshots>
      </pluginRepository>
    </pluginRepositories>
  </profile>

Do not forgete to activate thins new profile <activeProfiles>

   <activeProfile>nexus</activeProfile>

</activeProfiles>

Now your maven client knows only your nexus and everything it needs and how it gets it, should be controlled by nexus.


References