程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 數據庫知識 >> MYSQL數據庫 >> 關於MYSQL數據庫 >> mysql集群 一

mysql集群 一

編輯:關於MYSQL數據庫
整體架構圖如下:
 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狀態。

    1. 上一頁:
    2. 下一頁:
    Copyright © 程式師世界 All Rights Reserved