NATS Multiple Server Setup

From TMM Wiki
Revision as of 11:59, 24 December 2009 by Tmmdavid (talk | contribs)
Jump to navigationJump to search
NATS 4
About NATS 4
NATS4 Requirements
NATS4 vs NATS3 Advantages
IPSP Integration
NATS4 Changelog
Members Admin
The Members Admin
View Member Details
Add Member
MySQL Auth
Mod Authn DB
Multisite Access
Member Logging
Member Password Retrieval
OpenID Connect
Mod Auth OpenIDC
ID Numbers

This article explains how to setup NATS across multiple servers. The are a number of solutions you can implement to use multiple servers/databases to improve performance and distribute the work load across multiple servers.

Database Server(s)

NATS supports the ability of querying a secondary "slave" database when running any non-essential reports. A slave database is essentially an exact copy of your actual NATS database that is typically used by NATS for larger, time-intensive queries. You can have as many slave databases attached to your master NATS database as you want at no extra charge from us. Using a slave database will greatly improve performance on both your join pages and on your reporting pages, as they will not be fighting for the same database resources when they are both running at the same time.


To use a slave database in NATS, your host must first create the slave database in MySQL and set up replication between the two. Replication is how the master and slave databases keep data up-to-date between each other. MySQL's official documentation on replication can be found here.
(NOTE: NATS Tech Support CANNOT and WILL NOT do this step as it this is something that is set up outside of the NATS system)


Once replication is set up by your host, the next step is to tell NATS how to connect to the primary slave database. Before you start this next step, you need to get the following information from your host:

  • The hostname/address of the slave database
  • The username for the slave database
  • The password for the slave database
  • The name of the slave database


Then in your includes/config.php file, add the following lines:

$config['STATS_DB_SERVER'] = 'localhost';     //replace localhost with address/hostname of where slave database lives
$config['STATS_DB_USER'] = 'access';          //replace access with the username for slave database
$config['STATS_DB_PASSWORD'] = 'my_password'; //replace my_password with the password for slave database
$config['STATS_DB_DB'] = 'db_name';           //replace db_name with the name of the slave database


THE FOLLOWING STEP ONLY APPLIES TO USERS OF NATS V4
THE FOLLOWING STEP IS OPTIONAL

If you have multiple slave databases replicating from your master NATS database, you can have NATS automatically choose one of your slave databases at random when a user hits a page/script that uses the slave database(s). You can add an array of slave databases to your includes/config.php file in the following manner:

$config['DB_REPORTING_SERVERS'] = Array(
	"0" => Array(
		'SERVER' => 'localhost',   //replace localhost with address of where first slave database lives
		'USER' => 'access1',       //replace access1 with the username for the first slave database
		'PASSWORD' => 'password1', //replace password1 with the password for first slave database
		'DB' => 'slave_name1'      //replace slave_name1 with the name of the first slave database
	),
	"1" => Array(
		'SERVER' => 'localhost',   //replace localhost with address of where second slave database lives
		'USER' => 'access2',       //replace access2 with the username for the second slave database
		'PASSWORD' => 'password2', //replace password2 with the password for second slave database
		'DB' => 'slave_name2'      //replace slave_name2 with the name of the second slave database
	)
	//continue in this manner for as many slave databases you wish to configure
);


Load Balancing Web Files

It is possible to run your NATS install across multiple servers. You will need to get in touch with us to provide an extra license for each additional server.
There are many possible ways to set this up, here is an example:

SERVER1 Main install of NATS. SERVER2 Replicated version of NATS.

  • The nats/templates_c and nats/logs directory should NOT be replicated from SERVER1 to SERVER2. Everything else in the nats/ directory should be.
  • If possible, have nats/logs on SERVER2 replicated to some location on SERVER1 (like nats/logs2). This makes it easier for us to debug any issues that may arise, without needing you to copy files for us every time. In this example 'logs2' would be another directory that shouldn't be replicated back over to SERVER2.
  • NATS has a feature called 'db_session' which can be enabled in the nats configuration admin which will have nats store session information in the database. This way we can identify the surfer even if they switch servers for some reason. It is also possible that your load balancing appliance manage session issues across servers.
  • In this setup, both installs of NATS are connecting to the same mysql db. The slave database(a replication of the master database) is used by NATS to handle some reporting and otherwise intensive lookups that may put some strain on the database, leaving the master free to handle inserts.
  • It is important that there is some way to force the main server, so the admins can always get the master ( and not the replicated server) to perform adminstrative functions. Usually a special domain is set aside for just admins.
  • It is important that the nats cron is set up on the master server, and only the master server.
  • When we are requesting access, we will need access to the master and not one of the replicated servers.


This method can be expanded by adding SERVER3, SERVER 4 etc, and setting them up just like SERVER2.