1、下載mysql-cluster 7.3.7
http://dev.mysql.com/downloads/cluster/
2、環境清理及安裝
1)清理CentOS6 ,其中第一個指令我不執行也可以,其他系統如果不可以,還是建議執行
# yum -y remove mysql # rpm -qa | grep mysql* # rpm -e --nodeps mysql-libs-5.1.71-1.el6.x86_64
2)環境準備
建立資料夾(分如下3個類別來建立對應的資料夾)
存储节点:# mkdir /var/lib/mysql/data 管理节点:# mkdir /var/lib/mysql-cluster SQL节点:可不用 文件夹授权 进程DIR:# mkdir /var/run/mysqld 使用如下的命令来变更权限保证可写入: # chmod -R 1777 /var/lib/mysql # chmod -R 1777 /var/run/mysqld # chmod -R 1777 /var/lib/mysql-cluster
3)安裝mysql-cluster
首先解压MySQL-Cluster-gpl-7.4.2-1.el6.x86_64.rpm-bundle.tar # tar xvf MySQL-Cluster-gpl-7.4.2-1.el6.x86_64.rpm-bundle.tar 然后执行如下命令安装 # rpm -ivh MySQL-Cluster-server-gpl-7.3.4-1.el6.x86_64.rpm # rpm -ivh MySQL-Cluster-client-gpl-7.3.4-1.el6.x86_64.rpm
特別注意,當安裝完畢server gpl包後,將出現如下提示信息,提醒我們整個cluster安裝後的初次超級帳戶密碼存在/root/.mysql_secret這個文件當中。
--------------------------------------------------------------------------------------------------------------------- A RANDOM PASSWORD HAS BEEN SET FOR THE MySQL root USER ! You will find that password in '/root/.mysql_secret'. You must change that password on your first connect, no other statement but 'SET PASSWORD' will be accepted. See the manual for the semantics of the 'password expired' flag. Also, the account for the anonymous user has been removed. In addition, you can run: /usr/bin/mysql_secure_installation which will also give you the option of removing the test database. This is strongly recommended for production servers. -----------------------------------------------------------
3、設定管理節點
1)執行下列指令:
# cd /var/lib/mysql-cluster # vi config.ini
2)設定config.ini文件,如附件
100.218的設定檔:
config.iniini
100.218的設定檔:config.iniini100.218的設定檔:
config.iniini
config.ini
[computer] Id=mgr-server-01 HostName=192.168.100.218 [mgm default] datadir=/var/lib/mysql-cluster [mgm] HostName=192.168.100.218 NodeId=60 [mgm] HostName=192.168.100.217 NodeId=61 [ndbd default] NoOfReplicas = 2 DataMemory = 50M IndexMemory = 50M MaxNoOfTables = 1024 MaxNoOfAttributes = 5000000 MaxNoOfOrderedIndexes = 10000 [ndbd] HostName=192.168.100.217 DataDir=/var/lib/mysql NodeId=1 [ndbd] HostName=192.168.100.218 DataDir=/var/lib/mysql NodeId=2 [mysqld] HostName=192.168.100.217 NodeId=81 [mysqld] HostName=192.168.100.218 NodeId=82其實兩個檔案差異不大,就在於computer設定中的名稱和識別id
4、SQL節點和資料節點的設定檔
4、SQL節點和資料節點的設定
,新增以下內容:
[computer] Id=mgr-server-02 HostName=192.168.100.217 [mgm default] datadir=/var/lib/mysql-cluster [mgm] HostName=192.168.100.218 NodeId=60 [mgm] HostName=192.168.100.217 NodeId=61 [ndbd default] NoOfReplicas = 2 DataMemory = 50M IndexMemory = 50M MaxNoOfTables = 1024 MaxNoOfAttributes = 5000000 MaxNoOfOrderedIndexes = 10000 [ndbd] HostName=192.168.100.217 DataDir=/var/lib/mysql NodeId=1 [ndbd] HostName=192.168.100.218 DataDir=/var/lib/mysql NodeId=2 [mysqld] HostName=192.168.100.217 NodeId=81 [mysqld] HostName=192.168.100.218 NodeId=82
------------------------------------------------- -------------------------------------------------- ------
如果一起正常,使用以下指令將Management console開啟: ndb_mgm
檢查是否各個節點都已經完全啟動,如下,每個節點都已經連接,如果有節點沒連接,會看到
[client] socket=/var/lib/mysql/mysql.sock [mysqld] max_connections=100 datadir=/var/lib/mysql socket=/var/lib/mysql/mysql.sock ndbcluster ndb-connectstring=192.168.100.218,192.168.100.217 [mysqld_safe] log-error=/var/log/mysqld.log #pid-file=/var/run/mysqld/mysqld.pid pid-file=/var/lib/mysql/mysqld.pid [mysql_cluster] ndb-connectstring=192.168.100.218,192.168.100.217
ndb_mgm> show Connected to Management Server at: 192.168.100.218:1186 Cluster Configuration --------------------- [ndbd(NDB)] 2 node(s) id=1 @192.168.100.217 (mysql-5.6.21 ndb-7.4.2, Nodegroup: 0) id=2 @192.168.100.218 (mysql-5.6.21 ndb-7.4.2, Nodegroup: 0, *) [ndb_mgmd(MGM)] 1 node(s) id=60 @192.168.100.218 (mysql-5.6.21 ndb-7.4.2) id=61 @192.168.100.217 (mysql-5.6.21 ndb-7.4.2) [mysqld(API)] 2 node(s) id=81 @192.168.100.217 (mysql-5.6.21 ndb-7.4.2) id=82 @192.168.100.218 (mysql-5.6.21 ndb-7.4.2)
然而執行上面命令,會讓你先設定密碼,鬱悶,又繞回來了,那就去其他地方的mysql上執行下吧
111111的hash值是「*FD571203974BA9AFE270FE62151AE967ECA5E0AA」
SET PASSWORD = PASSWORD('AE*571203702053256950
好鬱悶啊,設定完以後,登陸還必須使用密文,那好吧,就用密文進去,進去後使用如下命令,強制使用明文進行登陸
ndb_mgm> show Cluster Configuration --------------------- [ndbd(NDB)] 2 node(s) id=1 @192.168.100.217 (mysql-5.6.21 ndb-7.4.2, Nodegroup: 0) id=2 @192.168.100.218 (mysql-5.6.21 ndb-7.4.2, Nodegroup: 0, *) [ndb_mgmd(MGM)] 1 node(s) id=60 @192.168.100.218 (mysql-5.6.21 ndb-7.4.2) id=61 @192.168.100.217 (mysql-5.6.21 ndb-7.4.2) [mysqld(API)] 2 node(s) id=81 (not connected, accepting connect from 192.168.100.217) id=82 @192.168.100.218 (mysql-5.6.21 ndb-7.4.2)
use mysql; delete from user; grant all on *.* to root@'%' identified by "111111" with grant option; flush privileges; quit;
然后,可以使用明文密码登陆了 几台装有SQL数据节点的服务器皆需要执行一遍上述命令; 6、当上面步奏都操作完成以后,测试cluster是否正常工作 1)简单功能测试 在218上进入mysql后执行如下:
注意:ENGINE=NDBCLUSTER; 引擎必須使用NDBCLUSTER才可以同步,否則不會進行同步
檢查是否成功,在217上,進去mysql,查看是否自動創建了database和table,如果創建,則表示成功,如果失敗,請檢查環境配置
停掉217上的mysql服務,在218上執行
create database clustertest; use clustertest; CREATE TABLE testtable(Count INT) ENGINE=NDBCLUSTER;啟動217的mysql服務,使用show確認217的資料庫節點已經連接上了,執行如下語句
insert into testtable values (1);如果發現有數據,則表示功能完備
7、關閉Cluster:(需要嚴格按照次序執行)
關閉數據:# mysqlSQLd stopmd
或別的方式關閉。 )
在管理節點上執行:# ndb_mgm -e shutdown
關閉後使用如下的進程檢測指令查看是否退出了:
select * from testtable;如果沒有,找到對應的pid進行kill 操作即可
kill -9 進程號
🎜🎜🎜8、再次啟動Cluster方案: 🎜🎜啟動整個cluster的次序,注意,有些語句已經減去了初始化的內容:🎜ndb_mgmd -f /var/lib/mysql-cluster/config.ini ndbd mysqld_safe --defaults-file=/usr/my.cnf --explicit_defaults_for_timestamp &
备注:
1、mysql安装后,默认会自动启动的,每次启动cluster的时候,都需要先把mysql的服务关闭,太麻烦,于是可以执行如下命令(我出手有点狠):
chkconfig --level 123456 mysql off
2、防火墙问题,偷个懒,我懒得去一一开放端口,干脆把防火墙直接关了(极不推荐的做法)
chkconfig --level 123456 iptables off
参考相关文档:
MySQL Cluster config.ini文件配置详解:
http://note.youdao.com/share/?id=376407a1136d2032afb6ef68aa39fba5&type=note
http://note.youdao.com/share/?id=3906996cbe3298a22fbb5a2196d6cbed&type=note
MySQL Cluster 备份与恢复 http://www.linuxidc.com/Linux/2013-06/85295.htm
MySQL Cluster安装配置 http://www.linuxidc.com/Linux/2013-07/87705.htm
MySQL Cluster 3台机器搭建集群环境 DOC http://www.linuxidc.com/Linux/2013-01/78249.htm
MySQL Cluster7.2在线增加数据节点存在重大弊端 http://www.linuxidc.com/Linux/2012-08/67605.htm
搭建MySQL-Cluster集群架构 http://www.linuxidc.com/Linux/2014-05/102218.htm
以上就是 MySQL之——MySQL Cluster集群搭建详解(基于RPM安装包 双管理中心)的内容,更多相关内容请关注PHP中文网(www.php.cn)!