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!

No comments:

Post a Comment