MySQL NDB Cluster 7.5.16 部署OGG同步

安装MySQL NDB Cluster 7.5.16

环境:

mgmd:192.168.121.133

sqlndbd1: 192.168.121.134

sqlndbd2: 192.168.121.135

 

每个节点先关闭防火墙:

[root@localhost ~]# systemctl disable firewalld

[root@localhost ~]# chkconfig iptables off

 

(sql节点和数据节点都在同一台机器上,但是生产环境建议sql节点和数据节点分开配置。)

下载MySQL NDB Cluster:https://dev.mysql.com/downloads/cluster/

 

一、安装管理节点:mgmd

[root@localhost ~]# tar -xvf mysql-cluster-gpl-7.5.16-linux-glibc2.12-x86_64.tar.gz

[root@localhost ~]# mv mysql-cluster-gpl-7.5.16-linux-glibc2.12-x86_64 /usr/local/mysql

[root@localhost ~]# cp /usr/local/mysql/bin/ndb_mgm* /usr/local/bin  

[root@localhost ~]# mkdir /data/mysql-cluster

[root@localhost ~]# 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

 

查看节点状态:

[root@localhost ~]# ndb_mgm

二、安装sql节点和数据节点:sqlndbd1和sqlndbd2

新增用户和用户组:

[root@localhost ~]#groupadd mysql

[root@localhost ~]#useradd -g mysql -s /bin/false mysql

 

[root@localhost ~]# tar -xvf mysql-cluster-gpl-7.5.16-linux-glibc2.12-x86_64.tar.gz

[root@localhost ~]# mv mysql-cluster-gpl-7.5.16-linux-glibc2.12-x86_64 /usr/local/mysql

[root@localhost ~]# chown -R mysql:mysql  /usr/local/mysql

[root@localhost ~]# mkdir -p /data/mysql/db_file

[root@localhost ~]# mkdir -p /data/mysql/log

[root@localhost ~]# mkdir -p /data/mysql/log_bin

[root@localhost ~]# 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启动脚本:

[root@localhost ~]# cp /usr/local/mysql/support-files/mysql.server  /etc/rc.d/init.d/

[root@localhost ~]# chmod +x /etc/rc.d/init.d/mysql.server

[root@localhost ~]# chkconfig --add mysql.server

 

启动MySQL节点:

[root@localhost ~]# /etc/init.d/mysql.server start

 

登录MySQL以及修改密码:

[root@localhost ~]# /usr/local/mysql/bin/mysql -u root -p  # 将刚才存储的随机MySQL密码 复制进来

mysql>ALTER USER 'root'@'localhost'IDENTIFIED BY '123456'; # 修改密码为123456

mysql> flush privileges;

 

启动NDB

[root@localhost ~]# /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

[root@localhost ~]# 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)

 

保存好配置文件后,需要执行以下命令使配置立即生效:

[root@localhost ~]# exportfs –r

 

3.创建共享目录,和修改权限

[root@localhost ~]# mkdir /data/share

[root@localhost ~]# chmod 755 -R /data/share/

 

4.启动服务

[root@localhost ~]# systemctl start rpcbind

[root@localhost ~]# systemctl start nfs

 

5.开机启动

[root@localhost ~]# systemctl enable rpcbind

[root@localhost ~]# systemctl enable nfs

 

客户端:本例是在SQL节点

1.安装NFS和rpc

[root@localhost ~]# yum install -y  nfs-utils  rpcbind

 

2.查询挂载目录

[root@localhost ~]# showmount -e 192.168.121.133

 

 

3.建立挂载目录,执行挂载命令

[root@localhost ~]# mkdir -p /data/share

[root@localhost ~]# mount -t nfs 192.168.121.133:/data/share /data/share/ -o nolock,nfsvers=3,vers=3

 

//如果不加 -onolock,nfsvers=3 则在挂载目录下的文件属主和组都是nobody,如果指定nfsvers=3则显示root。

 

如果要解除挂载,可执行命令:

[root@localhost ~]# umount /data/share

 

4.开机自动挂载

[root@localhost ~]# 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

 

 

[root@localhost ~]# unzip 191003_ggs_Linux_x64_MySQL_64bit.zip

[root@localhost ~]# tar –xvf ggs_Linux_x64_MySQL_64bit.tar –C /data/share/ogg

[root@localhost ~]# cd /data/share/ogg

[root@localhost ogg]# ./ggsci

GGSCI (localhost.localdomain) 1>create subdirs

GGSCI (localhost.localdomain) 2>dblogin sourcedb test@localhost: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 test@localhost: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.*;

posted @ 2020-02-07 12:51  smandar  阅读(258)  评论(0编辑  收藏  举报