Architecture
http://www.cnblogs.com/shihaiming/p/6084965.html
Guide
https://dev.mysql.com/doc/refman/5.7/en/mysql-cluster-installation.html
http://www.cnblogs.com/ziqang/p/6108176.html
http://blog.csdn.net/songxixi/article/details/8439927
Download
https://dev.mysql.com/downloads/cluster/
http://packages.atrpms.net/dist/el6/perl-Class-MethodMaker/(perl-Class-MethodMaker)
ftp://rpmfind.net/linux/atrpms/el6-x86_64/atrpms/stable/atrpms-77-1.noarch.rpm(atrpms-perl-module-helper)
Steps
1、卸载
#卸载所有和mysql有关的东西 #rpm -qa | grep mysql #rpm -e mysql-libs-5.1.73-5.el6_6.x86_64 --nodeps #yum remove xxxx |
2、依赖包安装
# yum -y install perl # rpm -ivh atrpms-77-1.noarch.rpm # rpm -ivh perl-Class-MethodMaker-2.15-7.el6.x86_64.rpm |
3、在每个mgm服务器
#安装 tar -xvf mysql-cluster-community-7.5.6-1.el6.x86_64.rpm-bundle.tar rpm -ivh mysql-cluster-community-common-7.5.6-1.el6.x86_64.rpm rpm -ivh mysql-cluster-community-libs-* #rpm -ivh mysql-cluster-community-devel-7.5.6-1.el6.x86_64.rpm rpm -ivh mysql-cluster-community-management-server-7.5.6-1.el6.x86_64.rpm #需MethodMaker依赖包 rpm -ivh mysql-cluster-community-client-7.5.6-1.el6.x86_64.rpm #查看安装情况 rpm -qa|grep mysql
|
#配置 vi /var/lib/mysql-cluster/config.ini #config.ini配置参数官方说明------ https://dev.mysql.com/doc/refman/5.7/en/mysql-cluster-install-configuration.html http://dev.mysql.com/doc/refman/5.7/en/mysql-cluster-ndbd-definition.html#ndbparam-ndbd-arbitration http://zkread.com/article/1313403.html (details) [computer]:the computer on which the data node is to reside [ndbd default]:affecting ndbd processes on all data nodes [ndbd]:configure the behavior of the cluster's data nodes. # The maximum number of data nodes is 48. The total maximum number of nodes in an NDB Cluster is 255. This number includes all SQL nodes, data nodes, and management servers. # A data node must have a node ID in the range of 1 to 48, management and mysqld(API) nodes may use node IDs in the range 1 to 255
[ndb_mgmd default] DataDir=/var/lib/mysql-cluster
[ndb_mgmd] nodeid=1 HostName=centos2
[ndb_mgmd] nodeid=2 HostName=centos3
[ndbd default] NoOfReplicas=1 DataMemory=64M IndexMemory=32M DataDir=/var/lib/mysql-cluster
[ndbd] nodeid=11 HostName=centos2
[ndbd] nodeid=12 HostName=centos3
[mysqld] nodeid=21 HostName=centos2
[mysqld] nodeid=22 HostName=centos3
--------- chmod -R 644 /var/lib/mysql-cluster/config.ini
|
#启动 ndb_mgmd -f /var/lib/mysql-cluster/config.ini --configdir=/var/lib/mysql-cluster
|
#检验 ps -ef|grep ndb
ndb_mgm -e show (或者: ndb_mgm ndb_mgm> show Connected to Management Server at: localhost:1186 Cluster Configuration --------------------- [ndbd(NDB)] 2 node(s) id=11 (not connected, accepting connect from centos2) id=12 (not connected, accepting connect from centos3)
[ndb_mgmd(MGM)] 2 node(s) id=1 @22.117.68.102 (mysql-5.7.18 ndb-7.5.6) id=2 @22.117.68.101 (mysql-5.7.18 ndb-7.5.6)
[mysqld(API)] 2 node(s) id=21 (not connected, accepting connect from centos2) id=22 (not connected, accepting connect from centos3)
ndb_mgm> (不用关闭窗口) |
4、在每个DataNode
#(1)安装 cd /mk/soft tar -xvf mysql-cluster-community-7.5.6-1.el6.x86_64.rpm-bundle.tar rpm -ivh mysql-cluster-community-data-node-7.5.6-1.el6.x86_64.rpm
#(2)首次启动,需要添加--initial参数,进行NDB节点的初始化工作,在以后的启动过程中,则是不能添加该参数,否则NDBD程序会清除之前建立的所有用于恢复的数据文件和日志文件 ndbd --initial [ndbd] INFO -- Angel connected to 'localhost:1186' [ndbd] INFO -- Angel allocated nodeid: 11
#(3)检验 ps -ef|grep ndb netstat –anpt
|
5、在每个SQLNode
#(1)解压 tar –xvzf mysql-cluster-gpl-7.5.6-linux-glibc2.5-x86_64.tar.gz cd mysql-cluster-gpl-7.5.6-linux-glibc2.5-x86_64 mv mysql-cluster-gpl-7.5.6-linux-glibc2.5-x86_64 /var/lib cd /var/lib mv mysql-cluster-gpl-7.5.6-linux-glibc2.5-x86_64 mysql
#(2)配置 vi /etc/my.cnf # ndb-connectstring连到mgm所在服务器 [client] socket=/appl/mysql-cluster/mysqld/mysql.sock
[mysqld] ndbcluster max_connections=100 datadir=/appl/mysql-cluster/mysqld socket=/appl/mysql-cluster/mysqld/mysql.sock ndb-connectstring=centos2 max_connections=1000
[mysqld_safe] log-error=/var/log/mysqld.log pid-file=/appl/mysql-cluster/mysqld/mysqld.pid
[mysql_cluster] # ndb-connectstring= location of management server ndb-connectstring=centos2
chmod 644 /etc/my.cnf
#(3)安装 cd bin ./mysqld --initialize-insecure --explicit_defaults_for_timestamp tail -f /var/log/mysqld.log (同一时间在另一个session窗口)
#建mysql用户 #groupadd mysql #useradd -g mysql -s /bin/false mysql
#(4)启动 cd .. chown -R root . chown -R mysql . chgrp -R mysql . cp support-files/mysql.server /etc/rc.d/init.d/ chmod +x /etc/rc.d/init.d/mysql.server chkconfig --add mysql.server mkdir /var/run/mysqld chown -R mysql:mysql /var/run/mysqld
/etc/init.d/mysql.server start mysql -uroot set password=password('123456'); grant all privileges on *.* to root@'%' identified by '123456';
#(5)检验 mysql -uroot -p
|
6、测试
ndb_mgm ndb_mgm> show Connected to Management Server at: centos2:1186 Cluster Configuration --------------------- [ndbd(NDB)] 2 node(s) id=11 @22.117.68.102 (mysql-5.7.18 ndb-7.5.6, Nodegroup: 0, *) id=12 @22.117.68.101 (mysql-5.7.18 ndb-7.5.6, Nodegroup: 1)
[ndb_mgmd(MGM)] 2 node(s) id=1 @22.117.68.102 (mysql-5.7.18 ndb-7.5.6) id=2 @22.117.68.101 (mysql-5.7.18 ndb-7.5.6)
[mysqld(API)] 2 node(s) id=21 @22.117.68.102 (mysql-5.7.18 ndb-7.5.6) id=22 @22.117.68.101 (mysql-5.7.18 ndb-7.5.6)
ndb_mgm> exit
|
(切换到centos2) mysql -uroot -p123456 create database test; use test; create table test1(id int,name char(10)) engine=ndbcluster; create table test2(id int,name char(10)) engine=ndb; create table test3(id int,name char(10)) engine=InnoDB; insert test1 values(1,'a1'); commit; select * from test1; (切换到centos3) mysql -uroot -p123456 show databases; select * from test.test1; use test; show tables; (test3不可见) |
7、压测
#基准测试 mysqlslap --user=root --password=123456 --concurrency=100 --number-of-queries=1000 --number-int-cols=5 --number-char-cols=20 --auto-generate-sql |
8、关闭
mysqladmin -u root shutdown bin/ndb_mgm -e shutdown |
9、报错处理
Q: sh./scripts/mysql_install_db --no-defaults--datadir=/home/weijianzhongwj/software/mysqlc/my_cluster/mysqld_data/
./bin/mysqld:error while loading shared libraries: libaio.so.1: cannot open shared objectfile: No such file or directory
A: sudoapt-get install libaio1
Q: ndb_mgmd -f /appl/mysql-cluster/config.ini--configdir=/appl/mysql-cluster
[MgmtSrvr] ERROR -- Could not determine which nodeid to usefor this node. Specify it with --ndb-nodeid=<nodeid> on command line
A: vi /etc/hosts
Q: ndbd --initial
Unable to connect with connect string:nodeid=0,localhost:1186
A: 关闭防火墙 -chkconfig iptables off; service iptables stop
Q: mysqld --initialize
World-writable config file '/etc/my.cnf' isignored
unknown variable'defaults-file=/etc/my.cnf'
A: chmod 664 /etc/my.cnf
Q: Could not create unix socket lock file/var/lib/mysql/mysql.sock.lock
A: chown -R mysql:mysql /var/lib/mysql
Q: Can't create/write to file'/var/run/mysqld/mysqld.pid'
A: chown -R mysql:mysql /var/run/mysqld