Title: MySQL-4.1.7 NDB Cluster How-To Subject: Configure MySQL Cluster with 2 servers with multi-master, load-balanced, high-availability. By: John Streeton Stile Date: Mon Oct 26 15:24:02 PDT 2004 Note: Thank you Joseph E. Sacco, Ph.D. for all your help and advice. Joseph helped me debug and load several of my mysql issues. Note: The real question is "load balancing" vs. "high availability" -------------- ------------------ Note: $6000 for Emic Application Cluster 2.0 for MySQL: High Availability Cluster . Note: $400/cpu for MySQL Cluster from MySQL.com Note: Also see: http://dev.mysql.com/doc/mysql/en/MySQL_Cluster_quick.html http://dev.mysql.com/doc/mysql/en/MySQL_Cluster_Limitations_in_4.1.html Note: Quick Backup: time mysqldump -uroot -p --all-databases --opt > /var/tmp/mysql-`date +%Y%M%d`.sql --------------------------------------------------------- Table of contents: 1. Topology 2. File structure 3. Startup sequence (see end for a script) 4. Shutdown sequence 5. Install: 6. Upgrade notes 7. If shutdown dirty 8. Config Files 9. Manage cluster commands and logs 10. Configuring database to use cluser (ENGINE=NDBCLUSTER) 11. References Under construction: 12. Use Heart Beat to keep ndb_mgmd availabile. --------------------------------------------------------- 1. Topology: ------ ------ | |---10.0.0.1....heartbeat...10.0.0.2-------| | |Postal| |Postal| | 1 |---192.168.0.40------------192.168.0.41---| 2 | ------ mgm port 2200 ------ mysql port 3306 Always start in this order: First: start management node. (ndb_mgmd) Second: start ndb database nodes. (ndbd) Third: start mysql database. (mysqld_safe) Fourth: verify everyting is running. (ndb_mgm -> SHOW) --------------------------------------------------------- 2. File structure: Postal1: /etc/my.cnf /usr/local/mysql/ data/ Ndb.cfg ndb/ mgmt/ config.ini Ndb.cfg ndb1/ Ndb.cfg Postal2: /etc/my.cnf /usr/local/mysql/ data/ Ndb.cfg ndb/ ndb1/ Ndb.cfg --------------------------------------------------------- 3. Startup sequence: *NOTE: See my startup script at boottom of document On server running MGM,DNB,API: cd /usr/local/mysql\ export MYSQL_HOME=/usr/local/mysql\ export NDB_HOME=$MYSQL_HOME/ndb \ export PATH="$MYSQL_HOME/bin:$PATH" \ export LD_LIBRARY_PATH=$MYSQL_HOME/lib \ export MANPATH=$MANPATH:$MYSQL_HOME/man \ pushd /usr/local/mysql/ndb/mgmt/ && ndb_mgmd -c config.ini -l Ndb.cfg && popd \ pushd /usr/local/mysql/ndb/ndb1/ && ndbd --initial && popd \ mysqld_safe & On server running DNB,API: cd /usr/local/mysql\ export MYSQL_HOME=/usr/local/mysql\ export NDB_HOME=$MYSQL_HOME/ndb \ export PATH="$MYSQL_HOME/bin:$PATH" \ export LD_LIBRARY_PATH=$MYSQL_HOME/lib \ export MANPATH=$MANPATH:$MYSQL_HOME/man \ pushd /usr/local/mysql/ndb/ndb1/ && ndbd --initial && popd \ mysqld_safe & --------------------------------------------------------- 4. Shutdown sequence: On server running DNB,API: cd /usr/local/mysql \ export MYSQL_HOME=/usr/local/mysql \ export NDB_HOME=$MYSQL_HOME/ndb \ export PATH="$MYSQL_HOME/bin:$PATH" \ export LD_LIBRARY_PATH=$MYSQL_HOME/lib \ export MANPATH=$MANPATH:$MYSQL_HOME/man \ mysqladmin -u root -p shutdown On server running MGM,DNB,API: cd /usr/local/mysql \ export MYSQL_HOME=/usr/local/mysql \ export NDB_HOME=$MYSQL_HOME/ndb \ export PATH="$MYSQL_HOME/bin:$PATH" \ export LD_LIBRARY_PATH=$MYSQL_HOME/lib \ export MANPATH=$MANPATH:$MYSQL_HOME/man \ mysqladmin -u root -p shutdown echo "shutdown" | ndb_mgm --------------------------------------------------------- 5. Install: Download latest binary mysql release or gama-release from mysql.org: At this time it is: mysql-4.1.17-max Add user, unpack, and set base config groupadd mysql useradd -g mysql mysql cd /usr/local tar -zxvpf mysql-max-4.1.7-pc-linux-i686.tar.gz ln -s mysql-max-4.1.7-pc-linux-i686 mysql mkdir -p /usr/local/mysql/ndb/{mgmt,ndb1} mkdir -p /var/run/mysqld chown -R mysql.mysql /usr/local/mysql /var/run/mysqld Add the config files listed below --------------------------------------------------------- 6. Upgrade notes: cd /usr/local/ tar -zxvpf mysql-max-4.1.7-pc-linux-i686.tar.gz mv mysql-max-4.1.7-pc-linux-i686/data mysql-max-4.1.7-pc-linux-i686/data.orig cp -Rfp /usr/local/mysql/{data,ndb} mysql-max-4.1.7-pc-linux-i686/ rm -rf /usr/local/mysql ln -s mysql-max-4.1.7-pc-linux-i686 mysql chown -R mysql.mysql mysql cd mysql --------------------------------------------------------- 7. If shutdown dirty During my testing phayse, I had to clear out the system to get it to restart. cd /usr/local/mysql/ rm -rf data/ib* data/postal1.err ndb/ndb_* ndb/mgmt/ndb_* --------------------------------------------------------- 8. Config Files: ######################################### # On host Postal1 (which runs MGM,DNB,API) ######################################### cat /usr/local/mysql/data/Ndb.cfg nodeid=20;host=postal1:2200 ----------------------------------------- cat /usr/local/mysql/ndb/ndb1/Ndb.cfg nodeid=1;host=postal1:2200 ------------------------------------------ cat /usr/local/mysql/ndb/mgmt/Ndb.cfg nodeid=63;host=postal1:2200 ------------------------------------------ cat /usr/local/mysql/ndb/mgmt/config.ini # /usr/local/mysql/ndb/mgmt/config.ini # # First Machine: # /usr/local/mysql/data/Ndb.cfg # /usr/local/mysql/ndb/mgmt/config.ini # /usr/local/mysql/ndb/mgmt/Ndb.cfg # /usr/local/mysql/ndb/ndb1/Ndb.cfg # Second Machine: # /usr/local/mysql/data/Ndb.cfg # /usr/local/mysql/ndb/ndb1/Ndb.cfg [DB DEFAULT] NoOfReplicas: 2 DataMemory: 80M IndexMemory: 24M HeartbeatIntervalDbDb: 3000 TimeBetweenWatchDogCheck: 30000 TransactionDeadlockDetectionTimeout: 30000 MaxNoOfOrderedIndexes: 720 MaxNoOfUniqueHashIndexes: 720 MaxNoOfConcurrentOperations: 40000 #LockPagesInMainMemory: N #StopOnError: Y #[TCP DEFAULT] #PortNumber: 28002 # postal1 [COMPUTER] Id: 1 HostName: postal1 # postal2 [COMPUTER] Id: 2 HostName: postal2 # ndb_mgmd on postal1 [MGM] Id: 63 ExecuteOnComputer: 1 PortNumber: 2200 LogDestination: SYSLOG:facility=local0,;FILE:filename=/usr/local/mysql/ndb/mgmt/mgmd.log # ndbd on postal1 [DB] Id: 1 ExecuteOnComputer: 1 FileSystemPath: /usr/local/mysql/ndb/mgmt/ # ndbd on postal2 [DB] Id: 2 ExecuteOnComputer: 2 FileSystemPath: /usr/local/mysql/ndb/ndb1/ # mysqld on postal1 [API] Id: 20 ExecuteOnComputer: 1 # mysqld on postal2 [API] Id: 21 ExecuteOnComputer: 2 #For the ndb_show_tables command [API] Id: 22 ExecuteOnComputer: 1 ------------------------------------------ cat /etc/my.cnf [client] #password = port = 3306 socket = /var/run/mysqld/mysqld.sock [mysqld] port = 3306 socket = /var/run/mysqld/mysqld.sock skip-locking key_buffer = 32M max_allowed_packet = 2M table_cache = 64 sort_buffer_size = 1M net_buffer_length = 16K read_buffer_size = 512K read_rnd_buffer_size = 1024K myisam_sort_buffer_size = 16M datadir=/usr/local/mysql/data ndbcluster log-bin server-id = 1 [mysqldump] quick max_allowed_packet = 16M [mysql] no-auto-rehash # Remove the next comment character if you are not familiar with SQL #safe-updates [isamchk] key_buffer = 35M sort_buffer_size = 25M read_buffer = 2M write_buffer = 2M [myisamchk] key_buffer = 35M sort_buffer_size = 25M read_buffer = 2M write_buffer = 2M [mysqlhotcopy] interactive-timeout ######################################### # On host Postal2 (which runs DNB,API) ######################################### cat /usr/local/mysql/data/Ndb.cfg nodeid=21;host=postal1:2200 --------------------------------- cat /usr/local/mysql/ndb/ndb1/Ndb.cfg nodeid=2;postal1:2200 --------------------------------- cat /etc/my.cnf [client] #password = port = 3306 socket = /var/run/mysqld/mysqld.sock [mysqld] port = 3306 socket = /var/run/mysqld/mysqld.sock skip-locking key_buffer = 32M max_allowed_packet = 2M table_cache = 64 sort_buffer_size = 1M net_buffer_length = 16K read_buffer_size = 512K read_rnd_buffer_size = 1M myisam_sort_buffer_size = 16M datadir=/usr/local/mysql/data ndbcluster log-bin server-id = 2 [mysqldump] quick max_allowed_packet = 16M [mysql] no-auto-rehash [isamchk] key_buffer = 35M sort_buffer_size = 25M read_buffer = 2M write_buffer = 2M [myisamchk] key_buffer = 35M sort_buffer_size = 25M read_buffer = 2M write_buffer = 2M [mysqlhotcopy] interactive-timeout --------------------------------------------------------- 9. Manage cluster commands, tools, and logs - Your first tool is ps. Look for ndb_mgm, ndbd, and mysql ps -elf |egrep 'ndbd_mgm|ndbd|mysql' - Your second tool is ndb_mgm: NDB> show Cluster Configuration --------------------- [ndbd(NDB)] 2 node(s) id=1 @192.168.0.40 (Version: 3.5.2, Nodegroup: 0, Master) id=2 @192.168.0.41 (Version: 3.5.2, Nodegroup: 0) [ndb_mgmd(MGM)] 1 node(s) id=63 @192.168.0.40 (Version: 3.5.2) [mysqld(API)] 2 node(s) id=20 @192.168.0.40 (Version: 3.5.2) id=21 @192.168.0.41 (Version: 3.5.2) NDB> shutdown 2 NDB Cluster storage node(s) have shutdown. NDB Cluster management server shutdown. - Your third tool is 'ndb_show_tables' ndb_show_tables -u --connect-string=postal1:2200 - Your fouth tool is 'ndb_show_tables' mysql_convert_table_format --user=root --password= --type=NDB - Your fifth tool is perror. If you see an error use this tool to see what it means. perror - Your sixth tool is 'ndb_desc' Read the documentation on the [DB] parameters in config.ini Do the capacity planning exercise to determine 'DataMemory' and 'IndexMemory'. - Logs: /usr/local/mysql/ndb/mgmt/mgmd.log /usr/local/mysql/ndb/*.log /usr/local/mysql/data/*.err --------------------------------------------------------- 10. Configuring database to use cluser (ENGINE=NDBCLUSTER) This is where I am still learning so these are more raw notes. It is still a mystery to me how to calculate proper values for all the variables, *) To use the cluster, one must convert the table TYPE (now called ENGINE) to NDBCLUSTER (or NDB). One could use the 'ALTER TABLE' mysql command to convert on a table by table conversion. i.e. mysql> alter table . type=ndbcluster; Alternatively there is a cool perl script called "mysql_convert_table_format" i.e. mysql_convert_table_format --user=root --password= --type=NDB **) You will see several errors if /usr/local/mysql/ndb/mgmt/config.ini if config.ini is missing either of these variables: MaxNoOfOrderedIndexes: 2400 MaxNoOfUniqueHashIndexes: 2400 Remember to restart after config file changes, in this order: MySQLD API down -> NDBD down -> MGM down -> MGM up -> NDBD up ->MySQLD API up ***) Use the script 'ndb_show_tables' and count Start with the default values, feed in your schema definition file (replacing MyISAM with NDB). When the table creation dies, check what NDB thinks it made using ndb_show_table. Then kick up the [DB DEFAULT] parameters by a "reasonable amount" and try again. ****) Count arguments in each CREATE statements: * UserTables * OrderIndexes * UniqueHashIndexes * IndexTriggers * HashIndexTriggers *****) To use ndb_show_tables, config.ini needs an additional API Id. [API] Id: 22 ExecuteOnComputer: 1 Example: ndb_show_tables -u --connect-string=postal1:2200 Example Output: id type state logging database schema name 0 SystemTable Online Yes sys def SYSTAB_0 2 SystemTable Online Yes sys def NDB$EVENTS_0 My Test Tables: create table t1 (a int, b longblob, PRIMARY KEY (`a`)) engine=ndb; create table t2 (a int, b longblob, PRIMARY KEY (`a`), UNIQUE KEY `PRI` (`a`)) engine=ndb; create table t3 (a int, b longblob, PRIMARY KEY (`a`), UNIQUE KEY `PRI` (`a`)) engine=ndb; create table t4 (a char, b longblob, PRIMARY KEY (`a`), UNIQUE KEY `PRI` (`a`)) engine=ndb; create table t5 (a varchar(255), PRIMARY KEY (`a`), UNIQUE KEY `PRI` (`a`)) engine=ndb; create table t6 (a char, b longblob, PRIMARY KEY (`a`), UNIQUE KEY `PRI` (`a`)) engine=ndb; create table t7 (a varchar(255),b MEDIUMBLOB,PRIMARY KEY (`a`), UNIQUE KEY `PRI` (`a`)) engine=ndb; # This one alywas crashes for some unknown reason: create table t8 (a varchar(255),b LONGBLOB, PRIMARY KEY (`a`), UNIQUE KEY `PRI` (`a`)) engine=ndb; # This one alywas crashes for some unknown reason: create table t9 (a varchar(255),b LONGBLOB, PRIMARY KEY (`a`)) engine=ndb; - Got an answer from the list 'cluster@lists.mysql.com' This is bug in blob code which does not adjust for long primary key. If you replace "longblob" by "mediumblob", it will work. Output from my perl one liner: Output: UserTable: 16 OrderedIndex: 6 UniqueHashIndex: 3 UniqueHashIndex: 3 IndexTrigger: 15 HashIndexTrigger: 9 perl -e '$Mgm_server=postal1;$Port=2200;$UserTable=$OrderIndexes=$UniqueHashIndexes=$IndexTriggers=$HashIndexTriggers=0; open ( SHOW, "ndb_show_tables -u --connect-string=$Mgm_server:$Port |" ) || die; while (){ chomp($_); if ($_ =~ m/UserTable/g){$UserTable++;}; if ($_ =~ m/OrderedIndex/ ){$OrderedIndex++;}; if ($_ =~ m/UniqueHashIndex/){$UniqueHashIndex++;}; if ($_ =~ m/IndexTrigger/){$IndexTrigger++;} if ($_ =~ m/HashIndexTrigger/){$HashIndexTrigger++;}} print "UserTable:$UserTable\n OrderedIndex:$OrderedIndex\n UniqueHashIndex:$UniqueHashIndex\n UniqueHashIndex:$UniqueHashIndex\n IndexTrigger:$IndexTrigger\n HashIndexTrigger:$HashIndexTrigger \n";' Processes ----------------------------------------------------------- postal1:/usr/local/mysql# ps aux |egrep 'mysqld|ndb|MEM'| grep -v grep USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND root 18800 0.0 0.4 13500 9008 ? Ss 11:47 0:00 ndb_mgmd -c config.ini -l Ndb.cfg root 18812 0.0 0.1 6192 2768 ? Ss 11:47 0:00 ndbd --initial root 18813 4.0 59.3 2907056 1228644 ? S 11:47 0:03 ndbd --initial root 18846 0.0 0.0 2580 1068 pts/4 S+ 11:47 0:00 ndb_mgm root 18862 0.0 0.0 2344 1100 pts/3 S+ 11:48 0:00 /bin/sh /usr/local/mysql/bin/mysqld_safe mysql 18885 0.2 0.9 131300 18892 pts/3 S+ 11:48 0:00 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --user=mysql --pid-file=/usr/local/mysql/data/postal1.passionparties.com.pid --skip-locking --port=3306 --socket=/var/run/mysqld/mysqld.sock postal2://usr/local/mysql# ps aux |egrep 'mysqld|ndb|MEM' | grep -v grep USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND root 2076 0.0 0.1 3716 2332 pts/6 S+ 10:48 0:00 vi yourpassionstructure.ndb2.sql root 2822 0.0 0.1 6188 2764 ? Ss 11:47 0:00 ndbd --initial root 2823 2.8 59.3 2907052 1228572 ? S 11:47 0:03 ndbd --initial root 2855 0.0 0.0 2344 1100 pts/3 S+ 11:48 0:00 /bin/sh /usr/local/mysql/bin/mysqld_safe mysql 2878 0.0 0.9 132332 18892 pts/3 S+ 11:48 0:00 /usr/local/mysql/bin/mysqld --defaults-extra-file=/usr/local/mysql/data/my.cnf --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --user=mysql --pid-file=/usr/local/mysql/data/postal2.passionparties.com.pid --skip-locking --port=3306 --socket=/var/run/mysqld/mysqld.sock Ports ----------------------------------------------------------- postal1:/usr/local/mysql# lsof -n -i tcp |egrep -n 'ndb|mysql|COMMAND' COMMAND PID USER FD TYPE DEVICE SIZE NODE NAME ndb_mgmd 14055 root 3u IPv4 6129830 TCP *:2200 (LISTEN) ndb_mgmd 14055 root 8u IPv4 6130691 TCP 192.168.0.40:41367->192.168.0.40:2202 (ESTABLISHED) ndb_mgmd 14055 root 9u IPv4 6130606 TCP 192.168.0.40:2200->192.168.0.40:41362 (ESTABLISHED) ndb_mgmd 14055 root 10u IPv4 6131289 TCP 192.168.0.40:2200->192.168.0.41:37217 (ESTABLISHED) ndb_mgmd 14055 root 11u IPv4 6131300 TCP 192.168.0.40:41513->192.168.0.41:2202 (ESTABLISHED) ndb_mgmd 14055 root 12u IPv4 6136141 TCP 192.168.0.40:2200->192.168.0.40:41616 (ESTABLISHED) ndb_mgmd 14055 root 13u IPv4 6140791 TCP 127.0.0.1:2200->127.0.0.1:41638 (ESTABLISHED) ndb_mgmd 14055 root 14u IPv4 6132547 TCP 192.168.0.40:2200->192.168.0.41:37224 (ESTABLISHED) ndbd 14067 root 3u IPv4 6130605 TCP 192.168.0.40:41362->192.168.0.40:2200 (ESTABLISHED) ndbd 14068 root 3u IPv4 6130605 TCP 192.168.0.40:41362->192.168.0.40:2200 (ESTABLISHED) ndbd 14068 root 5u IPv4 6130687 TCP 192.168.0.40:2202 (LISTEN) ndbd 14068 root 6u IPv4 6130692 TCP 192.168.0.40:2202->192.168.0.40:41367 (ESTABLISHED) ndbd 14068 root 7u IPv4 6131301 TCP 192.168.0.40:2202->192.168.0.41:37219 (ESTABLISHED) ndbd 14068 root 18u IPv4 6136177 TCP 192.168.0.40:2202->192.168.0.40:41618 (ESTABLISHED) ndbd 14068 root 19u IPv4 6132551 TCP 192.168.0.40:2202->192.168.0.41:37226 (ESTABLISHED) mysqld 18885 mysql 3u IPv4 6182980 TCP *:mysql (LISTEN) mysqld 18885 mysql 12u IPv4 6182991 TCP 192.168.0.40:42374->192.168.0.40:2200 (ESTABLISHED) mysqld 18885 mysql 14u IPv4 6183027 TCP 192.168.0.40:42376->192.168.0.40:2202 (ESTABLISHED) mysqld 18885 mysql 15u IPv4 6183032 TCP 192.168.0.40:42377->192.168.0.41:2202 (ESTABLISHED) postal2:/usr/local/mysql# lsof -n -i tcp |egrep -n 'ndb|mysql|COMMAND' COMMAND PID USER FD TYPE DEVICE SIZE NODE NAME ndbd 31183 root 3u IPv4 5276222 TCP 192.168.0.41:37217->192.168.0.40:2200 (ESTABLISHED) ndbd 31184 root 3u IPv4 5276222 TCP 192.168.0.41:37217->192.168.0.40:2200 (ESTABLISHED) ndbd 31184 root 5u IPv4 5276290 TCP 192.168.0.41:2202 (LISTEN) ndbd 31184 root 6u IPv4 5276291 TCP 192.168.0.41:2202->192.168.0.40:41513 (ESTABLISHED) ndbd 31184 root 7u IPv4 5276295 TCP 192.168.0.41:37219->192.168.0.40:2202 (ESTABLISHED) ndbd 31184 root 18u IPv4 5279093 TCP 192.168.0.41:2202->192.168.0.40:41619 (ESTABLISHED) ndbd 31184 root 19u IPv4 5276824 TCP 192.168.0.41:2202->192.168.0.41:37227 (ESTABLISHED) mysqld 2878 mysql 3u IPv4 5322187 TCP *:mysql (LISTEN) mysqld 2878 mysql 12u IPv4 5322198 TCP 192.168.0.41:37369->192.168.0.40:2200 (ESTABLISHED) mysqld 2878 mysql 14u IPv4 5322230 TCP 192.168.0.41:37371->192.168.0.40:2202 (ESTABLISHED) mysqld 2878 mysql 15u IPv4 5322234 TCP 192.168.0.41:37372->192.168.0.41:2202 (ESTABLISHED) ----------------------------------------------------------------- 11. Use Heart Beat to keep ndb_mgmd availabile. Home of Heartbeat - http://linux-ha.org/heartbeat/ The MGM is needed for "arbitration". Arbitration occurs during startup, and when individual nodes join the cluster. But if you only have 2 hosts, and the host running MGM dies, you have no MGM. They say the MGM node should not be run on a NDB node, but that's not practical for me. Using heartbeat, I want to manage ndb_mgmd. One can use drbd (Distributed Replication Block Device) to keep file systems on different hosts synched. ----------------------------------------------------------------- 11. References: Books: (1) "Client/Server Survival Guide" by Orfali etal. [Wiley] An introduction to the database world. (2) "An Introduction to Database Systems" by C.J. Date [Addison Wesley] "academic classic" that is a "must read" (3) "MySQL Reference Manual" by Widenius etal [O'Reilly] Written by the creator of the database MySQL (4) "MySQL Cookbook" by DuBois [O'Reilly] "howto" do "real stuff" with MySQL. ----------------------------------------------------------------- 12. Setup key-based authentication (no passwd needed) between nodes: As root on postal1: ssh root@postal1 'sh-keygen -t rsa' ssh root@postal2 'sh-keygen -t rsa' ssh root@postal1 'mkdir ~/.ssh/pub_keys' ssh root@postal2 'mkdir ~/.ssh/pub_keys' scp root@postal1:~/.ssh/id_rsa.pub root@postal2:~/.ssh/pub_keys/hosta.id_rsa.pub scp root@postal2:~/.ssh/id_rsa.pub root@postal1:~/.ssh/pub_keys/hosta.id_rsa.pub ssh root@postal1 'cat ~/.ssh/pub_keys/hosta.id_rsa.pub >> ~/.ssh/authorized_keys2' ssh root@postal2 'cat ~/.ssh/pub_keys/hosta.id_rsa.pub >> ~/.ssh/authorized_keys2' ssh root@postal1 'chmod 700 ~/.ssh; chmod 600 ~/.ssh/id_rsa ; chmod 644 ~/.ssh/authorized_keys2' ssh root@postal2 'chmod 700 ~/.ssh; chmod 600 ~/.ssh/id_rsa ; chmod 644 ~/.ssh/authorized_keys2' ###################################################### # My startup script ##################################################### cat start_cluster.sh #!/bin/sh # Title: start_cluster.sh # Author: john@stilen.com # Description: Starts nodes in the cluser # Options: ndb_mgmd, ndbd, and api Start_nodes='ndb_mgmd ndbd api' export MYSQL_HOME=/usr/local/mysql export NDB_HOME=$MYSQL_HOME/ndb export PATH="$MYSQL_HOME/bin:$PATH" export LD_LIBRARY_PATH=$MYSQL_HOME/lib export MANPATH=$MANPATH:$MYSQL_HOME/man cd $MYSQL_HOME # # Check system status before starting # vmstat -a for Node in $Start_nodes do if [[ "$Node" -eq "ndb_mgmd" ]] then # # Start MGM # mysql_ndb_mgmd=`ps -elf |grep 'ndb_mgmd -c config.ini'` if [[ -z $mysql_ndb_mgmd ]] then pushd /usr/local/mysql/ndb/mgmt/ && ndb_mgmd -c config.ini -l Ndb.cfg --no-nodeid-checks && popd # Wait for it, wait for it, .... sleep 10 else echo -e "ndb_mgmd alreay running. Skipping ndb_mgmd start.\n\t$mysql_ndb_mgmd\n" fi elif [[ "$Node" -eq "ndbd" ]] then ################################################################## # This will remove any pre-existing clustered data and start DNBD # # pushd /usr/local/mysql/ndb/ndb1/ && ndbd --initial && popd # ################################################################## # This will start the NDBD with pre-existing data # mysql_ndb_ndbd=`ps -elf |grep 'ndbd'` if [[ -z $mysql_ndb_ndbd ]] then pushd /usr/local/mysql/ndb/ndb1/ && ndbd && popd # Wait for it, wait for it, .... sleep 10 else echo -e "ndbd alreay running. Skipping ndbd start.\n\t$mysql_ndb_ndbd\n" fi elif [[ "$Node" -eq "api" ]] then ################################################################## mysql_api=`ps -elf |grep 'mysql_safe'` if [[ -z $mysql_api ]] then # check system status after vmstat -a # start mysqld mysqld_safe& else echo -e "mysqld_safe alreay running. Skipping mysqld_safe start.\n\t$mysql_api\n" fi fi done # Start the cli interface to MGM ndb_mgm