-
Notifications
You must be signed in to change notification settings - Fork 0
/
README
229 lines (162 loc) · 9.09 KB
/
README
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
Contents
========
Introduction
Collecting and Summarizing Host Metrics
Answering DNS Queries
TTLs and MXes
Configuring lbnamed
The Load-Balanced Client Daemon
Duh
Conclusion
Introduction
============
lbnamed is a load balancing name server written in Perl using the Stanford::
DNSserver perl module. lbnamed allows you to create dynamic groups of hosts
that have one name in the DNS. A host may be in multiple groups at the same
time. For example, the name
www.best.stanford.edu
represents a dynamic group of 5 web servers named:
www{1,2,3,4,5}.stanford.edu
When someone tries to connect to www.best.stanford.edu, a DNS query is
performed. That query eventually gets sent to the lbnamed server which
responds with the name of the least loaded of those 5 web servers.
Of course advertising a web service in a subdomain like "best.stanford.edu"
is less than desirable. Fortunately, that can be avoided with the simple
alias:
www.stanford.edu -> www.best.stanford.edu
Now when someone tries to connect to www.stanford.edu and their DNS resolver
queries for the IP address of www.stanford.edu it gets the following answer:
www.stanford.edu is an alias for www.best.stanford.edu (1)
www.best.stanford.edu is an alias for www3.stanford.edu (2)
www3.stanford.edu has address 171.64.10.89 (3)
In this "alias chain" type answer, the middle link, (2), is provided by
lbnamed; the others are provided by the normal name service serving the
"stanford.edu" zone.
lbnamed can return the address of the least loaded group member instead of
its name. In that case, the query for the IP address of www.stanford.edu
would get the following answer:
www.stanford.edu is an alias for www.best.stanford.edu (1)
www.best.stanford.edu has address 171.64.10.89 (2)
This is somewhat less "honest", DNS-wise, because a reverse lookup on the
IP address yields the name www3.stanford.edu, not www.best.stanford.edu.
It does however avoid the "alias chain", which some older BIND versions
have trouble with (note that all those old BIND versions have security
problems, so no one should be running them now!).
Collecting and Summarizing Host Metrics
=======================================
The poller script queries the load-balanced client daemon, lbcd, on hosts
participating in load-balanced name groups. It collects the system load
and other data from the lbcd running on each host (more on lbcd later).
The poller uses the collected information to calculate an overall "weight"
for each host. The host names and weights are written to a file that the
lbnamed name server uses to determine which host names to pass out in
response to queries.
The poller calculates the weights using the following algorithm:
// constants
WEIGHT_PER_USER = 10
WEIGHT_PER_LOAD_UNIT = 3
// data retrieved from lbcd by the poller
l1 = current host load
tot = total number of users logged into the host
uniq = number of unique users logged into the host
// data provided in the lbnamed configuration file
sf = this host's "server factor" in the range 0 to 10
weight = WEIGHT_PER_USER * (0.2 * tot + 0.8 * uniq) * (10 - sf)
+ WEIGHT_PER_LOAD_UNIT * l1 * sf
As you can see, the "server factor" controls the relative importance of
interactive user sessions. A value of zero represents a purely interactive,
user-oriented host; a value of 10 represents a server with no logins.
Answering DNS Queries
=====================
The lbnamed script uses the weights calculated by the poller and the host
"participation factors" to determine which host's name to pass out in
response to a DNS query. The participation factor is a configuration
parameter that allows for unequal load sharing between hosts in a group.
lbnamed sorts a group of hosts by (weight / participation factor) and passes
out the name of the host with the lowest value. A host with a participation
factor of 0.10 would have to have a weight ten times that of a host with a
participation factor of 1.0 before they would sort equally. A very small
participation factor, say 0.001, can be used to make one host a backup for a
set of other hosts with the default participation factor of 1.0.
Once lbnamed has determined which host's name to use in the DNS response,
it sends the response and increments the host's weight. The increment is
calculated using the following formula:
// constants
WEIGHT_PER_USER = 10
WEIGHT_PER_LOAD_UNIT = 3
// data provided in the lbnamed configuration file
sf = this host's "server factor" in the range 0 to 10
increment = WEIGHT_PER_USER * (10 - sf)
+ WEIGHT_PER_LOAD_UNIT * sf
Note that eventually all the hosts in a group will have the same weight and
their names will be passed out in round-robin fashion from then on.
TTLs and MXes
=============
By default, lbnamed uses TTL of 0 in its DNS responses. That tells the DNS
not to cache the response and to always make a new query for the name in
question. This gives the most accurate load sharing across the hosts in a
group. But it may generate too many DNS queries. If that's the case, you
can provide a non-zero TTL value for the group in the configuration file.
It's still best to keep the value small to promote a truly balanced load.
DNS queries for MX records must be handled in lbnamed for groups not using
the alias chain response type. For those using the alias chain, the MX
response is "inherited" from the host's real name. For example, an MX
query on www.stanford.edu might get the following alias chain answer:
www.stanford.edu is an alias for www.best.stanford.edu (1)
www.best.stanford.edu is an alias for www3.stanford.edu (2)
www3.stanford.edu mail is handled by 10 leland.stanford.edu (3)
As mentioned before, only link (2) comes from lbnamed, so it doesn't have to
handle the MX data. But without the alias chain, the answer would be:
www.stanford.edu is an alias for www.best.stanford.edu (1)
www.best.stanford.edu mail is handled by 10 leland.stanford.edu (2)
Once again part (2) is provided by the load-balanced name server, but this
time it's the MX record, so lbnamed must have the data to respond properly.
In order to support this, the lbnamed configuration file includes a section
where you may provide MX information.
Configuring lbnamed
===================
lbnamed is configured using a configuration file. The first section of the
file lists the names of the hosts and the names of the groups in which they
participate (remember that a group is a load-balanced name). Each host also
has a server factor and a participation factor for each group it's in. The
file may have an optional second section for listing load-balanced name TTLs
and MXes. Here's a short sample configuration file:
# SF = server factor; default participation factor = 1.0;
host SF group(participation factor)
#################### ## #########################################
foo.stanford.edu 2 quux
bar.stanford.edu 10 www
baz.stanford.edu 5 quux www(.01)
# default TTL = 0 seconds; top slice - see lbnamed POD;
# default MX = none;
group TTL top slice MX
############ ##### ######### ##################
www 6 0 mail.stanford.edu
The Load-Balanced Client Daemon
===============================
The load-balanced client daemon, lbcd, runs on the hosts participating in
load-balanced name groups. The poller queries lbcd to get the host load
and other information. lbcd is a mildly complex beast because it has to
understand how to get all that information from a plethora of Unix
variants. Because of that complexity, lbcd is distributed and maintained
separately from lbnamed.
If lbcd doesn't support your flavor of Unix, or round-robin satisfies your
load-balancing needs, or you just want to play with lbnamed without down-
loading lbcd, this package does include slbcd, a static/simple load-balanced
client daemon. slbcd is written in perl. It provides a complete lbcd with
hard-coded values for the load and other data. When you run it on the hosts
participating in a load-balanced name group, they will always have the same
weight and therefore their names will always be passed out in round-robin
fashion.
Duh
===
The lbnamed and lbnamed.config files in this package contain Stanford-
specific configuration data. Unless you're going to run a load-balanced
name service for Stanford, you'll want to edit those files replacing that
data with values appropriate for your DNS domain.
Conclusion
==========
Hopefully this has been enough of an introduction to lbnamed that you can
make it work for you. Be sure to check out the POD documentation for both
lbnamed and the poller, and the sample configuration file, lbnamed.config.
Share and enjoy.