1BALANCE(1)                  General Commands Manual                 BALANCE(1)
2
3
4

NAME

6       balance  3.42  -  A  simple  TCP proxy with load balancing and failover
7       mechanisms.
8

SYNOPSIS

10       balance [ -b addr ] [ -B addr ] [ -t sec ] [ -T sec ] [ -adfpHM ]  port
11       host1[:port1[:maxc]] [!|%] [ ... hostn[:portn[:maxc]]]
12
13       balance [ -b addr ] -i [ -d ] [ -M ] port
14
15       balance [ -b addr ] -c cmd [ -d ] [ -M ] port
16

DESCRIPTION

18       Balance  is a simple, generic "userland" TCP proxy, which allows simple
19       round-robin load balancing and graceful failover between several desti‐
20       nation servers.
21
22       Balance  supports IPv6 on the listening side which makes it a very use‐
23       ful tool for IPv6 migration of IPv4 only services and servers.
24
25       Balance is available at http://balance.sourceforge.net.
26
27       Definitions: A possible destination consisting of a host address and  a
28       port  is called a "channel".  A channel is member of a "channel group".
29       Channels are numbered in a group starting with 0.  Groups are  numbered
30       starting with 0, which is the initial default group.
31
32       Balance  accepts connections on the given port and forwards them to the
33       supplied channels.  At least one channel (in the default group) must be
34       specified.  If there are two or more channels specified in a group bal‐
35       ance performs a simple round-robin load balancing between the channels.
36
37       Balance allows the definition of further channel groups. The connection
38       scheme  works as follows: balance tries first to establish a connection
39       to a channel in the first group (0),  performing  the  standard  round-
40       robin  load balancing scheme. If no channel in this group is available,
41       balance proceeds with the next higher channel group. Groups are  simply
42       separated  with  a  "!"  at the command line at startup and can be con‐
43       trolled interactively with the "group" command.
44
45       A "%" instead of a "!" as a group separator declares the previous group
46       to  be  of type "hash".  This means that instead of a round-robin algo‐
47       rithm, a hash distribution based on the client ip address  is  used  to
48       determine  the  destination  channel. This allows connecting one client
49       always to the same server (e.g. balancing http  sessions  to  a  single
50       server).
51
52       Hosts  may  be specified either by hostname or by IP address. Ports may
53       be specified either by name (as listed  in  /etc/services)  or  numeri‐
54       cally.   If no port is specified in a destination, the destination port
55       defaults to the source port that balance controls.
56
57       Balance allows the specification of the maximum number  of  connections
58       per  channel.  This  parameter  can  be optionally added after the port
59       specification separated by a colon (":"). If a maximum number  of  con‐
60       nections is specified a channel will only be used for this maximum num‐
61       ber of simultaneous connections. A maxc value of 0 denotes an unlimited
62       number of connections. This is the initial default value of a channel.
63
64       The  maximum number of groups and channels balance can handle is speci‐
65       fied at compile time and is initially 16 channels in 16 groups.
66
67       Failover to another destination (a "channel") occurs if the  connection
68       is  refused on the current channel or if the connect timeout is reached
69       trying to establish a connection. If all possible  destinations  (chan‐
70       nels) currently fail, the client connection to balance is closed.
71
72       Balance accepts the following options:
73
74       a      Enable  autodisable  option:  A channel needs to be manually re-
75              enabled after a failure.
76
77       b      Bindhost: Balance binds to the specified host (or  address)  for
78              listen() instead to INADDR_ANY.
79
80       B      Bindhost:  Balance  binds to the specified host (or address) for
81              outgoing connections (the connection will be initiated from this
82              address).
83
84       c      Command:  allows to send a command to the balance master process
85              (see interactive mode)
86
87       d      Debug: Balance outputs debugging and  tracing  information  mes‐
88              sages on stderr.
89
90       H      Hashfailover: Balance does failover to next node even if hash is
91              used.
92
93       F      Foreground: tells balance to stay in foreground. This  might  be
94              useful for testing and debugging since balance can be stopped in
95              that mode using ^C (or other interrupt character).
96
97       M      Use memory mapping for IPC instead of shared memory
98
99       i      Interactive Control: Balance connects to  the  running  instance
100              defined  by  local  port  and bind address via shared memory and
101              allows to control the behaviour  of  it  using  a  command  line
102              interface. The access permission using this interface are deter‐
103              mined by the access restrictions of the shared memory segment in
104              effect.   help or ?  prints out a short command overview, create
105              allows to establish a new destination definition (channel)  con‐
106              sisting  of host and port in the current group, disable disables
107              a channel in the current group, enable enables a  channel  again
108              in  the current group, group changes the current group in inter‐
109              active mode where all  following  commands  are  targeted,  hash
110              changes  the current group to be of type "Hash", help prints out
111              online help informations, kill shuts down the master process and
112              exits  interactive  mode, maxc <channel> <maxc> sets the maximum
113              number of connection ot the channel (0  means  infinite),  mrtg-
114              bytes  <group>  <channel>  prints out the bytes received/sent in
115              MRTG compatible format (intended to be called with -c  automati‐
116              cally  by  MRTG),  mrtg-conns  <group>  <channel> prints out the
117              total connections in MRTG  compatible  format  (intended  to  be
118              called  with  -c automatically by MRTG), quit exits the interac‐
119              tive mode, reset resets the  byte  counters  of  a  channel,  rr
120              changes  the  current  group  to  be of type "Round Robin", show
121              shows an overview and the status of all channels  including  the
122              incoming  and  outgoing  transfer volume in bytes. The output is
123              sorted by groups. Additionally the current connections  (c)  and
124              the  maximum  allowed  connections  (maxc)  are printed, version
125              prints out the version and MAXGROUPS and  MAXCHANNELS  constants
126              at compile time.
127
128       p      Packetdump: Balance shows all incoming and outgoing data on std‐
129              out using a simple always readable  external  representation  of
130              data.  This might be useful for debugging and protocol analysis.
131
132       t      Connect  Timeout: the default timeout trying to establish a con‐
133              nection to any destination can be changed using this option. The
134              default timeout after which a destination is regarded to be cur‐
135              rently inaccessible is 5 seconds.
136
137       T      Select Timeout: Timeout for select(), default = 0 (never).  This
138              feature is currently untested.
139

