Internet Gateway: 192.168.50.1
Frontend & Host1 IP: 192.168.50.2 – OpenNebula-Server, OneFlow, Sunstone, OpenNebula-Node
Host2 IP: 192.168.50.3 – OpenNebula-Node
In Sunstone Interface:
A. Create 2 Virtual Networks:
Public Network: 192.168.50.0/24 – StartIP: 192.168.50.100
Private Network: 10.0.0.0/24 – StartIP: 10.0.0.10
Use ebtables
Create 2 Reserved Private Networks
RouterPrivateNetwork: 10.0.0.10 IP Size: 1 -> This will ensure one ip to Router/LB
ServerPrivateNetwork: 10.0.0.11-15 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
Network:
NIC1: Public Network
Advance Option: TCP Firewall & UDP Firewall:
Select Whitelist and Ports: *
NIC2: RouterPrivateNetwork
Input/Output:
Select VNC checkbox
Listen IP: 0.0.0.0
Context:
Enable SSH contextualization:
1. Created rsa key of local machine and pasted public key inside this box.
In Custom Vars:
DHCP NO
RADVD NO
DNS 8.8.8.8
PRIVNET $NETWORK[TEMPLATE, NETWORK_ID=”6“]
PUBNET $NETWORK[TEMPLATE, NETWORK_ID=”3“] –>
ROOT_PASSWORD JDEkTHoxZXFoV1UkWVl5QzE0QXJnSklOZ2VTbjNJOWl3MQo=
TARGET hdb
TEMPLATE $TEMPLATE
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
Network
NIC1: ServerPrivateNetwork
TCP & UDPFirewall:
Select Whitelist * Ports: *
Input/Output:
Select VNC checkbox
Listen IP: 0.0.0.0
Context:
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:
ftp://distrib-coffee.ipsl.jussieu.fr/pub/linux/alpine/alpine/v2.5/main
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 127.0.0.1 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 0.0.0.0:8080 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 10.0.0.11:80 check server lamp2 10.0.0.12:80 check
server lamp3 10.0.0.13:80 check
server lamp4 10.0.0.14:80 check
server lamp5 10.0.0.15:80 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
iptables-save
/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
http://dev.opennebula.org/attachments/download/817/fix.patch
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.