一、安裝要求
安裝環(huán)境:CentOS-6.5-32bit
軟件名稱:mysql-cluster-gpl-7.2.25-linux2.6-i686.tar.gz
下載地址:http://mysql.mirror.kangaroot.net/Downloads/
軟件包:mysql-cluster-gpl-7.2.25-linux2.6-i686.tar.gz
軟件包存放目錄:/usr/local
管理節(jié)點(MGM): 192.168.1.71
數(shù)據(jù)節(jié)點1(NDBD1):192.168.1.72
數(shù)據(jù)節(jié)點2(NDBD2):192.168.1.73
sql節(jié)點1(SQL1): 192.168.1.74
sql節(jié)點2(SQL2): 192.168.1.75
二、安裝部署
1.安裝前:(所有節(jié)點服務(wù)器需執(zhí)行)
[root@MGM ]#rpm -qa|grep mysql* (查詢系統(tǒng)中存在的mysql)
[root@MGM ]#rpm -e –nodeps mysql-libs-5.1.71-1.el6.i686 (根據(jù)自己查出來的mysql版本)
2.開始部署:(所有節(jié)點服務(wù)器需執(zhí)行)
[root@MGM ]#groupadd mysql
[root@MGM ]#useradd mysql -g mysql
[root@MGM ]#cd /usr/local (軟件包在此目錄下,根據(jù)自己存放位置進入)
[root@MGM local]#tar -xvfmysql-cluster-gpl-7.2.25-linux2.6-i686.tar.gz
[root@MGM local]#mkdir /usr/local/mysql (創(chuàng)建mysql目錄)
[root@MGM local]#mvmysql-cluster-gpl-7.2.25-linux2.6-i686/* mysql
[root@MGM local]#chown -R mysql:mysql mysql/
[root@MGM local]#cd mysql
[root@MGM mysql]#scripts/mysql_install_db –user=mysql (管理及數(shù)據(jù)節(jié)點執(zhí)行這條命令)
#scripts/mysql_install_db –user=mysql –datadir=/var/mysql/data (sql節(jié)點執(zhí)行這條命令)
三、集群配置
1.管理節(jié)點配置:
[root@MGM mysql]#mkdir /var/lib/mysql-cluster
[root@MGM ]#mkdir /var/mysql
[root@MGM ]#mkdir /var/mysql/data
[root@MGM ]#mkdit /var/mysql/log
[root@MGM mysql]#vi /var/lib/mysql-cluster/config.ini (添加以下內(nèi)容)
[NDBD DEFAULT]
NoOfReplicas=2
#[TCP DEFAULT]
#PortNumber=1186
[NDB_MGMD]
#設(shè)置管理節(jié)點服務(wù)器
nodeid=1
HostName=192.168.1.71
DataDir=/var/mysql/data
[NDBD]
nodeid=2
HostName=192.168.1.72
DataDir=/var/mysql/data
[NDBD]
nodeid=3
HostName=192.168.1.73
DataDir=/var/mysql/data
[MYSQLD]
nodeid=4
HostName=192.168.1.74
[MYSQLD]
nodeid=5
HostName=192.168.1.75
#必須有空的mysqld節(jié)點,不然數(shù)據(jù)節(jié)點斷開后啟動有報錯
[MYSQLD]
nodeid=6
[mysqld]
nodeid=7
拷貝ndb_mgm、ndb_mgmd、config.ini到bin目錄:
[root@MGM mysql]#cd /usr/local/mysql/bin
[root@MGM bin]#cp ./ndb_mgm /usr/local/bin/
[root@MGM bin]#cp ./ndb_mgmd /usr/local/bin/
[root@MGM bin]#cp /var/lib/mysql-cluster/config.ini /usr/local/bin/
[root@MGM bin]#vi /etc/sysconfig/iptables (添加紅色方框內(nèi)容)
[root@MGM bin]/etc/init.d/iptables restart 重啟防火墻
2.數(shù)據(jù)節(jié)點配置:(所有數(shù)據(jù)節(jié)點需執(zhí)行)
[root@NDBD1 ]#mkdir /var/mysql
[root@NDBD1 ]#mkdir /var/mysql/data
[root@NDBD1 ]#mkdit /var/mysql/log
[root@NDBD1 ]#/etc/init.d/iptables stop (關(guān)閉防火墻,也可自行添加開放端口)
[root@NDBD1 ]#vi /etc/my.cnf (添加以下內(nèi)容)
[mysqld]
datadir=/var/mysql/data
socket=/var/mysql/mysql.sock
user=mysql
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
#運行NDB存儲引擎
ndbcluster
#指定管理節(jié)點
ndb-connectstring=192.168.1.71
[MYSQL_CLUSTER]
ndb-connectstring=192.168.1.71
[NDB_MGM]
connect-string=192.168.1.71
[mysqld_safe]
log-error=/var/mysql/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
3.sql節(jié)點配置:(所有sql節(jié)點需執(zhí)行)
[root@SQL1 ]#cd /usr/local/mysql/
[root@SQL1 mysql]#cp support-files/mysql.server /etc/rc.d/init.d/mysqld
[root@SQL1 mysql]#chmod +x /etc/rc.d/init.d/mysqld
[root@SQL1 mysql]#chkconfig –add mysqld
[root@SQL1 mysql]#mkdir /var/mysql
[root@SQL1 mysql]#mkdir /var/mysql/data
[root@SQL1 mysql]#mkdir /var/mysql/log
[root@SQL1 mysql]#chown -R mysql:mysql /var/mysql
[root@SQL1 mysql]#ln -s /usr/local/mysql/bin/mysql /usr/bin
[root@SQL1 mysql]#ln -s /var/mysql/mysql.sock /tmp/mysql.sock
[root@SQL1 mysql]#vi /etc/my.cnf
[mysqld]
datadir=/var/mysql/data
socket=/var/mysql/mysql.sock
user=mysql
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
log-bin = /var/mysql/log/mysql-bin.log
max_connections=1000
#以下為mysql 主主模式的配置文件
# 忽略mysql數(shù)據(jù)庫復(fù)制
binlog-ignore-db=mysql
# 每次增長2
auto-increment-increment=2
# 設(shè)置自動增長的字段的偏移量,即初始值為2
auto-increment-offset=1
ndbcluster
ndb-connectstring=192.168.1.71
[MYSQL_CLUSTER]
ndb-connectstring=192.168.1.71
[NDB_MGM]
connect-string=192.168.1.71
[mysqld_safe]
log-error=/var/mysql/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
四、mysql-cluster啟動
1.啟動mysql-cluster
mysql集群的啟動順序為:管理節(jié)點->數(shù)據(jù)節(jié)點->SQL節(jié)點
mysql集群的關(guān)閉順序為,SQL節(jié)點->數(shù)據(jù)節(jié)點->管理節(jié)點
2.管理節(jié)點:
[root@MGM ]#ndb_mgmd -f /var/lib/mysql-cluster/config.ini –initial
(注意第一次或者對config文件進行修改后,打開服務(wù)一定要加上initial否則新增加的內(nèi)容不會被使用)
3.數(shù)據(jù)節(jié)點:
[root@NDBD1 ]#/usr/local/mysql/bin/ndbd –initial
(此處同上)
4.sql節(jié)點:
[root@SQL1 ]#service mysqld start
5.驗證:(在管理節(jié)點上)
[root@MGM ]#ndb_mgm
ndb_mgm>show
五、測試
1.在sql1節(jié)點執(zhí)行:
[root@SQL1 ]#mysql 調(diào)用mysql
mysql>create database tianyuan; 創(chuàng)建數(shù)據(jù)庫
mysql>use tianyuan; 使用數(shù)據(jù)庫
mysql>create table test(i int,name varchar(10)) engine=ndbcluster; 創(chuàng)建表
mysql>insert into test values(1,'ceshi'); 插入表數(shù)據(jù)
mysql>select * from test; 查詢驗證
2.在sql2節(jié)點驗證sql1的數(shù)據(jù)是否已同步到sql2:
[root@SQL2 ]#mysql 調(diào)用mysql
mysql>show databases; 查詢數(shù)據(jù)庫
mysql>use tianyuan; 使用數(shù)據(jù)庫
mysql>select * from test; 查詢驗證
3.可通過中斷數(shù)據(jù)節(jié)點或sql節(jié)點來驗證數(shù)據(jù)是否會同步。
您可能感興趣的文章:- 快速實現(xiàn)MySQL的部署以及一機多實例部署
- CentOS6.5 上部署 MySQL5.7.17 二進制安裝以及多實例配置