Monday 13 December 2010

Writing your first Grails Application

Writing your first grails application without the use of an IDE. Ensure grails is installed by running grails from a command prompt, then continue with the steps below to create your first app.

http://www.grails.org/Quick+Start

Thursday 9 December 2010

Configure Ejabberd chat server to use PostgreSQL ODBC

In order to make data persistent with in any application you can link it to a PostgreSQL relational database.
As default Ejabberd messaging server uses it's internal Mnesia database.

1. To change the default to use a postgres database we first need to create a new postgresql database on the server (this assumes you have PgSQL installed and configured)


run ./createdb ejabberd

2. Create the tables using the supplied script

./psql ejabberd < /opt/ejabberd-2.1.5/lib/ejabberd-2.1.5/priv/odbc/pg.sql

3. Add a user for the database

./createuser ejabberd

4. Configure ODBC options in ejabberd.cfg:

Scroll down to the section headed Database setup.

edit the following, remove the %% commenting


{odbc_server, {pgsql, "127.0.0.1", "ejabberd", "ejabberd", "yourpassword"}}.
5. Add _odbc to modules you wish to use the odbc database

e.g. mod_offline_odbc instead of mod_offline.

full list in ejabberd user guide

6. Under authentication comment out internal authentication :

%%{auth_method, internal}.

Then un comment {auth_method, odbc}.

7. Register a new user and appear online using PSI client or similar application

8. Add a user to allowed admin access control list in ejabberd.cfg


{acl, admin, {user, "username", "server"}}.

9. Confirm registered user and status in web admin:


http://serverIP:5280/admin/

10. Connect to database using PgAdmin to view tables with data and confirm ejabberd is now using PostgreSQL

Initial setup and install of PostgreSQL Database and connecting using pgadmin

PostgreSQL is the worlds most advanced open source relational database. PgSQL can be used as a standard database in its own right or can be used to store the data from a number of applications.
In this post I will explain how to install and configure PgSQL. Then go onto to explain how to connect to the data using PGAdmin.


Installing PostgreSQL:

 1. Download source code from http://www.postgresql.org/ftp/source/
2. Extract the downloaded contents: tar -xzvf postgresql-12... .tar.gz
3. ./configure , make, make install. (this may have to be sudo..)
4. create a postgres user : adduser postgres
5. log in as postgres user and initialise the database 
/usr/local/pgsql/bin/initdb -D /usr/local/pgsql/data


This will initilise the database then you can start it any time using:


/usr/local/pgsql/bin/postmaster -D /usr/local/pgsql/data
or
/usr/local/pgsql/bin/pg_ctl -D /usr/local/pgsql/data -l start


6. From in the bin, file create Database: ./createdb test


7. Access Database ./psql test

Use sql commands to add tables / data etc.

\q to quit

You now have a working database you can access.


Access the database from PgAdmin

To access the databases you have from a gui where you can see how the tables are structured and the data within them, pgadmin is a great opensource management tool.

1. Install pgadmin on your local machine by your preferred method, either source or packages. Source downloadable at  http://www.pgadmin.org/download/source.php .
app-get is also an easy install.

2. From the server side configure pg_hba.conf : add trusted hosts. The easiest thing to do is trust local host
host    all         all         192.168.0.0/24        md5


3. Then from your local machine port forward to your server


ssh postgres@serverIP -L 5432:localhost:5432

4. Launch pgadmin, add server. Connect to local host, rather than server IP

5. Manage all postgres databases / tables / data when connected.

Tuesday 7 December 2010

Load testing Ejabberd XMPP Server with Tsung

In order to determine how many servers and what technology is required for a back end Jabber/XMPP server instance I used Tsung to complete a load test.

Tsung is another open source tool written in erlang. Tsung can be used to load test on multiple protocols, including HTTP, LDAP, PostgreSQL and Jabber/XMPP servers.

Tsung can be used to simulate real users and log them all in simultaneously, stress testing the scalability of your servers. For XMPP Tsung can test authentication, logins, chats, requests and much more.

Refer to http://tsung.erlang-projects.org/ for full details.

For initial install load Tsung on one client machine using the instructions below. The same tsung test can be run from multiple clients simultaneously in order to offer maximum stress testing.


