How To Set Up A Load-Balanced MySQL Cluster With MySQL 5.1 - Page 3
5 How To Restart The ClusterNow let's asume you want to restart the MySQL cluster, for example because you have changed /usr/local/mysql/var/mysql-cluster/config.ini on mysql-mngt.example.com or for some other reason. To do this, you use the ndb_mgm cluster management client on mysql-mngt.example.com: mysql-mngt.example.com: ndb_mgm On the ndb_mgm console, you type shutdown; You will then see something like this:
This means that the cluster data nodes mysql-data1.example.com and mysql-data2.example.com and also the cluster management server have shut down. Run quit; to leave the ndb_mgm console. To start the cluster management server, do this on mysql-mngt.example.com: mysql-mngt.example.com: ndb_mgmd -f /usr/local/mysql/mysql-cluster/config.ini and on mysql-data1.example.com and mysql-data2.example.com you can run mysql-data1.example.com / mysql-data2.example.com: ndbd or, if you have changed /usr/local/mysql/var/mysql-cluster/config.ini on mysql-mngt.example.com: ndbd --initial Afterwards, you can check on mysql-mngt.example.com if the cluster has restarted: mysql-mngt.example.com: ndb_mgm On the ndb_mgm console, type show; to see the current status of the cluster. It might take a few seconds after a restart until all nodes are reported as connected. Type quit; to leave the ndb_mgm console.
6 Configure The Load BalancersOur MySQL cluster is finished now, and you could start using it now. However, we don't have a single IP address that we can use to access the cluster, which means you must configure your applications in a way that a part of it uses the MySQL cluster node 1 (mysql-data1.example.com), and the rest uses the other node (mysql-data2.example.com). Of course, all your applications could just use one node, but what's the point then in having a cluster if you do not split up the load between the cluster nodes? Another problem is, what happens if one of the cluster nodes fails? Then the applications that use this cluster node cannot work anymore. The solution is to have a load balancer in front of the MySQL cluster which (as its name suggests) balances the load between the MySQL cluster nodes. The load blanacer configures a virtual IP address that is shared between the cluster nodes, and all your applications use this virtual IP address to access the cluster. If one of the nodes fails, then your applications will still work, because the load balancer redirects the requests to the working node. Now in this scenario the load balancer becomes the bottleneck. What happens if the load balancer fails? Therefore we will configure two load balancers (mysql-lb1.example.com and mysql-b2.example.com) in an active/passive setup, which means we have one active load balancer, and the other one is a hot-standby and becomes active if the active one fails. Both load balancers use heartbeat to check if the other load balancer is still alive, and both load balancers also use ldirectord, the actual load balancer the splits up the load onto the cluster nodes. heartbeat and ldirectord are provided by the Ultra Monkey package that we will install. It is important that mysql-lb1.example.com and mysql-lb2.example.com have support for IPVS (IP Virtual Server) in their kernels. IPVS implements transport-layer load balancing inside the Linux kernel.
6.1 Install Ultra MonkeyOk, let's start: first we enable IPVS on mysql-lb1.example.com and mysql-lb2.example.com: mysql-lb1.example.com / mysql-lb2.example.com: modprobe ip_vs_dh In order to load the IPVS kernel modules at boot time, we list the modules in /etc/modules: mysql-lb1.example.com / mysql-lb2.example.com: vi /etc/modules
Now we edit /etc/apt/sources.list and add the Ultra Monkey repositories (don't remove the other repositories), and then we install Ultra Monkey: mysql-lb1.example.com / mysql-lb2.example.com: vi /etc/apt/sources.list
apt-get update Now Ultra Monkey is being installed. If you see this warning:
you can ignore it. Answer the following questions: Do you want to automatically load IPVS rules on boot? Select a daemon method. The libdbd-mysql-perl package we've just installed does not work with MySQL 5 (we use MySQL 5 on our MySQL cluster...), so we install the newest DBD::mysql Perl package: mysql-lb1.example.com / mysql-lb2.example.com: cd /tmp We must enable packet forwarding: mysql-lb1.example.com / mysql-lb2.example.com: vi /etc/sysctl.conf
sysctl -p
6.2 Configure heartbeatNext we configure heartbeat by creating three files (all three files must be identical on mysql-lb1.example.com and mysql-lb2.example.com): mysql-lb1.example.com / mysql-lb2.example.com: vi /etc/ha.d/ha.cf
Please note: you must list the node names (in this case mysql-lb1 and lmysql-lb2) as shown by uname -n IP addresses does not work here, it is also good idea to add proper entries on both load balancers(mysql-lb1 and lmysql-lb2) in vi /etc/hosts
Now let's change here your Virtual MySQL IP: vi /etc/ha.d/haresources
You must list one of the load balancer node names (here: mysql-lb1) and list the virtual IP address (10.0.1.10) together with the correct netmask (24) and broadcast address (10.0.1.255). If you are unsure about the correct settings, http://www.subnetmask.info/ might help you. vi /etc/ha.d/authkeys
somerandomstring is a password which the two heartbeat daemons on loadb1 and loadb2 use to authenticate against each other. Use your own string here. You have the choice between three authentication mechanisms. I use md5 as it is the most secure one. /etc/ha.d/authkeys should be readable by root only, therefore we do this: mysql-lb1.example.com / mysql-lb2.example.com: chmod 600 /etc/ha.d/authkeys
6.3 Configure ldirectordNow we create the configuration file for ldirectord, the load balancer: mysql-lb1.example.com / mysql-lb2.example.com: vi /etc/ha.d/ldirectord.cf
Please fill in the correct virtual IP address (10.0.1.10) and the correct IP addresses of your MySQL cluster nodes (10.0.1.33 and 10.0.1.34). 3306 is the port that MySQL runs on by default. We also specify a MySQL user (ldirector) and password (ldirectorpassword), a database (ldirectordb) and an SQL query. ldirectord uses this information to make test requests to the MySQL cluster nodes to check if they are still available. We are going to create the ldirector database with the ldirector user in the next step. Now we create the necessary system startup links for heartbeat and remove those of ldirectord (bacause ldirectord will be started by heartbeat): mysql-lb1.example.com / mysql-lb2.example.com: update-rc.d -f heartbeat remove
6.4 Create A Database Called ldirectorNext we create the ldirector database on our MySQL cluster nodes mysql-data1.example.com and mysql-data2.example.com. This database will be used by our load balancers to check the availability of the MySQL cluster nodes. mysql-data1.example.com: mysql -u root -p mysql-data2.example.com: mysql -u root -p
6.5 Prepare The MySQL Cluster Nodes For Load BalancingFinally we must configure our MySQL cluster nodes mysql-data1.example.com and mysql-data2.example.com to accept requests on the virtual IP address 192.168.0.105. mysql-data1.example.com / mysql-data2.example.com: apt-get install iproute Add the following to /etc/sysctl.conf: mysql-data1.example.com / mysql-data2.example.com: vi /etc/sysctl.conf
sysctl -p Add this section for the virtual IP address to /etc/network/interfaces: mysql-data1.example.com / mysql-data2.example.com: vi /etc/network/interfaces
ifup lo:0
|




print: 
Recent comments
9 hours 38 min ago
9 hours 49 min ago
10 hours 32 min ago
11 hours 36 min ago
15 hours 40 min ago
17 hours 57 min ago
19 hours 13 min ago
19 hours 13 min ago
19 hours 28 min ago
1 day 1 hour ago