Mgmd:management server sqld:mysql server ndb:storaged node (share-nothing,base in memory)
安装
从http://dev.mysql.com/downloads/mysql/4.1.html下载mysql-max-4.1.12-pc-linux-gnu-i686.tar.gz到/var/tmp Storage and SQL Node Installation
在两台主机上执行如下过程
shell>groupadd mysql shell>useradd -g mysql mysql shell>tar zxfv mysql-max-4.1.12-pc-linux-gnu-i686.tar.gz shell>cp -vr mysql-max-4.1.12-pc-linux-gnu-i686 /usr/local/mysql-max-4.1.12-pc-linux-gnu-i686 shell>cd /usr/local shell>ln -s mysql-max-4.1.12-pc-linux-gnu-i686 mysql shell>cd mysql;scripts/mysql_install_db –user=mysql shell>chown -R root .;chown -R mysql data;chgrp -R mysql . shell>cp support-files/mysql.server /etc/rc.d/init.d/ shell>chmod +x /etc/rc.d/init.d/mysql.server shell>chkconfig --add mysql.server shell>chkconfig –level 3 mysql.server off Management Node Installation
在主机ndb1_mgmd_sqld1上执行如下过程
shell>cd /var/tmp shell>tar -zxvf mysql-max-4.1.12a-pc-linux-gnu-i686.tar.gz /usr/local/bin '*/bin/ndb_mgm*' Configuration Configuring the Storage and SQL Nodes
在两台主机上执行如下过程:
shell>vi /etc/my.cnf [MYSQLD] # Options for mysqld process: ndbcluster # run NDB engine ndb-connectstring=192.168.1.100 # location of MGM node
[MYSQL_CLUSTER] # Options for ndbd process: ndb-connectstring=192.168.1.100 # location of MGM node
Configuring the Management Node
在主机ndb1_mgmd_sqld1上执行如下过程
shell>mkdir /var/lib/mysql-cluster shell>cd /var/lib/mysql-cluster shell>vi config.ini [NDBD DEFAULT] # Options affecting ndbd processes on all data nodes: NoOfReplicas=2 # Number of replicas DataMemory=80M # How much memory to allocate for data storage IndexMemory=52M # How much memory to allocate for index storage # For DataMemory and IndexMemory, we have used the # default values. Since the "world" database takes up # only about 500KB, this should be more than enough for # this example Cluster setup. [TCP DEFAULT]
[NDB_MGMD] # Management process options: hostname=192.168.1.100 # Hostname or IP address of MGM node datadir=/var/lib/mysql-cluster # Directory for MGM node logfiles
[NDBD] # Options for data node "A": # (one [NDBD] section per data node) HostName=192.168.1.100 # Hostname or IP address DataDir=/usr/local/mysql/data # Directory for this data node's datafiles
[NDBD] # Options for data node "B": hostname=192.168.1.200 # Hostname or IP address datadir=/usr/local/mysql/data # Directory for this data node's datafiles
[MYSQLD] # SQL node options: hostname=192.168.1.100 # Hostname or IP address # Directory for SQL node's datafiles # (additional mysqld connections can be # specified for this node for various # purposes such as running ndb_restore)
[MYSQLD] # SQL node options: hostname=192.168.1.200 # Hostname or IP address # Directory for SQL node's datafiles # (additional mysqld connections can be # specified for this node for various # purposes such as running ndb_restore)
shell>/usr/local/mysql/bin/mysql -u root test MySQL>DROP TABLE IF EXISTS City; CREATE TABLE City ( ID int(11) NOT NULL auto_increment, Name char(35) NOT NULL default '', CountryCode char(3) NOT NULL default '', District char(20) NOT NULL default '', Population int(11) NOT NULL default '0', PRIMARY KEY (ID) ) ENGINE=NDBCLUSTER;
MySQL>INSERT INTO City VALUES (1,'Kabul','AFG','Kabol',1780000); INSERT INTO City VALUES (2,'Qandahar','AFG','Qandahar',237500); INSERT INTO City VALUES (3,'Herat','AFG','Herat',186800);
在主机ndb2_sqld2上执行如下过程
shell>/usr/local/mysql/bin/mysql -u root mysql MySQSL>select * from City;
[MGM|NDB_MGMD]: Defines the management server node in the cluster. [TCP]: Defines TCP/IP connections between nodes in the cluster, with TCP/IP being the default connection protocol. [SHM]: Defines shared-memory connections between nodes. 在MySQL 4.1.9之前,这个功能必须使用--with-ndb-shm option编译进去, 从MySQL 4.1.9-max版本开始, it is enabled by default(默认为打开状态)