1. wget http://tsung.erlang-projects.org/dist/tsung-1.3.3.tar.gz

2. extract the contents, e.g. to usr/local/share/tsung on ubuntu

3. run ./configure from inside the the tsung-1.3.3 folder
then make
make install

4. Run tsung from command prompt, the following should be displayed:

Usage: tsung start|stop|debug|status
Options:
    -f      set configuration file (default is ~/.tsung/tsung.xml)
    -l   set log file (default is ~/.tsung/log/YYYYMMDD-HH:MM/tsung.log)
    -i        set controller id (default is empty)
    -r   set remote connector (default is ssh)
    -s            enable erlang smp on client nodes
    -F            use long names (FQDN) for erlang nodes
    -v            print version information and exit
    -h            display this help and exit


You can simulate logins in a number of different way; for my benchmark test I initially created thousands of users within ejabberd using the following script:

for i in `seq 1 10000`; do echo $i &amp;&amp; ejabberdctl register test$i servername password$i; done

This created 10000 users from test1 to test10000 with respective passwords.
These users can then be simulated by modifying the tsung.xml file usually located in ~/.tsung . Sample files for different test purposes are available at /usr/local/share/doc/tsung/examples/ . 
Configure this file to match whatever benchmarking criteria you require; whether it be load progressions or test duration, all these values can be specified here.


Full explanation of file structure is available in the tsung user manual
The file I used is similar to those in the samples, it made all users appear online simultaneously.

Some snippets from the tsung.xml file I used:

<clients>
     <client host="localhost" use_controller_vm="true" maxusers="100000"></client>

  </clients>

  <servers>
   <server host="serverIP" port="5222" type="tcp"></server>
  </servers>

<load>
    <arrivalphase phase="1" duration="1" unit="minute">
     <users maxnumber="10000" interarrival="0.001" unit="second"></users>
    </arrivalphase>
   </load>



<options>
   <option type="ts_jabber" name="global_number" value="10000"></option>
   <option type="ts_jabber" name="userid_max" value="100000"></option>
   <option type="ts_jabber" name="domain" value="server domain"></option>
   <option type="ts_jabber" name="username" value="test"></option>
   <option type="ts_jabber" name="passwd" value="password"></option>
  </options>

<sessions> 
<session probability="100" name="jabber-example" type="ts_jabber"
    

<request>
      <jabber type="connect" ack="local"></jabber>
    </request>


    <thinktime value="2"></thinktime>


 <transaction name="authenticate">

<request> <jabber type="auth_get" ack="local"></jabber></request>
    <request> <jabber type="auth_set_plain" ack="local"></jabber></request>
</transaction>

    <request>
      <jabber type="presence:initial" ack="global"></jabber></request>
    <thinktime value="6000"></thinktime>

<transaction name="close">
    <request> <jabber type="close" ack="local"></jabber></request>

</transaction>
  </session>
 </sessions>
</tsung>
</tsung>


To run the test execute tsung -f tsung.xml start . Ensuring tsung.xml points to your own configuration file.

N.B If you are testing large number of users you need to look at changing max values in /opt/ejabberd/conf/ejabberdctl.cfg on the server instance. There are a number of options that can be set here, the file explains what each value does.

See results and witness logons by accessing http://MYSERVER:5280/admin and viewing log files in ~/.tsung/log

Refer to Tsung User manual for full usage


Support posts and archives http://lists.jabber.ru/pipermail/ejabberd/

Saturday 4 December 2010

Using PSI chat client to access Ejabberd Chat messaging server

PSI is one of many jabber/XMPP clients available across the net. You can use these type of clients to test connectivity to or use functions available on most instant messaging server instances; in this case ejabberd.

1. Firstly ensure ejabberd is running on the server and there is a user account you can log in with.

use ./ejabberdctl [start/stop/status] to view status or start instance

use ./ejabberdctl register username password to register a new user


2. Install PSI from source or package

Cross platform support available from http://psi-im.org/download/

3. Launch PSI, add a new account, ensuring you fill in the following fields:

jabber id - this is the account you create on the ejabberd server.
password - corresponding password with above account

