Thursday, March 27, 2014

Java-Cluster: Wildfly and User Configuration

Now for the Tricky parts:

First lets add a user to the raspberry for the Wildfly (we don't need to make it a sudo (administrator) user).

"sudo useradd -c "JBoss AS User" -s /bin/bash -d /home/jboss -mr jboss"

The users name is "jboss".We should then give ownership of the wildfly folder to this user
"sudo chown -R jboss:jboss /usr/jboss/wildfly-8.0.0.Final"

It's also a good idea to give the user a password:
"sudo passwd jboss"

Now lets switch to that user:
"sudo su - jboss"

First of all we need to change the memory usage of the Wildfly-server. Per default it uses a maximum of 512mb (which is ALL of the memory the Raspberry Pi has! And we need some memory for other stuff).

So edit the file /usr/jboss/wildfly-8.0.0.Final/bin/domain.conf, I usually use nano for editing (you can use vi or something else if you prefer it)
"nano /usr/jboss/wildfly-8.0.0.Final/bin/domain.conf"

Somewhere in the file there is a line "-Xms64m -Xmx512m -XX:MaxPermSize=256m"
change this to:
"-Xms64m -Xmx196m -XX:MaxPermSize=256m"

Exit nano using CTRL + X and choosing "y" to save the changes.

Now we can try to start the server, go in to the Wildfly bin-folder and run:
"./domain.sh"

It may show some red text but wait and see if it starts.

Do these steps for all the Raspberry Pi's that should be part of the Java-Cluster.

Now it's time to choose a Master. One of the Raspberries have to be the Master, the rest will be "slaves".

Ssh into the master

In the Master we will now create som Wildfly users. In the Wildfly bin-folder of the master:
./adduser.sh

Pick a Username (like "master") and a password
Choose the Management option

The Master-user don't need a secret value (the last question the scripts asks)

Now add a user for every slave (In the Master). Give them individual names, choose Management option and answer yes to the last question.
Copy the value to a file with the user names. Example:

master
slave01 <secret value="THE VALUE IT GETS" />
slave02 <secret value="THE VALUE IT GETS" />

Now lets config The Master: edit the file host.xml in the domain/configuration folder:
change:

<interfaces>
    <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>
    <interface name="unsecured">      
       <inet-address value="127.0.0.1" />  
    </interface>
</interfaces>

To: where Masters IP should be the IP of the master

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

That's it for the Master!

Now the steps that needs to be made for every slave:
Ssh into the slave

Edit the host.xml in domain/configurations of the wildfly-folder

change:
<host name="master" xmlns="urn:jboss:domain:1.1">
to:
<host name="slave01" xmlns="urn:jboss:domain:1.1">
where slave01 is the name of the management-user created in the host for this slave

Then we need to modify domain-controller section so slave can connect to master's management port (in the same file):

Change it to:
<domain-controller>
   <remote host="Masters IP!!!" port="9999" security-realm="ManagementRealm"/>
</domain-controller>

Change the interface part to:
<interfaces>
    <interface name="management">
        <inet-address value="${jboss.bind.address.management:SLAVE IP!!!!}"/>
    </interface>
    <interface name="public">
       <inet-address value="${jboss.bind.address:SLAVE IP!!!!}"/>
    </interface>
    <interface name="unsecured">      
       <inet-address value="SLAVE IP!!!!" />  
    </interface>
</interfaces>

Chane security-realm part: Chane the value of secret to that you got from creating users in Master.
comment out <local default...

<security-realms>
   <security-realm name="ManagementRealm">
       <server-identities>
           <secret value="THE SECRET VALUE of SLAVE"/>
       </server-identities>
       <authentication>
           <properties path="mgmt-users.properties" relative-to="jboss.domain.config.dir"/>
       </authentication>
   </security-realm>
</security-realms>

Now repeat for every slave.

Now test to start the master with ./domain.sh
When its started, try to start the slaves the same way.

Check the information on master, if it registers the slaves then it works!

In the next part I will discuss my results of trying a simple web-project and deploying it.

Code ahoy!

Wednesday, March 26, 2014

Java Cluster: Software SD-card Part

In this part I will explain all the steps for installing the system, the next part will be configuring Wildfly.

First you need a SD-card slot/reader.

Second Download Rasbian from: http://www.raspberrypi.org/downloads

See http://www.raspberrypi.org/wp-content/uploads/2012/04/quick-start-guide-v2_1.pdf for instructions on how to prepare your SD-card and get the image to it.

Repeat with all 4 (you can probably make a script for automating all these tasks but I'll keep it simple)

My tip is to power up one raspberry at a time. Because my router gives the same IP-number to the devices, and if we power up all 4 I would have 4 devices named raspberry.

So I start one, change its host name and save the IP-number in a file with the hostname for later referencing.

So start the first and find out it's IP-number.

Ssh into the raspberry with: "shh pi@<ip-number>" the password is rasberry

run sudo raspi-config:


  1. First choose "Advanced" and "Update" so the setup-program updates to the latest version.
  2. Expand the Filesystem so it uses the whole SD-card
  3. Change password (your choice)
  4. Choose "Advanced Options" and memory split. Give the GPU 16 (instead of 64) we don't need so much memory for the graphics.
  5. In "Advanced" you can also change the hostname. I choose to have a system like cluster01 through cluster03.
  6. I choose to overclock mine to 900mhz but It's up to you.
  7. Choose "Finish"

My Raspberries usually complain on the locale, but we can fix it by editing the Locale manually:
"sudo nano /etc/default/Locale" and adding these lines to the file:


LC_ALL=en_gb.UTF-8
LANGUAGE=en_gb.UTF-8

After that run "update-locale", don't worry if it still says some bad stuff.
Reboot by "sudo reboot" then ssh to it again.

Do a full system update
"sudo apt-get update" then "sudo apt-get upgrade"

Then install oracles java 8
"sudo apt-get install oracle-java8-jdk"

You can log out of the ssh for a little while now

Now its time to download Wildfly 8
http://wildfly.org/downloads/

I choose to download it on my desktop computer and copy it via scp to the raspberry
(used via Linux on my desktop in the folder where Wildfly zip is)
"scp pi@<ip of raspberry>:. Wildfly-8.0.0.Final.zip"

this copies it to the home-folder of the user "pi".

Ssh into the raspberry again

Make a folder in the /usr with the name jboss where we will unzip the zip
"sudo mkdir /usr/jboss"

Then by standing in the folder which the zip is (check with "ls")
"sudo unzip -d /usr/jboss /home/pi/wildfly-8.0.0.Final.zip"


Repeat all the steps with all 4 (you can probably make a script for automating all these tasks but I'll keep it simple)

It's now time for configs!
(Continued in the next Part)



Java Cluster: Hardware

I'll first show the Hardware setup then later show the Software configs.

The hardware is:
4 x Raspberry Pi Model B rev 2 (512mb)
4 x Raspberry Pi Heatsink (keeping it cool!)
2 x Stackable case (https://www.modmypi.com/blog/multi-pi-assembly-guide)
4 x Short Networkscables
4 x short Usb-Micro Usb
1 x Deltaco 7 port Powered Usb-hub (http://www.dustinhome.se/product/5010144399/deltaco-usb-hub-7-portar-usb-2-0-svart/)
1 x 5 port switch
4 x SD-cards (8gb or higher class 10)


First set the Heatsinks (cooling paste is already applied)

I choose to angle them sideways if I want to add a fan at the side.

Next is to screw the Raspberries to the cases and stacking them. 

Connect the Network cables to the switch, the usb cables to the usb hub. 
Connect a cable from your modem/router to port 1 of your switch (should give all your raspberries access to Internet).



All that's left is fixing the SD-cards. But that is a part of the Software explanation.
(Turn on the power AFTER all the SD-cards are fixed)

Cluster Time!

Cluster Time!


I'm not the most knowledgeable person when it comes to hardware and networks. Hey I'm a programmer, I work with software :)

But for some reasons I wanted to make a Java-server-solution at home. I'm not a big fan of having a computer with a loud fan going at it in my living room. So what's the options?

I actually have a mini-ITX motherboard with passive cooling, but the parts have started dying, first the nic and now the display connection.

So what's the current solution for every nerd? Raspberry Pi!

So I went to the local hardware store and bought yet another one of these little cuties. (I have one for streaming media from my NAS, awesome that I can control it via the TV-remote through HDMI).

Rasbian (Debian Wheezy for Raspberry Pi) was the distro of my choice. It has Oracle Java (even the new 8!), It didn't take long to get a Glassfish-server up and running. And with a little wrestling with the router I made so I could reach a website (written in JSP) from the web.

The problem was the CPU. Even with the overclocked option to 900 mhz the cpu got upp to 85-95% with little demand.


So what to do now?

I'm still just in the beginning of my JavaEE learning quest. But one thing that has caught my attention is Wildfly (JBoss newest server). I wanted to see if it was more lightweight then Glassfish (the opinion seems to be that ANYTHING is faster then Glassfish).

But is this nerdy enough? Short answer: Of course not!

So what can I do to make this better? Cluster time!

Cause Raspberries are so cheap I could by several and get them in a cluster, challenge accepted!

I will explain how to actually do this in a future post. I'm missing another stackable chassi (out of stock at the store).
Al the raspberries have heatsinks on them. They (3 soon to be 4) are powered by a usb hub (powered) and is connected to a switch which is connect to the hub.

One of these will be a database-server the other ones will be master and slaves with Wildfly.

Right now to Master-slave is done but have not been tested with any applications.

Coding ahoy!

To be continued...

Intro

Hi

This blog is going to be mostly about my growing knowledge of Java and some nerdy projects I'm doing. English isn't my native language so I will use this opportunity to practice it.

If it's a demand I can do the blog in both Swedish and English

/Karl