vi /usr/local/mysql/mysql-cluster/config.ini
[ndbd default]
DataMemory = 100M
IndexMemory = 100M
NoOfReplicas = 2
DataDir = /usr/local/mysql/var/mysql-cluster
[ndbd]
Id = 1
HostName = 172.20.86.188
[ndbd]
Id = 2
HostName = 172.20.86.189
[mgm]
HostName = 172.20.86.185
Id = 10
[mysqld]
Id=20
HostName = 172.20.86.185
2 在185 上运行ndb_mgm
Ndb_mgm>show
-- NDB Cluster -- Management Client --ndb_mgm> SHOWConnected to Management Server at: 172.20.86.185:1186Cluster Configuration---------------------[ndbd(NDB)] 2 node(s)id=1 @172.20.86.188 (5.1.32-ndb-7.0.5, Nodegroup: 0, Master)id=2 @172.20.86.189 (5.1.32-ndb-7.0.5, Nodegroup: 0) [ndb_mgmd(MGM)] 1 node(s)id=10 @172.20.86.185 (5.1.32-ndb-7.0.5) [mysqld(API)] 2 node(s)id=20 @172.20.86.185 (5.1.32-ndb-7.0.5)
[ndbd default]DataMemory = 100MIndexMemory = 100MNoOfReplicas = 2DataDir = /usr/local/mysql/var/mysql-cluster [ndbd]Id = 1HostName = 172.20.86.188 [ndbd]Id = 2HostName = 172.20.86.189 [ndbd]Id = 3HostName = 172.20.86.187
[ndbd]Id = 4HostName = 172.20.86.186
[mgm]HostName = 172.20.86.185Id = 10 [mysqld]Id=20HostName = 172.20.86.185
ndb_mgm> 10 STOPNode 10 has shut down.Disconnecting to allow Management Server to shutdownshell>
shell> ndb_mgmd -f config.ini --reload2008-12-08 17:29:23 [MgmSrvr] INFO -- NDB Cluster Management Server. 5.1.34-ndb-7.0.72008-12-08 17:29:23 [MgmSrvr] INFO -- Reading cluster configuration from 'config.ini'
-- NDB Cluster -- Management Client --ndb_mgm> SHOWConnected to Management Server at: 172.20.86.185:1186Cluster Configuration---------------------[ndbd(NDB)] 2 node(s)id=1 @172.20.86.188 (5.1.32-ndb-7.0.5, Nodegroup: 0, Master)id=2 @172.20.86.189 (5.1.32-ndb-7.0.5, Nodegroup: 0)id=3 (not connected, accepting connect from 172.20.86.186)id=4 (not connected, accepting connect from 172.20.86.187) [ndb_mgmd(MGM)] 1 node(s)id=10 @172.20.86.185 (5.1.32-ndb-7.0.5) [mysqld(API)] 1 node(s)id=20 @172.20.86.185 (5.1.32-ndb-7.0.5)
ndb_mgm> 1 RESTARTNode 1: Node shutdown initiatedNode 1: Node shutdown completed, restarting, no start.Node 1 is being restarted ndb_mgm> Node 1: Start initiated (version 7.0.5)Node 1: Started (version 7.0.5) ndb_mgm> 2 RESTARTNode 2: Node shutdown initiatedNode 2: Node shutdown completed, restarting, no start.Node 2 is being restarted
本案仅有一个sql节点
shell> mysqladmin -uroot -ppassword shutdownshell> mysqld_safe &
在新增的数据节点上 186 和187 上执行
Shell>ndbmtd –initial
或者
Shell>ndbd –initial
登陆管理节点查看集群状态
Connected to Management Server at: 172.20.86.185:1186Cluster Configuration---------------------[ndbd(NDB)] 2 node(s)id=1 @172.20.86.188 (5.1.32-ndb-7.0.5, Nodegroup: 0, Master)id=2 @172.20.86.189 (5.1.32-ndb-7.0.5, Nodegroup: 0)id=3 @172.20.86.186 (5.1.32-ndb-7.0.5, no nodegroup)id=4 @172.20.86.187 (5.1.32-ndb-7.0.5, no nodegroup) [ndb_mgmd(MGM)] 1 node(s)id=10 @172.20.86.185 (5.1.32-ndb-7.0.5) [mysqld(API)] 2 node(s)id=20 @172.20.86.185 (5.1.32-ndb-7.0.5)
ndb_mgm> CREATE NODEGROUP 3,4Nodegroup 1 created ndb_mgm> SHOWConnected to Management Server at: 172.20.86.185:1186Cluster Configuration---------------------[ndbd(NDB)] 2 node(s)id=1 @172.20.86.188 (5.1.32-ndb-7.0.5, Nodegroup: 0, Master)id=2 @172.20.86.189 (5.1.32-ndb-7.0.5, Nodegroup: 0)id=3 @172.20.86.186 (5.1.32-ndb-7.0.5, Nodegroup: 1)id=4 @172.20.86.187 (5.1.32-ndb-7.0.5, Nodegroup: 1) [ndb_mgmd(MGM)] 1 node(s)id=10 @172.20.86.185 (5.1.32-ndb-7.0.5) [mysqld(API)] 1 node(s)id=20 @172.20.86.185 (5.1.32-ndb-7.0.5)
对于新增的数据节点一些访问量较高的数据和比较重要的数据需要从新分配。
分发数据命令:
Alter online table ips reorganize partition;
查看数据的分配情况:
ndb_mgm> ALL REPORT MEMORY Node 1: Data usage is 5%(177 32K pages of total 3200)Node 1: Index usage is 0%(108 8K pages of total 12832)Node 2: Data usage is 5%(177 32K pages of total 3200)Node 2: Index usage is 0%(108 8K pages of total 12832)Node 3: Data usage is 0%(0 32K pages of total 3200)Node 3: Index usage is 0%(0 8K pages of total 12832)Node 4: Data usage is 0%(0 32K pages of total 3200)Node 4: Index usage is 0%(0 8K pages of total 12832)
或者
shell> ndb_desc -c 192.168.0.10 -d n ips -p-- ips --Version: 1Fragment type: 9K Value: 6Min load factor: 78Max load factor: 80Temporary table: noNumber of attributes: 6Number of primary keys: 1Length of frm data: 340Row Checksum: 1Row GCI: 1SingleUserMode: 0ForceVarPart: 1FragmentCount: 2TableStatus: Retrieved-- Attributes --id Bigint PRIMARY KEY DISTRIBUTION KEY AT=FIXED ST=MEMORY AUTO_INCRcountry_code Char(2;latin1_swedish_ci) NOT NULL AT=FIXED ST=MEMORYtype Char(4;latin1_swedish_ci) NOT NULL AT=FIXED ST=MEMORYip_address Varchar(15;latin1_swedish_ci) NOT NULL AT=SHORT_VAR ST=MEMORYaddresses Bigunsigned NULL AT=FIXED ST=MEMORYdate Bigunsigned NULL AT=FIXED ST=MEMORY -- Indexes --PRIMARY KEY(id) - UniqueHashIndexPRIMARY(id) - OrderedIndex -- Per partition info --Partition Row count Commit count Frag fixed memory Frag varsized memory0 26086 26086 1572864 5570561 26329 26329 1605632 557056 NDBT_ProgramExit: 0 - OK
You can cause the data to be redistributed among all of the data nodes by performing, for each NDBCLUSTER table, an ALTER ONLINE TABLE ... REORGANIZE PARTITION statement in the mysql client. After issuing the statement ALTER ONLINE TABLE ips REORGANIZE PARTITION, you can see using ndb_desc that the data for this table is now stored using 4 partitions, as shown here (with the relevant portions of the output in bold type):
shell> ndb_desc -c 172.20.86.185 -d n ips -p-- ips --Version: 16777217Fragment type: 9K Value: 6Min load factor: 78Max load factor: 80Temporary table: noNumber of attributes: 6Number of primary keys: 1Length of frm data: 341Row Checksum: 1Row GCI: 1SingleUserMode: 0ForceVarPart: 1FragmentCount: 4TableStatus: Retrieved-- Attributes --id Bigint PRIMARY KEY DISTRIBUTION KEY AT=FIXED ST=MEMORY AUTO_INCRcountry_code Char(2;latin1_swedish_ci) NOT NULL AT=FIXED ST=MEMORYtype Char(4;latin1_swedish_ci) NOT NULL AT=FIXED ST=MEMORYip_address Varchar(15;latin1_swedish_ci) NOT NULL AT=SHORT_VAR ST=MEMORYaddresses Bigunsigned NULL AT=FIXED ST=MEMORYdate Bigunsigned NULL AT=FIXED ST=MEMORY -- Indexes --PRIMARY KEY(id) - UniqueHashIndexPRIMARY(id) - OrderedIndex -- Per partition info --Partition Row count Commit count Frag fixed memory Frag varsized memory0 12981 52296 1572864 5570561 13236 52515 1605632 5570562 13105 13105 819200 2949123 13093 13093 819200 294912
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/90618/viewspace-604979/ ,如需转载,请注明出处,否则将追究法律责任。