Implementation of DNS-based multi-machine load balancing in Linux

Source: Internet
Author: User
Tags nslookup
A server was added to a customer two days ago. Jointly undertake the operation of a forum. However. To achieve load balancing. It is indeed difficult.
I have tried several methods before,

I. DNS rotation .. Advantages: simple implementation. Disadvantage: the load of each server cannot be detected. It is difficult to control the visitor's access address (generally, DNS servers have caches, so. The effect is not obvious)
Ii. Front-endProgram.. A service program similar to Zeus Load balancer is used. Accept access requests at the front-end. And then distributed to the actual servers.

However, none of the above methods applies to me ..
First. Visitor traffic cannot be allocated correctly... A server is often overloaded. The other is very low...
Second. Will occupy more traffic. Resources also occupy a large amount.

Best. I still used a DNS load balancing method-lbname.
Its main effects are described as follows:
1. Perl-based DNS server. Simple application.
2. Automatically detect the load of each server. Then, DNS resolution is prioritized based on the results.
Iii. DNS resolution takes effect in real time. It will not be cached by the DNS server.
4. The installation method is simple...

Lbname webpage Introduction
Http://www.stanford.edu /~ Schemers/docs/lbnamed/lbnamed.html
Http://www.stanford.edu /~ Riepel/lbnamed/
.
.

Download:
Http://www.stanford.edu /~ Riepel/lbnamed/lbnamed-1.2.1.tar.gz
Http://www.stanford.edu /~ Schemers/Dist/lb.tar
.
.

Download Package Description:
Memory directory
1) lbcdSource code.... Lbcd is the server load check program used by lbnamed .. Every server that requires load balancing needs to be installed and run...
We recommend that you download and use the latest lbcd compilation package. Http://www.stanford.edu /~ Riepel/lbnamed/often gets compilation errors before lbcd-3.1.0.tar.gz. (This is also true. Hey .)
Compile this package. Errors often occur. How to install it successfully. It depends on your skills. (Edit util. C line 123rd. Add // to the front //)
After lbcd is compiled successfully. Copy it to/usr/sbin. Then you can run it .. You do not need to add any parameters. (To stop it after running, it is lbcd-S)

2) lbnamed's server program Perl... has two versions. One is perl4. the other is perl5. I use perl5. So use it to describe.
Go to the perl5 directory ..... Configure the lbnamed and poller programs first.
Note:
The lbnamed program is the main program. Provides dynamic DNS resolution. Strictly speaking. It is already a DNS server program.
Poller is used to provide load conditions for lbnamed balancing servers. (Used with the previously installed lbcd Program)
But the two programs may need to be changed. Please refer to the Perl program address in the first line of the program .. Change to your Perl address.

Then you need to change the configuration file of the program.
1. There are several places to change lbnamed. conf.
I. $ hostmaster = "schemers.leland.stanford.edu"; change schemers.leland.stanford.edu to the domain name of your server .. For example, host.abc.com does not have much relationship.
2. Change all Stanford to the middle section of your domain name (for example, bendy.com, change it to bendy), and change all EDU to the suffix of the domain name (for example, bendy.com, change it to com ).. This is very important .. I do not recommend that you change the best. You can also change
2. You can use another file name for the sweet. config file, which is set in lbnamed. conf. I suggest you clear the file first. Create a new one.
The configuration method of this file is
Load server host weight-bearing group
For example. My own situation. There are two servers. The configuration files are bbs1.bendy.com and bendy2.bendy.com respectively.

Bbs1 1 BBS
Bbs2 2 bbs

After this file is configured. You need a method to resolve the domain name bbs1. Is to modify the/etc/hosts file. My situation is
192.168.1.1 bbs1
192.168.1.2 bbs2

In this case. The poroller program will detect the load of 111.222.333.001 and 111.222.333.002.

So far, the DNS server and the Server Load balancer program have been completed. Maybe my explanation is not clear. Now I will describe the list one by one

Bbs1 server lbserver1 192.168.1.1 compile and run lbcd
Bbs2 server lbserver2 192.168.1.2 compile and run lbcd
Configure lbnamed on the DNS server dnsserver 10.0.0.1 and configure bbs1 and bbs2 domain name resolution in/etc/hosts.

In this case .. Run the lbnamed program on the DNS server. The system starts to act .. The main startup parameters of lbnamed are-l logfile and-D (Debug)
./Lbnamed-l lb. Log-d
View records (similar)
Cat lb. Log

-====
05/30 21442 lbnamed starting poller
05/30 21442 lbnamed load_config
Loading 1452 bbs2 192.168.1.2 BBS
Loading 837 bbs1 192.168.1.1 BBS
05/30 21442 lbnamed ready to answer requests
05/30 21442 lbnamed do_maint
05/30 21442 lbnamed reloading config
05/30 21442 lbnamed load_config
Loading 1671 bbs2 192.168.1.2 BBS
Loading 1086 bbs1 192.168.1.1 BBS

If you do not have those records. Check the sweet. config. unreach file. This indicates that the poller program cannot receive load information from the server of the other party .. Check whether the lbcd program is running ..

If the program runs normally. Then your DNS server runs normally.
If you check whether the program is normal... You can use NSLookup...

C: \ Documents ents and Settings \ administrator. XINGKONG-SERVER> NSLookup
Default Server: ns.guangzhou.gd.cn
Address: 202.96.128.143

> Server 10.0.0.1 // directly use the DNS server
Default Server: [10.0.0.1]
Address: 10.0.0.1

> Set type = All // set the query type

> Bbs.best.bendy.com // bbs is the group name set by sweet. config, and best.bendy.com is set in lbnamed. conf.
Server: [10.0.0.1]
Address: 10.0.0.1

Bbs.best.bendy.com canonical name = bbs2.bendy.com // The returned information. The DNS system assigned bbs2 to you for this query (allocated based on the load returned by the two servers, not randomly allocated)
Bbs2.bendy.com Internet address = 192.168.1.2 // while bbs.bendy.com's a record in the DNS system is 192.168.1.2 // the final result is bbs.best.bendy.com and the IP address obtained is 192.168.1.2.

====
Since then .. The server configuration has been completed.
Next we configure the DNS resolution for the specific domain name...

The method is also very simple. Taking bendy.com as an example, add the following record to the DNS Management of bendy.com
I. Add two best.bendy.com NS records: ns1.bendy.com and ns2.bendy.com (or more than two. Depending on how many servers you have run lbnamed
2. Add the first added NS record to the actual IP address and point to each server running lbnamed, for example, ns1.bendy.com address 10.0.0.1/ns2.bendy.com address 10.0.0.2.
3. Add the actual IP addresses of bbs1.bendy.com and bbs2.bendy.com... As mentioned above, ...bbs.best.bendy.com only transfers DNS records to bbs1.bendy.com or bbs2.bendy.com. Lbnamed does not have the right to parse bbs1.bendy.com and bbs2.bendy.com... So. The nameserer of bendy.com is required to parse it.
(PS: bbs1.bendy.com records are not necessarily the same as those of the lbnamed program ...)
4. Finally .. Add bbs.bendy.com cname to bbs.best.bendy.com... Haha... Success...

After DNS resolution is complete, we will complete this task.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.