Setting up NewRelic Monitoring on Ubuntu 12.4

NewRelic has become more and more popular over the years, and at the moment, they are offering a free T-Shirt and a donation of $10 to Movember for new account deployments. They do have instructions on their site, but I wanted to put my preferred method of installation and configuration somewhere central.

We start by adding a new apt sources list to our Ubuntu installation, which NewRelic have kindly made easier by creating a downloadable sources.list.d file, which you can get like so:

$ sudo wget -O /etc/apt/sources.list.d/newrelic.list http://download.newrelic.com/debian/newrelic.list

Next we need to fetch the correct keys from the key server:

$ sudo apt-key adv --keyserver hkp://subkeys.pgp.net --recv-keys 548C16BF

Now we have all that we need, we can update apt, and install the NewRelic System Monitoring Daemon:

$ sudo apt-get update
$ sudo apt-get install newrelic-sysmond

Now all that’s left to do is adding our license key and starting the service, which can be done using the following commands (substituting XXXXXXXXXX with your own license key):

$ sudo nrsysmond-config --set license_key=XXXXXXXXXX
$ sudo /etc/init.d/newrelic-sysmond start

Your server should now magically appear in your NewRelic account.

Simple Install Script

For convenience, I have created this process as a simple bash script, which you can download below. Simply run it as a privileged user with the license key as the parameter:

$ sudo ./install_newrelic_ubuntu-12.4.sh XXXXXXXXXX

Download Installer Script

JBoss AS 7.1.1 on an Ubuntu 12.04 AWS Instance running Oracle Java 7

JBoss AS 7.1.1 is currently unavailable as a nicely installable Ubuntu package, officially, or as a PPA, and since I was installing it on an AWS instance, there are a couple of steps you need to do to make sure the correct ports are opened.

Setting up your AWS instance for JBoss AS

I will assume that you have created an instance, and that you have already set up SSH access rules on the Security Group that you have assigned to that instance.

Once you have got to this point, go to the Security Groups section under the NETWORK & SECURITY heading, and highlight the Security Group that is assigned to your Instance. Make sure that the Inbound tab is selected. From here, you should see a form to add a new inbound rule, as below:

AWS Console Security Group Add New Rule

You will need to add two port ranges to your Security Group:

  • 8080 for your applications.
  • 9990 for the admin interface.

To do this you will need to fill in the form above like so:

AWS Console Security Group Add Port 8080

Once it looks like this, click on “Add Rule” and move on to the next port, like so:

AWS Console Security Group Add Port 9990

Again, click on “Add Rule”, so your ports list should look like this:

AWS Console Security Group Ports List

The “Apply Rule Changes” button should now be enabled:

AWS Console Security Group Apply Changes Button

Click on the “Apply Rule Changes” to commit the new rules you’ve just added. If you don’t click on this button, the added ports will be lost when you navigate away from this page.

You have now completed the AWS setup, so let’s move on to getting a Java 7 JRE installed & configured.

Oracle Java 7 JRE on Ubuntu 12.04

To install this, we will use an Ubuntu PPA. To start with, you will need to add the PPA to your apt sources. You can do this on the command line using the following command:

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

Test this by typing in:

  $ java -version

The result should be something like this:

  java version "1.7.0_09"
  Java(TM) SE Runtime Environment (build 1.7.0_09-b05)
  Java HotSpot(TM) 64-Bit Server VM (build 23.5-b02, mixed mode)

Oracle Java 7 is taken care of, so we’ll move on to installing JBoss AS.

Installing JBoss AS 7.1.1

We need to start by downloading the JBoss AS binaries. We can do this using wget like so:

  $ wget http://download.jboss.org/jbossas/7.1/jboss-as-7.1.1.Final/jboss-as-7.1.1.Final.tar.gz

This will download the tar file, and when it’s completed, we can uncompress it using the following command:

  $ tar -xzvf jboss-as-7.1.1.Final.tar.gz

