mysql集群整理版
mysql集群架构主要分为:数据节点(ndbd),管理节点(mgmd),服务节点(mysqld)
附件是mysql集群整体架构图
1. 下载:http://dev.mysql.com/downloads/mysql/5.0.html#linux 可以从这里下载 mysql-5.0.45-linux-i686.tar.gz
此包里已经包含了mysql-max包(mysql集群需要安装mysql-max包)。
2. 解压:
tar -zxvf apache-tomcat-5.5.25.tar.gz
下载的这个.tar.gz是编译后的文件,只需要解压即可。
3. 配置
比如解压后的文件都放在:/home/mahaibo/mysql-5.0.45-linux-i686目录下。
数据节点(ndbd),管理节点(mgmd),服务节点(mysqld) 三个启动顺序是
mgmd —> ndbd —> mysqld
可以在同一台电脑上做个简单的配置和测试。
以在同一台电脑上不同端口为例。实际中肯定是需要分布在不同的服务器上的。
A: 配置mgmd,并启动
在/home/mahaibo/mysql-5.0.45-linux-i686建立一个mgmd.cnf和mgmd的数据目录mgmddata ,编辑mgmd.cnf文件:
# 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)
可以看到配置了2个数据节点ndbd,也就是说改管理节点可以管理小于或等于2个数据节点。管理节点mgmd的端口为2203。
启动mgmd服务:
bin/ndb_mgmd -f mgmd.cnf
启动后,登录mgmd的客户端mgm可以查看具体信息:
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>
可以看到ndbd和mysqld都是
not connected状态,因为这2个服务都还没有启动。
B: 启动数据节点(ndbd)
以启动2个数据节点为例。