如何在同一台主机配置MySQL Cluster
这篇文章主要为大家展示了“如何在同一台主机配置MySQL Cluster”,内容简而易懂,条理清晰,希望能够帮助大家解决疑惑,下面让小编带领大家一起研究并学习一下“如何在同一台主机配置MySQL Cluster”这篇文章吧。
MySQL cluster是share nothing的集群,采用ndb存储引擎,和Oracle的RAC采用集中存储不同,是一种分布式的架构,所以可以很轻松的实现在同一台主机上配置MySQL Cluster,相对RAC来说要简单得多。
在MySQL Cluster中,有三种不同的节点:
管理节点:守护进程为ndb_mgmd,用于管理cluster。
数据节点: 守护进程为ndbd,用于存放数据
SQL节点:守护进程为mysqld,就是一个MySQL实例,对外供客户端连接访问数据。
本文将在一台64位linux主机上同时配置上述三种节点。在实际生产环境中,根据需要,可以在相同或者不同的机器部署节点。本次实例中共包含以下节点:
一个管理节点
两个数据节点
三个SQL节点
下载Mysql cluster,当前版本7.0.6,http://dev.mysql.com/downloads/cluster/7.0.html
解压,并复制到安装目录
tarzxvfmysql-cluster-gpl-7.0.6-linux-x86_64-glibc23.tar.gzcpmysql-cluster-gpl-7.0.6-linux-x86_64-glibc23/u01/mysql-clustercd/u01/mysql-cluster
创建三个MySQL实例的数据目录
mkdirdata/data1mkdirdata/data2mkdirdata/data3mkdirdata/data1/mysqlmkdirdata/data1/testmkdirdata/data2/mysqlmkdirdata/data2/testmkdirdata/data3/mysqlmkdirdata/data3/test
Cluster配置文件如下
$moreconf/config.ini[ndbddefault]noofreplicas=2[ndbd]hostname=localhostid=2[ndbd]hostname=localhostid=3[ndb_mgmd]id=1hostname=localhost[mysqld]id=4hostname=localhost[mysqld]id=5hostname=localhost[mysqld]id=6hostname=localhost
三个MySQL实例配置文件如下
$moreconf/my1.cnf[mysqld]ndb-nodeid=4ndbcluster=truedatadir=/u01/mysql-cluster/data/data1basedir=/u01/mysql-clusterport=9306server-id=1log-bin$moreconf/my2.cnf[mysqld]ndb-nodeid=5ndbcluster=truedatadir=/u01/mysql-cluster/data/data2basedir=/u01/mysql-clusterport=9307server-id=2log-bin$moreconf/my3.cnf[mysqld]ndb-nodeid=6ndbcluster=truedatadir=/u01/mysql-cluster/data/data3basedir=/u01/mysql-clusterport=9308server-id=3log-bin
初始化三个MySQL实例
script/mysql_install_db--basedir=/u01/mysql-cluster--datadir=/u01/mysql-cluster/data/data1script/mysql_install_db--basedir=/u01/mysql-cluster--datadir=/u01/mysql-cluster/data/data2script/mysql_install_db--basedir=/u01/mysql-cluster--datadir=/u01/mysql-cluster/data/data3
初始化管理节点
bin/ndb_mgmd--initial-fconf/config.ini--configdir=/u01/mysql-cluster
进入管理节点查看配置
$bin/ndb_mgm--NDBCluster--ManagementClient--ndb_mgm>help---------------------------------------------------------------------------NDBCluster--ManagementClient--Help---------------------------------------------------------------------------HELPPrinthelptextHELPCOMMANDPrintdetailedhelpforCOMMAND(e.g.SHOW)SHOWPrintinformationaboutclusterCREATENODEGROUP,...AddaNodegroupcontainingnodesDROPNODEGROUPDropnodegroupwithidNGSTARTBACKUP[NOWAIT|WAITSTARTED|WAITCOMPLETED]STARTBACKUP[][NOWAIT|WAITSTARTED|WAITCOMPLETED]STARTBACKUP[][SNAPSHOTSTART|SNAPSHOTEND][NOWAIT|WAITSTARTED|WAITCOMPLETED]Startbackup(defaultWAITCOMPLETED,SNAPSHOTEND)ABORTBACKUPAbortbackupSHUTDOWNShutdownallprocessesinclusterCLUSTERLOGON[]...EnableClus=ALERT|CRITICAL|ERROR|WARNING|INFO|DEBUG=STARTUP|SHUTDOWN|STATISTICS|CHECKPOINT|NODERESTART|CONNECTION|INFO|ERROR|CONGESTION|DEBUG|BACKUP=0-15=ALL|AnydatabasenodeidFordetailedhelponCOMMAND,useHELPCOMMAND.ndb_mgm>showConnectedtoManagementServerat:localhost:1186ClusterConfiguration---------------------[ndbd(NDB)]2node(s)id=2(notconnected,acceptingconnectfromlocalhost)id=3(notconnected,acceptingconnectfromlocalhost)[ndb_mgmd(MGM)]1node(s)id=1@localhost(mysql-5.1.34ndb-7.0.6)[mysqld(API)]3node(s)id=4(notconnected,acceptingconnectfromlocalhost)id=5(notconnected,acceptingconnectfromlocalhost)id=6(notconnected,acceptingconnectfromlocalhost)
初始化数据节点
bin/ndbd--initial-clocalhost:11862009-06-2123:13:19[ndbd]INFO--Configurationfetchedfrom'localhost:1186',generation:1bin/ndbd--initial-clocalhost:11862009-06-2123:13:50[ndbd]INFO--Configurationfetchedfrom'localhost:1186',generation:1
启动SQL节点
bin/mysqld--defaults-file=conf/my1.cnf&[1]1784309062123:14:36[Warning]Noargumentwasprovidedto--log-bin,and--log-bin-indexwasnotused;soreplicationmaybreakwhenthisMySQLserveractsasamasterandhashishostnamechanged!!Pleaseuse'--log-bin=test-bin'toavoidthisproblem.InnoDB:Thefirstspecifieddatafile./ibdata1didnotexist:InnoDB:anewdatabasetobecreated!09062123:14:36InnoDB:Settingfile./ibdata1sizeto10MBInnoDB:Databasephysicallywritesthefilefull:wait...09062123:14:36InnoDB:Logfile./ib_logfile0didnotexist:newtobecreatedInnoDB:Settinglogfile./ib_logfile0sizeto5MBInnoDB:Databasephysicallywritesthefilefull:wait...09062123:14:36InnoDB:Logfile./ib_logfile1didnotexist:newtobecreatedInnoDB:Settinglogfile./ib_logfile1sizeto5MBInnoDB:Databasephysicallywritesthefilefull:wait...InnoDB:Doublewritebuffernotfound:creatingnewInnoDB:DoublewritebuffercreatedInnoDB:CreatingforeignkeyconstraintsystemtablesInnoDB:Foreignkeyconstraintsystemtablescreated09062123:14:36InnoDB:Started;logsequencenumber0009062123:14:36[Note]NDB:NodeIDis4,managementserver'localhost:1186'09062123:14:37[Note]NDB[0]:NodeID:4,allstoragenodesconnected09062123:14:37[Note]StartingClusterBinlogThread09062123:14:37[Note]EventScheduler:Loaded0events09062123:14:37[Note]bin/mysqld:readyforconnections.Version:'5.1.34-ndb-7.0.6-cluster-gpl-log'socket:'/tmp/mysql.sock'port:9306MySQLClusterServer(GPL)09062123:14:38[Note]NDBBinlog:Ndbtablesinitiallyreadonly.09062123:14:38[Note]NDB:Creatingmysql.ndb_schema09062123:14:38[Note]NDBBinlog:CREATETABLEEvent:REPL$mysql/ndb_schema09062123:14:38[Note]NDBBinlog:logging./mysql/ndb_schema(UPDATED,USE_WRITE)09062123:14:38[Note]NDB:Creatingmysql.ndb_apply_status09062123:14:39[Note]NDBBinlog:CREATETABLEEvent:REPL$mysql/ndb_apply_status09062123:14:39[Note]NDBBinlog:logging./mysql/ndb_apply_status(UPDATED,USE_WRITE)2009-06-2123:14:39[NdbApi]INFO--FlushingincompleteGCI:s<20/32009-06-2123:14:39[NdbApi]INFO--FlushingincompleteGCI:s<20/309062123:14:39[Note]NDBBinlog:startinglogatepoch20/309062123:14:39[Note]NDBBinlog:ndbtableswritable
bin/mysqld--defaults-file=conf/my2.cnf&bin/mysqld--defaults-file=conf/my3.cnf&
查看cluster
bin/ndb_mgm--NDBCluster--ManagementClient--ndb_mgm>showConnectedtoManagementServerat:localhost:1186ClusterConfiguration---------------------[ndbd(NDB)]2node(s)id=2@127.0.0.1(mysql-5.1.34ndb-7.0.6,Nodegroup:0,Master)id=3@127.0.0.1(mysql-5.1.34ndb-7.0.6,Nodegroup:0)[ndb_mgmd(MGM)]1node(s)id=1@127.0.0.1(mysql-5.1.34ndb-7.0.6)[mysqld(API)]3node(s)id=4@127.0.0.1(mysql-5.1.34ndb-7.0.6)id=5@127.0.0.1(mysql-5.1.34ndb-7.0.6)id=6@127.0.0.1(mysql-5.1.34ndb-7.0.6)
创建测试表
bin/mysql-uroot-hlocalhost-P9306--socket=/tmp/mysql.sockWelcometotheMySQLmonitor.Commandsendwith;org.YourMySQLconnectionidis2Serverversion:5.1.34-ndb-7.0.6-cluster-gpl-logMySQLClusterServer(GPL)Type'help;'or'h'forhelp.Type'c'toclearthecurrentinputstatement.root@(none)11:21:24>usetestDatabasechangedroot@test11:21:26>createtabletest_ndb(iint,avarchar(20),primarykey(i))engine=ndb;09062123:22:32[Note]NDBBinlog:CREATETABLEEvent:REPL$test/test_ndb09062123:22:32[Note]NDBBinlog:logging./test/test_ndb(UPDATED,USE_WRITE)09062123:22:32[Note]NDBBinlog:DISCOVERTABLEEvent:REPL$test/test_ndb09062123:22:32[Note]NDBBinlog:DISCOVERTABLEEvent:REPL$test/test_ndb09062123:22:32[Note]NDBBinlog:logging./test/test_ndb(UPDATED,USE_WRITE)09062123:22:32[Note]NDBBinlog:logging./test/test_ndb(UPDATED,USE_WRITE)QueryOK,0rowsaffected(1.10sec)root@test11:22:32>insertintotest_ndbvalues(1,'NinGoo');QueryOK,1rowaffected(0.02sec)[mysql@dbconsolemysql-cluster]$ls-ldata/data1/testtotal12-rw-rw----1mysqldba8578Jun2123:22test_ndb.frm-rw-rw----1mysqldba0Jun2123:22test_ndb.ndb[mysql@dbconsolemysql-cluster]$ls-ldata/data2/testtotal12-rw-rw----1mysqldba8578Jun2123:22test_ndb.frm-rw-rw----1mysqldba0Jun2123:22test_ndb.ndb[mysql@dbconsolemysql-cluster]$ls-ldata/data3/testtotal12-rw-rw----1mysqldba8578Jun2123:22test_ndb.frm-rw-rw----1mysqldba0Jun2123:22test_ndb.ndb$bin/mysql-uroot-P9307--socket=/tmp/mysql.sockWelcometotheMySQLmonitor.Commandsendwith;org.YourMySQLconnectionidis3Serverversion:5.1.34-ndb-7.0.6-cluster-gpl-logMySQLClusterServer(GPL)Type'help;'or'h'forhelp.Type'c'toclearthecurrentinputstatement.root@(none)11:24:38>usetestReadingtableinformationforcompletionoftableandcolumnnamesYoucanturnoffthisfeaturetogetaquickerstartupwith-ADatabasechangedroot@test11:24:41>select*fromtest_ndb;+---+--------+|i|a|+---+--------+|1|NinGoo|+---+--------+1rowinset(0.02sec)
以上是“如何在同一台主机配置MySQL Cluster”这篇文章的所有内容,感谢各位的阅读!相信大家都有了一定的了解,希望分享的内容对大家有所帮助,如果还想学习更多知识,欢迎关注亿速云行业资讯频道!
声明:本站所有文章资源内容,如无特殊说明或标注,均为采集网络资源。如若本站内容侵犯了原著者的合法权益,可联系本站删除。