I have chosen to install JBossAS in the /opt folder, so If you chose another location, please ensure you make this change in your own actions. We will move it into the selected location:

  $ sudo mv jboss-as-7.1.1.Final /opt

Now we need to change the listener IP for the JBoss configuration so we can access it from a remote location:

  $ sudo vim /opt/jboss-as-7.1.1.Final/standalone/configuration/standalone.xml

You will need to find and edit the following lines (For reference, in the copy I downloaded, these were found at line #267):

  <interface name="management">
  <inet-address value="${jboss.bind.address.management:127.0.0.1}"/>
  </interface>
  <interface name="public">
  <inet-address value="${jboss.bind.address:127.0.0.1}"/>
  </interface>

You will need to change this to:

  <interface name="management">
  <inet-address value="0.0.0.0"/>
  </interface>
  <interface name="public">
  <inet-address value="0.0.0.0"/>
  </interface>

Now we are ready to test the installation, so we can just run it from the command line:

  $ /opt/jboss-as-7.1.1.Final/bin/standalone.sh

This should start up the server, and you should be able to get a JBoss AS welcome page by visiting http://xxx.xxx.xxx.xxx:8080/ where xxx.xxx.xxx.xxx is the Elastic IP/public IP of your AWS instance.

Now we just need to set up the new JBoss AS installation as a service. We will start with creating a user for the service, then changing ownership of the installation to this new user:

  $ sudo useradd -r jboss
  $ sudo chown jboss: /opt/jboss-as-7.1.1.Final/ -R

We now need to create a startup script for the service.

EDIT: As per the comment posted by blablub below, this solution apparently doesn’t work for everybody. It did work for me, but these are a couple of points to be aware of:

under [JBoss-7]/bin/init.d/ already does exist a init.d-script for jboss!

you dont have to write ur own and by the way a “jboss-admin.sh” doesnt exist under jboss 7!

To do this, we need to create a new file in the /etc/init.d/ folder:

  $ sudo vim /etc/init.d/jboss

Write the following into this new file:

  #!/bin/sh
  ### BEGIN INIT INFO
  # Provides: jboss
  # Required-Start: $local_fs $remote_fs $network $syslog
  # Required-Stop: $local_fs $remote_fs $network $syslog
  # Default-Start: 2 3 4 5
  # Default-Stop: 0 1 6
  # Short-Description: Start/Stop JBoss AS v7.1.1
  ### END INIT INFO
  #
  #source some script files in order to set and export environmental variables
  #as well as add the appropriate executables to $PATH
 
  export JAVA_HOME=/usr/lib/jvm/java-7-oracle
  export PATH=$JAVA_HOME/bin:$PATH
 
  export JBOSS_HOME=/opt/jboss-as-7.1.1.Final
  export PATH=$JBOSS_HOME/bin:$PATH
 
  case "$1" in
  start)
  echo "Starting JBoss AS 7.1.1"
  #original:
  #sudo -u jboss sh ${JBOSS_HOME}/bin/standalone.sh
 
  #updated:
  start-stop-daemon --start --quiet --background --chuid jboss --exec ${JBOSS_HOME}/bin/standalone.sh
  ;;
  stop)
  echo "Stopping JBoss AS 7.1.1"
  #original:
  #sudo -u jboss sh ${JBOSS_HOME}/bin/jboss-admin.sh --connect command=:shutdown
 
  #updated:
  start-stop-daemon --start --quiet --background --chuid jboss --exec ${JBOSS_HOME}/bin/jboss-admin.sh -- --connect command=:shutdown
  ;;
  *)
  echo "Usage: /etc/init.d/jboss {start|stop}"
  exit 1
  ;;
  esac
 
  exit 0

We will need to make sure the init script is writable:

  $ sudo chmod +x /etc/init.d/jboss

Finally, we need to update rc.d with the new service script:

  sudo update-rc.d jboss defaults

You can now use this script like any other /etc/init.d script.

The following sites were useful in determining how to do this, and deserve thanks: