close x

How to create a High Availability load balancer on SmartCloud Enterprise (2/2)

Hey guys,

I will try to show you, in this second part of the post, the way that you can automate the configuration of the image, I mean, do I need everytime I have to deploy the service ( in this case load balancing), do the following:

- provision the image from my private catalogue.

- wait for the image to be ready

- configure each service, each conf file…

- restart the services…

The answer is NO!

One of the greatest point of the SmartCloud Enterprise is the assets manager. You can modify the firewall in the hypervisor level, and automate some actions with starting scripts that can take info in the provisioning time.

I will show you where to find the asset manager:

Load_xml_11

We go to “My Dashboard”, and search the image that we want to modify from our private catalogue. When we choose the image, we can click on the “pen” in order to edit the configuration of the image:

Load_xml2-1024x532

We can see the file manager for the image conf files:

Load_xml3-1024x529

 

And here it is the parameters.xml file, in this file we can modify the firewall in the hypervisor level and take some info from the provisioning proccess. The default parameters.xml file looks like this:

<parameters¬†xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance”xsi:noNamespaceSchemaLocation=”platform:/resource/com.ibm.ccl.devcloud.client/schema/parameters.xsd”>
<firewall>
<rule>
<source>0.0.0.0/0</source>
<minport>1</minport>
<maxport>65535</maxport>
</rule>
</firewall>
</parameters>

 

 

 

If we want to modify the firewall from the hypervisor level, we should put this lines:

<firewall>

<rule>

<source>0.0.0.0/0</source>

<minport>80</minport>

<maxport>80</maxport>

</rule>

<rule>

<source>170.224.196.xx</source>

<minport>22</minport>

<maxport>22</maxport>

</rule>

<rule>

<source>170.224.196.xx</source>

<minport>5666</minport>

<maxport>5666</maxport>

</rule>

</firewall>

 

What this lines do is:

The machine with IP-> 170.224.196.xx can access to the port 22

The machine with IP->170.224.196.xx can access to the port 5666

Everyone can access to the port 80

The port 22 is opened for managing the image, the port 5666 for monitoring, and the port 80 because it is a web load balancer. We should adjust the iptables firewall in the operating system as well, but this will come in other post.

Now, if we can get some info in the moment of provisioning the image we need to add the following lines (in this case I needed get some info about the load balancing service):

<field name=”role” label=”ROLE 100(backup) 101(master)” type=”number”>

<values>

<value>101</value>

</values>

</field>

<field name=”ip” label=”IP virtual” type=”number”>

<values>

<value></value>

</values>

</field>

<field name=”ip_1″ label=”IP server 1″ type=”number”>

<values>

<value></value>

</values>

</field>

<field name=”ip_2″ label=”IP server 2″ type=”number”>

<values>

<value></value>

</values>

</field> <field name=”ip_3″ label=”IP server 3″ type=”number”>

<values>

<value></value>

</values>

</field>

 

With this conf I get the role of the Load BAlancer, the Virtual IP, and as much as I want IP’s to balance. It looks like this (once all the process is finished):

Step2_SCE

Ok, now we have solved the variables that we need to configure the load balancer, the next step it is create the scripts. These scripts have to be saved in the folder “activation_scripts”, maybe you have to create this folder. The one that is mandatory is the “cloud-startupX.sh”, where the X means the run level of the image. This script looks like:

#!/bin/sh
### BEGIN INIT INFO

# chkconfig 3 90 20# description: cloud-startup3.sh

# processname: cloud-startup3.sh

# Provides: cloud-startup3.sh

# Required-Start:# Should-Start:

# Required-Stop:

# Should-Stop:# Default-Start: 3

# Default-Stop:

# Short-Description: Cloud startup

# Description: Extract and set user password

### END INIT INFO

case “$1″ in

start)

echo “== Cloud Starting”

if [ ! -e /etc/cloud/idcuser_pw_randomized ]; then

echo “Randomizing idcuser password”

echo idcuser:`< /dev/urandom tr -dc _A-Z-a-z-0-9 |head -c16` | /usr/sbin/chpasswd

touch /etc/cloud/idcuser_pw_randomized

fi

/sbin/restorecon -R -v /home/idcuser/.ssh

if [ ! -e /etc/cloud/parameters.xml.done ]; then

sh /etc/cloud/register.sh

cp /etc/cloud/parameters.xml /etc/cloud/parameters.xml.done

fi ;;

stop)

echo “== Cloud Stopping”

;;

*)

echo “Usage: $0 {start|stop}”

exit 1

;;esac

 

 

This script has to has this look, the only think you should change is:

if [ ! -e /etc/cloud/parameters.xml.done ]; then

sh /etc/cloud/register.sh

cp /etc/cloud/parameters.xml /etc/cloud/parameters.xml.done

fi ;;

 

These lines are the scripts that I want to execute at the start of the image, and for checking that these lines are just executed in the first start of the image, I saved the parameters.xml with another name to use later as a condition.

 

The scripts of configuration of the image have this look:

register.sh

#!/bin/bash

NUM=1

IP=1

LETRA=(A B C D E F G H I J K)

IP_virtual=$(perl /usr/bin/extract-parameters.pl ip /etc/cloud/parameters.xml)

sed -i “s/IP_VIRTUAL/$IP_virtual/g” /etc/haproxy/haproxy.cfg

sed -i “s/IP_VIRTUAL/$IP_virtual/g” /etc/keepalived/keepalived.conf

ROLE=$(perl /usr/bin/extract-parameters.pl role /etc/cloud/parameters.xml)

sed -i “s/ROLE/$ROLE/g” /etc/keepalived/keepalived.conf

sh /etc/cloud/add_server.sh $IP_virtual

until [ $IP = 0 ]; do

IP=$(perl /usr/bin/extract-parameters.pl ip_$NUM /etc/cloud/parameters.xml)

if [ $IP != 0 ]; then

echo “server server_$NUM $IP:80 cookie ${LETRA[$NUM-1]} check” >> /etc/haproxy/haproxy.cfg

let NUM=$NUM+1

let LETRA=$LETRA+1

fi

done

 

Basically what this script does, it is taking the variables from the parameters.xml and putting in the conf files. I use words as a reference for sed, this way sed can search in the conf file saved in the image and replace it with the new value.

Once we have this, we have to tell the system what are the scripts that we can upload, in order to get that, we create the file scripts.txt inside the folder “activation scripts:

scripts.txt

cloud-startup3.sh=/etc/init.d/cloud-startup3.sh
register.sh=/etc/cloud/register.sh

And the process is done, now we just have to click on update and provision our new image.

 

Enjoy!!!

 

 

 

Cloud Computing0 comments

Leave a Reply