The Common Access Redundancy Protocol, or CARP allows multiple hosts to share the same IP address. In some configurations, this may be used for availability or load balancing. Hosts may use separate IP addresses as well, as in the example provided here.
To enable support for CARP, the FreeBSD kernel must be rebuilt with the following option:
CARP functionality should now be available
and may be tuned via several sysctl
OIDs. Devices themselves may be loaded via
the ifconfig
command:
#
ifconfig carp0 create
In a real environment, these interfaces will need unique identification numbers known as a VHID. This VHID or Virtual Host Identification will be used to distinguish the host on the network.
One use of CARP, as noted above, is for server availability. This example will provide failover support for three hosts, all with unique IP addresses and providing the same web content. These machines will act in conjunction with a Round Robin DNS configuration. The failover machine will have two additional CARP interfaces, one for each of the content server's IPs. When a failure occurs, the failover server should pick up the failed machine's IP address. This means the failure should go completely unnoticed to the user. The failover server requires identical content and services as the other content servers it is expected to pick up load for.
The two machines should be configured identically other
than their issued hostnames and VHIDs.
This example calls these machines
hosta.example.org
and
hostb.example.org
respectively. First, the
required lines for a CARP configuration have
to be added to rc.conf
. For
hosta.example.org
, the
rc.conf
file should contain the following
lines:
On hostb.example.org
the following lines
should be in rc.conf
:
It is very important that the passwords, specified by the
pass
option to ifconfig
,
are identical. The carp
devices will
only listen to and accept advertisements from machines with the
correct password. The VHID must also be
different for each machine.
The third machine,
provider.example.org
, should be prepared so that
it may handle failover from either host. This machine will require
two carp
devices, one to handle each
host. The appropriate rc.conf
configuration lines will be similar to the following:
Having the two carp
devices will
allow provider.example.org
to notice and pick
up the IP address of either machine should
it stop responding.
The default FreeBSD kernel may have
preemption enabled. If so,
provider.example.org
may not relinquish the
IP address back to the original content
server. In this case, an administrator may
“nudge” the interface. The following command
should be issued on
provider.example.org
:
#
ifconfig carp0 down && ifconfig carp0 up
This should be done on the carp
interface which corresponds to the correct host.
At this point, CARP should be completely enabled and available for testing. For testing, either networking has to be restarted or the machines need to be rebooted.
More information is always available in the carp(4) manual page.
Αυτό το κείμενο, και άλλα κείμενα, μπορεί να βρεθεί στο ftp://ftp.FreeBSD.org/pub/FreeBSD/doc/
Για ερωτήσεις σχετικά με το FreeBSD, διαβάστε την
τεκμηρίωση πριν να επικοινωνήσετε με την
<questions@FreeBSD.org>.
Για ερωτήσεις σχετικά με αυτή την τεκμηρίωση, στείλτε e-mail στην
<doc@FreeBSD.org>.