mysql cluster步骤基本取自官方文档,测试忘记参考哪里了^_^

系统Centos6.5
下载mysql-cluster-gpl-7.3.7-linux-glibc2.5-x86_64.tar.gz
下载地址:http://dev.mysql.com/get/Downloads/MySQL-Cluster-7.3/mysql-cluster-gpl-7.3.7-linux-glibc2.5-x86_64.tar.gz


参考文献:http://dev.mysql.com/doc/refman/5.6/en/mysql-cluster-installation.html
官网安装教程:http://dev.mysql.com/doc/refman/5.6/en/mysql-cluster-install-linux-binary.html
官网初始化教程:http://dev.mysql.com/doc/refman/5.6/en/mysql-cluster-install-configuration.html




本文结构
安装--初始化(配置文件)--开启服务--测试功能--关闭集群




SQL nodes. 


On each of the machines designated to host SQL nodes, perform the following steps as the system root user:


Check your /etc/passwd and /etc/group files (or use whatever tools are provided by your operating system for managing users and groups) to see whether there is already a mysql group and mysql user on the system. Some OS distributions create these as part of the operating system installation process. If they are not already present, create a new mysql user group, and then add a mysql user to this group:


shell> groupadd mysql
shell> useradd -g mysql mysql
The syntax for useradd and groupadd may differ slightly on different versions of Unix, or they may have different names such as adduser and addgroup.


Change location to the directory containing the downloaded file, unpack the archive, and create a symbolic link named mysql to the mysql directory. Note that the actual file and directory names vary according to the MySQL Cluster version number.




shell> tar -C /usr/local -xzvf mysql-cluster-gpl-7.4.3-linux2.6.tar.gz
shell> ln -s /usr/local/mysql-cluster-gpl-7.4.3-linux2.6-i686 /usr/local/mysql
Change location to the mysql directory and run the supplied script for creating the system databases:


shell> cd /usr/local/mysql
shell> scripts/mysql_install_db --user=mysql
Set the necessary permissions for the MySQL server and data directories:


shell> chown -R root .
shell> chown -R mysql data
shell> chgrp -R mysql .
Copy the MySQL startup script to the appropriate directory, make it executable, and set it to start when the operating system is booted up:


shell> cp support-files/mysql.server /etc/init.d/
shell> chmod +x /etc/init.d/mysql.server
shell> chkconfig mysql.server on


















Data nodes. 


 Installation of the data nodes does not require the mysqld binary. Only the MySQL Cluster data node executable ndbd (single-threaded) or ndbmtd (multi-threaded) is required. These binaries can also be found in the .tar.gz archive. Again, we assume that you have placed this archive in /var/tmp.


As system root (that is, after using sudo, su root, or your system's equivalent for temporarily assuming the system administrator account's privileges), perform the following steps to install the data node binaries on the data node hosts:


Change location to the /var/tmp directory, and extract the ndbd and ndbmtd binaries from the archive into a suitable directory such as /usr/local/bin:


shell> cd /var/tmp
shell> tar -zxvf mysql-5.6.21-ndb-7.4.3-linux-i686-glibc23.tar.gz
shell> cd mysql-5.6.21-ndb-7.4.3-linux-i686-glibc23
shell> cp bin/ndbd /usr/local/bin/ndbd
shell> cp bin/ndbmtd /usr/local/bin/ndbmtd
(You can safely delete the directory created by unpacking the downloaded archive, and the files it contains, from /var/tmp once ndb_mgm and ndb_mgmd have been copied to the executables directory.)


Change location to the directory into which you copied the files, and then make both of them executable:


shell> cd /usr/local/bin
shell> chmod +x ndb*












Management nodes.


  Installation of the management node does not require the mysqld binary. Only the MySQL Cluster management server (ndb_mgmd) is required; you most likely want to install the management client (ndb_mgm) as well. Both of these binaries also be found in the .tar.gz archive. Again, we assume that you have placed this archive in /var/tmp.


As system root, perform the following steps to install ndb_mgmd and ndb_mgm on the management node host:


Change location to the /var/tmp directory, and extract the ndb_mgm and ndb_mgmd from the archive into a suitable directory such as /usr/local/bin:


shell> cd /var/tmp
shell> tar -zxvf mysql-5.6.21-ndb-7.4.3-linux2.6-i686.tar.gz
shell> cd mysql-5.6.21-ndb-7.4.3-linux2.6-i686
shell> cp bin/ndb_mgm* /usr/local/bin
(You can safely delete the directory created by unpacking the downloaded archive, and the files it contains, from /var/tmp once ndb_mgm and ndb_mgmd have been copied to the executables directory.)