under connection settings:
specify server IP address or host name, ensuring you complete the port number; usually 5222

4. Save all settings and view the account in PSI application.
Change status to online.

5. Test chat to another user using same method of setup above, or log into web admin page of ejabberd server at http://SERVERIP:5280/admin to confirm successfully connectivity.

Installing Ejabberd Chat Messaging Server on Linux

Ejabberd is instant messaging server software that can be incorporated into any environment. Basic installation instructions for Unix / Linux are as follows:

1. Install Erlang:

sudo apt-get install erlang.

or from source,

Ensure all requirements are installed, Libncurses and OpenSS. Use apt-get for these.

Erlang:

wget http://www.erlang.org/download/otp_src_R14B.tar.gz
tar -xzvf otp_src_R14B.tar.gz
cd otp_src_R14B.tar.gz
LANG=C; export LANG 

./configure
make
make install 

Verify installation, type erl 
The following should be displayed:  

Erlang R14B (erts-5.8) [source] [smp:2:2] [rq:2] [async-threads:0] [kernel-poll:false]

Eshell V5.8  (abort with ^G)
1>
 

2.  Install Ejabberd:

debian package: 
apt-get install ejabberd

binary installer:

wget http://www.process-one.net/downloads/ejabberd/2.1.6/ejabberd-2.1.6-linux-x86_64-installer.bin.gz

gunzip ejabberd-2.1.6-linux-x86_64-installer.bin.gz
chmod a+x ejabberd-2.1.6-linux-x86_64-installer.bin.gz
./ejabberd-2.1.6-linux-x86_64-installer.bin 


Accept all default options, installation complete



or from source:

wget http://www.process-one.net/downloads/ejabberd/2.1.5/ejabberd-2.1.5.tar.gz
tar -xzvf ejabberd-2.1.5.tar.gz
cd ejabberd-2.1.5/src
./configure
make
make install

/bin/ejabberd.cfg to specify settings




Use ejabberdctl start to start node instance.

Browse to http://localhost:5280/admin/ for server web admin, you will need to add exception for user admin to browse to web admin page.

Enter the following in /bin/ejabberd.cfg:

{acl, admin, {user, "admin_user", "your_sever"}}.


N.B ejabberd uses an internal Mnesia database by default. But it possible to an alternative relational database or LDAP server to ensure data is persistent.

In later posts I will discuss using a PostgreSQL database to store data for various applications such as ejabberd.

Refer to Ejabberd installation and operation guide

Bulding your first android app

In order to build your first android app you will need to create a virtual device (AVD) and build an new project.

I will not re-type what is already available.

For full instructions on the Hello Android app refer to
http://developer.android.com/resources/tutorials/hello-world.html

Tuesday 30 November 2010

Installing android SDK and ADT plugin for Eclipse IDE

The easiest way to get started in developing Android apps is to use the Eclipse IDE with android SDK and ADT plugin. There are simple instructions on the android developers site, however to confirm the steps are as follows:

1. Install Eclipse IDE, see Installing eclipse IDE

2. Download the SDK starter package.
Extract the contents and save to a directory. Your home directory is safe place where you'll be able to find it later on.

3. Download and install the ADT plugin. This is very simple in Eclipse.

a. Launch Eclipse, Click Help, Install new software.

b. Click the option to add available software and type the following in the add site field:

https://dl-ssl.google.com/android/eclipse/ 

c. Click OK, then back in the available software list you will see Developer Tools. Selecting the check box for this will add Android DDMS and Developer Tools.


d. Click next, accept any licence agreements, then press finish. Eclipse will restart. 


4. a Finally to configure the ADT plugin. Go to preferences, available under the window tool menu.


b. Select Android, and for the SDK location browse to the saved directory you have from earlier.


c. Click apply, OK.


SDK and ADT plugin for eclipse are complete.

Installing Grails on Linux

Before installing or using Grails, set JAVA_HOME environment variable:

1. Add the following to  ~/.profile

export JAVA_HOME=/usr/local/jdk1.6.0_27/
export PATH=$PATH:/usr/local/jdk1.6.0_27/bin

Location will be where JDK is installed to.

