freebsd-cluster Digest, Vol 113, Issue 1

Andrei Manescu mandrei05 at
Tue Nov 11 05:18:56 PST 2008


I tried these solutions separately in test environments, but they should
work together:

For load balancing you can use CARP + 2 VHID. Each node being master for 1
vhid. This way, when one node fails, the other one will take both "service"
ip (vhid). 1 example here:
I would recommend you to read the manuals + 3-4 other links).
As for Mysql, you can use the dual master configuration. Be very carefull
here. This procedure is based on mysql internal binary logs to replicate
each entry from one node to the other. You will need to play with *
auto_increment_offset* option from MySQL (otherwise auto_incremented columns
will be screwed up). You have a lot to read, but it's worth it.

Here are some links for mysql dual master replication:,100718,100718
I know that this is not a very efficient method for load-balancing but at
least it offers redundancy & a little load balancing.
C) Unless I miss something, you configure your PHP scripts to point to
localhost/service IP (VHID)/nodes fixed ip address for mysql connection.
D) PHP & other web programming languages use sessions (depends on the
websites that you'll be hosting) that are stored usually on /tmp of the
server, so be carefull to have this in mind because some clients can loose
their sessions if they're redirected to the second node, unless you do
something about it (like rsync/nfs/csync/etc).
E) You can youse a 3rd machine running PF as firewall that will do NAT for
the nodes + port redirection + load balancing: Here is the example -
F) If your website(s) will use upload forms you will need to keep the
Directory_roots of Apache from both nodes in sync or you can use shared
storage (but I guess that's not your case).
G) This solution does not offer automatic automatic failover mechanisms in
case of service-failure. I mean that if mysql/apache processes will go down
or crash on one node (some bug or they are stopped), but the node stays up,
from cluster point of view everything will be ok. The master/firewall (point
E) will still forward part of the incoming packets to this failed node.  You
need to use the nc-netcat command (get exit status) to check ports 80,3306
(or those that your apache/mysql will listen to) from both nodes and take
action if one node is detected UP but apache is down (like change the
port-forwarding rule or connect one of the node and transfer the CARP vhid
from the node with apache not running).
Example of how to run netcat to check if apache and mysql are running
(Apache - Yes, mysql - No):
# nc -w 1 localhost 80 >/dev/null 2>&1; echo $?
# nc -w 1 localhost 3306 >/dev/null 2>&1; echo $?

H) You could also use daemon-tools to monitor and restart apache+mysql
processes in case they crash (of course, the start/stop procedure for both
will be different from standard one).

P.S.: I never used this complete configuration to say if it'll work, but
this is how I would do it.
P.S.2: If you are used to commercial clustering solutions, probably this
will seem a little strange, as there are no scripts/commands to show the
status of the cluster nodes/services, but you can make some scripts t

If anyone has anything to add or to correct, please do it, as this would be
important to me, also.

Good luck.
2008/11/11 <freebsd-cluster-request at>

> Send freebsd-cluster mailing list submissions to
>        freebsd-cluster at
> To subscribe or unsubscribe via the World Wide Web, visit
> or, via email, send a message with subject or body 'help' to
>        freebsd-cluster-request at
> You can reach the person managing the list at
>        freebsd-cluster-owner at
> When replying, please edit your Subject line so it is more specific
> than "Re: Contents of freebsd-cluster digest..."
> Today's Topics:
>   1. Full picture for "Load Balacing MySQL, Apache" (Anh Pham Tuan)
> ----------------------------------------------------------------------
> Message: 1
> Date: Tue, 11 Nov 2008 11:21:12 +0700
> From: "Anh Pham Tuan" <anhptnn at>
> Subject: Full picture for "Load Balacing MySQL, Apache"
> To: freebsd-cluster at
> Message-ID:
>        <e46552500811102021w5f007af4h4a6a56762c5486aa at>
> Content-Type: text/plain; charset=ISO-8859-1
> Hello,
> Does anybody give me a solution for this:
>                                        |
>         Load Balancer (IPVS, MySQL cluster management)
>                                        |
>                                     /     \
>                                   /         \
>                         Apache       Apache
>                         MySQL       MySQL
> Howto install IPVS, MySQL cluster management?
> How to configure 2 nodes including  of Apache+MySQL?
> Thanks in advance.
> ------------------------------
> _______________________________________________
> freebsd-cluster at mailing list
> To unsubscribe, send any mail to "freebsd-cluster-unsubscribe at"
> End of freebsd-cluster Digest, Vol 113, Issue 1
> ***********************************************

More information about the freebsd-cluster mailing list