|
Apple Mac Mini
How-to
|
Making a Mini cluster
The downside of running your own server at home
(especially if you receive all your e-mail there)
is that you're in trouble if the server dies.
Since Minis are so inexpensive,
you can get two and set up a Mini cluster
where one acts as a "fail-over" for the other.
Additionally, all files can be backed-up/mirrored
from one to the other.
Since I have two Minis,
I've appropriately named them
Itsy and Bitsy.
Service fail-over
The idea of service fail-over is that
if the server running services (web, e-mail, etc.)
goes down,
another server will automatically take over the services.
The services I run are:
DHCP,
mail (Sendmail),
web (Apache),
AppleTalk (Netatalk),
and
SSDP (for my Rio music player).
The
Linux High-Availability project
exists and supplies software to do this.
You can install the package by doing:
apt-get install heartbeat
It maintains a heartbeat between all machines in the cluster,
i.e., they all signal each other every couple of seconds.
One of the machines is the master
and the rest are slaves.
It also creates a virtual IP address
on the ethernet interface of the master
and sends an
ARP
request so routers and other devices know to which machine
to send packets having the virtual IP address as the destination.
The following figure shows an example:
![[Heartbeat before]](images/heartbeat1.jpg)
(a) Master up: has virtual IP address
|
|
![[Heartbeat after]](images/heartbeat2.jpg)
(b) Master down: slave took over
|
In (a),
Itsy, in addition to having its regular IP address ending in .200,
also has the virtual IP address ending in .42.
The router port-forwards services to .42.
If Itsy stops responding to the heartbeat signal as shown in (b),
Bitsy will take over by sending an ARP request for .42
plus start the services.
The router, having noticed the ARP,
will start sending packets to Bitsy.
There are two configuration files.
The first, /etc/ha.d/ha.cf, on Itsy is:
logfile /var/log/ha.log
logfacility local0
keepalive 2
warntime 10
deadtime 20
initdead 120
ucast eth0 10.0.1.201
auto_failback on
node itsy
node bitsy
where 10.0.1.201 is Bitsy's IP address.
Bitsy's ha.cf file is the same except for the line:
ucast eth0 10.0.1.200
since it talks to Itsy's IP address.
In environments where there is more than one slave,
other heartbeat signal broadcast methods exist.
The second configuration file, /etc/ha.d/haresources,
which is the same on both machines, is:
itsy 10.0.1.42 MailTo::notify dhcp3-server dovecot httpd ssdpd xinetd
Note that both files on both machines list itsy:
this is how they know which machine is the master.
The MailTo part is optional.
In my case, I have it be the e-mail address of the e-mail/SMS gateway
for my mobile phone so I'll be sent a text message instantly
if Bitsy takes over.
Sendmail isn't listed above because it needs to run all the time
on both machines in order to deliver e-mail, say, from cron to root.
Mirroring files
In addition to having service fail-over,
one also wants all the files to be mirrored.
There are several complicated ways to do this,
but a fairly simple way is to use
rsync
via cron.
I wrote a small
mirror-files script for this.
The cron file, /etc/cron.d/mirror, is:
25 3 * * * root mirror-files bitsy /root /usr/local
45 3 * * * root mirror-files -e /etc/mirror/etc.exclude bitsy /etc
5 0 * * * root mirror-files bitsy /home
*/10 0 * * * root mirror-files bitsy /var/mail
In order for this to work,
you need to allow root to ssh using RSA keys.
Additionally,
since all the RSA keys are also mirrored,
root's authorized_keys file on Itsy
has to contain an entry for it's own public key.
There are machine-specific files in /etc that
must not be mirrored, e.g.,
/etc/hostname;
the complete list for my current configuration is
here.
The list is given to mirror-files above.
Experimenting
Another benefit of having a second server is that I can experiment on it
without risking doing something "bad" to the live server.
For example, I can try new service configurations or new Linux kernels.
(For new kernels, I temporarily stop the heartbeat and mirroring.)
|