The distributed statistics feature allows OpenX to scale by moving some of the load from the central database to web servers. If you are using OpenX with one web server it has to deal with all tasks on one machine. Using many web servers allows you to split delivery and admin/maintenance. When using distributed statistics, the delivery web servers log raw data (impressions/clicks, etc.) into a local MySQL database and migrate it periodically into the central database. MySQL replication is used to replicate data from the central database into the delivery web servers.
It is relatively easy to set up replication using MySQL, but it is important that you read all of the replication documentation from the MySQL website before attempting configuration!
The following is a brief summary of how to enable replication using MySQL:
[mysqld] log-bin = mysql-bin server-id = 1
You might want to restrict the binary log to only your OpenX database; this can help reduce the amount of data in the binary log and prevent slaves from being dropped if non-OpenX databases fall out of sync:
binlog-do-db = your_openx_database_name |
mysql> GRANT REPLICATION SLAVE ON *.* TO 'replicant' identified by 'secret';
| Security tip For a production system you probably want to restrict the replication account to a particular host or subnet. |
mysql> FLUSH TABLES WITH READ LOCK;
mysql> SHOW MASTER STATUS\G
mysql> UNLOCK TABLES;
[mysqld] server-id=2
[mysqld] replicate-do-db = openx replicate-wild-ignore-table = openx.%data_% replicate-wild-ignore-table = openx.%tmp_% replicate-wild-ignore-table = openx.%lb_local% replicate-wild-ignore-table = mysql.%
mysql> CHANGE MASTER TO
-> MASTER_HOST='master_host_name',
-> MASTER_USER='replication_user_name',
-> MASTER_PASSWORD='replication_password',
-> MASTER_LOG_FILE='recorded_log_file_name',
-> MASTER_LOG_POS=recorded_log_position;
mysql> START SLAVE;
mysql> SHOW SLAVE STATUS;
The configuration file should match the admin one, but:
[database] type=mysql host=localhost port=3306 username=user password=secret name=openx
[lb] enabled=1 hasSuper=0 type=mysql host=10.0.0.10 port=3306 username=user password=password name=openx compactStats=1 compactStatsGrace=86400
| As of OpenX 2.6, if you set "hasSuper" to true then the code will execute the SQL "SET SQL_LOG_BIN = 0" before inserting the data into the central database server. This will reduce the replication load with MySQL. Of course, your username that inserts the data must have the SUPER privilege on the main database to be able to execute this command. |
# Run distributed maintenance every 5 minutes */5 * * * * /usr/local/php/bin/php -q /var/www/html/openx/scripts/maintenance/maintenance-distributed.php example.com
# Run maintenance every 5 minutes, but slightly after the 5 minute boundaries, to allow time for # the distributed maintenance scripts to complete the insertion of data into the central DB 4,9,14,19,24,29,34,39,44,49,54,59 * * * * /usr/local/php/bin/php -q /var/www/html/openx/scripts/maintenance/maintenance.php example.com
| Warning Please note that running maintenance more often than once per hour on the main box is only supported on OpenX 2.6 and higher. You will also need to ensure that your configuration settings for the Operation Interval are set appropriately. |