mysql ndbcluster集群复制到innodb单机环境配置搭建

mysql ndbcluster集群复制到innodb单机环境配置搭建

1.环境准备

一套ndbcluster集群环境

一套innodb单机环境

ndbcluster环境配置

IP192.168.1.91   mydb1

IP192.168.1.94   mydb2

innodb环境

IP192.168.1.39   mydb3

确保环境搭建完毕,能正常使用

2.复制配置

(1)确保集群的版本和mysql版本兼容

(2)在集群master上开启二进制日志

添加如下配置:(在集群的两个sql节点都开启)

#开启二进制日志

log-bin=/data/mysqllog/ndb1.bin

log-bin-index=/data/mysqllog/ndb1.index

expire_logs_days=10

#max_binlog_size=500M

(3)在master上创建复制的slave账号

 mysql> GRANT REPLICATION SLAVE

       ON *.* TO 'myslave'@'192.168.1.39'

       IDENTIFIED BY 'myslave';

(4)在slave创建ndb_apply_statusndb_index_stat_samplendb_index_stat_head

To create the table execute the following statements on the slave:

use mysql;

CREATE TABLE `ndb_apply_status` (

    `server_id`   INT(10) UNSIGNED NOT NULL,

    `epoch`       BIGINT(20) UNSIGNED NOT NULL,

    `log_name`    VARCHAR(255) CHARACTER SET latin1 COLLATE latin1_bin NOT NULL,

    `start_pos`   BIGINT(20) UNSIGNED NOT NULL,

    `end_pos`     BIGINT(20) UNSIGNED NOT NULL,

    PRIMARY KEY (`server_id`) USING HASH

) ENGINE=InnoDB DEFAULT CHARSET=latin1;

To use a replication filter, you can add the following to the MySQL configuration file on the slave:

 

use mysql;

SET GLOBAL innodb_file_per_table = ON,

    GLOBAL innodb_large_prefix = ON,

    GLOBAL innodb_file_format='barracuda';

CREATE TABLE `ndb_index_stat_sample` (                  

 `index_id` int(10) unsigned NOT NULL,                              

 `index_version` int(10) unsigned NOT NULL,                          

 `sample_version` int(10) unsigned NOT NULL,                        

 `stat_key` varbinary(3056) NOT NULL,                                

 `stat_value` varbinary(2048) NOT NULL,                              

 PRIMARY KEY (`index_id`,`index_version`,`sample_version`,`stat_key`),

 KEY `ndb_index_stat_sample_x1` (`index_id`,`index_version`,`sample_version`)    

) ENGINE=InnoDB DEFAULT CHARSET=latin1 ROW_FORMAT=DYNAMIC;

 

CREATE TABLE `ndb_index_stat_head` (

 `index_id` int(10) unsigned NOT NULL,

 `index_version` int(10) unsigned NOT NULL,

 `table_id` int(10) unsigned NOT NULL,

 `frag_count` int(10) unsigned NOT NULL,

 `value_format` int(10) unsigned NOT NULL,

 `sample_version` int(10) unsigned NOT NULL,

 `load_time` int(10) unsigned NOT NULL,

 `sample_count` int(10) unsigned NOT NULL,

 `key_bytes` int(10) unsigned NOT NULL,

 PRIMARY KEY (`index_id`,`index_version`)

) ENGINE=InnoDB DEFAULT CHARSET=latin1;

 

(5)在master配置文件添加如下配置

server-id = 1000

binlog_format = ROW

ndb-log-update-as-write=0

log-bin-use-v1-row-events = 1

注:mysql集群的my.cnf配置文件

[mysqld]

# Options for mysqld process:

ndbcluster                      #run NDB storage engine

server-id = 1000

binlog_format = ROW

ndb-log-update-as-write=0

log-bin-use-v1-row-events = 1

#skip-grant-tables

character_set_server=utf8

lower_case_table_names=1

max_connections=1000

ndb-connectstring=192.168.1.91,192.168.1.94  # location of management server

default-storage-engine=ndbcluster

datadir=/data/mysql

max_allowed_packet=20M

open_files_limit=65535

#开启二进制日志

log-bin=/data/mysqllog/ndb1.bin

log-bin-index=/data/mysqllog/ndb1.index

expire_logs_days=10

#max_binlog_size=500M

#开启慢查询日志

slow_query_log=1

slow-query-log-file=/data/mysqllog/mysqlslow.log

long_query_time=1

#错误日志

log-error=/data/mysqllog/mysqlerror.log

# provide connection string for management server host (default port: 1186)

[ndbd]

connect-string=192.168.1.91,192.168.1.94  # location of management server

#provide connection string for management server host (default port: 1186)

[ndb_mgm]

connect-string=192.168.1.91,192.168.1.94  # location of management server

