安装MySQL NDB Cluster 7.5.16
环境:
mgmd:192.168.121.133
sqlndbd1: 192.168.121.134
sqlndbd2: 192.168.121.135
每个节点先关闭防火墙:
[r[email protected] ~]# systemctl disable firewalld
[[email protected] ~]# chkconfig iptables off
(sql节点和数据节点都在同一台机器上,但是生产环境建议sql节点和数据节点分开配置。)
下载MySQL NDB Cluster:https://dev.mysql.com/downloads/cluster/
一、安装管理节点:mgmd
[[email protected] ~]# tar -xvf mysql-cluster-gpl-7.5.16-linux-glibc2.12-x86_64.tar.gz
[[email protected] ~]# mv mysql-cluster-gpl-7.5.16-linux-glibc2.12-x86_64 /usr/local/mysql
[[email protected] ~]# cp /usr/local/mysql/bin/ndb_mgm* /usr/local/bin
[[email protected] ~]# mkdir /data/mysql-cluster
[[email protected] ~]# vi /data/mysql-cluster/config.ini
config.ini 的配置:
[ndbd default]
NoOfReplicas=1
DataMemory=512M
IndexMemory=18M
[ndb_mgmd]
HostName=192.168.121.133
DataDir=/data/mysql-cluster
[ndbd]
HostName=192.168.121.134
DataDir=/data/mysql/db_file
[ndbd]
HostName=192.168.121.135
DataDir=/data/mysql/db_file
[mysqld]
HostName=192.168.121.134
[mysqld]
HostName=192.168.121.135
初始化管理节点:
/usr/local/bin/ndb_mgmd -f /data/mysql-cluster/config.ini –initial
查看节点状态:
[[email protected] ~]# ndb_mgm
二、安装sql节点和数据节点:sqlndbd1和sqlndbd2
新增用户和用户组:
[[email protected] ~]#groupadd mysql
[[email protected] ~]#useradd -g mysql -s /bin/false mysql
[[email protected] ~]# tar -xvf mysql-cluster-gpl-7.5.16-linux-glibc2.12-x86_64.tar.gz
[[email protected] ~]# mv mysql-cluster-gpl-7.5.16-linux-glibc2.12-x86_64 /usr/local/mysql
[[email protected] ~]# chown -R mysql:mysql /usr/local/mysql
[[email protected] ~]# mkdir -p /data/mysql/db_file
[[email protected] ~]# mkdir -p /data/mysql/log
[[email protected] ~]# mkdir -p /data/mysql/log_bin
[[email protected] ~]# chown -R mysql:mysql /data/mysql
初始化 MySQL:
/usr/local/mysql/bin/mysqld –initialize --user=mysql --basedir=/usr/local/mysql/ --datadir=/data/mysql/db_file
-----注意,初始化数据库会生成登录MySQL数据库的root密码,一定要记住,一会登录数据库要用
编辑SQL节点 my.cnf 文件:
[mysqld]
basedir=/usr/local/mysql/
datadir=/data/mysql/db_file
socket=/usr/local/mysql/ mysql.sock
log-error=/data/mysql/log/sqlnode.err
default-storage-engine=ndbcluster
ndbcluster
ndb-connectstring=192.168.121.133
server-id=1
skip-slave-start=true
log-bin = /data/mysql/log_bin/log-bin.bin
log-bin-index = /data/mysql/log_bin/log-bin.index
binlog-format = ROW //SQL节点ogg同步需要配置的
[mysql_cluster]
ndb-connectstring=192.168.121.133
拷贝MySQL启动脚本:
[[email protected] ~]# cp /usr/local/mysql/support-files/mysql.server /etc/rc.d/init.d/
[[email protected] ~]# chmod +x /etc/rc.d/init.d/mysql.server
[[email protected] ~]# chkconfig --add mysql.server
启动MySQL节点:
[[email protected] ~]# /etc/init.d/mysql.server start
登录MySQL以及修改密码:
[[email protected] ~]# /usr/local/mysql/bin/mysql -u root -p # 将刚才存储的随机MySQL密码 复制进来
mysql>ALTER USER ‘root‘@‘localhost‘IDENTIFIED BY ‘123456‘; # 修改密码为123456
mysql> flush privileges;
启动NDB:
[[email protected] ~]# /usr/local/mysql/bin/ndbd –initial
如果出现以下类似信息表示启动成功
2018-08-30 21:21:20 [ndbd] INFO -- Angel connected to ‘192.168.0.100:1186‘
2018-08-30 21:21:20 [ndbd] INFO -- Angel allocated nodeid: 2
---------------------------------------------------------------------------------------------------------------------------------
启动顺序:MGM初始化 —》 MySQL节点启动 —》 NDB启动
管理节点关闭命令:ndb_mgm -e shutdown
NBD关闭 /usr/local/mysql/bin/ndbd
注:建表时请注意 存储引擎 为 ENGINE=NDBCLUSTER
创建NFS共享文件夹
一、在一台服务器上创建NFS共享文件夹(本例是在管理节点创建的)
服务端:本例是在管理节点
1.安装NFS和rpc
[[email protected] ~]# yum install -y nfs-utils rpcbind
2.编辑/etc/exports
#在文本中添加内容:
/data/share/ 192.168.121.134(rw,no_root_squash,no_all_squash,sync)
/data/share/ 192.168.121.135(rw,no_root_squash,no_all_squash,sync)
保存好配置文件后,需要执行以下命令使配置立即生效:
[[email protected] ~]# exportfs –r
3.创建共享目录,和修改权限
[[email protected] ~]# mkdir /data/share
[[email protected] ~]# chmod 755 -R /data/share/
4.启动服务
[[email protected] ~]# systemctl start rpcbind
[[email protected] ~]# systemctl start nfs
5.开机启动
[[email protected] ~]# systemctl enable rpcbind
[[email protected] ~]# systemctl enable nfs
客户端:本例是在SQL节点
1.安装NFS和rpc
[[email protected] ~]# yum install -y nfs-utils rpcbind
2.查询挂载目录
[[email protected] ~]# showmount -e 192.168.121.133
3.建立挂载目录,执行挂载命令
[[email protected] ~]# mkdir -p /data/share
[[email protected] ~]# mount -t nfs 192.168.121.133:/data/share /data/share/ -o nolock,nfsvers=3,vers=3
//如果不加 -onolock,nfsvers=3 则在挂载目录下的文件属主和组都是nobody,如果指定nfsvers=3则显示root。
如果要解除挂载,可执行命令:
[[email protected] ~]# umount /data/share
4.开机自动挂载
[[email protected] ~]# vim /etc/rc.d/rc.local
#在文件最后添加一行:
mount -t nfs 192.168.121.133:/data/share /data/share/ -o nolock,nfsvers=3,vers=3
在NFS共享文件夹下安装OGG
下载OGG: https://www.oracle.com/middleware/technologies/goldengate-downloads.html
[[email protected] ~]# unzip 191003_ggs_Linux_x64_MySQL_64bit.zip
[[email protected] ~]# tar –xvf ggs_Linux_x64_MySQL_64bit.tar –C /data/share/ogg
[[email protected] ~]# cd /data/share/ogg
[[email protected] ogg]# ./ggsci
GGSCI (localhost.localdomain) 1>create subdirs
GGSCI (localhost.localdomain) 2>dblogin sourcedb [email protected]:3306,userid root,password xxx
配置MGR进程:
GGSCI (localhost.localdomain) 3> edit param mgr
port 7809
dynamicportlist 7800-8000
autorestart extract *,waitminutes 2,resetminutes 5
配置extract进程:
GGSCI (localhost.localdomain) 4> add extract ext,tranlog,begin now
GGSCI (localhost.localdomain) 5> add exttrail ./dirdat/es,extract ext
GGSCI (localhost.localdomain) 5> edit param ext
extract ext
setenv (MYSQL_HOME="/usr/local/mysql/data")
sourcedb [email protected]:3306,userid root,PASSWORD 123456
exttrail ./dirdat/es
tranlogoptions altlogdest /usr/local/mysql/data/log-bin.index
gettruncates
TABLE test.*;
配置pump进程:
GGSCI (localhost.localdomain) 6> add extract pu,exttrailsource ./dirdat/es
GGSCI (localhost.localdomain) 7> add rmttrail ./dirdat/et,extract pu
GGSCI (localhost.localdomain) 8> edit param pu
extract pump_1
rmthost 192.168.121.135,mgrport 7810 //目标端OGG地址和端口
rmttrail ./dirdat/et
passthru
gettruncates
table test.*;
原文地址:https://www.cnblogs.com/smandar/p/12272655.html