EXAMPLES

141       $ balance smtp host1.test.net host2.test.net
142              Connection  to  the local SMTP port will be forwarded alterating
143              to the SMTP port on host1 and host2.  Balance runs automatically
144              in background.
145
146       $ balance -b 2001:DB8::1 80 10.1.1.1 10.1.1.2
147              Balance   binds  on  port  80  of  the  local  IPv6  IP  address
148              2001:DB8::1 and distributes connections to  the  IPv4  addresses
149              10.1.1.1 and 10.1.1.2.
150
151       $ balance -fp imap mailserver
152              Connections  to  the local IMAP port will always be forwarded to
153              the host "mailserver".  Balance stays in foreground and all data
154              is printed in readable format on stdout.
155
156       $ balance -f 8888 host1 10.1.1.1:8000
157              Connections  to the local port 8888 are forwarded alternating to
158              host1, port 8888 and the  host  10.1.1.1,  port  8000.   Balance
159              stays in foreground connected to the "controlling tty".
160
161       $ balance imap mailserver1::16 ! mailserver2
162              Two  groups  are  specified, each containing one channel member.
163              First  up  to  16  simultaneous  connections  are  forwarded  to
164              "mailserver1".  As  soon  as they are consumed, balance proceeds
165              with the next group (1) which will consume all remaining connec‐
166              tions forwarding them to the imap ort on "mailserver2".
167
168       $ balance pop3 host1 host2 host3 ! failover1
169              Balance  does  round robin load balancing for the three hosts in
170              the default group 0 for pop3 services. If  all  three  hosts  in
171              group  0  fail,  all  connections are then forwarded to the host
172              "failover1".
173
174       $ balance telnet target.munich.net::1
175              Here balance is used to restrict all connections to exactly  one
176              at a time forwarding the telnet port.
177
178       $ balance 8888 localhost::12 ! localhost::4 ! localhost::2 localhost::2
179       ! localhost:25
180              This is a simple test, forming 5 groups where  balance  is  self
181              referencing  its  own  services  20 times. This is simply a test
182              which definitely can be tried at home.
183

BUGS

185       In case that balance is not able to forward the connection to any  des‐
186       tination  the inital connection to balance is always first accepted and
187       then closed again immediately. This is not in every case the  behaviour
188       that would have been seen directly on the destination host.
189

AUTHOR

191       Thomas Obermair, Inlab Software GmbH (obermair@acm.org)
192
193       Copyright  (c) 2000-2007,2008 by Thomas Obermair (obermair@acm.org) and
194       Inlab Software GmbH  (http://www.inlab.de),  Gruenwald,  Germany.   All
195       rights reserved.
196
197       Balance  is released under the GNU GENERAL PUBLIC LICENSE, see the file
198       COPYING in the source code distribution.
199
200
201
202                                  2008/04/08                        BALANCE(1)
Impressum