#provide location of cluster configuration file

[ndb_mgmd]

config-file=/var/lib/mysql-cluster/config.ini

 

(6)在slave配置文件中添加如下:

server-id = 3000

relay-log-purge=1

skip-slave-start

slave_exec_mode = IDEMPOTENT

sql_log_bin = 0

replicate-ignore-table=mysql.ndb_apply_status

replicate-wild-ignore-table = mysql.ndb\_index\_stat\_%

注:mysql slave配置文件:

[mysqld]

# Options for mysqld process:

#skip-grant-tables

character_set_server=utf8

lower_case_table_names=1

max_connections=1000

datadir=/data/mysql

server-id = 3000

relay-log-purge=1

skip-slave-start

slave_exec_mode = IDEMPOTENT

replicate-ignore-table=mysql.ndb_apply_status

replicate-wild-ignore-table = mysql.ndb\_index\_stat\_%

innodb_buffer_pool_size=4000M

innodb_log_file_size=256M

innodb_log_files_in_group=3

innodb_io_capacity=500

innodb_flush_method=O_DIRECT

innodb_flush_log_at_trx_commit=1

innodb_open_files=8192

7)在slave执行如下语句配置复制

mysqlS> CHANGE MASTER TO

 MASTER_HOST='192.168.1.91',

 MASTER_PORT=3306,

 MASTER_USER='myslave',

 MASTER_PASSWORD='myslave';

(8)初始化数据把mysql cluster数据迁移到slave

导出全部数据包括(mysql

 mysqldump  -uroot -p  --add-drop-database --all-databases --master-data=2 > db.dump

导出指定的数据库

 mysqldump  -uroot -p --add-drop-database --databases uxpay uxorder --master-data=2 > ux.dump

把导出的dump文件传输到slave

转换dump文件中表的引擎 ndbcluster转换为innodb

sed -i 's/ENGINE=ndbcluster/ENGINE=innodb/g' db.dump

 

8)在slave执行编辑后的dump文件

mysql -uroot -p < db.dmp

 

9)执行change master设置日志应用开始的位置

  CHANGE MASTER TO

  MASTER_LOG_FILE='@file',

  MASTER_LOG_POS=@pos;

例如:

CHANGE MASTER TO MASTER_LOG_FILE='ndb1.000006', MASTER_LOG_POS=141993409;

启动复制

mysql> START SLAVE;

(10)查看复制的状态

mysql> show slave status \G;

*************************** 1. row ***************************

               Slave_IO_State: Waiting for master to send event

                  Master_Host: 192.168.1.91

                  Master_User: myslave

                  Master_Port: 3306

                Connect_Retry: 60

              Master_Log_File: ndb1.000010

          Read_Master_Log_Pos: 6268

               Relay_Log_File: mydb3-relay-bin.000006

                Relay_Log_Pos: 4544

        Relay_Master_Log_File: ndb1.000010

             Slave_IO_Running: Yes

            Slave_SQL_Running: Yes

              Replicate_Do_DB:

          Replicate_Ignore_DB:

           Replicate_Do_Table:

       Replicate_Ignore_Table: mysql.ndb_apply_status

      Replicate_Wild_Do_Table:

  Replicate_Wild_Ignore_Table: mysql.ndb\_index\_stat\_%

                   Last_Errno: 0

                   Last_Error:

                 Skip_Counter: 0

          Exec_Master_Log_Pos: 6268

              Relay_Log_Space: 5312

              Until_Condition: None

               Until_Log_File:

                Until_Log_Pos: 0

           Master_SSL_Allowed: No

           Master_SSL_CA_File:

           Master_SSL_CA_Path:

              Master_SSL_Cert:

            Master_SSL_Cipher:

               Master_SSL_Key:

        Seconds_Behind_Master: 0

Master_SSL_Verify_Server_Cert: No

                Last_IO_Errno: 0

                Last_IO_Error:

               Last_SQL_Errno: 0

               Last_SQL_Error:

  Replicate_Ignore_Server_Ids:

             Master_Server_Id: 1000

                  Master_UUID: 67004af0-0c27-11e6-9fff-7427eaa3c20f

             Master_Info_File: /data/mysql/master.info

                    SQL_Delay: 0

          SQL_Remaining_Delay: NULL

      Slave_SQL_Running_State: Slave has read all relay log; waiting for the slave I/O thread to update it

           Master_Retry_Count: 86400

                  Master_Bind:

      Last_IO_Error_Timestamp:

     Last_SQL_Error_Timestamp:

               Master_SSL_Crl:

           Master_SSL_Crlpath:

           Retrieved_Gtid_Set:

            Executed_Gtid_Set:

                Auto_Position: 0

1 row in set (0.00 sec)


3.最后验证复制


你可能感兴趣的:(mysql)