MySQL Cluster

    版本為 20:35, 20 Nov 2024

    到這個版本。

    返回到 版本存檔.

    查閱目前版本

    前言

     

    實做環境介紹
    node ip address package process
    Management & SQL node 10.10.10.131 MySQL-server-community-5.0.67-0.rhel5
    MySQL-client-community-5.0.67-0.rhel5
    MySQL-clustertools-community-5.0.67-0.rhel5
    MySQL-clustermanagement-community-5.0.67-0.rhel5
    ndb_mgmd & ndb_mgm(for Mgm node)
    mysqld(for SQL node)
    data node #1 10.10.10.132 MySQL-clusterstorage-community-5.0.67-0.rhel5 ndbd
    data node #2 10.10.10.133 MySQL-clusterstorage-community-5.0.67-0.rhel5 ndbd

    架構示意圖如下,圖片引用自官方網站的資料,圖示內的 IP 請以上述表格所列的為主,而且本篇實作將 Management node 和 SQL node 裝在同一台,與下圖有些不同。

    multi-comp-1.png

     

    安裝設定 Management & SQL node

    到官方下載需要的套件檔,請參考上方表格的內容。
    MySQL-5.0.67 MySQL-6.3.20

    rpm -ivh MySQL-client-community-5.0.67-0.rhel5.i386.rpm
    rpm -ivh MySQL-shared-compat-5.0.67-0.rhel5.i386.rpm
    rpm -ivh MySQL-devel-community-5.0.67-0.rhel5.i386.rpm
    rpm -ivh MySQL-server-community-5.0.67-0.rhel5.i386.rpm
    

    以上套件是 SQL node 會用到的

    rpm -ivh perl-HTML-Template-2.9-1.el5.rf.noarch.rpm
    rpm -ivh MySQL-clustermanagement-community-5.0.67-0.rhel5.i386.rpm
    rpm -ivh MySQL-clustertools-community-5.0.67-0.rhel5.i386.rpm
    

    以上套件是 Management node 會用到,其中 perl-HTML-Template 不在官方網站的下載連結,請自行用 Google 搜尋。

    新增設定檔:

    /etc/my.cnf (SQL node 會用到)

    # Options for mysqld process:
    
    [MYSQLD]
    ndbcluster                      # run NDB engine
    ndb-connectstring=10.10.10.131  # location of MGM node
    
    # Options for ndbd process:
    
    [MYSQL_CLUSTER]
    ndb-connectstring=10.10.10.131  # location of MGM node
    

    /var/lib/mysql-cluster/config.ini (Management node 會用到)

    # Options affecting ndbd processes on all data nodes:
    [NDBD DEFAULT]
    NoOfReplicas=2    # Number of replicas
    DataMemory=256M    # 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=10.10.10.131           # Hostname or IP address of MGM node
    datadir=/var/lib/mysql-cluster  # Directory for MGM node logfiles
    
    # Options for data node "A":
    [NDBD]
    # (one [NDBD] section per data node)
    hostname=10.10.10.132           # Hostname or IP address
    datadir=/mysql-data             # Directory for this data node's datafiles
    
    # Options for data node "B":
    [NDBD]
    hostname=10.10.10.133     # Hostname or IP address
    datadir=/mysql-data       # Directory for this data node's datafiles
    
    # SQL node options:
    [MYSQLD]
    hostname=10.10.10.131       # Hostname or IP address
                                # (additional mysqld connections can be
                                # specified for this node for various
                                # purposes such as running ndb_restore)


    安裝設定 Data node

    到官方下載需要的套件檔,請參考上方表格的內容。
    MySQL-5.0.67 MySQL-6.3.20

    rpm -ivh MySQL-clusterstorage-community-5.0.67-0.rhel5.i386.rpm
    

    新增設定檔
    /etc/my.cnf

    # Options for mysqld process:
    [MYSQLD]
    ndbcluster                      # run NDB engine
    ndb-connectstring=10.10.10.131  # location of MGM node
    
    # Options for ndbd process:
    [MYSQL_CLUSTER]
    ndb-connectstring=10.10.10.131  # location of MGM node


     

    第一次啟動作初使化

    先啟動 Managemnet console,登入 Management & SQL node,執行

    nbd_mgmd -f /var/lib/mysql-cluster/config.ini
    

    在 data node #1 及 #2,分別執行

    ndbd --initial
    

    注意,第一次執行時才需要加上 --initial,爾後啟動時,就不能在加此參數,除非是要重新作初始化。

    在 Management & SQL node 啟動 MySQL
    service mysql stop
    service mysql start

    在 Management node 可以檢查 Cluster 狀態,執行

    ndb_mgm
    >show
    Connected to Management Server at: 10.10.10.131:1186
    Cluster Configuration
    ---------------------
    [ndbd(NDB)]     2 node(s)
    id=2    @10.10.10.132  (Version: 5.0.67, Nodegroup: 0)
    id=3    @10.10.10.133  (Version: 5.0.67, Nodegroup: 0, Master)

    [ndb_mgmd(MGM)] 1 node(s)
    id=1    @10.10.10.131  (Version: 5.0.67)

    [mysqld(API)]   1 node(s)
    id=4    @10.10.10.131  (Version: 5.0.67)


    >all status
    Node 2: started (Version 5.0.67)
    Node 3: started (Version 5.0.67)

    My Tips:

    • data-node 狀態要顯示 started 才算成功,如果是 starting,表示尚未啟動完成。
    • 由於 config.ini 設定 NoOfReplicas=2,所以要啟動兩個 data-node 才會顯示狀態為 started。
    • 若 mysqld(API) 無法連接,請檢查 SQL node 的 MySQL 服務程序。

     

     

    參考連結

    MySQL Cluster 叢集安裝環境介紹
    http://www.neo.com.tw/archives/869

    MySQL 5.0 FAQ — MySQL Cluster
    http://dev.mysql.com/doc/refman/5.0/...item-23-10-1-1

    MySQL Cluster Overview
    http://dev.mysql.com/doc/refman/5.0/...-overview.html

    MySQL Cluster Multi-Computer How-To
    http://dev.mysql.com/doc/refman/5.0/...-computer.html

    MySQL Cluster Multi-Computer Configuration
    http://dev.mysql.com/doc/refman/5.0/...ti-config.html

    Safe Shutdown and Restart of MySQL Cluster
    http://dev.mysql.com/doc/refman/5.0/...n-restart.html

    MySQL叢集
    http://twpug.net/docs/mysql-5.1/ndbcluster.html

    MySQL Cluster學習筆記-1
    http://www.ithome.com.tw/plog/index....015&blogId=257

    MySQL Cluster學習筆記-2
    http://www.ithome.com.tw/plog/index....176&blogId=257

    MySQL Forums :: Cluster :: API not connecting to ndb_mgm
    http://forums.mysql.com/read.php?25,182996,182996

     

    Powered by MindTouch Core