﻿{"id":852,"date":"2012-06-04T18:22:37","date_gmt":"2012-06-04T10:22:37","guid":{"rendered":"http:\/\/nick.workao.org\/?p=852"},"modified":"2012-06-04T18:22:38","modified_gmt":"2012-06-04T10:22:38","slug":"%e5%9c%a8%e5%90%8c%e4%b8%80%e5%8f%b0%e4%b8%bb%e6%9c%ba%e9%85%8d%e7%bd%aemysql-cluster","status":"publish","type":"post","link":"https:\/\/nick.txtcc.com\/index.php\/linux\/852","title":{"rendered":"\u5728\u540c\u4e00\u53f0\u4e3b\u673a\u914d\u7f6eMySQL Cluster"},"content":{"rendered":"<p>MySQL cluster\u662fshare nothing\u7684\u96c6\u7fa4\uff0c\u91c7\u7528ndb\u5b58\u50a8\u5f15\u64ce\uff0c\u548cOracle\u7684RAC\u91c7\u7528\u96c6\u4e2d\u5b58\u50a8\u4e0d\u540c\uff0c\u662f\u4e00\u79cd\u5206\u5e03\u5f0f\u7684\u67b6\u6784\uff0c\u6240\u4ee5\u53ef\u4ee5\u5f88\u8f7b\u677e\u7684\u5b9e\u73b0\u5728\u540c\u4e00\u53f0\u4e3b\u673a\u4e0a\u914d\u7f6eMySQL Cluster\uff0c\u76f8\u5bf9RAC\u6765\u8bf4\u8981\u7b80\u5355\u5f97\u591a\u3002<\/p>\n<p>\u5728MySQL Cluster\u4e2d\uff0c\u6709\u4e09\u79cd\u4e0d\u540c\u7684\u8282\u70b9\uff1a<\/p>\n<ul>\n    <li>\u7ba1\u7406\u8282\u70b9\uff1a\u5b88\u62a4\u8fdb\u7a0b\u4e3andb_mgmd\uff0c\u7528\u4e8e\u7ba1\u7406cluster\u3002<\/li>\n    <li>\u6570\u636e\u8282\u70b9: \u5b88\u62a4\u8fdb\u7a0b\u4e3andbd\uff0c\u7528\u4e8e\u5b58\u653e\u6570\u636e<\/li>\n    <li>SQL\u8282\u70b9\uff1a\u5b88\u62a4\u8fdb\u7a0b\u4e3amysqld\uff0c\u5c31\u662f\u4e00\u4e2aMySQL\u5b9e\u4f8b\uff0c\u5bf9\u5916\u4f9b\u5ba2\u6237\u7aef\u8fde\u63a5\u8bbf\u95ee\u6570\u636e\u3002<\/li>\n<\/ul>\n<p>\u672c\u6587\u5c06\u5728\u4e00\u53f064\u4f4dlinux\u4e3b\u673a\u4e0a\u540c\u65f6\u914d\u7f6e\u4e0a\u8ff0\u4e09\u79cd\u8282\u70b9\u3002\u5728\u5b9e\u9645\u751f\u4ea7\u73af\u5883\u4e2d\uff0c\u6839\u636e\u9700\u8981\uff0c\u53ef\u4ee5\u5728\u76f8\u540c\u6216\u8005\u4e0d\u540c\u7684\u673a\u5668\u90e8\u7f72\u8282\u70b9\u3002\u672c\u6b21\u5b9e\u4f8b\u4e2d\u5171\u5305\u542b\u4ee5\u4e0b\u8282\u70b9\uff1a<\/p>\n<ul>\n    <li>\u4e00\u4e2a\u7ba1\u7406\u8282\u70b9<\/li>\n    <li>\u4e24\u4e2a\u6570\u636e\u8282\u70b9<\/li>\n    <li>\u4e09\u4e2aSQL\u8282\u70b9<\/li>\n<\/ul>\n<p>\u4e0b\u8f7dMysql cluster\uff0c\u5f53\u524d\u7248\u672c7.0.6\uff0c<a href=\"http:\/\/dev.mysql.com\/downloads\/cluster\/7.0.html\"><a href=\"http:\/\/dev.mysql.com\/downloads\/cluster\/7.0.html\">http:\/\/dev.mysql.com\/downloads\/cluster\/7.0.html<\/a>\n<\/a>\n\u89e3\u538b\uff0c\u5e76\u590d\u5236\u5230\u5b89\u88c5\u76ee\u5f55<\/p>\n<pre>tar zxvf mysql-cluster-gpl-7.0.6-linux-x86_64-glibc23.tar.gz\ncp mysql-cluster-gpl-7.0.6-linux-x86_64-glibc23 \/u01\/mysql-cluster\n\ncd \/u01\/mysql-cluster<\/pre>\n<p>\u521b\u5efa\u4e09\u4e2aMySQL\u5b9e\u4f8b\u7684\u6570\u636e\u76ee\u5f55<\/p>\n<pre>mkdir data\/data1\nmkdir data\/data2\nmkdir data\/data3\n\nmkdir data\/data1\/mysql\nmkdir data\/data1\/test\n\nmkdir data\/data2\/mysql\nmkdir data\/data2\/test\n\nmkdir data\/data3\/mysql\nmkdir data\/data3\/test<\/pre>\n<p>Cluster\u914d\u7f6e\u6587\u4ef6\u5982\u4e0b<\/p>\n<pre>$ more conf\/config.ini\n[ndbd default]\nnoofreplicas=2\n[ndbd]\nhostname=localhost\nid=2\n[ndbd]\nhostname=localhost\nid=3\n[ndb_mgmd]\nid = 1\nhostname=localhost\n[mysqld]\nid=4\nhostname=localhost\n[mysqld]\nid=5\nhostname=localhost\n[mysqld]\nid=6\nhostname=localhost<\/pre>\n<p>\u4e09\u4e2aMySQL\u5b9e\u4f8b\u914d\u7f6e\u6587\u4ef6\u5982\u4e0b<\/p>\n<pre>$ more conf\/my1.cnf\n[mysqld]\nndb-nodeid=4\nndbcluster=true\ndatadir=\/u01\/mysql-cluster\/data\/data1\nbasedir=\/u01\/mysql-cluster\nport=9306\nserver-id=1\nlog-bin\n\n$ more conf\/my2.cnf\n[mysqld]\nndb-nodeid=5\nndbcluster=true\ndatadir=\/u01\/mysql-cluster\/data\/data2\nbasedir=\/u01\/mysql-cluster\nport=9307\nserver-id=2\nlog-bin\n\n$ more conf\/my3.cnf\n[mysqld]\nndb-nodeid=6\nndbcluster=true\ndatadir=\/u01\/mysql-cluster\/data\/data3\nbasedir=\/u01\/mysql-cluster\nport=9308\nserver-id=3\nlog-bin<\/pre>\n<p>\u521d\u59cb\u5316\u4e09\u4e2aMySQL\u5b9e\u4f8b<\/p>\n<pre>script\/mysql_install_db --basedir=\/u01\/mysql-cluster --datadir=\/u01\/mysql-cluster\/data\/data1\nscript\/mysql_install_db --basedir=\/u01\/mysql-cluster --datadir=\/u01\/mysql-cluster\/data\/data2\nscript\/mysql_install_db --basedir=\/u01\/mysql-cluster --datadir=\/u01\/mysql-cluster\/data\/data3<\/pre>\n<p>\u521d\u59cb\u5316\u7ba1\u7406\u8282\u70b9<\/p>\n<pre>bin\/ndb_mgmd --initial -f conf\/config.ini --configdir=\/u01\/mysql-cluster<\/pre>\n<p>\u8fdb\u5165\u7ba1\u7406\u8282\u70b9\u67e5\u770b\u914d\u7f6e<\/p>\n<pre>$ bin\/ndb_mgm\n-- NDB Cluster -- Management Client --\nndb_mgm> help\n---------------------------------------------------------------------------\n NDB Cluster -- Management Client -- Help\n---------------------------------------------------------------------------\nHELP                                   Print help text\nHELP COMMAND                           Print detailed help for COMMAND(e.g. SHOW)\nSHOW                                   Print information about cluster\nCREATE NODEGROUP ,...          Add a Nodegroup containing nodes\nDROP NODEGROUP                     Drop nodegroup with id NG\nSTART BACKUP [NOWAIT | WAIT STARTED | WAIT COMPLETED]\nSTART BACKUP [] [NOWAIT | WAIT STARTED | WAIT COMPLETED]\nSTART BACKUP [] [SNAPSHOTSTART | SNAPSHOTEND] [NOWAIT | WAIT STARTED | WAIT COMPLETED]\n                                       Start backup (default WAIT COMPLETED,SNAPSHOTEND)\nABORT BACKUP                Abort backup\nSHUTDOWN                               Shutdown all processes in cluster\nCLUSTERLOG ON [] ...         Enable Clus\n = ALERT | CRITICAL | ERROR | WARNING | INFO | DEBUG\n = STARTUP | SHUTDOWN | STATISTICS | CHECKPOINT | NODERESTART | CONNECTION\n| INFO | ERROR | CONGESTION | DEBUG | BACKUP\n    = 0 - 15\n       = ALL | Any database node id\n\nFor detailed help on COMMAND, use HELP COMMAND.\n\nndb_mgm> show\nConnected to Management Server at: localhost:1186\nCluster Configuration\n---------------------\n[ndbd(NDB)]     2 node(s)\nid=2 (not connected, accepting connect from localhost)\nid=3 (not connected, accepting connect from localhost)\n\n[ndb_mgmd(MGM)] 1 node(s)\nid=1    @localhost  (mysql-5.1.34 ndb-7.0.6)\n\n[mysqld(API)]   3 node(s)\nid=4 (not connected, accepting connect from localhost)\nid=5 (not connected, accepting connect from localhost)\nid=6 (not connected, accepting connect from localhost)<\/pre>\n<p>\u521d\u59cb\u5316\u6570\u636e\u8282\u70b9<\/p>\n<pre>bin\/ndbd --initial -c localhost:1186\n2009-06-21 23:13:19 [ndbd] INFO     -- Configuration fetched from 'localhost:1186', generation: 1\nbin\/ndbd --initial -c localhost:1186\n2009-06-21 23:13:50 [ndbd] INFO     -- Configuration fetched from 'localhost:1186', generation: 1<\/pre>\n<p>\u542f\u52a8SQL\u8282\u70b9<\/p>\n<pre>bin\/mysqld --defaults-file=conf\/my1.cnf&\n[1] 17843\n 090621 23:14:36 [Warning] No argument was provided to --log-bin,\nand --log-bin-index was not used; so replication may break when this MySQL server acts as a master\nand has his hostname changed!! Please use '--log-bin=test-bin' to avoid this problem.\nInnoDB: The first specified data file .\/ibdata1 did not exist:\nInnoDB: a new database to be created!\n090621 23:14:36  InnoDB: Setting file .\/ibdata1 size to 10 MB\nInnoDB: Database physically writes the file full: wait...\n090621 23:14:36  InnoDB: Log file .\/ib_logfile0 did not exist: new to be created\nInnoDB: Setting log file .\/ib_logfile0 size to 5 MB\nInnoDB: Database physically writes the file full: wait...\n090621 23:14:36  InnoDB: Log file .\/ib_logfile1 did not exist: new to be created\nInnoDB: Setting log file .\/ib_logfile1 size to 5 MB\nInnoDB: Database physically writes the file full: wait...\nInnoDB: Doublewrite buffer not found: creating new\nInnoDB: Doublewrite buffer created\nInnoDB: Creating foreign key constraint system tables\nInnoDB: Foreign key constraint system tables created\n090621 23:14:36  InnoDB: Started; log sequence number 0 0\n090621 23:14:36 [Note] NDB: NodeID is 4, management server 'localhost:1186'\n090621 23:14:37 [Note] NDB[0]: NodeID: 4, all storage nodes connected\n090621 23:14:37 [Note] Starting Cluster Binlog Thread\n090621 23:14:37 [Note] Event Scheduler: Loaded 0 events\n090621 23:14:37 [Note] bin\/mysqld: ready for connections.\nVersion: '5.1.34-ndb-7.0.6-cluster-gpl-log'  socket: '\/tmp\/mysql.sock'\nport: 9306  MySQL Cluster Server (GPL)\n090621 23:14:38 [Note] NDB Binlog: Ndb tables initially read only.\n090621 23:14:38 [Note] NDB: Creating mysql.ndb_schema\n090621 23:14:38 [Note] NDB Binlog: CREATE TABLE Event: REPL$mysql\/ndb_schema\n090621 23:14:38 [Note] NDB Binlog: logging .\/mysql\/ndb_schema (UPDATED,USE_WRITE)\n090621 23:14:38 [Note] NDB: Creating mysql.ndb_apply_status\n090621 23:14:39 [Note] NDB Binlog: CREATE TABLE Event: REPL$mysql\/ndb_apply_status\n090621 23:14:39 [Note] NDB Binlog: logging .\/mysql\/ndb_apply_status (UPDATED,USE_WRITE)\n2009-06-21 23:14:39 [NdbApi] INFO     -- Flushing incomplete GCI:s < 20\/3\n2009-06-21 23:14:39 [NdbApi] INFO     -- Flushing incomplete GCI:s < 20\/3\n090621 23:14:39 [Note] NDB Binlog: starting log at epoch 20\/3\n090621 23:14:39 [Note] NDB Binlog: ndb tables writable<\/pre>\n<pre>bin\/mysqld --defaults-file=conf\/my2.cnf&\nbin\/mysqld --defaults-file=conf\/my3.cnf&<\/pre>\n<p>\u67e5\u770bcluster<\/p>\n<pre>bin\/ndb_mgm\n-- NDB Cluster -- Management Client --\nndb_mgm> show\nConnected to Management Server at: localhost:1186\nCluster Configuration\n---------------------\n[ndbd(NDB)]     2 node(s)\nid=2    @127.0.0.1  (mysql-5.1.34 ndb-7.0.6, Nodegroup: 0, Master)\nid=3    @127.0.0.1  (mysql-5.1.34 ndb-7.0.6, Nodegroup: 0)\n\n[ndb_mgmd(MGM)] 1 node(s)\nid=1    @127.0.0.1  (mysql-5.1.34 ndb-7.0.6)\n\n[mysqld(API)]   3 node(s)\nid=4    @127.0.0.1  (mysql-5.1.34 ndb-7.0.6)\nid=5    @127.0.0.1  (mysql-5.1.34 ndb-7.0.6)\nid=6    @127.0.0.1  (mysql-5.1.34 ndb-7.0.6)<\/pre>\n<p>\u521b\u5efa\u6d4b\u8bd5\u8868<\/p>\n<pre>bin\/mysql -uroot -h localhost -P 9306  --socket=\/tmp\/mysql.sock\nWelcome to the MySQL monitor.  Commands end with ; or g.\nYour MySQL connection id is 2\nServer version: 5.1.34-ndb-7.0.6-cluster-gpl-log MySQL Cluster Server (GPL)\n\nType 'help;' or 'h' for help. Type 'c' to clear the current input statement.\n\nroot@(none) 11:21:24>use test\nDatabase changed\nroot@test 11:21:26>create table test_ndb(i int,a varchar(20),primary key(i)) engine=ndb;\n090621 23:22:32 [Note] NDB Binlog: CREATE TABLE Event: REPL$test\/test_ndb\n090621 23:22:32 [Note] NDB Binlog: logging .\/test\/test_ndb (UPDATED,USE_WRITE)\n090621 23:22:32 [Note] NDB Binlog: DISCOVER TABLE Event: REPL$test\/test_ndb\n090621 23:22:32 [Note] NDB Binlog: DISCOVER TABLE Event: REPL$test\/test_ndb\n090621 23:22:32 [Note] NDB Binlog: logging .\/test\/test_ndb (UPDATED,USE_WRITE)\n090621 23:22:32 [Note] NDB Binlog: logging .\/test\/test_ndb (UPDATED,USE_WRITE)\nQuery OK, 0 rows affected (1.10 sec)\n\nroot@test 11:22:32>insert into test_ndb values(1,'NinGoo');\nQuery OK, 1 row affected (0.02 sec)\n\n[mysql@dbconsole mysql-cluster]$ ls -l data\/data1\/test\ntotal 12\n-rw-rw----  1 mysql dba 8578 Jun 21 23:22 test_ndb.frm\n-rw-rw----  1 mysql dba    0 Jun 21 23:22 test_ndb.ndb\n[mysql@dbconsole mysql-cluster]$ ls -l data\/data2\/test\ntotal 12\n-rw-rw----  1 mysql dba 8578 Jun 21 23:22 test_ndb.frm\n-rw-rw----  1 mysql dba    0 Jun 21 23:22 test_ndb.ndb\n[mysql@dbconsole mysql-cluster]$ ls -l data\/data3\/test\ntotal 12\n-rw-rw----  1 mysql dba 8578 Jun 21 23:22 test_ndb.frm\n-rw-rw----  1 mysql dba    0 Jun 21 23:22 test_ndb.ndb\n\n$ bin\/mysql -uroot -P 9307 --socket=\/tmp\/mysql.sock\nWelcome to the MySQL monitor.  Commands end with ; or g.\nYour MySQL connection id is 3\nServer version: 5.1.34-ndb-7.0.6-cluster-gpl-log MySQL Cluster Server (GPL)\n\nType 'help;' or 'h' for help. Type 'c' to clear the current input statement.\n\nroot@(none) 11:24:38>use test\nReading table information for completion of table and column names\nYou can turn off this feature to get a quicker startup with -A\n\nDatabase changed\nroot@test 11:24:41>select * from test_ndb;\n+---+--------+\n| i | a      |\n+---+--------+\n| 1 | NinGoo |\n+---+--------+\n1 row in set (0.02 sec)<\/pre>\n<div><\/div>\n<p><a href=\"http:\/\/www.wumii.com\/widget\/relatedItems.htm\"><img decoding=\"async\" src=\"http:\/\/nick.txtcc.com\/wp-content\/uploads\/remote_image\/2012\/06\/1022389Kt.png\" alt=\"\u65e0\u89c5\u76f8\u5173\u6587\u7ae0\u63d2\u4ef6\uff0c\u5feb\u901f\u63d0\u5347\u6d41\u91cf\" \/><\/a><\/p>","protected":false},"excerpt":{"rendered":"<p>MySQL cluster\u662fshare nothing\u7684\u96c6\u7fa4\uff0c\u91c7\u7528ndb\u5b58\u50a8\u5f15\u64ce\uff0c\u548cOracle\u7684RAC\u91c7\u7528\u96c6\u4e2d\u5b58\u50a8\u4e0d\u540c\uff0c\u662f\u4e00\u79cd\u5206\u5e03\u5f0f\u7684\u67b6\u6784\uff0c\u6240\u4ee5\u53ef\u4ee5\u5f88\u8f7b\u677e\u7684\u5b9e\u73b0\u5728\u540c\u4e00\u53f0\u4e3b\u673a\u4e0a\u914d\u7f6eMySQL Clus&#46;&#46;&#46;<\/p>","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[324,100,325],"class_list":["post-852","post","type-post","status-publish","format-standard","hentry","category-linux","tag-cluster","tag-mysql","tag-ndb"],"_links":{"self":[{"href":"https:\/\/nick.txtcc.com\/index.php\/wp-json\/wp\/v2\/posts\/852","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/nick.txtcc.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/nick.txtcc.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/nick.txtcc.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/nick.txtcc.com\/index.php\/wp-json\/wp\/v2\/comments?post=852"}],"version-history":[{"count":1,"href":"https:\/\/nick.txtcc.com\/index.php\/wp-json\/wp\/v2\/posts\/852\/revisions"}],"predecessor-version":[{"id":854,"href":"https:\/\/nick.txtcc.com\/index.php\/wp-json\/wp\/v2\/posts\/852\/revisions\/854"}],"wp:attachment":[{"href":"https:\/\/nick.txtcc.com\/index.php\/wp-json\/wp\/v2\/media?parent=852"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/nick.txtcc.com\/index.php\/wp-json\/wp\/v2\/categories?post=852"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/nick.txtcc.com\/index.php\/wp-json\/wp\/v2\/tags?post=852"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}