I'm using CentOS 5 distribution on both machines, MySQL 5.1 and a mounted directory on both servers to /var/lib/mysql
Pre-Configuration
You need to install MySQL on both machines.
Assign hostname dbserver01, dbserver02.
dbserver01 is the primary node with IP address 192.168.1.101 to eth0.
and dbserver02 is the slave one with ip address 192.168.1.102.
192.168.1.103 is the virtual IP that will be used for MySQL.
Configuration (do those steps on both servers)
install the Heartbeat package:
# yum install heartbeat
copy the next configuration files to the /etc/ha.d directory:
# cp /usr/share/doc/heartbeat-version/authkeys /etc/ha.d
# cp /usr/share/doc/heartbeat-version/ha.cf /etc/ha.d
# cp /usr/share/doc/heartbeat-version/haresources /etc/ha.d
First we will edit the authkeys file,
# vi /etc/ha.d/authkeys
copy from here:
auth 2 2 sha1 test-HAchange the permission of the authkeys file:
# chmod 600 /etc/ha.d/authkeys
Now let's edit the most important file (ha.cf)
# vi /etc/ha.d/ha/cf
add the following lines into the file:
logfile /var/log/ha-log logfacility local0 keepalive 2 deadtime 30 initdead 120 bcast eth0 udpport 694 auto_failback on node dbserver01 node dbserver02
The last file we need to edit is haresources:
# vi /etc/ha.d/haresources
add the following line:
dbserver01 192.168.1.103 netfs mysqld
Now all we need to do is to start the hearbeat service on both machines:
# /etc/init.d/heartbeat start
the virtual IP address 192.168.1.103 is now on dbserver01 and MySQL is up and running.
if dbserver01 will crashed from any reason the IP address will jump to dbserver02 the the MySQL service will start automatic.
Enjoy.
And please comment (-;
works perfectly.
ReplyDeleteI wonder if you know how to setup a load balance between the servers on the cluster. This setup has the dataserver2 as slave waiting for server1 to fail. A good idea will be to loadbalance with the virtual ip, however I can't find any specific to mysql.