PDA

View Full Version : Multiple hostnames in the config.php for load balancing / round robin


SnapOff Racing
05-05-2010, 09:27 PM
I am wondering if under the ****** MASTER DATABASE SERVER NAME AND PORT ****** I can add multiple hostnames that will point to one server that is hosting the database but yet that same server has 3 different WAN connections pointing to it. So basically it would look like this in config.php

// ****** MASTER DATABASE SERVER NAME AND PORT ******
// This is the hostname or IP address and port of the database server.
// If you are unsure of what to put here, leave the default values.
$config['MasterServer']['servername'] = '123.123.123.1';
$config['MasterServer']['servername'] = '123.123.123.2';
$config['MasterServer']['servername'] = '123.123.123.3';
$config['MasterServer']['port'] = 3306;

Will vbulletin automatically round robin these entries or will it only use the first connection and then just ignore the rest??

Dismounted
05-06-2010, 06:13 AM
That will use whichever you place last. Use:
$servers = array(
'123.123.123.1',
'123.123.123.2',
'123.123.123.3'
);
$serv_index = mt_rand(0, (count($servers) - 1));

$config['MasterServer']['servername'] = $servers[$serv_index];

Angel-Wings
05-06-2010, 11:11 AM
Hmm - and if you use instead of some PHP function a real loadbalancer ? Then you can do real load-balancing based on the load of the backends instead of just plain rotating between the backeneds.

SnapOff Racing
05-06-2010, 06:04 PM
That will use whichever you place last. Use:
$servers = array(
'123.123.123.1',
'123.123.123.2',
'123.123.123.3'
);
$serv_index = mt_rand(0, (count($servers) - 1));

$config['MasterServer']['servername'] = $servers[$serv_index];

Excellent Thank You for that. I will give it a try :up:

--------------- Added 1273190169 at 1273190169 ---------------

Alright I tried that script you posted and it works but if I pull any of the connections the forum stops working. Could you double check the script for me and make certain that a character wasn't accidentally overlooked somewhere?

Dismounted
05-07-2010, 06:13 AM
Alright I tried that script you posted and it works but if I pull any of the connections the forum stops working. Could you double check the script for me and make certain that a character wasn't accidentally overlooked somewhere?
What do you mean by 'pulling any of the connections'?

Angel-Wings
05-07-2010, 05:34 PM
Alright I tried that script you posted and it works but if I pull any of the connections the forum stops working. Could you double check the script for me and make certain that a character wasn't accidentally overlooked somewhere?

Well - you may use that PHP code or read the official MySQL documentation since there's already a tool doing exactly what you're looking for. ;)
But if you prefer PHP - ok - your choice

SnapOff Racing
05-08-2010, 05:14 AM
What do you mean by 'pulling any of the connections'?

Ok it's like this, I am running a local webserver with 5 separate internet connections going into one server. They are all run into one router that does the load balancing. But what I wanna do is put my forum on a different server but still host the database from here. So in the config.php file I need to be able to tell it that I have 5 separate connections that it can choose to connect to. I tried using the script you provided which seems to work but if I pull one of the 5 local connections offline then everything stops working where really it should just skip to the next connection if it sees that connection is down. Basically a failover.

Dismounted
05-08-2010, 09:57 AM
That's difficult to achieve due to the current internal design of vBulletin. It assumes that only one server exists, and this is merely a hacked-up way of getting around that. A solution would be to comment out that server's IP in config.php whenever you take it offline.

Angel-Wings
05-08-2010, 11:28 AM
Thanks for ignoring me but still mysqlproxy can do exactly what you're looking for

SnapOff Racing
05-08-2010, 10:31 PM
That's difficult to achieve due to the current internal design of vBulletin. It assumes that only one server exists, and this is merely a hacked-up way of getting around that. A solution would be to comment out that server's IP in config.php whenever you take it offline.

Ahhh that makes sense, I suppose that would work then. I was also just thinking of creating a new domain specifically for the MySQL database and then just put that one single domain in the config.php then use DNS to round robin the IP Addresses.

But so the script you provided should work just fine with all the connections working then correct? vBulletin will then round robin all of the addresses that I put in that array correct?

Thanks for ignoring me but still mysqlproxy can do exactly what you're looking for

Sorry but your post wasn't really all that specific on how this could help my situation. You simply just said I should read the MySQL documentation but didn't specify what exactly I should be looking for. Hence the reason for my paying attention to Dismounted's posts as he has given me something to work with :)

Angel-Wings
05-09-2010, 12:00 PM
Yes - https://launchpad.net/mysql-proxy

With this software you can specify several backends and with a small LUA script you can check the health of these backends to have a failover solution.
With simple round-robin like the PHP script is doing there's no check if all backends are really available which may result in timeouts.