mysql集群整理版
mysql集群架构主要分为:数据节点(ndbd),管理节点(mgmd),服务节点(mysqld)
附件是mysql集群整体架构图
1. 下载:http://dev.mysql.com/downloads/mysql/5.0.html#linux 可以从这里下载 mysql-5.0.45-linux-i686.tar.gz
此包里已经包含了mysql-max包(mysql集群需要安装mysql-max包)。
2. 解压:
tar -zxvf apache-tomcat-5.5.25.tar.gz
# Options affecting ndbd processes on all data nodes:[NDBD DEFAULT] NoOfReplicas=1 # Number of replicasDataMemory=80M # How much memory to allocate for data storageIndexMemory=18M # 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/IP options:[TCP DEFAULT] #portnumber=2202 # This the default; however, you can use any # port that is free for all the hosts in cluster # Note: It is recommended beginning with MySQL 5.0 that # you do not specify the portnumber at all and simply allow # the default value to be used instead# Management process options:[NDB_MGMD] hostname=127.0.0.1 # Hostname or IP address of MGM node ,mgmd's hostnamedatadir=/home/mahaibo/mysql-5.0.45-linux-i686/mgmddata # Directory for MGM node logfilesPortNumber=2203 #default value: 1186# Options for data node "A":[NDBD] # (one [NDBD] section per data node)hostname=127.0.0.1 # Hostname or IP address ,allow to accessdatadir=/home/mahaibo/mysql-5.0.45-linux-i686/mgmddata # Directory for this data node's datafiles# Options for data node "B":[NDBD] hostname=127.0.0.1 # Hostname or IP addressdatadir=/home/mahaibo/mysql-5.0.45-linux-i686/mgmddata # Directory for this data node's datafiles[MYSQLD] hostname=127.0.0.1 # Hostname or IP address # (additional mysqld connections can be # specified for this node for various # purposes such as running ndb_restore)
bin/ndb_mgmd -f mgmd.cnf
bin/ndb_mgm 127.0.0.1 2203 //因为mgmd服务用的端口是2203,所以要通过该端口链接
[mahaibo@client mysql-5.0.45-linux-i686]$ bin/ndb_mgm 127.0.0.1 2203-- NDB Cluster -- Management Client --ndb_mgm> showConnected to Management Server at: 127.0.0.1:2203Cluster Configuration---------------------[ndbd(NDB)] 2 node(s)id=2 (not connected, accepting connect from 127.0.0.1)id=3 (not connected, accepting connect from 127.0.0.1)[ndb_mgmd(MGM)] 1 node(s)id=1 @127.0.0.1 (Version: 5.0.45)[mysqld(API)] 1 node(s)id=4 (not connected, accepting connect from 127.0.0.1)ndb_mgm>
[mysqld]DataDir=/home/mahaibo/mysql-5.0.45-linux-i686/ndbd1data//数据目录skip-lockingkey_buffer = 16Mmax_allowed_packet = 1Mtable_cache = 64sort_buffer_size = 512Knet_buffer_length = 8Kread_buffer_size = 256Kread_rnd_buffer_size = 512Kmyisam_sort_buffer_size = 8Mndbclusterndb-connectstring=127.0.0.1:2203[mysql_cluster]ndb-connectstring=127.0.0.1:2203 // 连接mgmd服务的ip与端口
bin/ndbd --defaults-file=ndbd1.cnf --initial
bin/ndbd --defaults-file=ndbd2.cnf --initial
[mahaibo@client mysql-5.0.45-linux-i686]$ bin/ndb_mgm 127.0.0.1 2203-- NDB Cluster -- Management Client --ndb_mgm> showConnected to Management Server at: 127.0.0.1:2203Cluster Configuration---------------------[ndbd(NDB)] 2 node(s)id=2 @127.0.0.1 (Version: 5.0.45, Nodegroup: 0, Master)id=3 @127.0.0.1 (Version: 5.0.45, Nodegroup: 1)[ndb_mgmd(MGM)] 1 node(s)id=1 @127.0.0.1 (Version: 5.0.45)[mysqld(API)] 1 node(s)id=4 (not connected, accepting connect from 127.0.0.1)ndb_mgm>
#!/bin/shif test ! -x ./scripts/mysql_install_dbthen echo "I didn't find the script './scripts/mysql_install_db'." echo "Please execute this script in the mysql distribution directory!" exit 1;fiecho "NOTE: This is a MySQL binary distribution. It's ready to run, you don't"echo "need to configure it!"echo ""echo "To help you a bit, I am now going to create the needed MySQL databases"echo "and start the MySQL server for you. If you run into any trouble, please"echo "consult the MySQL manual, that you can find in the Docs directory."echo ""./scripts/mysql_install_db --no-defaultsif [ $? = 0 ]then echo "Starting the mysqld server. You can test that it is up and running" echo "with the command:" echo "./bin/mysqladmin version" ./bin/mysqld_safe --no-defaults & #默认会去根据/etc/my.cnf这个配置文件进行启动,并且生成的sock端口会放在/tmp/mysql.sockfi
./bin/mysqld_safe --defaults-file=my3.cnf & #当前目录下的my.cnf,也可以自己指定绝对路径
[mysqld]port = 3306socket = /home/mahaibo/mysql-5.0.45-linux-i686/mysql3.sockdatadir = /home/mahaibo/mysql-5.0.45-linux-i686/data3ndbcluster # run NDB enginendb-connectstring=127.0.0.1:2203 # location of MGM nodeskip-lockingkey_buffer = 16Mmax_allowed_packet = 1Mtable_cache = 64sort_buffer_size = 512Knet_buffer_length = 8Kread_buffer_size = 256Kread_rnd_buffer_size = 512Kmyisam_sort_buffer_size = 8M
./configure3
[mahaibo@client mysql-5.0.45-linux-i686]$ bin/ndb_mgm 127.0.0.1 2203-- NDB Cluster -- Management Client --ndb_mgm> showConnected to Management Server at: 127.0.0.1:2203Cluster Configuration---------------------[ndbd(NDB)] 2 node(s)id=2 @127.0.0.1 (Version: 5.0.45, Nodegroup: 0, Master)id=3 @127.0.0.1 (Version: 5.0.45, Nodegroup: 1)[ndb_mgmd(MGM)] 1 node(s)id=1 @127.0.0.1 (Version: 5.0.45)[mysqld(API)] 1 node(s)id=4 @127.0.0.1 (Version: 5.0.45)
show variables like 'have%';
create table table1 (aa int) engine=ndbcluster;insert into table1 values(11);insert into table1 values(22);都没有问题。
mysql> show create table table1;+--------+------------------------------------------------------------+| Table | Create Table |+--------+------------------------------------------------------------+| table1 | CREATE TABLE `table1` ( `aa` int(11) default NULL) ENGINE=ndbcluster DEFAULT CHARSET=latin1 |+--------+------------------------------------------------------------+1 row in set (0.00 sec)
# Options affecting ndbd processes on all data nodes:[NDBD DEFAULT] NoOfReplicas=1 # Number of replicasDataMemory=80M # How much memory to allocate for data storageIndexMemory=18M # 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/IP options:[TCP DEFAULT] #portnumber=2202 # This the default; however, you can use any # port that is free for all the hosts in cluster # Note: It is recommended beginning with MySQL 5.0 that # you do not specify the portnumber at all and simply allow # the default value to be used instead# Management process options:[NDB_MGMD] hostname=127.0.0.1 # Hostname or IP address of MGM node ,mgmd's hostnamedatadir=/home/mahaibo/mysql-5.0.45-linux-i686/mgmddata # Directory for MGM node logfilesPortNumber=2203 #default value: 1186# Options for data node "A":[NDBD] # (one [NDBD] section per data node)hostname=127.0.0.1 # Hostname or IP address ,allow to accessdatadir=/home/mahaibo/mysql-5.0.45-linux-i686/mgmddata # Directory for this data node's datafiles# Options for data node "B":[NDBD] hostname=127.0.0.1 # Hostname or IP addressdatadir=/home/mahaibo/mysql-5.0.45-linux-i686/mgmddata # Directory for this data node's datafiles[MYSQLD] hostname=127.0.0.1 # Hostname or IP address # (additional mysqld connections can be # specified for this node for various # purposes such as running ndb_restore)
bin/ndb_mgmd -f mgmd.cnf
bin/ndb_mgm 127.0.0.1 2203 //因为mgmd服务用的端口是2203,所以要通过该端口链接
[mahaibo@client mysql-5.0.45-linux-i686]$ bin/ndb_mgm 127.0.0.1 2203-- NDB Cluster -- Management Client --ndb_mgm> showConnected to Management Server at: 127.0.0.1:2203Cluster Configuration---------------------[ndbd(NDB)] 2 node(s)id=2 (not connected, accepting connect from 127.0.0.1)id=3 (not connected, accepting connect from 127.0.0.1)[ndb_mgmd(MGM)] 1 node(s)id=1 @127.0.0.1 (Version: 5.0.45)[mysqld(API)] 1 node(s)id=4 (not connected, accepting connect from 127.0.0.1)ndb_mgm>
[mysqld]DataDir=/home/mahaibo/mysql-5.0.45-linux-i686/ndbd1data//数据目录skip-lockingkey_buffer = 16Mmax_allowed_packet = 1Mtable_cache = 64sort_buffer_size = 512Knet_buffer_length = 8Kread_buffer_size = 256Kread_rnd_buffer_size = 512Kmyisam_sort_buffer_size = 8Mndbclusterndb-connectstring=127.0.0.1:2203[mysql_cluster]ndb-connectstring=127.0.0.1:2203 // 连接mgmd服务的ip与端口
bin/ndbd --defaults-file=ndbd1.cnf --initial
bin/ndbd --defaults-file=ndbd2.cnf --initial
[mahaibo@client mysql-5.0.45-linux-i686]$ bin/ndb_mgm 127.0.0.1 2203-- NDB Cluster -- Management Client --ndb_mgm> showConnected to Management Server at: 127.0.0.1:2203Cluster Configuration---------------------[ndbd(NDB)] 2 node(s)id=2 @127.0.0.1 (Version: 5.0.45, Nodegroup: 0, Master)id=3 @127.0.0.1 (Version: 5.0.45, Nodegroup: 1)[ndb_mgmd(MGM)] 1 node(s)id=1 @127.0.0.1 (Version: 5.0.45)[mysqld(API)] 1 node(s)id=4 (not connected, accepting connect from 127.0.0.1)ndb_mgm>
#!/bin/shif test ! -x ./scripts/mysql_install_dbthen echo "I didn't find the script './scripts/mysql_install_db'." echo "Please execute this script in the mysql distribution directory!" exit 1;fiecho "NOTE: This is a MySQL binary distribution. It's ready to run, you don't"echo "need to configure it!"echo ""echo "To help you a bit, I am now going to create the needed MySQL databases"echo "and start the MySQL server for you. If you run into any trouble, please"echo "consult the MySQL manual, that you can find in the Docs directory."echo ""./scripts/mysql_install_db --no-defaultsif [ $? = 0 ]then echo "Starting the mysqld server. You can test that it is up and running" echo "with the command:" echo "./bin/mysqladmin version" ./bin/mysqld_safe --no-defaults & #默认会去根据/etc/my.cnf这个配置文件进行启动,并且生成的sock端口会放在/tmp/mysql.sockfi
./bin/mysqld_safe --defaults-file=my3.cnf & #当前目录下的my.cnf,也可以自己指定绝对路径
[mysqld]port = 3306socket = /home/mahaibo/mysql-5.0.45-linux-i686/mysql3.sockdatadir = /home/mahaibo/mysql-5.0.45-linux-i686/data3ndbcluster # run NDB enginendb-connectstring=127.0.0.1:2203 # location of MGM nodeskip-lockingkey_buffer = 16Mmax_allowed_packet = 1Mtable_cache = 64sort_buffer_size = 512Knet_buffer_length = 8Kread_buffer_size = 256Kread_rnd_buffer_size = 512Kmyisam_sort_buffer_size = 8M
./configure3
[mahaibo@client mysql-5.0.45-linux-i686]$ bin/ndb_mgm 127.0.0.1 2203-- NDB Cluster -- Management Client --ndb_mgm> showConnected to Management Server at: 127.0.0.1:2203Cluster Configuration---------------------[ndbd(NDB)] 2 node(s)id=2 @127.0.0.1 (Version: 5.0.45, Nodegroup: 0, Master)id=3 @127.0.0.1 (Version: 5.0.45, Nodegroup: 1)[ndb_mgmd(MGM)] 1 node(s)id=1 @127.0.0.1 (Version: 5.0.45)[mysqld(API)] 1 node(s)id=4 @127.0.0.1 (Version: 5.0.45)
show variables like 'have%';
create table table1 (aa int) engine=ndbcluster;insert into table1 values(11);insert into table1 values(22);都没有问题。
mysql> show create table table1;+--------+------------------------------------------------------------+| Table | Create Table |+--------+------------------------------------------------------------+| table1 | CREATE TABLE `table1` ( `aa` int(11) default NULL) ENGINE=ndbcluster DEFAULT CHARSET=latin1 |+--------+------------------------------------------------------------+1 row in set (0.00 sec)
13 楼 xianglei 2008-12-04 galaxystar 写道mysql的master-slave部署方式,听说有延迟?