rss· 投稿· 设为首页· 加入收藏· 繁體版
当前位置: 火魔网 » 数据库 » MySQL

mysql集群 一

[From: http://www.bsdlover.cn/html/01/n-301.html] 整体架构图如下:
 mysql集群 一mysql集群架构主要分为:数据节点(ndbd),管理节点(mgmd),服务节点(mysqld)BSD爱好者乐园 B8p4t f/j U E T
BSD爱好者乐园 E ` l d J V/h p M
1. 下载:http://dev.mysql.com/downloads/mysql/5.0.html#linux 可以从这里下载 mysql-5.0.45-linux-i686.tar.gzBSD爱好者乐园%Z q B S k [ a ~ x8D/g1P(F l8u$a此包里已经包含了mysql-max包(mysql集群需要安装mysql-max包)。BSD爱好者乐园 C t ` @ K o*c X
BSD爱好者乐园 c Y9z l V&c"u M } b
2. 解压:BSD爱好者乐园 ~ k1F!g t&A'e [
tar -zxvf apache-tomcat-5.5.25.tar.gz
Q-N w(b h X o X { | x

[ o E4g*|#B O x,s下载的这个.tar.gz是编译后的文件,只需要解压即可。
M%_ t;s k Q l0`2F R GBSD爱好者乐园(t K t m N P1k
3. 配置BSD爱好者乐园 B n N w/{ l:y s ^
比如解压后的文件都放在:/home/mahaibo/mysql-5.0.45-linux-i686目录下。BSD爱好者乐园;u ` q%v U j u r"D"U h }数据节点(ndbd),管理节点(mgmd),服务节点(mysqld) 三个启动顺序是BSD爱好者乐园 B5P q6M$e \0l s*O
BSD爱好者乐园 A8Y B1o1T B$q6m
mgmd ---> ndbd ---> mysqld
J P p r/H,R8q ^
l&b l r T可以在同一台电脑上做个简单的配置和测试。以在同一台电脑上不同端口为例。实际中肯定是需要分布在不同的服务器上的。
/u q&w u ^ E6y/t7h d
+? C:`'V3@2@,~"F%ZA: 配置mgmd,并启动BSD爱好者乐园)K)a!x*n1O.f+Y r.p U
BSD爱好者乐园 ^ i1L u C6O:J
在/home/mahaibo/mysql-5.0.45-linux-i686建立一个mgmd.cnf和mgmd的数据目录mgmddata ,编辑mgmd.cnf文件:

L+V _ C"p N7y
  •   
  • # Options affecting ndbd processes on all data nodes:   
  • [NDBD DEFAULT]       
  • NoOfReplicas=1     # Number of replicas   
  • DataMemory=80M     # How much memory to allocate for data storage   
  • IndexMemory=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 hostname   
  • datadir=/home/mahaibo/mysql-5.0.45-linux-i686/mgmddata   # Directory for MGM node logfiles   
  • PortNumber=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 access   
  • datadir=/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 address   
  • datadir=/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)  
  • # Options affecting ndbd processes on all data nodes: [NDBD DEFAULT]     NoOfReplicas=1    # Number of replicas DataMemory=80M    # How much memory to allocate for data storage IndexMemory=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 hostname datadir=/home/mahaibo/mysql-5.0.45-linux-i686/mgmddata  # Directory for MGM node logfiles PortNumber=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 access datadir=/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 address datadir=/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)

    3^ l z J6E6q"I _可以看到配置了2个数据节点ndbd,也就是说改管理节点可以管理小于或等于2个数据节点。管理节点mgmd的端口为2203。
    }!U ^ r%@(eBSD爱好者乐园 y'C0~(t+b
    启动mgmd服务:

    !p d Y+r*u { I3w v N
  • bin/ndb_mgmd -f mgmd.cnf   
  • bin/ndb_mgmd -f mgmd.cnf
    BSD爱好者乐园,O U n x p7P c

    K s D"g ? l r启动后,登录mgmd的客户端mgm可以查看具体信息:

    C8t!c)k3E ?
  • bin/ndb_mgm 127.0.0.1 2203 //因为mgmd服务用的端口是2203,所以要通过该端口链接  
  • 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> show   
  • Connected to Management Server at: 127.0.0.1:2203  
  • Cluster 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>   
  • [mahaibo@client mysql-5.0.45-linux-i686]$ bin/ndb_mgm 127.0.0.1 2203 -- NDB Cluster -- Management Client -- ndb_mgm> show Connected to Management Server at: 127.0.0.1:2203 Cluster 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>
    BSD爱好者乐园5g V*t8g/C6b2S,s+?
    可以看到ndbd和mysqld都是not connected状态,因为这2个服务都还没有启动。
    2h l x2E:P/m E J N
    #K @ K&C'q u5{
    f%^)N j R A T M @.{"? JB: 启动数据节点(ndbd)BSD爱好者乐园 p-| b-k9P \"N R @%F9O s V x以启动2个数据节点为例。
    9z0| j0G;z*D
    f g a&n0F7{分别建立ndbd1.cnf ,ndbd1data数据目录
    A e d&{0z.j
    E.x:e b g*|1u编辑ndbd1.cnf:
  • [mysqld]   
  • DataDir=/home/mahaibo/mysql-5.0.45-linux-i686/ndbd1data//数据目录  
  • skip-locking   
  • key_buffer = 16M   
  • max_allowed_packet = 1M   
  • table_cache = 64  
  • sort_buffer_size = 512K   
  • net_buffer_length = 8K   
  • read_buffer_size = 256K   
  • read_rnd_buffer_size = 512K   
  • myisam_sort_buffer_size = 8M   
  •   
  • ndbcluster   
  • ndb-connectstring=127.0.0.1:2203  
  • [mysql_cluster]   
  • ndb-connectstring=127.0.0.1:2203 // 连接mgmd服务的ip与端口  
  • [mysqld] DataDir=/home/mahaibo/mysql-5.0.45-linux-i686/ndbd1data//数据目录 skip-locking key_buffer = 16M max_allowed_packet = 1M table_cache = 64 sort_buffer_size = 512K net_buffer_length = 8K read_buffer_size = 256K read_rnd_buffer_size = 512K myisam_sort_buffer_size = 8M  ndbcluster ndb-connectstring=127.0.0.1:2203 [mysql_cluster] ndb-connectstring=127.0.0.1:2203 // 连接mgmd服务的ip与端口

    y1v m S g T i启动第一个ndbd数据节点

    k Y z q ~4}7_ M
  • bin/ndbd --defaults-file=ndbd1.cnf --initial  
  • bin/ndbd --defaults-file=ndbd1.cnf --initial
    BSD爱好者乐园 m ~3R0b V

    D4f n A:h9n i第一次启动需要加--initial参数。BSD爱好者乐园 j F#N e*Y%E J ~ ^ k(T v @+M T @ ]第2个数据节点(ndbd)也需要做同样的配置和启动操作。分别建立ndbd2.cnf ,ndbd2data数据目录BSD爱好者乐园 t O C A)D X b
    ndbd2.cnf的配置和ndbd1.cnf的配置几乎是一样的,只是数据目录不一样。BSD爱好者乐园#d _ O k @'V;i
    启动第2个数据节点ndbd:BSD爱好者乐园4c w q P ^ s+y [(E

  • bin/ndbd --defaults-file=ndbd2.cnf --initial  
  • bin/ndbd --defaults-file=ndbd2.cnf --initial
    BSD爱好者乐园0t-} K b(M P

    u a-P P"}这时,如果登录到mgmd管理节点的客户端mgm,BSD爱好者乐园2t A w&g }6|+G n w$n

  • [mahaibo@client mysql-5.0.45-linux-i686]$ bin/ndb_mgm 127.0.0.1 2203  
  • -- NDB Cluster -- Management Client --   
  • ndb_mgm> show   
  • Connected to Management Server at: 127.0.0.1:2203  
  • Cluster 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>   
  • [mahaibo@client mysql-5.0.45-linux-i686]$ bin/ndb_mgm 127.0.0.1 2203 -- NDB Cluster -- Management Client -- ndb_mgm> show Connected to Management Server at: 127.0.0.1:2203 Cluster 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>

    ~/s } z5X A V可以看到ndbd的2个节点都是连接状态了,而不是not connected状态了,但是mysqld还是not connected状态。
    A.I I4| BBSD爱好者乐园"B G k ^ w/

    顶一下
    (0)
    踩一下
    (0)