Configure AutoScaling using OpenNebula 4.8 & Flow

Internet Gateway:

Frontend & Host1 IP: – OpenNebula-Server, OneFlow, Sunstone, OpenNebula-Node

Host2 IP: – OpenNebula-Node

In Sunstone Interface:

A. Create 2 Virtual Networks:

Public Network: – StartIP:

Private Network: – StartIP:

Use ebtables

Create 2 Reserved Private Networks

RouterPrivateNetwork: IP Size: 1 -> This will ensure one ip to Router/LB

ServerPrivateNetwork: IP Size: 5 -> This will create pool of 5 IP addresses for servers.

B. Download 2 images from MarketPlace

1. OpenNebula Virtual Router 4.8 for Router/LoadBalancer

2. CentOS6.5 KVM for Server

C. Clone above images and make them Persistent

OpenNebula Virtual Router 4.8 –> LoadBalancerImage

CentOS6.5 KVM for Server –> ServerImage

D. Create 2 templates:

1. LoadBalancer:

CPU: 1

Memory: 256 MB

Storage: LoadBalancerImage


NIC1: Public Network

Advance Option: TCP Firewall & UDP Firewall:

Select Whitelist and Ports: *

NIC2: RouterPrivateNetwork


Select VNC checkbox

Listen IP:


Enable SSH contextualization:

1. Created rsa key of local machine and pasted public key inside this box.

In Custom Vars:









Please NOTE:

In PRIVNET line 6 is Network ID of RouterPrivateNetwork

In PUBNET line 3 is Network ID of Public Network

Root password is generated by below command:

openssl passwd -1 test | base64

2. Server

CPU: 1

Memory: 256 MB

Storage: ServerImage


NIC1: ServerPrivateNetwork

TCP & UDPFirewall:

Select Whitelist * Ports: *


Select VNC checkbox

Listen IP:


Enable SSH contextualization

Generate RSA Key on Router VM and paste its Public key in this box. So that you can do password-less login to Server VM from Router VM using user root.

E. Open LoadBalancer template and click on Instantiate and launched LoadBalancer Instance. In VNC please use username: root and password: test (As per our Context parameters in template)

Add Alpine Linux repository & Installed HAproxy on it.

In /etc/apk/repositories file Comment both lines and append below repo:

Update Index

apk update

Install haproxy

apk add haproxy

Move original haproxy.cfg to /root

       mv /etc/haproxy/haproxy.cfg /root/haproxy.cfg_ORIG

Create new haproxy.cfg and entered below text in it:

          global              log local0 notice              maxconn 2000              user haproxy              group haproxy

          defaults              log     global              mode    http              option  httplog              option  dontlognull              retries 3              option redispatch              timeout connect  5000              timeout client  10000              timeout server  10000

          listen appname              mode http              stats enable              stats uri /haproxy?stats              stats realm Strictly Private              stats auth A_Username:YourPassword              stats auth Another_User:passwd              balance roundrobin              option httpclose              option forwardfor              server lamp1 check              server lamp2 check               
server lamp3 check
              server lamp4 check               
server lamp5 check


Restart haproxy service

/etc/init.d/haproxy restart

F. Launch one server instance from Server template.

Please login using SSH from LoadBalancer instance.

Disable Firewall –

iptables -F


/etc/init.d/iptables stop

chkconfig iptables off

Disable selinux in /etc/selinux/config

Install apache, mysql-server, php on it using yum.

Create user in mysql-server and database for wordpress

Download wordpress or any other php web application and install on it.

Create /var/www/html/file.php on Server to test and enter below text. This script will show us the ip of server.

<?phpheader('Content-Type: text/plain');echo "Server IP: ".$_SERVER['SERVER_ADDR'];echo "nClient IP: ".$_SERVER['REMOTE_ADDR'];echo "nX-Forwarded-for: ".$_SERVER['HTTP_X_FORWARDED_FOR'];?>

Do require settings on Server instance.

Shutdown & delete the instance.

In Images click on ServerImage and make it non-persistent.

H. Configure Service in OneFLow:

First need to patch /usr/lib/one/sunstone/public/plugins/js/Opeflow-template.js using fix.patch from below link

patch /usr/lib/one/sunstone/public/plugins/js/Opeflow-template.js < fix.patch

In OneFlow create Template:

Name: Scalling

Roles: Role1

VM Template: Server

Elasticity Role:

Min VMs: 1

Max VMs: 5

Elasticity Policies:

Policy 1:

Type: Change

Adjust: 1

Expression: CPU > 70

# : 3

Period: 10

Policy 2:

Type: Change

Adjust: -1

CPU < 15

And click on Update

Click on Instantiate button and provide Service Name as AutoScalling (You can give any name here.)

In Services click on the AutoScalling –> Roles

Now increase CPU load on server using below command:

while true; do cat /proc/cpuinfo > /dev/null; done

And Click on OneFlow –> Services –> AutoScalling –> Roles –> Role

Now keep monitoring Virtual Machines Section. You will notice # Periods will increase upto 3

And you will see new virtual machines get spawn. Because as per Role If CPU loads stays above 70% for 3 times, then new instance will get automatically spawned.

Now decrese CPU load on server by stopping while command.

Press Ctrl+C to stop while command.

After few seconds first server instance will get Shutdown automatically.

Neelesh Gurjar has written 122 articles