2. Log out and back in again, run echo $JAVA_HOME and echo $PATH to confirm. Also check by typing java -version.

To install Grails:

1. Download grails from http://www.grails.org/Download
2. Extract the archive into a home directory. Typically /usr/local in Linux
3. Append a reference to grails as a variable, as with JAVA_HOME above

export GRAILS_HOME=/usr/local/grails-1.3.7/
export PATH=$PATH:/usr/local/grails-1.3.7/bin


Location path will be the directory you saved the extracted files to.

4. Log out and back in again.
5. Type grails in a terminal window to test. You should see:


Welcome to Grails 1.3.5 - http://grails.org/
Licensed under Apache Standard License 2.0
Grails home is set to: /home/lee/grails-1.3.5

No script name specified. Use 'grails help' for more info or 'grails interactive' to enter interactive mode


You can now begin writing grails applications

Installing Eclipse IDE onto Ububtu Linux

Rather than just using a basic text editor for writing java language applications, or an other programming language, it is always good to use an IDE. The following explains how to install the Eclipse IDE on an Ubuntu machine. Similar setup applies to most Linux flavors:

1. Download eclipse from the download site, http://www.eclipse.org/downloads/packages/eclipse-ide-java-developers/heliossr1

2. Extract the contents:
tar xzf eclipse-java-helios-SR1-linux-gtk.tar

3. Moved the extracted contents to /opt
sudo mv eclipse /opt/eclipse

4. Change permissions and create executable
sudo chmod +rx
sudo touch /usr/bin/eclipse
sudo chmod 755 /usr/bin/eclipse
sudoedit /usr/bin/eclipse

Input the following contents:


#!/bin/sh
export ECLIPSE_HOME="/opt/eclipse"

$ECLIPSE_HOME/eclipse $* 


5. If you want a menu item:
sudoedit /usr/share/applications/eclipse.desktop

with the following contents:

[Desktop Entry]
Encoding=UTF-8
Name=Eclipse
Comment=Eclipse IDE
Exec=eclipse
Icon=/opt/eclipse/icon.xpm
Terminal=false
Type=Application
Categories=GNOME;Application;Development;
StartupNotify=true



Now run from the programming menu under applications. 

Writing your first Java application

In order to test if your Java JDK installation is working correctly the best thing to do is write a simple Hello App!

1. Open a terminal window
2. Create a new java file, e.g. vi Hello.java
3. Write a basic program to announce some text or comment:

public class Hello {
        public static void main(String[] args) {
                System.out.println("I am a java App!");
        }
}


4. Save the file
5. Run javac Hello.java (This should complete without any errors)
6. Run java Hello
7.  I am a java App! appears in the terminal

Installing Java SDK Linux - Ubuntu

Having never used Linux before when you first starting using any Linux flavor, even the most simplest of tasks performed under Microsoft operating systems can cause you some trouble.

For programming and general purpose user I required  Java JDK and JRE installed on my Ubuntu machine. See basic steps below on how this install takes place.

Installation of Java JRE

You can download the source code or self extracting binaries from the Sun Java site, however the quickest way on this OS is to complete the following:

1. Open a terminal window
2. Run sudo vi '/etc/apt/sources.list'
3. Add the following line to the bottom of the file:
deb http://archive.canonical.com/ lucid partner
4. Run sudo apt-get install sun-java6-jre sun-java6-plugin sun-java6-fonts
5. Accept all license terms etc..
6. Run java from terminal window to confirm installation

Installation of Java JDK (for developers)


You can download the source code or self extracting binaries from the Sun Java site, however the  quickest way on this OS is to complete the following:

1. Open a terminal window
2. Run sudo apt-get install sun-java6-jdk
3. Run java -version to confirm installation

Introduction

I intend to use this blog to write simple instructions and setup procedures that I have completed in order to get various IT solutions in place.
I will document basic software installations right through to steps taken in order to get various applications to communicate with each other.

Having worked as an IT Support technician for Microsoft based products I decided that it was time for a complete turn around and for me to learn Unix, Linux, open source solutions and programming.

Not only will this be a reference for all you, I can use this blog as as documentation for myself if I need to complete these installations again.