Install MySQL Replication and Cluster using Galera

INFO: Updated version of Galera cluster installation with high-availability MySQL setup can be refer here

What is Galera? Its generic synchronous multi-master replication plugin for transactional applications.

I will not telling you about this application cause you can read and understand by go to http://www.codership.com/content/using-galera-cluster or refer to the image for Galera overview. I just show you on how to install Galera/MySQL with 1 master and 1 slave (joined node) architecture.

Please find variables that I used as below:

OS: CentOS 5.6 64bit
Server1: 192.168.1.1 (master)
Server2: 192.168.1.2 (joined node)
MySQL root password: rootpass
SST MySQL user: sst
SST MySQL password: sstpass123

Configuration in both servers are quite similar. So I will show you on how to install Galera MySQL in Server1 and then same procedure in Server2 with some minor changes. Lets configure Server1 first:

1. Install gcc44 and gcc44-c++ packages and set CC and CXX variables accordingly:

[root@centos ~] yum install gcc44 gcc44-c++ -y
export CC=gcc44
export CXX=g++44

2. Lets check what kind of MySQL applications installed in the box:

[[email protected] ~] rpm -qa | grep mysql
mysql-5.0.77-4.el5_6.6
mod_auth_mysql-3.0.0-3.2.el5_3
mysql-bench-5.0.77-4.el5_6.6
mysql-connector-odbc-3.51.26r1127-1.el5
mysql-server-5.0.77-4.el5_6.6
mysql-test-5.0.77-4.el5_6.6
libdbi-dbd-mysql-0.8.1a-1.2.2
mysql-devel-5.0.77-4.el5_6.6
mysql-devel-5.0.77-4.el5_6.6
php53-mysql-5.3.3-1.el5_6.1
mysql-5.0.77-4.el5_6.6

3. Lets download all needed applications. Download following applications in respective site:

URL: https://launchpad.net/codership-mysql/+download
Download MySQL-server-wsrep-5.1.53-0.8.0b-x86_64.rpm = the MySQL server
URL: https://launchpad.net/galera/0.8/0.8.0
Download galera-0.8.0-x86_64.rpm = Galera library
URL: http://dev.mysql.com/downloads/mysql/5.1.html
Download the client-community and shared-community for 64bit

4. Following files should exist if you download the correct version:

[[email protected] galera] ls -1
galera-0.8.0-x86_64.rpm
MySQL-client-community-5.1.57-1.rhel5.x86_64.rpm
MySQL-server-wsrep-5.1.53-0.8.0b-x86_64.rpm
MySQL-shared-community-5.1.57-1.rhel5.x86_64.rpm

5. Lets remove currently installed mysql. Dont worry about this, because we are actually upgrading our MySQL to version 5.1:

[[email protected] galera] rpm -e --nodeps mysql.i386 mysql.x86_64 mysql-devel.i386 mysql-devel.x86_64 mysql-server mysql-bench

Continue reading “Install MySQL Replication and Cluster using Galera” »

The Best Way to Setup MySQL Replication

In this case, I have 2 servers installed with MySQL 5 and running in CentOS 5. Assuming Server1 is master server and currently host a database called db1 and Server2 is slave server and have nothing inside.

Variable used in this case:

Server1 IP=192.168.1.1
Server2 IP=192.168.1.2
Database name=db1
Replication user=replicator
Replication user password=slavepass

Now we configure Server1 first. Login to the server and do following:

1. Login to Server1 and open MySQL configuration file, /etc/my.cnf and add following lines under [mysqld] section:

[mysqld]
server-id=100
log-bin=master-bin
									

2. Restart MySQL:

service mysqld restart
									

3. Create a user account so slave can use to connect to this master server:

mysql> GRANT REPLICATION SLAVE on *.* to 'replicator'@'%' IDENTIFIED BY 'slavepass';
									

4. Dump the database so we can bring the database to the slave server:

mysqldump -u[root] -p[password] --master-data --single-transaction db1 > db1.sql
									

Continue reading “The Best Way to Setup MySQL Replication” »