How to Configure Linux Load Balancers and Highly Available MySQL Database Structure on centos 6.2.
Introduction:
This step by step guide shows you how to configure Load Balancers in Linux environment and how we can make mysql database structure highly available with the help of DRBD & Heartbeat.
`Note:
1: Our main focus to make the things simplest for our reader to have easy understandings.
2: we will complete this lab in several parts.
Part-1: Initial Configurations on All Servers.
Part-2: NTP Server & Client settings.
Part-3: Bind Server Installation + configurations.
Part-4: lvs (Linux virtual server) Active & Backup Load-Balancer settings.
Part-5: Webservers Configurations.
Part-6: Database server’s configurations with DRBD & Heartbeat.
Design illustration :
Figure 1.1
Note: You can use multiple load balancers and same for others, in this lab we are using 2 servers for load balancing & 2 for web services & 2 for mysql Database servers which is minimum requirement.
You can add more servers according to your needs.
As you can see above figure 1.1
LVS Setup :
Scenario:
As you read further in this tutorial you will also see the high level of flexibility built in this lab i.e. we will have multiple load balancers servers for fail back. We will also have more than one web servers for high availability using virtual IP Address & in this lab we will not use any special hardware load balancers.
Load balancing Methods :
a. NAT
b. Direct Routing
c. Tunneling
we will use Direct Routing Method in our lab.
My Setup :
OS : CentOs 6.2Â ( Final )
For this lab I’ll be using 8 virtual machines:
Name : loadb1.broexperts.comIP : 192.168.2.1
Name : loadb2.broexperts.com IP : 192.168.2.2
Name : websrv1.broexperts.comIP : 192.168.2.10
Name : websrv2.broexperts.comIP : 192.168.2.11
Name : dbase1.broexperts.com IP : 192.168.2.20
Name : dbase2.broexperts.comIP : 192.168.2.21
Name : dns.broexperts.com IP : 192.168.2.30
Name : ntp.broexperts.com IP : 192.168.2.31
Goal of this Guide :
As i mentioned earlier this guide will provide us step by step installation of Linux load-blancer and highly available MySQL Database structure to get fault tolerance. Suppose if dbase1.broexperts.com ( that would be primary database server ) goes down the secondary server would be dbase2.broexperts.com will takes place and second server will keep you alive. for resource handling we will install DRBD that would provide us real-time replication and HearBeat will take care of services. we will achieve this using a virtual ip 192.168.2.200 this ip address will rotate in real servers.
About web servers websrv1.broexperts.com and websrv2.broexperts.com will do the same if in case of disconnection or failure of websrv1 the second server provide the consistency. for this area we have one virtual ip 192.168.2.100.
Now look on Load-Balance Area, here we use two servers and configure Linux Virtual Server ( LVS ), one server defined as primary and second will be backup state using piranha when we install piranha it will automatically get two more tool ipvsadm and nanny. in this area both Servers will generate heartbeat channels if one server stops working then backup server will be up for serving.
And two more servers will participate in this lab one will serve Time Synchronization for all nodes to keep network time identical and other one will provide the Name Resolution as DNS Server.
Note : My main focus to make this article easily understandable.
Part-1:
Initial Configurations on All Servers.
1.1 : host file’s entries for all servers.
[root@loadb1 /]# vi /etc/hosts
127.0.0.1 localhost.localdomain localhost # Don't Remove any line , will network goes down if u do so.# ### Entries for Load-Balancers IPs ### 192.168.2.1 loadb1.broexperts.com loadb1 192.168.2.2 loadb2.broexperts.com loadb2 ### Entries for DNS & NTP ### 192.168.2.30 dns.broexperts.com dns 192.168.2.31 ntp.broexperts.com ntp ### Entries for Web-Servers IPs ### 192.168.2.10 websrv1.broexperts.com websrv1 192.168.2.11 websrv2.broexperts.com websrv2 ### Entries for MySQL Server's IPs ### 192.168.2.20 dbase1.broexperts.com dbase1 192.168.2.21 dbase2.broexperts.com dbase2 ### Entries for Virtual IPs of Mysql DB server & webserver ### 192.168.2.100 www.broexperts.com www 192.168.2.200 db.broexperts.com db
1.2 : Copy this file on all server using scp command
[root@loadb1 /]# scp /etc/hosts loadb2:/etc/ The authenticity of host 'loadb2 (192.168.2.2)' can't be established. RSA key fingerprint is 99:6b:a1:cb:2c:90:10:79:24:01:29:e7:4a:60:84:33. Are you sure you want to continue connecting (yes/no)? yes Warning: Permanently added 'loadb2' (RSA) to the list of known hosts. root@loadb2's password: hosts 100{1c918b003a0fec779e46518dd4d8df22f3dc554de918030f5a1a0cfd93cb28be} 805 0.8KB/s 00:00 [root@loadb1 /]# scp /etc/hosts websrv1:/etc/ The authenticity of host 'websrv1 (192.168.2.10)' can't be established. RSA key fingerprint is 54:36:ac:6b:86:62:da:3a:ec:b2:94:a4:28:1a:64:c5. Are you sure you want to continue connecting (yes/no)? yes Warning: Permanently added 'websrv1' (RSA) to the list of known hosts. root@websrv1's password: hosts 100{1c918b003a0fec779e46518dd4d8df22f3dc554de918030f5a1a0cfd93cb28be} 805 0.8KB/s 00:00 [root@loadb1 /]# scp /etc/hosts websrv2:/etc/ The authenticity of host 'websrv2 (192.168.2.11)' can't be established. RSA key fingerprint is 65:dd:9a:ab:22:ad:74:b6:63:cd:f2:92:c5:8f:02:e1. Are you sure you want to continue connecting (yes/no)? yes Warning: Permanently added 'websrv2' (RSA) to the list of known hosts. root@websrv2's password: hosts 100{1c918b003a0fec779e46518dd4d8df22f3dc554de918030f5a1a0cfd93cb28be} 805 0.8KB/s 00:00 [root@loadb1 /]# scp /etc/hosts dbase1:/etc/ The authenticity of host 'dbase1 (192.168.2.20)' can't be established. RSA key fingerprint is 2e:2f:23:93:07:e3:19:47:8f:62:a2:00:89:4e:41:21. Are you sure you want to continue connecting (yes/no)? yes Warning: Permanently added 'dbase1' (RSA) to the list of known hosts. root@dbase1's password: hosts 100{1c918b003a0fec779e46518dd4d8df22f3dc554de918030f5a1a0cfd93cb28be} 805 0.8KB/s 00:00 [root@loadb1 /]# scp /etc/hosts dbase2:/etc/ The authenticity of host 'dbase2 (192.168.2.21)' can't be established. RSA key fingerprint is 8f:0d:90:8a:d7:ff:fc:56:60:f5:1e:dd:76:bf:c7:94. Are you sure you want to continue connecting (yes/no)? yes Warning: Permanently added 'dbase2' (RSA) to the list of known hosts. root@dbase2's password: hosts 100{1c918b003a0fec779e46518dd4d8df22f3dc554de918030f5a1a0cfd93cb28be} 805 0.8KB/s 00:00 [root@loadb1 /]# scp /etc/hosts ntp:/etc/ The authenticity of host 'ntp (192.168.2.31)' can't be established. RSA key fingerprint is d5:c7:e9:3f:bf:29:b4:92:d1:86:ec:62:4b:44:d5:71. Are you sure you want to continue connecting (yes/no)? yes Warning: Permanently added 'ntp' (RSA) to the list of known hosts. root@ntp's password: hosts 100{1c918b003a0fec779e46518dd4d8df22f3dc554de918030f5a1a0cfd93cb28be} 805 0.8KB/s 00:00 [root@loadb1 /]# scp /etc/hosts dns:/etc/ root@dns's password: hosts 100{1c918b003a0fec779e46518dd4d8df22f3dc554de918030f5a1a0cfd93cb28be} 805 0.8KB/s 00:00
1.3 : ssh-key genration ( for Password Free Authantications. )
RSA key
[root@loadb1 /]# ssh-keygen -t rsa Generating public/private rsa key pair. Enter file in which to save the key (/root/.ssh/id_rsa): Enter passphrase (empty for no passphrase): Enter same passphrase again: Your identification has been saved in /root/.ssh/id_rsa. Your public key has been saved in /root/.ssh/id_rsa.pub. The key fingerprint is: f1:c9:c4:fe:69:55:b0:5d:ff:bb:43:b8:a7:f7:de:68 root@loadb1.broexperts.com The key's randomart image is: +--[ RSA 2048]----+ | . .| | . +o| | . o . +| | * . ..| | S = o .| | . + ..| | + o. | | . .E=o| | o=o*| +-----------------+
DSA key
[root@loadb1 /]# ssh-keygen -t dsa Generating public/private dsa key pair. Enter file in which to save the key (/root/.ssh/id_dsa): Enter passphrase (empty for no passphrase): Enter same passphrase again: Your identification has been saved in /root/.ssh/id_dsa. Your public key has been saved in /root/.ssh/id_dsa.pub. The key fingerprint is: fb:84:9f:b8:22:28:f5:69:7c:51:ca:0e:9c:d2:9b:8b root@loadb1.broexperts.com The key's randomart image is: +--[ DSA 1024]----+ | | | | | | | . | | o o oS | | o = + o | | . = * .o . | |. ..O + = . | | .E..+ .o.+ | +-----------------+
1.4 : Copy both keys information in authorized_keys file
[root@loadb1 /]# cd /root/.ssh/ [root@loadb1 .ssh]# cat *.pub > authorized_keys
1.5 : verify your file using cat
[root@loadb1 .ssh]#cd .. [root@loadb1 ~]# cat .ssh/authorized_keys ssh-dss AAAAB3NzaC1kc3MAAACBAMUSn3Aq/eKvhxMqXbVmWO5ArFncOfnwSaFOELATDRRO/9Y+zmk7itenXcalrXF3Q64WfOfZY07yQnT/ +AM2V/eA0thDgOWjB3+7EJSMKXe0OZUynJ2G3cnaOLfbkLZPb5UZxbLfuztMC850aCEqTVvW5QNf7VjtPhY6vFuraMs1AAAAFQDa1VrrX+ jDbdOPrwWKHqVL2z8zrwAAAIByscUK4jep9jWSbIqkA7Zp613OGZsd35FkQjHSWaQ/ycJfODFbG4v7rZR6m5nCiCgXOwlXXolfZ7Ak4waW dtLItd8WDks4+mkTEtrYE2cE3aw2IKScCKesWvS4hPZSttaqgtIpjtepUpWhLANpztqsL6X1zjnPF7rcY94ydGv6jwAAAIEAh9+GvC2lJF KLMluOrRI89AfsGF5NkeUXvdiofPOBDs4H3EJE8tpTkLtnL1T9iaAlhHy7ZVOzf0HVh1c8XJbgLors2qYGYZqLiUGLygtp7Vt9XL3AONZDX Sq/gCBjbCJcTFF5KIpqQe7bEF36ZPnJqIRh3Vr98LDJ0yt+RB087Eo= root@loadb1.broexperts.com ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEArboU59BlSLb+69tHQFg3fWIA1OSVPhNkOzWZYJZfN6NVWLbTwcsjbKg8SZUyBrnEtdmV3 USn/dvRoXawwxBhIvqFzu22i3mywqb95qsO14wGVIFeRFUqThCfHc3/ZBR/3VlfWM9O15Pd0E98cDgiandgJzPeeBu8BvuB0seSrrTs/dY nsMr6VOlOUmUhjkqXSIHmBhZ6UcJiOFAE5S4Owz3Y4pbalLPBngIUisVchuthAxfsdb6kX09Ndu22iSxg+UpNJd/W7TJd8ITkPruA gD1qRyICFIRcPeT1g/jqmFcAyVaHYkkIxayKkJKF+nhpu+9hHq9qgZUqFiljJqTnOw== root@loadb1.broexper ts.com
1.6 : copy this information on all server using scp
[root@loadb1 ~]# scp -r /root/.ssh/ loadb2:/root/ root@loadb2's password: id_dsa 100{1c918b003a0fec779e46518dd4d8df22f3dc554de918030f5a1a0cfd93cb28be} 668 0.7KB/s 00:00 id_dsa.pub 100{1c918b003a0fec779e46518dd4d8df22f3dc554de918030f5a1a0cfd93cb28be} 616 0.6KB/s 00:00 authorized_keys 100{1c918b003a0fec779e46518dd4d8df22f3dc554de918030f5a1a0cfd93cb28be} 1024 1.0KB/s 00:00 id_rsa 100{1c918b003a0fec779e46518dd4d8df22f3dc554de918030f5a1a0cfd93cb28be} 1675 1.6KB/s 00:00 known_hosts 100{1c918b003a0fec779e46518dd4d8df22f3dc554de918030f5a1a0cfd93cb28be} 5481 5.4KB/s 00:00 id_rsa.pub 100{1c918b003a0fec779e46518dd4d8df22f3dc554de918030f5a1a0cfd93cb28be} 408 0.4KB/s 00:00 [root@loadb1 ~]# scp -r /root/.ssh/ websrv1:/root/ root@websrv1's password: id_dsa 100{1c918b003a0fec779e46518dd4d8df22f3dc554de918030f5a1a0cfd93cb28be} 668 0.7KB/s 00:00 id_dsa.pub 100{1c918b003a0fec779e46518dd4d8df22f3dc554de918030f5a1a0cfd93cb28be} 616 0.6KB/s 00:00 authorized_keys 100{1c918b003a0fec779e46518dd4d8df22f3dc554de918030f5a1a0cfd93cb28be} 1024 1.0KB/s 00:00 id_rsa 100{1c918b003a0fec779e46518dd4d8df22f3dc554de918030f5a1a0cfd93cb28be} 1675 1.6KB/s 00:00 known_hosts 100{1c918b003a0fec779e46518dd4d8df22f3dc554de918030f5a1a0cfd93cb28be} 5481 5.4KB/s 00:00 id_rsa.pub 100{1c918b003a0fec779e46518dd4d8df22f3dc554de918030f5a1a0cfd93cb28be} 408 0.4KB/s 00:00 [root@loadb1 ~]# scp -r /root/.ssh/ websrv2:/root/ root@websrv2's password: id_dsa 100{1c918b003a0fec779e46518dd4d8df22f3dc554de918030f5a1a0cfd93cb28be} 668 0.7KB/s 00:00 id_dsa.pub 100{1c918b003a0fec779e46518dd4d8df22f3dc554de918030f5a1a0cfd93cb28be} 616 0.6KB/s 00:00 authorized_keys 100{1c918b003a0fec779e46518dd4d8df22f3dc554de918030f5a1a0cfd93cb28be} 1024 1.0KB/s 00:00 id_rsa 100{1c918b003a0fec779e46518dd4d8df22f3dc554de918030f5a1a0cfd93cb28be} 1675 1.6KB/s 00:00 known_hosts 100{1c918b003a0fec779e46518dd4d8df22f3dc554de918030f5a1a0cfd93cb28be} 5481 5.4KB/s 00:00 id_rsa.pub 100{1c918b003a0fec779e46518dd4d8df22f3dc554de918030f5a1a0cfd93cb28be} 408 0.4KB/s 00:00 [root@loadb1 ~]# scp -r /root/.ssh/ dbase1:/root/ root@dbase1's password: id_dsa 100{1c918b003a0fec779e46518dd4d8df22f3dc554de918030f5a1a0cfd93cb28be} 668 0.7KB/s 00:00 id_dsa.pub 100{1c918b003a0fec779e46518dd4d8df22f3dc554de918030f5a1a0cfd93cb28be} 616 0.6KB/s 00:00 authorized_keys 100{1c918b003a0fec779e46518dd4d8df22f3dc554de918030f5a1a0cfd93cb28be} 1024 1.0KB/s 00:00 id_rsa 100{1c918b003a0fec779e46518dd4d8df22f3dc554de918030f5a1a0cfd93cb28be} 1675 1.6KB/s 00:00 known_hosts 100{1c918b003a0fec779e46518dd4d8df22f3dc554de918030f5a1a0cfd93cb28be} 5481 5.4KB/s 00:00 id_rsa.pub 100{1c918b003a0fec779e46518dd4d8df22f3dc554de918030f5a1a0cfd93cb28be} 408 0.4KB/s 00:00 [root@loadb1 ~]# scp -r /root/.ssh/ dbase2:/root/ root@dbase2's password: id_dsa 100{1c918b003a0fec779e46518dd4d8df22f3dc554de918030f5a1a0cfd93cb28be} 668 0.7KB/s 00:00 id_dsa.pub 100{1c918b003a0fec779e46518dd4d8df22f3dc554de918030f5a1a0cfd93cb28be} 616 0.6KB/s 00:00 authorized_keys 100{1c918b003a0fec779e46518dd4d8df22f3dc554de918030f5a1a0cfd93cb28be} 1024 1.0KB/s 00:00 id_rsa 100{1c918b003a0fec779e46518dd4d8df22f3dc554de918030f5a1a0cfd93cb28be} 1675 1.6KB/s 00:00 known_hosts 100{1c918b003a0fec779e46518dd4d8df22f3dc554de918030f5a1a0cfd93cb28be} 5481 5.4KB/s 00:00 id_rsa.pub 100{1c918b003a0fec779e46518dd4d8df22f3dc554de918030f5a1a0cfd93cb28be} 408 0.4KB/s 00:00 [root@loadb1 ~]# scp -r /root/.ssh/ ntp:/root/ root@ntp's password: id_dsa 100{1c918b003a0fec779e46518dd4d8df22f3dc554de918030f5a1a0cfd93cb28be} 668 0.7KB/s 00:00 id_dsa.pub 100{1c918b003a0fec779e46518dd4d8df22f3dc554de918030f5a1a0cfd93cb28be} 616 0.6KB/s 00:00 authorized_keys 100{1c918b003a0fec779e46518dd4d8df22f3dc554de918030f5a1a0cfd93cb28be} 1024 1.0KB/s 00:00 id_rsa 100{1c918b003a0fec779e46518dd4d8df22f3dc554de918030f5a1a0cfd93cb28be} 1675 1.6KB/s 00:00 known_hosts 100{1c918b003a0fec779e46518dd4d8df22f3dc554de918030f5a1a0cfd93cb28be} 5481 5.4KB/s 00:00 id_rsa.pub 100{1c918b003a0fec779e46518dd4d8df22f3dc554de918030f5a1a0cfd93cb28be} 408 0.4KB/s 00:00 [root@loadb1 ~]# scp -r /root/.ssh/ dns:/root/ root@dns's password: id_dsa 100{1c918b003a0fec779e46518dd4d8df22f3dc554de918030f5a1a0cfd93cb28be} 668 0.7KB/s 00:00 id_dsa.pub 100{1c918b003a0fec779e46518dd4d8df22f3dc554de918030f5a1a0cfd93cb28be} 616 0.6KB/s 00:00 authorized_keys 100{1c918b003a0fec779e46518dd4d8df22f3dc554de918030f5a1a0cfd93cb28be} 1024 1.0KB/s 00:00 id_rsa 100{1c918b003a0fec779e46518dd4d8df22f3dc554de918030f5a1a0cfd93cb28be} 1675 1.6KB/s 00:00 known_hosts 100{1c918b003a0fec779e46518dd4d8df22f3dc554de918030f5a1a0cfd93cb28be} 5481 5.4KB/s 00:00 id_rsa.pub 100{1c918b003a0fec779e46518dd4d8df22f3dc554de918030f5a1a0cfd93cb28be} 408 0.4KB/s 00:00
Note : Make sure once you made ssh session among all servers.
Part-2: NTP Server & Client settings.
If you like this Post, please give us your valuable feedback by pressing Vote Up / Vote Down Button. Thanks.
[thumbs-rating-buttons]