czwartek, 4 czerwca 2015

Apache Load Balancing with Haproxy on Ubuntu 14.04 - English

I want to show how you can config Load Balancing with Haproxy on Ubuntu 14.04. More info about Load Balancing you can find here, something about Haproxy you find here.

What we need to config Load Balancing:
1.  Load Balancer(Haproxy) on Ubuntu 14.04 - IP 192.168.1.15
2. Web1 on Ubuntu 14.04 - IP 192.168.1.16
3. Web2 on Ubuntu 14.04 - IP 192.168.1.17

Below screen our test network:









 1. Config Load Balancer/ Web1/Web2:

After installing Ubuntu on Load Balancer we need config some features.



Set new root passwd.
Open Terminal and write

sudo passwd root 
Enter new UNIX password:             
Retype new UNIX password:            
passwd: password updated successfully


Set  new Hostname

sudo nano /etc/hostname

write inside the file haproxy



These same steps we must do on Web1 and Web2, of cource we must write Web1 and Web3 on hostname file.





2.Config Haproxy:


Install Haproxy:

apt-get install haproxy

Afer installation, we can check haproxy version:

haproxy -v

Next we open

sudo nano /etc/default/haproxy

inside we must change Enabled=0 on Enabled=1



Now we can start haproxy service

sudo service haproxy start


Next we backup original config file.

sudo cp /etc/haproxy/haproxy.cfg /etc/haproxy/haproxy.cfg.original

Inside the file we must write this parameters:








3.Config LAMP on the Web1 and Web2:

We start installation Apache2.

sudo apt-get install apache2

After installation we can check if apache is running.

http://localhost

If everything will be ok, we will see following result.



Next we will install mysql databasse.

sudo apt-get install mysql-server php5-mysql

During the installation, server will ask about root password.

Next we install php.

sudo apt-get install php5 libapache2-mod-php5 php5-mcrypt

Next we change below file.

sudo nano /etc/apache2/mods-enabled/dir.conf

In this file we save this:


At the end we must restart apache2

sudo service apache2 restart

After installation we check if the php is running.

sudo nano /var/www/html/info.php

we add this code:

We can check if PHP is ok.

http://localhost/info.php

We get this:








4.Configure LAN settings.

If we used physical computer we should change only IP addresse, net mask etc. But if we used virtual machines mu must select something like that: Host-only:A private netowrk shared with the host.

Haproxy:

# The primary network interface
auto eth0

# DHCP not needed
# iface eth0 inet dhcp
iface eth0 inet static
address 192.168.1.15
netmask 255.255.255.0
network 192.168.1.0
broadcast 192.168.1.255
gateway 192.168.1.1
dns-nameservers 8.8.8.8


Web1:

# The primary network interface
auto eth0

# DHCP not needed
# iface eth0 inet dhcp
iface eth0 inet static
address 192.168.1.16
netmask 255.255.255.0
network 192.168.1.0
broadcast 192.168.1.255
gateway 192.168.1.1
dns-nameservers 8.8.8.8

Web2:

# The primary network interface
auto eth0

# DHCP not needed
# iface eth0 inet dhcp
iface eth0 inet static
address 192.168.1.17
netmask 255.255.255.0
network 192.168.1.0
broadcast 192.168.1.255
gateway 192.168.1.1
dns-nameservers 8.8.8.8

5.Testing, testing :)


On the Web1 with IP- 192.168.205.16, append below line as:

sudo sh -c "echo Hostname: web1 \(192.168.205.16\)\ >> /var/www/index.html"

On the Web2 with IP- 192.168.205.17, append below line as:

sudo sh -c "echo Hostname: web2 \(192.168.205.17\)\ >> /var/www/index.html"

For the first time when I visit http://192.168.205.15 , I get:


And for the second time, i.e. when I refresh the page, I get:






Brak komentarzy:

Prześlij komentarz