In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces how to use DNS to achieve simple load balancing on Linux. It is very detailed and has a certain reference value. Interested friends must read it!
DNS polling maps multiple servers to the same hostname and does not do much for the magic shown here.
If your back-end server is made up of multiple servers, such as clustered or mirrored Web or file servers, it provides a single entry point through load balancers. Large e-commerce companies with busy business spend a lot of money on high-end load balancers, using it to perform a variety of tasks: proxy, cache, health check, SSL processing, configurable priority, traffic shaping and many other tasks.
But you don't need to do that much of a load balancer. What you need is a simple way to distribute load across servers that provides failover and doesn't care much about whether it's efficient and perfect. DNS polling and subdomain delegation using polling are two simple ways to achieve this goal.
DNS polling maps multiple servers to the same hostname, and multiple servers can be used to process their requests when users access foo.example.com.
Using polling subdomain delegation is more useful when you have multiple subdomains or when your servers are geographically dispersed. You have a primary domain name server, and subdomains have their own domain name servers. Your primary domain name server directs all requests to the subdomain to their own domain name server. This increases response time because the DNS protocol automatically finds the fastest link.
DNS polling
Polling has nothing to do with robins, which, according to librarians I know, was originally a French phrase, ruban rond, or round ribbon. A long time ago, French government officials signed petitions in ungraded circles, wavy lines, or straight lines to cover the original sponsors.
DNS polling is also unhierarchical, simply configure a list of servers, and then transfer the request to each server. It does not do real load balancing because it does not measure load at all and there is no health check, so if a server goes down, the request will still be sent to that down server. Its advantage is simplicity. If you have a small cluster of files or Web servers and want to spread the load between them in a simple way, then DNS polling is perfect for you.
All you do is create multiple An or AAAA records that map multiple servers to a single hostname. This BIND example uses both the IPv4 and IPv6 private address classes:
Fileserv.example.com. IN A 172.16.10.10fileserv.example.com. IN A 172.16.10.11fileserv.example.com. IN A 172.16.10.12fileserv.example.com. IN AAAA fd02:faea:f561:8fa0:1::10fileserv.example.com. IN AAAA fd02:faea:f561:8fa0:1::11fileserv.example.com. IN AAAA fd02:faea:f561:8fa0:1::12
Dnsmasq saves An and AAAA records in the / etc/hosts file:
172.16.1.10 fileserv fileserv.example.com172.16.1.11 fileserv fileserv.example.com172.16.1.12 fileserv fileserv.example.comfd02:faea:f561:8fa0:1::10 fileserv fileserv.example.comfd02:faea:f561:8fa0:1::11 fileserv fileserv.example.comfd02:faea:f561:8fa0:1::12 fileserv fileserv.example.com
Please note that these examples are very simple, and there are many ways to resolve fully qualified domain names, so learn by yourself on how to configure DNS.
Use the dig command to check that your configuration works as expected. Replace ns.example.com with your domain name server:
$dig @ ns.example.com fileserv A fileserv AAA
It will display polling records for both IPv4 and IPv6.
Subdomain delegation and polling
Subdomain delegation combined with polling will have more configuration to do, but this has some benefits. When you have multiple subdomains or geographically dispersed servers, you should use it. Its response time is faster, and the down server will not respond, so the client will not be hung up waiting for a reply. A short TTL, such as 60 seconds, can help you do it.
This method requires multiple domain name servers. In the simplest scenario, you need a primary domain name server and two subdomains, each with its own domain name server. Configure your polling record on the subdomain server, and then configure the delegation on your primary domain name server.
In BIND on the primary domain name server, you need at least two additional configurations, a zone declaration and an A/AAAA record in the zone data file. The delegation in the primary domain name server should look like this:
Ns1.sub.example.com. IN A 172.16.1.20ns1.sub.example.com. IN AAAA fd02:faea:f561:8fa0:1::20ns2.sub.example.com. IN A 172.16.1.21ns2.sub.example.com. IN AAA fd02:faea:f561:8fa0:1::21sub.example.com. IN NS ns1.sub.example.com.sub.example.com. IN NS ns2.sub.example.com.
Each of the next subdomain servers has its own zone file. Its key point here is that each server returns its own IP address. In the zone declaration in named.conf, all services are the same:
Zone "sub.example.com" {type master; file "db.sub.example.com";}
Then the data file is the same, except that the A/AAAA record uses each server's own IP address. SOA records all point to the primary domain name server:
; first subdomain name server$ORIGIN sub.example.com.$TTL 60sub.example.com IN SOA ns1.example.com. Admin.example.com. (2018123456; serial 3H; refresh 15; retry 3600000; expire) sub.example.com. IN NS ns1.sub.example.com.sub.example.com. IN A 172.16.1.20ns1.sub.example.com. IN AAAA fd02:faea:f561:8fa0:1::20; second subdomain name server$ORIGIN sub.example.com.$TTL 60sub.example.com IN SOA ns1.example.com. Admin.example.com. (2018234567; serial 3H; refresh 15; retry 3600000; expire) sub.example.com. IN NS ns1.sub.example.com.sub.example.com. IN A 172.16.1.21ns2.sub.example.com. IN AAAA fd02:faea:f561:8fa0:1::21
Next, the polling record on the sub-domain server is generated in the same way as before. Now you have multiple domain name servers to process requests to your subdomain. Again, BIND is very complex, and there are many ways to do the same thing, so the homework left for you is to find the best configuration method for you to use.
It is easy to delegate subdomains in Dnsmasq. Add the following line to the dnsmasq.conf file on your primary domain server to point to the domain name server in the subdomain:
Server=/sub.example.com/172.16.1.20server=/sub.example.com/172.16.1.21server=/sub.example.com/fd02:faea:f561:8fa0:1::20server=/sub.example.com/fd02:faea:f561:8fa0:1::21
Then configure polling in / etc/hosts on the domain name server of the subdomain.
For more information and help on configuration methods, please refer to these resources:
Dnsmasq
DNS and BIND, 5th Edition
What is Linux system Linux is a free-to-use and free-spread UNIX-like operating system, is a POSIX-based multi-user, multi-task, multi-threaded and multi-CPU operating system, using Linux can run major Unix tools, applications and network protocols.
These are all the contents of the article "how to use DNS to achieve simple load balancing on Linux". Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.