Change location to the directory into which you copied the files, and then make both of them executable:


shell> cd /usr/local/bin
shell> chmod +x ndb_mgm*












初始化(配置文件)
Configuring the data nodes and SQL nodes.
shell> vi /etc/my.cnf
For each data node and SQL node in our example setup, my.cnf should look like this:
[mysqld]
# Options for mysqld process:
ndbcluster                      # run NDB storage engine


[mysql_cluster]
# Options for MySQL Cluster processes:
ndb-connectstring=192.168.0.5 # location of management server


Configuring the management node.  
shell> mkdir /var/lib/mysql-cluster
shell> cd /var/lib/mysql-cluster
shell> 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=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.5           # 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.4           # 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.6          # 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.4          # Hostname or IP address
                                # (additional mysqld connections can be
                                # specified for this node for various
                                # purposes such as running ndb_restore)


[mysqld]
# SQL node options:
hostname=192.168.0.6          # Hostname or IP address
                                # (additional mysqld connections can be
                                # specified for this node for various
                                # purposes such as running ndb_restore)







Initial Startup of MySQL Cluster开启服务
启用顺序:管理节点--Sql节点--数据节点
On the management host:
shell> ndb_mgmd -f /var/lib/mysql-cluster/config.ini --initial
#仅初次使用--initial参数
On each of the data node hosts, run this command to start the ndbd process:
shell> ndbd --initial  
#仅初次使用--initial参数
启动sql节点
service mysql.server start
检验是否成功开启
管理节点上,如下显示说明启动成功
[root@node1 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.4  (mysql-5.6.21 ndb-7.3.7, Nodegroup: 0, *)
id=3    @192.168.0.6  (mysql-5.6.21 ndb-7.3.7, Nodegroup: 0)


[ndb_mgmd(MGM)] 1 node(s)
id=1    @192.168.0.5  (mysql-5.6.21 ndb-7.3.7)


[mysqld(API)]   2 node(s)
id=4    @192.168.0.4  (mysql-5.6.21 ndb-7.3.7)
id=5    @192.168.0.6  (mysql-5.6.21 ndb-7.3.7)




★非常重要:
1.在建表的时候一定要用ENGINE=NDB或ENGINE=NDBCLUSTER指定使用NDB集群存储引擎,或用ALTER TABLE选项更改表的存储引擎。
2.NDB表必须有一个主键,因此创建表的时候必须定义主键,否则NDB存储引擎将自动生成隐含的主键。
3.Sql节点的用户权限表仍然采用MYISAM存储引擎保存的,所以在一个Sql节点创建的MySql用户只能访问这个节点,如果要用同样的用户访问别的Sql节点,需要在对应的Sql节点追加用户。虽然在MySql Cluster7.2版本开始提供了”用户权限共享”.


功能测试:
1.在任意数据节点上,创建数据库并插入数据,测试另一台上是否能够同步
shell> /usr/local/mysql/bin/mysql -u root -p  
mysql>show databases;  
mysql>create database aa;  
mysql>use aa;  
mysql>CREATE TABLE ctest2 (i INT) ENGINE=NDB; //这里必须指定数据库表的引擎为NDB,否则同步失败  
mysql> INSERT INTO ctest2 () VALUES (1);  
mysql> SELECT * FROM ctest2;  


注意:
如果在创建数据库时遇到如下错误
Access denied for user ''@'localhost' to database 'mysql  
解决方法:
首先停止mysqld服务,然后后台运行  
shell> /usr/local/mysql/bin/mysqld_safe --skip-grant-tables &  
shell> service mysql.server start  
再用root登录,就一切正常  
2.同样,在另一数据节点上,执行插入数据操作,测试是否可以双向同步。
3.关闭一个数据节点,另一个节点插入数据,然后开启数据节点,测试是否可以自动同步




关闭集群
1.关闭管理节点和数据节点,只需要在管理节点里执行:
shell> /usr/local/mysql/bin/ndb_mgm -e shutdown  
显示
Connected to Management Server at: localhost:1186  
2 NDB Cluster node(s) have shutdown.  
Disconnecting to allow management server to shutdown.  


2.然后关闭Sql节点(135,136),分别在2个节点里运行:
shell> /etc/init.d/mysql.server stop  
Shutting down MySQL... SUCCESS!  




注意:要再次启动集群,就按照启动顺序重新启动,不过再次启动数据节点的时候就不要加”–initial”参数了。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值