MySQL叢集安裝與配置

來源:互聯網
上載者:User

標籤:des   http   os   io   使用   strong   ar   for   檔案   

MySQL叢集安裝與配置 文章目錄[隱藏]
  • 一、mysql叢集安裝
  • 二、節點配置
  • 三、初次開機節點
  • 四、測試服務是否正常
  • 五、安全關閉和重啟

MySQL Cluster 是 MySQL 適合於分散式運算環境的高實用、高冗餘版本。它採用了NDB Cluster 儲存引擎,允許在1個 Cluster 中運行多個MySQL伺服器。MySQL Cluster 能夠使用多種故障切換和Server Load Balancer選項配置NDB儲存引擎,但在 Cluster 層級上的儲存引擎上做這個最簡單。下面我們簡單介紹MySQL Cluster如何安裝與配置。
基本設定
管理(MGM)節點:192.168.0.111
MySQL伺服器(SQL)節點:192.168.0.110
資料(NDBD)節點"A":192.168.0.112
資料(NDBD)節點"B":192.168.0.113

一、mysql叢集安裝

mysql的叢集安裝可以有三種方式,一是直接下載二進位使用,二是使用rpm安裝,三是源碼編譯。我們這裡使用第一種安裝。
1、每個節點做相同的操作

  1. cd /tmp
  2. wget http://cdn.mysql.com/Downloads/MySQL-Cluster-7.2/mysql-cluster-gpl-7.2.8-linux2.6-i686.tar.gz
  3. tar xzf mysql-cluster-gpl-7.2.8-linux2.6-i686.tar.gz
  4. mv mysql-cluster-gpl-7.2.8-linux2.6-i686 /usr/local/mysql

注意:這裡下載的是32位的二進位包,如果你的系統是64位,需要下載64位的包。
2、儲存節點和SQL節點安裝

  1. groupadd mysql
  2. useradd -g mysql mysql
  3. /usr/local/mysql/scripts/mysql_install_db --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --user=mysql
  4. chown -R root /usr/local/mysql
  5. chown -R mysql /usr/local/mysql/data
  6. chgrp -R mysql /usr/local/mysql
  7. cp /usr/local/mysql/support-files/my-medium.cnf /etc/my.cnf
二、節點配置

1、配置儲存節點和SQL節點

  1. vi /etc/my.cnf
  2. 類似於:
  3. # Options for mysqld process:
  4. [MYSQLD]                       
  5. ndbcluster                      # run NDB engine
  6. ndb-connectstring=198.168.0.111  # location of MGM node
  7.  
  8. # Options for ndbd process:
  9. [MYSQL_CLUSTER]                 
  10. ndb-connectstring=198.168.0.111  # location of MGM node

2、組態管理節點

  1. mkdir /var/lib/mysql-cluster
  2. cd /var/lib/mysql-cluster
  3. vi config.ini
  4.  
  5. config.ini檔案應類似於:
  6.  
  7. # Options affecting ndbd processes on all data nodes:
  8. [NDBD DEFAULT]   
  9. NoOfReplicas=2    # Number of replicas
  10. DataMemory=80M    # How much memory to allocate for data storage
  11. IndexMemory=18M   # How much memory to allocate for index storage
  12.                   # For DataMemory and IndexMemory, we have used the
  13.                   # default values. Since the "world" database takes up
  14.                   # only about 500KB, this should be more than enough for
  15.                   # this example Cluster setup.
  16.  
  17. # TCP/IP options:
  18. [TCP DEFAULT]     
  19. portnumber=2202   # This the default; however, you can use any
  20.                   # port that is free for all the hosts in cluster
  21.                   # Note: It is recommended beginning with MySQL 5.0 that
  22.                   # you do not specify the portnumber at all and simply allow
  23.                   # the default value to be used instead
  24.  
  25. # Management process options:
  26. [NDB_MGMD]                     
  27. hostname=198.168.0.111           # Hostname or IP address of MGM node
  28. datadir=/var/lib/mysql-cluster  # Directory for MGM node logfiles
  29.  
  30. # Options for data node "A":
  31. [NDBD]                         
  32.                                 # (one [NDBD] section per data node)
  33. hostname=198.168.0.112         # Hostname or IP address
  34. datadir=/usr/local/mysql/data   # Directory for this data node‘s datafiles
  35.  
  36. # Options for data node "B":
  37. [NDBD]                         
  38. hostname=198.168.0.113       # Hostname or IP address
  39. datadir=/usr/local/mysql/data   # Directory for this data node‘s datafiles
  40.  
  41. # SQL node options:
  42. [MYSQLD]                       
  43. hostname=198.168.0.110           # Hostname or IP address
  44.                                 # (additional mysqld connections can be
  45.                                 # specified for this node for various
  46.                                 # purposes such as running ndb_restore)
三、初次開機節點

1、啟動管理節點

  1. /usr/local/mysql/bin/ndb_mgmd --configdir=/var/lib/mysql-cluster -f /var/lib/mysql-cluster/config.ini

2、啟動資料節點
初次開機需要--initial參數初始化,下一次啟動就不需要了。

  1. /usr/local/mysql/bin/ndbd --initial

3、啟動SQL節點

  1. /usr/local/mysql/bin/mysqld_safe  &

4、檢查狀態
如果一切正常,執行命令 /usr/local/mysql/bin/ndb_mgm -e show應該會輸出類似資訊:

[[email protected] mysql-cluster]# /usr/local/mysql/bin/ndb_mgm -e show
Connected to Management Server at: localhost:1186
Cluster Configuration
---------------------
[ndbd(NDB)] 2 node(s)
id=2 @192.168.0.112 (mysql-5.5.27 ndb-7.2.8, Nodegroup: 0, Master)
id=3 @192.168.0.113 (mysql-5.5.27 ndb-7.2.8, Nodegroup: 0)

[ndb_mgmd(MGM)] 1 node(s)
id=1 @192.168.0.111 (mysql-5.5.27 ndb-7.2.8)

[mysqld(API)] 1 node(s)
id=4 @192.168.0.110 (mysql-5.5.27 ndb-7.2.8)

四、測試服務是否正常

在SQL節點上執行如下資料庫操作:

  1. /usr/local/mysql/bin/mysql -uroot -p
  2. mysql> create database clusterdb;use clusterdb;
  3. mysql> create table simples (id int not null primary key) engine=ndb;
  4. mysql> insert into simples values (1),(2),(3),(4);
  5. mysql> select * from simples;

如果出現:
+----+
| id |
+----+
| 1 |
| 2 |
| 4 |
| 3 |
+----+
則表示工作正常。

五、安全關閉和重啟

1、關閉mysql叢集,可在管理節點在執行如下命令:

  1. /usr/local/mysql/bin/ndb_mgm -e shutdown

2、重啟管理節點

  1. /usr/local/mysql/bin/ndb_mgmd --configdir=/var/lib/mysql-cluster -f /var/lib/mysql-cluster/config.ini

3、重啟資料節點

  1. /usr/local/mysql/bin/ndbd

參考:http://dev.mysql.com/doc/refman/5.1/zh/ndbcluster.html

 

轉載請標明文章來源:《https://www.centos.bz/2012/11/mysql-cluster-install-configure/》

MySQL叢集安裝與配置

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.