Template:OXLoadBalancingClustering Database: Difference between revisions
No edit summary |
|||
Line 37: | Line 37: | ||
mysql> GRANT REPLICATION SLAVE ON *.* TO 'replication'@'9.9.9.9' IDENTIFIED BY 'secret'; | mysql> GRANT REPLICATION SLAVE ON *.* TO 'replication'@'9.9.9.9' IDENTIFIED BY 'secret'; | ||
Verify that the MySQL daemon writes a binary log and remember the log Position: | Verify that the MySQL daemon writes a binary log and remember the log Position and File name: | ||
mysql> SHOW MASTER STATUS; | mysql> SHOW MASTER STATUS; | ||
+------------------+----------+--------------+------------------+ | +------------------+----------+--------------+------------------+ | ||
Line 53: | Line 53: | ||
$ chown mysql:adm /var/log/mysql/* | $ chown mysql:adm /var/log/mysql/* | ||
Configure 1.1.1.1 as Master Server. Use the remembered log file position from 1.1.1.1. | Configure 1.1.1.1 as Master Server. Use the remembered log file and position from 1.1.1.1. | ||
mysql> CHANGE MASTER TO MASTER_HOST='1.1.1.1', MASTER_USER='replication', MASTER_PASSWORD='secret', MASTER_LOG_FILE='mysql-bin.000001', MASTER_LOG_POS=1111; | mysql> CHANGE MASTER TO MASTER_HOST='1.1.1.1', MASTER_USER='replication', MASTER_PASSWORD='secret', MASTER_LOG_FILE='mysql-bin.000001', MASTER_LOG_POS=1111; | ||
Line 75: | Line 75: | ||
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB | | | File | Position | Binlog_Do_DB | Binlog_Ignore_DB | | ||
+------------------+----------+--------------+------------------+ | +------------------+----------+--------------+------------------+ | ||
| mysql-bin. | | mysql-bin.000009 | 9999| | | | ||
+------------------+----------+--------------+------------------+ | +------------------+----------+--------------+------------------+ | ||
Line 82: | Line 82: | ||
1.1.1.1 is now the slave in this context and 9.9.9.9 one is the master. Log in to 1.1.1.1 | 1.1.1.1 is now the slave in this context and 9.9.9.9 one is the master. Log in to 1.1.1.1 | ||
Configure 9.9.9.9 as Master Server. Use the remembered log file position from | Configure 9.9.9.9 as Master Server. Use the remembered log and file position from 1.1.1.1. | ||
mysql> CHANGE MASTER TO MASTER_HOST='9.9.9.9', MASTER_USER='replication', MASTER_PASSWORD='secret', MASTER_LOG_FILE='mysql-bin. | mysql> CHANGE MASTER TO MASTER_HOST='9.9.9.9', MASTER_USER='replication', MASTER_PASSWORD='secret', MASTER_LOG_FILE='mysql-bin.000009', MASTER_LOG_POS=9999; | ||
start the MySQL slave replication | start the MySQL slave replication | ||
Line 95: | Line 95: | ||
Also check the syslog if the replication has been sucessfully started | Also check the syslog if the replication has been sucessfully started | ||
$ tail -fn20 /var/log/syslog | $ tail -fn20 /var/log/syslog | ||
Jul 26 19:03:45 dbslave mysqld[4718]: 090726 19:03:45 [Note] Slave I/O thread: connected to master 'replication@ | Jul 26 19:03:45 dbslave mysqld[4718]: 090726 19:03:45 [Note] Slave I/O thread: connected to master 'replication@1.1.1.17:3306', replication started in log 'mysql-bin.000001' at position 10000 | ||
=== Testing Master/Master === | === Testing Master/Master === | ||
On the first | On the first 1.1.1.1, create a new database in MySQL: | ||
mysql> CREATE DATABASE foo; | mysql> CREATE DATABASE foo; | ||
Check if this database is available on | Check if this database is available on 2.2.2.2: | ||
mysql> SHOW DATABASES; | mysql> SHOW DATABASES; | ||
+--------------------+ | +--------------------+ | ||
Line 112: | Line 112: | ||
+--------------------+ | +--------------------+ | ||
Delete the database on | Delete the database on 2.2.2.2: | ||
mysql> DROP DATABASE foo; | mysql> DROP DATABASE foo; | ||
Check if the database has been removed at | Check if the database has been removed at 1.1.1.1 | ||
mysql> SHOW DATABASES; | mysql> SHOW DATABASES; | ||
+--------------------+ | +--------------------+ |
Revision as of 06:54, 3 March 2011
Master/Master database setup
This article describes the setup process "Master/Master replication" for new Open-Xchange database cluster. During configuration and initialization, other database operations must be prohibited.
The Master/Master replication is a vice versa setup of Master/Slave configurations. This Means each server is afterwards the slave of the other.
Server IPs in the example are 1.1.1.1 and 9.9.9.9
Startup both database machines and install the mysql server packages
$ apt-get install mysql-server
During the installation, a dialog will show up to set a password for the MySQL 'root' user.
Open the MySQL configuration file on both servers:
$ vim /etc/mysql/my.cnf
Modify or enable the following configuration options in the mysqld-section, use 1 as ${unique Number} on the server 1.1.1.1 and 2 for 2.2.2.2:
bind-address = 0.0.0.0 server-id = ${unique Number} log-bin = /var/log/mysql/mysql-bin.log
- bindaddress specifies the network address where MySQL is listening for network connections. Since the MySQL slave and both Open-Xchange Servers are dedicated machines it is required to have the master accessible through the network.
- server-id is just a unique number within a environment with multiple MySQL servers. It needs to be unique for each server in a replication cluster.
- log-bin enables the MySQL binary log which is required for Master/Master replication. In general every statement triggered at the database is stored there to get distributed through the database cluster.
To apply the configuration changes, restart the MySQL servers.
$ /etc/init.d/mysql restart
Then login to MySQL with the credentials given at the MySQL installation process
$ mysql -u root -p Enter password:
First Master configuration
Choose one server to start with as the first Master (here we use 1.1.1.1).
Create a MySQL user with rights "REPLICATION". This account is used by the MySQL slave to fetch database updates. In this example, the username is "replication":
mysql> GRANT REPLICATION SLAVE ON *.* TO 'replication'@'9.9.9.9' IDENTIFIED BY 'secret';
Verify that the MySQL daemon writes a binary log and remember the log Position and File name:
mysql> SHOW MASTER STATUS; +------------------+----------+--------------+------------------+ | File | Position | Binlog_Do_DB | Binlog_Ignore_DB | +------------------+----------+--------------+------------------+ | mysql-bin.000001 | 1111 | | | +------------------+----------+--------------+------------------+
Copy the MySQL binary logs and the index file to the slave. This is required for the initial synchronization.
$ scp /var/log/mysql/mysql-bin.* root@9.9.9.9:/var/log/mysql
First Slave configuration
On 9.9.9.9, set the MySQL system user as owner of the binary log that has just been copied to the slave.
$ chown mysql:adm /var/log/mysql/*
Configure 1.1.1.1 as Master Server. Use the remembered log file and position from 1.1.1.1.
mysql> CHANGE MASTER TO MASTER_HOST='1.1.1.1', MASTER_USER='replication', MASTER_PASSWORD='secret', MASTER_LOG_FILE='mysql-bin.000001', MASTER_LOG_POS=1111;
Start the MySQL slave replication
mysql> START SLAVE;
An check the status
mysql> SHOW SLAVE STATUS;
"Slave_IO_Running" and "Slave_SQL_Running" should be set to "yes".
Second Master configuration
This means, the first Master/Slave Replication is working and the "reverse" replication needs to be prepared. Please now create the replication user on 9.9.9.9:
mysql> GRANT REPLICATION SLAVE ON *.* TO 'replication'@'1.1.1.1' IDENTIFIED BY 'secret';
Verify that the MySQL daemon writes a binary log and remember the log Position:
mysql> SHOW MASTER STATUS; +------------------+----------+--------------+------------------+ | File | Position | Binlog_Do_DB | Binlog_Ignore_DB | +------------------+----------+--------------+------------------+ | mysql-bin.000009 | 9999| | | +------------------+----------+--------------+------------------+
Second Slave configuration
1.1.1.1 is now the slave in this context and 9.9.9.9 one is the master. Log in to 1.1.1.1
Configure 9.9.9.9 as Master Server. Use the remembered log and file position from 1.1.1.1.
mysql> CHANGE MASTER TO MASTER_HOST='9.9.9.9', MASTER_USER='replication', MASTER_PASSWORD='secret', MASTER_LOG_FILE='mysql-bin.000009', MASTER_LOG_POS=9999;
start the MySQL slave replication
mysql> START SLAVE;
and check the status
mysql> SHOW SLAVE STATUS;
"Slave_IO_Running" and "Slave_SQL_Running" should be set to "yes".
Also check the syslog if the replication has been sucessfully started
$ tail -fn20 /var/log/syslog Jul 26 19:03:45 dbslave mysqld[4718]: 090726 19:03:45 [Note] Slave I/O thread: connected to master 'replication@1.1.1.17:3306', replication started in log 'mysql-bin.000001' at position 10000
Testing Master/Master
On the first 1.1.1.1, create a new database in MySQL:
mysql> CREATE DATABASE foo;
Check if this database is available on 2.2.2.2:
mysql> SHOW DATABASES; +--------------------+ | Database | +--------------------+ | information_schema | | foo | | mysql | +--------------------+
Delete the database on 2.2.2.2:
mysql> DROP DATABASE foo;
Check if the database has been removed at 1.1.1.1
mysql> SHOW DATABASES; +--------------------+ | Database | +--------------------+ | information_schema | | mysql | +--------------------+
Creating Open-Xchange user
Now setup access for the Open-Xchange Server database user 'openexchange' to configdb and the oxdb for both groupware server addresses. These databases do not exist yet, but will be created during the Open-Xchange Server installation.
mysql> GRANT ALL PRIVILEGES ON *.* TO 'openexchange'@'10.20.30.213' IDENTIFIED BY 'secret'; mysql> GRANT ALL PRIVILEGES ON *.* TO 'openexchange'@'10.20.30.215' IDENTIFIED BY 'secret';