2013-02-06
Lu
上次安裝測試的MySQL Cluster 7.0.9 似乎是修改自 MySQL 5.1,這次安裝測試的 MySQL Cluster 7.2.10 是修改自 MySQL 5.5,一些套件整併了,某些舊套件不存在了
參考文件
Chapter 17. MySQL Cluster NDB 7.2
http://dev.mysql.com/doc/refman/5.5/en/mysql-cluster.html
http://dev.mysql.com/doc/refman/5.5/en/mysql-cluster-install-linux-rpm.html
[教學][研究] 4主機 MySQL Cluster 7.0.9 架設
http://forum.icst.org.tw/phpbb/viewtopic.php?f=10&t=17903
[教學][研究] 雙主機 MySQL Cluster 7.0.9架設
http://forum.icst.org.tw/phpbb/viewtopic.php?f=10&t=17904
---------------------------------------------------------------------------
一、概念說明
MySQL Cluster(叢集,大陸稱為 "集群" 或 "群集") 架構大致如下,此為官方網站的圖片,網址
http://dev.mysql.com/doc/refman/5.5/en/images/cluster-components-1.png
NDB 是 Network DataBase (網路資料庫)
MySQL Cluster中主機分三類
1. 管理主機 : 服務程式(Deamon) 稱為 ndb_mgmd (NDB Management Daemon的意思)
管理工具稱為 ndb_mgm (NDB Management 的意思),預設使用 Port 1186。
2. Data Node: 實際存放資料的主機 (Storage),服務程式稱為 ndbd (NDB Daemon的意思)。
3. SQL Node : 提供存取資料庫內容,服務程式稱為 mysqld (MySQL Deamon的意思)。
---------------------------------------------------------------------------
二、環境
Windows 2008 R2 + VMware Workstation 9.0.1 架設4台 VM,都安裝 CentOS 6.3 x64
centos1 eth0:192.168.128.101 (MGM Node)
centos2 eth0:192.168.128.102 (SQL Node)
centos2 eth0:192.168.128.103 (Data Node)
centos2 eth0:192.168.128.104 (Data Node)
CentOS 6.3 x64 在 600MB,無法用圖形模式安裝,也不會安裝 X Window
CentOS 6.3 x64 在 640MB,可用圖形模式安裝,會安裝 X Window
CentOS 6.3 x86 在 512MB,無法用圖形模式安裝,也不會安裝 X Window
VM 種類選 Red Hat Enterprise Linux 6 64-bit,記憶體設 640 MB
( 其實不管選 Red Hat Enterprise Linux 6 或 Red Hat Enterprise Linux 6 64-bit,VMware Workstation 9.0.1 建議的 RAM 是 2048 MB,但是小弟電腦總共只有 4GB )
---------------------------------------------------------------------------
三、套件下載
套件下載 (免費註冊登入後才能下載)
http://dev.mysql.com/downloads/cluster/#downloads
http://dev.mysql.com/get/Downloads/MySQL-Cluster-7.2/MySQL-Cluster-test-gpl-7.2.10-1.el6.x86_64.rpm/from/http://cdn.mysql.com/
http://dev.mysql.com/get/Downloads/MySQL-Cluster-7.2/MySQL-Cluster-test-gpl-7.2.10-1.el6.i686.rpm/from/http://cdn.mysql.com/
http://dev.mysql.com/get/Downloads/MySQL-Cluster-7.2/MySQL-Cluster-shared-gpl-7.2.10-1.el6.x86_64.rpm/from/http://cdn.mysql.com/
http://dev.mysql.com/get/Downloads/MySQL-Cluster-7.2/MySQL-Cluster-shared-gpl-7.2.10-1.el6.i686.rpm/from/http://cdn.mysql.com/
http://dev.mysql.com/get/Downloads/MySQL-Cluster-7.2/MySQL-Cluster-shared-compat-gpl-7.2.10-1.el6.x86_64.rpm/from/http://cdn.mysql.com/
http://dev.mysql.com/get/Downloads/MySQL-Cluster-7.2/MySQL-Cluster-shared-compat-gpl-7.2.10-1.el6.i686.rpm/from/http://cdn.mysql.com/
http://dev.mysql.com/get/Downloads/MySQL-Cluster-7.2/MySQL-Cluster-server-gpl-7.2.10-1.el6.x86_64.rpm/from/http://cdn.mysql.com/
http://dev.mysql.com/get/Downloads/MySQL-Cluster-7.2/MySQL-Cluster-server-gpl-7.2.10-1.el6.i686.rpm/from/http://cdn.mysql.com/
http://dev.mysql.com/get/Downloads/MySQL-Cluster-7.2/MySQL-Cluster-embedded-gpl-7.2.10-1.el6.x86_64.rpm/from/http://cdn.mysql.com/
http://dev.mysql.com/get/Downloads/MySQL-Cluster-7.2/MySQL-Cluster-embedded-gpl-7.2.10-1.el6.i686.rpm/from/http://cdn.mysql.com/
http://dev.mysql.com/get/Downloads/MySQL-Cluster-7.2/MySQL-Cluster-devel-gpl-7.2.10-1.el6.x86_64.rpm/from/http://cdn.mysql.com/
http://dev.mysql.com/get/Downloads/MySQL-Cluster-7.2/MySQL-Cluster-devel-gpl-7.2.10-1.el6.i686.rpm/from/http://cdn.mysql.com/
http://dev.mysql.com/get/Downloads/MySQL-Cluster-7.2/MySQL-Cluster-client-gpl-7.2.10-1.el6.x86_64.rpm/from/http://cdn.mysql.com/
http://dev.mysql.com/get/Downloads/MySQL-Cluster-7.2/MySQL-Cluster-client-gpl-7.2.10-1.el6.i686.rpm/from/http://cdn.mysql.com/
因為要登入後才能下載,下載速度請別太低,一旦登入時間 time out,下載會自動中斷
小弟下載的環境限制每個下載 session 只有 500 Kbits/s,下載最大的兩個檔案很容易發生下載被中斷的情況
MySQL-Cluster-server-gpl-7.2.10-1.el6.x86_64.rpm
MySQL-Cluster-server-gpl-7.2.10-1.el6.i686.rpm
下載後,可用 WinSCP 丟到 VM 中;或用 UltraISO 做成 .iso 檔案,掛載到 VMware 光碟機,然後用 mount 掛載到 Linux 上的 /media 目錄使用
---------------------------------------------------------------------------
四、安裝
為了省麻煩,防火牆先關閉,請把 SELinux 也關閉
要立刻關閉 SELinux (但 reboot 後仍會開啟)可執行 /usr/sbin/setenforce 0
要永久關閉,請修改 /etc/selinux/config
把 SELINUX=enforcing 改為 SELINUX=disabled
此修改不會立刻生效,要 reboot 才有效
CentOS 用 yum 安裝的 MySQL 是不能架設 Cluster 的,必須移除,
然後去 MySQL 官方網站註冊和下載 MySQL Cluster 使用的套件
(rpm 安裝和 tar.gz 安裝的很多路徑不同,如果使用非 rpm 請自己另外研究)
/usr/sbin/setenforce 0
sed -i -e "s@SELINUX=enforcing@#SELINUX=enforcing@" /etc/selinux/config sed -i -e "s@SELINUX=permissive@#SELINUX=permissive@" /etc/selinux/config sed -i -e "/SELINUX=/aSELINUX=disabled" /etc/selinux/config service iptables stop yum -y remove mysql* |
各Node基本需要的套件如下
MGM Node
rpm -Uhv MySQL-Cluster-server-gpl-7.2.10-1.el6.x86_64.rpm |
SQL Node
rpm -Uhv MySQL-Cluster-server-gpl-7.2.10-1.el6.x86_64.rpm rpm -Uhv MySQL-Cluster-client-gpl-7.2.10-1.el6.x86_64.rpm |
Data Node
rpm -Uhv MySQL-Cluster-server-gpl-7.2.10-1.el6.x86_64.rpm |
安裝情況
[root@localhost ~]# rpm -Uhv MySQL-Cluster-server-gpl-7.2.10-1.el6.x86_64.rpm Preparing... ########################################### [100%] 1:MySQL-Cluster-server-gp########################################### [100%] PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER ! To do so, start the server, then issue the following commands: /usr/bin/mysqladmin -u root password 'new-password' /usr/bin/mysqladmin -u root -h localhost.localdomain password 'new-password' Alternatively you can run: /usr/bin/mysql_secure_installation which will also give you the option of removing the test databases and anonymous user created by default. This is strongly recommended for production servers. See the manual for more instructions. Please report any problems with the /usr/bin/mysqlbug script! [root@localhost ~]# |
五、設定
參考
17.2.3. Initial Configuration of MySQL Cluster
http://dev.mysql.com/doc/refman/5.5/en/mysql-cluster-install-configuration.html
17.3.2.1. MySQL Cluster Configuration: Basic Example
http://dev.mysql.com/doc/refman/5.5/en/mysql-cluster-config-example.html
(1) 設定 Data Nodes 和 SQL Nodes
vi /etc/my.cnf |
內容 (要把 IP 改為自己環境的
[mysqld] # Options for mysqld process: ndbcluster # run NDB storage engine [mysql_cluster] # Options for MySQL Cluster processes: ndb-connectstring=192.168.128.101 # location of management server |
(2) 設定 MGM Node
mkdir /var/lib/mysql-cluster cd /var/lib/mysql-cluster vi config.ini |
內容 (要把 IP 改為自己環境的
[ndbd default] # Options affecting ndbd processes on all data nodes: NoOfReplicas=2 # 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 default] # TCP/IP options: portnumber=2202 # This the default; however, you can use any # port that is free for all the hosts in the cluster # Note: It is recommended that you do not specify the port # number at all and simply allow the default value to be used # instead [ndb_mgmd] # Management process options: hostname=192.168.0.101 # Hostname or IP address of MGM node datadir=/var/lib/mysql-cluster # Directory for MGM node log files [ndbd] # Options for data node "A": # (one [ndbd] section per data node) hostname=192.168.0.103 # Hostname or IP address datadir=/usr/local/mysql/data # Directory for this data node's data files [ndbd] # Options for data node "B": hostname=192.168.0.104 # Hostname or IP address datadir=/usr/local/mysql/data # Directory for this data node's data files [mysqld] # SQL node options: hostname=192.168.0.102 # Hostname or IP address # (additional mysqld connections can be # specified for this node for various # purposes such as running ndb_restore) |
---------------------------------------------------------------------------
六、啟動
17.2.4. Initial Startup of MySQL Cluster
http://dev.mysql.com/doc/refman/5.5/en/mysql-cluster-install-first-start.html
啟動 MySQL Cluster 順序: 首先啟動管理節點服務器(ndb_mgmd),然後啟動存儲節點服務器(ndbd),最後才啟動SQL節點服務器(service mysql start)
(1) MGM 主機上
ndb_mgmd -f /var/lib/mysql-cluster/config.ini --initial [root@localhost mysql-cluster]# ndb_mgmd -f /var/lib/mysql-cluster/config.ini MySQL Cluster Management Server mysql-5.5.29 ndb-7.2.10 2013-02-07 22:10:45 [MgmtSrvr] WARNING -- at line 13: [tcp] portnumber is deprecated [root@localhost mysql-cluster]# |
如果 config.ini 檔案有修改過,要加上 --initial 參數,否則可以不用加上。
(2) 啟動 Data Node (兩台都要做)
[root@localhost ~]# mkdir -p /usr/local/mysql/data/ [root@localhost ~]# ndbd 2013-02-07 22:12:57 [ndbd] INFO -- Angel connected to '192.168.128.101:1186' 2013-02-07 22:12:57 [ndbd] INFO -- Angel allocated nodeid: 2 [root@localhost ~]# |
[root@localhost ~]# mkdir -p /usr/local/mysql/data/ [root@localhost ~]# ndbd 2013-02-07 22:13:02 [ndbd] INFO -- Angel connected to '192.168.128.101:1186' 2013-02-07 22:13:07 [ndbd] INFO -- Angel allocated nodeid: 3 [root@localhost ~]# |
(3) 啟動 SQL Node
[root@localhost ~]# service mysql start Starting MySQL.... SUCCESS! [root@localhost ~]# |
(4) 檢查目前狀況
到 MGM 主機上檢查目前狀況
[root@localhost mysql-cluster]# 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 @192.168.128.103 (mysql-5.5.29 ndb-7.2.10, Nodegroup: 0, Master) id=3 @192.168.128.104 (mysql-5.5.29 ndb-7.2.10, Nodegroup: 0) [ndb_mgmd(MGM)] 1 node(s) id=1 @192.168.128.101 (mysql-5.5.29 ndb-7.2.10) [mysqld(API)] 1 node(s) id=4 @192.168.128.102 (mysql-5.5.29 ndb-7.2.10) ndb_mgm> [root@localhost mysql-cluster]# 按下 Ctrl-C 跳出 |
或
[root@localhost mysql-cluster]# ndb_mgm -e show Connected to Management Server at: localhost:1186 Cluster Configuration --------------------- [ndbd(NDB)] 2 node(s) id=2 @192.168.128.103 (mysql-5.5.29 ndb-7.2.10, Nodegroup: 0, Master) id=3 @192.168.128.104 (mysql-5.5.29 ndb-7.2.10, Nodegroup: 0) [ndb_mgmd(MGM)] 1 node(s) id=1 @192.168.128.101 (mysql-5.5.29 ndb-7.2.10) [mysqld(API)] 1 node(s) id=4 @192.168.128.102 (mysql-5.5.29 ndb-7.2.10) [root@localhost mysql-cluster]# |
停止 MySQL Cluster : 執行
ndb_mgm -e shuwdown |
[root@localhost mysql-cluster]# ndb_mgm -e SHUTDOWN Connected to Management Server at: localhost:1186 3 NDB Cluster node(s) have shutdown. Disconnecting to allow management server to shutdown. [root@localhost mysql-cluster]# |
在 SQL Node 上停止 mysqld 服務命令為 (其實 ndb_mgm -e showdown 就足夠讓 Cluster 幾乎停工)
[root@centos1 ~]# mysqladmin -u root shutdown |
資料庫的備份和還原請參考這篇 "七.測試"
[研究] 2主機 MySQL Cluster 7.2.10-1 架設
http://shaurong.blogspot.tw/2013/02/2-mysql-cluster-7210-1.html
---------------------------------------------------------------------------
附錄1:設定主機名稱
在 Server A 上執行 uname -n 或 hostname 可查詢目前的主機名稱是甚麼
[root@server1 ~]# uname -n server1 |
[root@server1 ~]# hostname server1 |
[root@server1 ~]# hostname mgm |
另外 vim /etc/hosts,增加
192.168.128.101 mgm |
(完)
沒有留言:
張貼留言