這篇文章主要為大家展示了“如何在同一臺(tái)主機(jī)配置MySQL Cluster”,內(nèi)容簡(jiǎn)而易懂,條理清晰,希望能夠幫助大家解決疑惑,下面讓小編帶領(lǐng)大家一起研究并學(xué)習(xí)一下“如何在同一臺(tái)主機(jī)配置MySQL Cluster”這篇文章吧。
創(chuàng)新互聯(lián)是一家專(zhuān)業(yè)提供上思企業(yè)網(wǎng)站建設(shè),專(zhuān)注與網(wǎng)站建設(shè)、成都網(wǎng)站制作、H5技術(shù)、小程序制作等業(yè)務(wù)。10年已為上思眾多企業(yè)、政府機(jī)構(gòu)等服務(wù)。創(chuàng)新互聯(lián)專(zhuān)業(yè)網(wǎng)絡(luò)公司優(yōu)惠進(jìn)行中。MySQL cluster是share nothing的集群,采用ndb存儲(chǔ)引擎,和Oracle的RAC采用集中存儲(chǔ)不同,是一種分布式的架構(gòu),所以可以很輕松的實(shí)現(xiàn)在同一臺(tái)主機(jī)上配置MySQL Cluster,相對(duì)RAC來(lái)說(shuō)要簡(jiǎn)單得多。
在MySQL Cluster中,有三種不同的節(jié)點(diǎn):
管理節(jié)點(diǎn):守護(hù)進(jìn)程為ndb_mgmd,用于管理cluster。
數(shù)據(jù)節(jié)點(diǎn): 守護(hù)進(jìn)程為ndbd,用于存放數(shù)據(jù)
SQL節(jié)點(diǎn):守護(hù)進(jìn)程為mysqld,就是一個(gè)MySQL實(shí)例,對(duì)外供客戶(hù)端連接訪問(wèn)數(shù)據(jù)。
本文將在一臺(tái)64位linux主機(jī)上同時(shí)配置上述三種節(jié)點(diǎn)。在實(shí)際生產(chǎn)環(huán)境中,根據(jù)需要,可以在相同或者不同的機(jī)器部署節(jié)點(diǎn)。本次實(shí)例中共包含以下節(jié)點(diǎn):
一個(gè)管理節(jié)點(diǎn)
兩個(gè)數(shù)據(jù)節(jié)點(diǎn)
三個(gè)SQL節(jié)點(diǎn)
下載Mysql cluster,當(dāng)前版本7.0.6,/tupian/20230522/ppretar zxvf mysql-cluster-gpl-7.0.6-linux-x86_64-glibc23.tar.gz cp mysql-cluster-gpl-7.0.6-linux-x86_64-glibc23 /u01/mysql-cluster cd /u01/mysql-cluster
創(chuàng)建三個(gè)MySQL實(shí)例的數(shù)據(jù)目錄
mkdir data/data1 mkdir data/data2 mkdir data/data3 mkdir data/data1/mysql mkdir data/data1/test mkdir data/data2/mysql mkdir data/data2/test mkdir data/data3/mysql mkdir data/data3/test
Cluster配置文件如下
$ more conf/config.ini [ndbd default] noofreplicas=2 [ndbd] hostname=localhost id=2 [ndbd] hostname=localhost id=3 [ndb_mgmd] id = 1 hostname=localhost [mysqld] id=4 hostname=localhost [mysqld] id=5 hostname=localhost [mysqld] id=6 hostname=localhost
三個(gè)MySQL實(shí)例配置文件如下
$ more conf/my1.cnf [mysqld] ndb-nodeid=4 ndbcluster=true datadir=/u01/mysql-cluster/data/data1 basedir=/u01/mysql-cluster port=9306 server-id=1 log-bin $ more conf/my2.cnf [mysqld] ndb-nodeid=5 ndbcluster=true datadir=/u01/mysql-cluster/data/data2 basedir=/u01/mysql-cluster port=9307 server-id=2 log-bin $ more conf/my3.cnf [mysqld] ndb-nodeid=6 ndbcluster=true datadir=/u01/mysql-cluster/data/data3 basedir=/u01/mysql-cluster port=9308 server-id=3 log-bin
初始化三個(gè)MySQL實(shí)例
script/mysql_install_db --basedir=/u01/mysql-cluster --datadir=/u01/mysql-cluster/data/data1 script/mysql_install_db --basedir=/u01/mysql-cluster --datadir=/u01/mysql-cluster/data/data2 script/mysql_install_db --basedir=/u01/mysql-cluster --datadir=/u01/mysql-cluster/data/data3
初始化管理節(jié)點(diǎn)
bin/ndb_mgmd --initial -f conf/config.ini --configdir=/u01/mysql-cluster
進(jìn)入管理節(jié)點(diǎn)查看配置
$ bin/ndb_mgm -- NDB Cluster -- Management Client -- ndb_mgm> help --------------------------------------------------------------------------- NDB Cluster -- Management Client -- Help --------------------------------------------------------------------------- HELP Print help text HELP COMMAND Print detailed help for COMMAND(e.g. SHOW) SHOW Print information about cluster CREATE NODEGROUP,... Add a Nodegroup containing nodes DROP NODEGROUPDrop nodegroup with id NG START BACKUP [NOWAIT | WAIT STARTED | WAIT COMPLETED] START BACKUP [] [NOWAIT | WAIT STARTED | WAIT COMPLETED] START BACKUP [] [SNAPSHOTSTART | SNAPSHOTEND] [NOWAIT | WAIT STARTED | WAIT COMPLETED] Start backup (default WAIT COMPLETED,SNAPSHOTEND) ABORT BACKUPAbort backup SHUTDOWN Shutdown all processes in cluster CLUSTERLOG ON [] ... Enable Clus= ALERT | CRITICAL | ERROR | WARNING | INFO | DEBUG= STARTUP | SHUTDOWN | STATISTICS | CHECKPOINT | NODERESTART | CONNECTION | INFO | ERROR | CONGESTION | DEBUG | BACKUP= 0 - 15= ALL | Any database node id For detailed help on COMMAND, use HELP COMMAND. ndb_mgm> show Connected to Management Server at: localhost:1186 Cluster Configuration --------------------- [ndbd(NDB)] 2 node(s) id=2 (not connected, accepting connect from localhost) id=3 (not connected, accepting connect from localhost) [ndb_mgmd(MGM)] 1 node(s) id=1 @localhost (mysql-5.1.34 ndb-7.0.6) [mysqld(API)] 3 node(s) id=4 (not connected, accepting connect from localhost) id=5 (not connected, accepting connect from localhost) id=6 (not connected, accepting connect from localhost)
初始化數(shù)據(jù)節(jié)點(diǎn)
bin/ndbd --initial -c localhost:1186 2009-06-21 23:13:19 [ndbd] INFO -- Configuration fetched from 'localhost:1186', generation: 1 bin/ndbd --initial -c localhost:1186 2009-06-21 23:13:50 [ndbd] INFO -- Configuration fetched from 'localhost:1186', generation: 1
啟動(dòng)SQL節(jié)點(diǎn)
bin/mysqld --defaults-file=conf/my1.cnf& [1] 17843 090621 23:14:36 [Warning] No argument was provided to --log-bin, and --log-bin-index was not used; so replication may break when this MySQL server acts as a master and has his hostname changed!! Please use '--log-bin=test-bin' to avoid this problem. InnoDB: The first specified data file ./ibdata1 did not exist: InnoDB: a new database to be created! 090621 23:14:36 InnoDB: Setting file ./ibdata1 size to 10 MB InnoDB: Database physically writes the file full: wait... 090621 23:14:36 InnoDB: Log file ./ib_logfile0 did not exist: new to be created InnoDB: Setting log file ./ib_logfile0 size to 5 MB InnoDB: Database physically writes the file full: wait... 090621 23:14:36 InnoDB: Log file ./ib_logfile1 did not exist: new to be created InnoDB: Setting log file ./ib_logfile1 size to 5 MB InnoDB: Database physically writes the file full: wait... InnoDB: Doublewrite buffer not found: creating new InnoDB: Doublewrite buffer created InnoDB: Creating foreign key constraint system tables InnoDB: Foreign key constraint system tables created 090621 23:14:36 InnoDB: Started; log sequence number 0 0 090621 23:14:36 [Note] NDB: NodeID is 4, management server 'localhost:1186' 090621 23:14:37 [Note] NDB[0]: NodeID: 4, all storage nodes connected 090621 23:14:37 [Note] Starting Cluster Binlog Thread 090621 23:14:37 [Note] Event Scheduler: Loaded 0 events 090621 23:14:37 [Note] bin/mysqld: ready for connections. Version: '5.1.34-ndb-7.0.6-cluster-gpl-log' socket: '/tmp/mysql.sock' port: 9306 MySQL Cluster Server (GPL) 090621 23:14:38 [Note] NDB Binlog: Ndb tables initially read only. 090621 23:14:38 [Note] NDB: Creating mysql.ndb_schema 090621 23:14:38 [Note] NDB Binlog: CREATE TABLE Event: REPL$mysql/ndb_schema 090621 23:14:38 [Note] NDB Binlog: logging ./mysql/ndb_schema (UPDATED,USE_WRITE) 090621 23:14:38 [Note] NDB: Creating mysql.ndb_apply_status 090621 23:14:39 [Note] NDB Binlog: CREATE TABLE Event: REPL$mysql/ndb_apply_status 090621 23:14:39 [Note] NDB Binlog: logging ./mysql/ndb_apply_status (UPDATED,USE_WRITE) 2009-06-21 23:14:39 [NdbApi] INFO -- Flushing incomplete GCI:s < 20/3 2009-06-21 23:14:39 [NdbApi] INFO -- Flushing incomplete GCI:s < 20/3 090621 23:14:39 [Note] NDB Binlog: starting log at epoch 20/3 090621 23:14:39 [Note] NDB Binlog: ndb tables writable
bin/mysqld --defaults-file=conf/my2.cnf& bin/mysqld --defaults-file=conf/my3.cnf&
查看cluster
bin/ndb_mgm -- NDB Cluster -- Management Client -- ndb_mgm> show Connected to Management Server at: localhost:1186 Cluster Configuration --------------------- [ndbd(NDB)] 2 node(s) id=2 @127.0.0.1 (mysql-5.1.34 ndb-7.0.6, Nodegroup: 0, Master) id=3 @127.0.0.1 (mysql-5.1.34 ndb-7.0.6, Nodegroup: 0) [ndb_mgmd(MGM)] 1 node(s) id=1 @127.0.0.1 (mysql-5.1.34 ndb-7.0.6) [mysqld(API)] 3 node(s) id=4 @127.0.0.1 (mysql-5.1.34 ndb-7.0.6) id=5 @127.0.0.1 (mysql-5.1.34 ndb-7.0.6) id=6 @127.0.0.1 (mysql-5.1.34 ndb-7.0.6)
創(chuàng)建測(cè)試表
bin/mysql -uroot -h localhost -P 9306 --socket=/tmp/mysql.sock Welcome to the MySQL monitor. Commands end with ; or g. Your MySQL connection id is 2 Server version: 5.1.34-ndb-7.0.6-cluster-gpl-log MySQL Cluster Server (GPL) Type 'help;' or 'h' for help. Type 'c' to clear the current input statement. root@(none) 11:21:24>use test Database changed root@test 11:21:26>create table test_ndb(i int,a varchar(20),primary key(i)) engine=ndb; 090621 23:22:32 [Note] NDB Binlog: CREATE TABLE Event: REPL$test/test_ndb 090621 23:22:32 [Note] NDB Binlog: logging ./test/test_ndb (UPDATED,USE_WRITE) 090621 23:22:32 [Note] NDB Binlog: DISCOVER TABLE Event: REPL$test/test_ndb 090621 23:22:32 [Note] NDB Binlog: DISCOVER TABLE Event: REPL$test/test_ndb 090621 23:22:32 [Note] NDB Binlog: logging ./test/test_ndb (UPDATED,USE_WRITE) 090621 23:22:32 [Note] NDB Binlog: logging ./test/test_ndb (UPDATED,USE_WRITE) Query OK, 0 rows affected (1.10 sec) root@test 11:22:32>insert into test_ndb values(1,'NinGoo'); Query OK, 1 row affected (0.02 sec) [mysql@dbconsole mysql-cluster]$ ls -l data/data1/test total 12 -rw-rw---- 1 mysql dba 8578 Jun 21 23:22 test_ndb.frm -rw-rw---- 1 mysql dba 0 Jun 21 23:22 test_ndb.ndb [mysql@dbconsole mysql-cluster]$ ls -l data/data2/test total 12 -rw-rw---- 1 mysql dba 8578 Jun 21 23:22 test_ndb.frm -rw-rw---- 1 mysql dba 0 Jun 21 23:22 test_ndb.ndb [mysql@dbconsole mysql-cluster]$ ls -l data/data3/test total 12 -rw-rw---- 1 mysql dba 8578 Jun 21 23:22 test_ndb.frm -rw-rw---- 1 mysql dba 0 Jun 21 23:22 test_ndb.ndb $ bin/mysql -uroot -P 9307 --socket=/tmp/mysql.sock Welcome to the MySQL monitor. Commands end with ; or g. Your MySQL connection id is 3 Server version: 5.1.34-ndb-7.0.6-cluster-gpl-log MySQL Cluster Server (GPL) Type 'help;' or 'h' for help. Type 'c' to clear the current input statement. root@(none) 11:24:38>use test Reading table information for completion of table and column names You can turn off this feature to get a quicker startup with -A Database changed root@test 11:24:41>select * from test_ndb; +---+--------+ | i | a | +---+--------+ | 1 | NinGoo | +---+--------+ 1 row in set (0.02 sec)
以上是“如何在同一臺(tái)主機(jī)配置MySQL Cluster”這篇文章的所有內(nèi)容,感謝各位的閱讀!相信大家都有了一定的了解,希望分享的內(nèi)容對(duì)大家有所幫助,如果還想學(xué)習(xí)更多知識(shí),歡迎關(guān)注創(chuàng)新互聯(lián)-成都網(wǎng)站建設(shè)公司行業(yè)資訊頻道!