mysql集羣技術

1、環境描述
Mysql manager 節點:192.168.0.1
MysqlServer節點:192.168.0.100
Mysql 節點:192.168.0.160
Mysql 節點:192.168.0.161

說明:至少需要四臺服務器纔可以做mysql的集羣。建議5臺,再增加一臺MysqlServer。
2安裝mysql二進制包
2.1 安裝之前的準備工作
下載mysql-max-4.1.13-pc-linux-gnu-i686.tar.gz包
(注意:可以做集羣的mysql都是mysql-max的,下載地點www.mysql.org)
#groupadd mysql
#useradd -g mysql mysql
#cd /usr/local
#tar xfz mysql-max-4.1.13-pc-linux-gnu-i686.tar.gz
#ln -s /usr/local/mysql-max-4.1.13-pc-linux-gnu-i686 /opt/mysql4.1.13

2.2 分別在manager,server,node節點上安裝二進制的mysql包
#cd mysql4.1.13
#scripts/mysql_install_db --user=mysql (必須帶目錄執行,否則出錯)
#chown -R root /opt/mysql4.1.13
#chgrp -R mysql /opt/mysql4.1.13
#chown -R mysql.mysql /opt/mysql4.1.13/data
#cp support-files/mysql.server /etc/rc.d/init.d/ 配置mysql啓動設置
#chmod +x /etc/rc.d/init.d/mysql.server
#chkconfig --add mysql.server

3配置server,note節點
在192.168.0.160和192.168.0.161機器上
# ./mysql –help 該命令可以查看mysql啓動時是怎麼尋找my.cnf文件的順序。
Default options are read from the following files in the given order:
/etc/my.cnf /usr/local/mysql-max-4.1.13/data/my.cnf ~/.my.cnf
# cp support-files/my-medium.cnf data/my.cnf 將mysql的配置文件考到data下
Vi /usr/local/mysql-max-4.1.13-pc-linux-gnu-i686/data/my.cnf
[MYSQLD]
ndbcluster
ndb-connectstring=192.168.0.1
[MYSQL_CLUSTER]
ndb-connectstring=192.168.0.1

4配置Management管理節點
在192.168.0.1機器上
#mkdir /var/lib/mysql-cluster
#cd /var/lib/mysql-cluster
#vi config.ini
[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=52M # 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 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=192.168.0.1 # 管理節點Hostname or IP address of MGM node
datadir=/var/lib/mysql-cluster # Directory for MGM node logfiles
# Options for data node "A"(定義羣集數據節點.)
# (one [NDBD] section per data node)
[NDBD]
hostname=192.168.0.160 # 節點Hostname or IP address
datadir=/usr/local/mysql/data # Directory for this data node's datafiles
# Options for data node "B"(定義羣集數據節點.)
[NDBD]
hostname=192.168.0.161 # 節點Hostname or IP address
datadir=/usr/local/mysql/data # Directory for this data node's datafiles
# SQL node options(定義Sql server節點.)
[MYSQLD]
hostname=192.168.0.100 # SQL節點Hostname or IP address
#datadir=/usr/local/mysql/data # Directory for SQL node's datafiles
# (additional mysqld connections can be
# specified for this node for various
# purposes such as running ndb_restore)

[NDB_MGMD]:後面不能有任何註釋信息,否則提示:
Error line 17: [TCP] Unknown parameter: [NDB_MGMD] # Management process options
Error line 17: Could not parse name-value pair in config file.
[SHM]: Defines shared-memory connections between nodes. 在MySQL 4.1.9之前,這個功能必須使用--with-ndb-shm option編譯進去, 從MySQL 4.1.9-max版本開始, it is enabled by default

5啓動mysql集羣
5.1 初始化啓動mysql集羣服務
1)啓動MysqlManagement管理節點(192.168.0.1)
#ndb_mgmd -f /var/lib/mysql-cluster/config.ini
2)啓動Data Node節點(192.168.0.160,192.168.0.161)
#ndbd --initial
(注意:這個參數只能在第一次啓動DataNode節點時使用,因爲—initial參數會刪除一些ndbd 實例先前創建的所有文件)

3)啓動MysqlServer節點(192.168.0.100)
# ./mysql.server start
5.2 重啓mysql集羣服務
1)啓動MysqlManagement管理節點(192.168.0.1)
#ndb_mgmd -f /var/lib/mysql-cluster/config.ini
2)啓動Data Node節點(192.168.0.160,192.168.0.161)
#ndbd
3)啓動MysqlServer節點(192.168.0.100)
# ./mysql.server start
(注意:Management管理節點和DataNote節點都不開啓mysql服務,只有MysqlServer節點開啓。The default port for Cluster management nodes is 1186; the default port for data nodes is 2202.)

6測試集羣的效果
6.1 在管理機上查看各節點運行狀況
[root@Proxy bin]# ./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.0.160 (Version: 4.1.13, Nodegroup: 0, Master)
id=3 @192.168.0.161 (Version: 4.1.12, Nodegroup: 0)
[ndb_mgmd(MGM)] 1 node(s)
id=1 @192.168.0.1 (Version: 4.1.13)
[mysqld(API)] 1 node(s)
id=4 @192.168.0.100 (Version: 4.1.12)
6.2 模擬寫入一個數據庫表,各MysqlServer節點是否能夠同步
1) 在一個MysqlServer節點上創建數據庫world和表,然後看看另一個MysqlServer節點是否也同樣可以看到。
答:數據都相同
2) 拔掉一個DataNote節點網線,看看兩臺MysqlServer節點是否還能正常工作。
答:可以
3) 拔掉兩臺DataNote節點網線,查看一下MysqlServer節點是否還能正常工作。
答:所有MysqlServer都不能正常工作
From:http://blog.liuts.com/post/12/
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章