Introduction I am going to talk about three servers, Server 1 192.168.0.1 Server 2 192.168.0.2 Server 3 192.168.0.3 Servers 1 and 2 will be the two that end up "clustered". Each of them will have mysql client and ndb installed on it. (ndb is the storage node). Server 3 will have the management node installed on it. Install MySQL on Server 1 and Server 2
groupadd mysql useradd -g mysql mysql cd /usr/local/ wget http://dev.mysql.com/get/Downloads/MySQL-5.0/mysql-max-5.0.15-linux-i686-glibc23.tar.gz /from/http://mirror.trouble-free.net/mysql_mirror/ tar -zxvf mysql-max-5.0.15-linux-i686-glibc23.tar.gz rm mysql-max-5.0.15-linux-i686-glibc23.tar.gz ln -s mysql-max-5.0.15-linux-i686-glibc23 mysql cd mysql scripts/mysql_install_db --user=mysql chown -R root . chown -R mysql data chgrp -R mysql . cp support-files/mysql.server /etc/rc.d/init.d/ chmod +x /etc/rc.d/init.d/mysql.server chkconfig --add mysql.server Install and configure the managment server
cd /tmp http://dev.mysql.com/get/Downloads/MySQL-4.1/mysql-max-5.0.15-pc-linux-gnu-i686.tar.gz/ from/http://www.signal42.com/mirrors/mysql/ tar -zxvf mysql-max-5.0.15-pc-linux-gnu-i686.tar.gz cd mysql-max-5.0.15-pc-linux-gnu-i686 mv bin/ndb_mgm . mv bin/ndb_mgmd . chmod +x ndb_mg* mv ndb_mg* /usr/bin/
mkdir /var/lib/mysql-cluster cd /var/lib/mysql-cluster vi config.ini
[NDBD DEFAULT] NoOfReplicas=2 [MYSQLD DEFAULT] [NDB_MGMD DEFAULT] [TCP DEFAULT] # Managment Server [NDB_MGMD] # the IP of THIS SERVER HostName=192.168.0.3 # Storage Engines [NDBD] # the IP of the FIRST SERVER (STORAGE NODE) HostName=192.168.0.1 DataDir= /var/lib/mysql-cluster [NDBD] # the IP of the SECOND SERVER (STORAGE NODE) HostName=192.168.0.2 DataDir=/var/lib/mysql-cluster # 2 MySQL Clients # I personally leave this blank to allow rapid changes of the mysql clients; # you can enter the hostnames of the above two servers here. I suggest you dont. [MYSQLD] [MYSQLD]
Configure the storage/SQL servers and start MySQL
vi /etc/my.cnf
[mysqld] ndbcluster # the IP of the MANAGMENT (THIRD) SERVER ndb-connectstring=192.168.0.3 [mysql_cluster] # the IP of the MANAGMENT (THIRD) SERVER ndb-connectstring=192.168.0.3
mkdir /var/lib/mysql-cluster cd /var/lib/mysql-cluster /usr/local/mysql/bin/ndbd --initial /etc/rc.d/init.d/mysql.server start If you have done one server now go back to the start of stage 3 and repeat exactly the same procedure on the second server. NOTE that you should ONLY use --initial if you are either starting from scratch or have changed the config.ini file on the managment. Check if its working You can now return to the managment server (Server 3) and enter the managment console: /usr/local/mysql/bin/ndb_mgm Enter the command SHOW to see what is going on. A sample output looks like this: [root@mysql3 mysql-cluster]# /usr/local/mysql/bin/ndb_mgm -- NDB Cluster -- Management Client -- ndb_mgm> show Connected to Management Server at: localhost:1186 Cluster Configuration --------------------- [ndbd(NDB)] 2 node(s) id=2 @192.168.0.1 (Version: 5.0.15, Nodegroup: 0, Master) id=3 @192.168.0.2 (Version: 5.0.15, Nodegroup: 0) [ndb_mgmd(MGM)] 1 node(s) id=1 @192.168.0.3 (Version: 5.0.15) [mysqld(API)] 2 node(s) id=4 (Version: 5.0.15) id=5 (Version: 5.0.15) ndb_mgm> If you see not connected, accepting connect from 192.168.0.[1/2/3] In the first or last two lines they you have a problem. If you are OK to here it is time to test mysql. On either server Server 1 or Server 2 enter the following commands: Note that we have no root password yet. mysql use test; CREATE TABLE ctest (i INT) ENGINE=NDBCLUSTER; INSERT INTO ctest () VALUES (1); SELECT * FROM ctest; You should see 1 row returned (with the value 1). If this works, now go to the other server and run the same SELECT and see what you get. Insert from that host and go back to host 1 and see if it works. If it works then congratulations. The final test is to kill one server to see what happens. If you have physical access to the machine simply unplug its network cable and see if the other server keeps on going fine (try the SELECT query). If you dont have physical access do the following: ps aux | grep ndbd You get an output like this: root 5578 0.0 0.3 6220 1964 ? S 03:14 0:00 ndbd root 5579 0.0 20.4 492072 102828 ? R 03:14 0:04 ndbd root 23532 0.0 0.1 3680 684 pts/1 S 07:59 0:00 grep ndbd In this case ignore the command "grep ndbd" (the last line) but kill the first two processes by issuing the command kill -9 pid pid: kill -9 5578 5579 Then try the select on the other server. While you are at it run a SHOW command on the managment node to see that the server has died. To restart it, just issue ndbd NOTE no --inital! Putting initial will clear the database Issues If a node goes down. Restart that node from the server the node resides in. Steps given below. (http://bugs.mysql.com/bug.php?id=23121)
If any issues arise try killing all the processes used for clustering. That is ndbd, ndb_mgmd, ndb_mdm and mysql.server. Bring the processes of Server 1, Server 2 and Server 3 down. Then start them back up. To locate processes use ps aux | grep ndb Processes ndbd is for the storage node mysql.server is for the mysql server ndb_mgmd is for the management node Sources http://www.davz.net/static/howto/mysqlcluster |
Thursday, April 22, 2010
MySQL Clustering on CentOS 5.2
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment