凯发app官方网站-凯发k8官网下载客户端中心 | | 凯发app官方网站-凯发k8官网下载客户端中心
  • 博客访问: 276175
  • 博文数量: 90
  • 博客积分: 41
  • 博客等级: 民兵
  • 技术积分: 400
  • 用 户 组: 普通用户
  • 注册时间: 2011-12-07 11:52
文章分类
文章存档

2014年(11)

2013年(3)

2012年(69)

2011年(7)

相关博文
  • ·
  • ·
  • ·
  • ·
  • ·
  • ·
  • ·
  • ·
  • ·
  • ·

分类: linux

2014-06-19 15:13:34

原文地址: 作者:

mysql架构之mysql dual-master双向同步

mysql架构之mysql dual-凯发app官方网站

  其实与master-slave同步方式并无太大的不同,只是双方相互为对方的主从服务器。并且可以扩展到多台服务器。如下图

操作系统: centos 6.4 64

mysql版本:5.1.50

mysql1ip地址:192.168.100.60

mysql2ip地址:192.168.100.61

 

此步骤从略,确保两台测试机器的my.cnf相同,安装后能成功启动即可。

mysql(1)配置

创建账号

mysql> grant replication slave on *.* to 'repl'@'192.168.100.61' identified by '123456';

query ok, 0 rows affected (0.00 sec)

 

mysql> flush privileges;

query ok, 0 rows affected (0.00 sec)

 

修改my.cnf

[mysqld]

user       = mysql

pid-file   = /var/run/mysqld/mysqld.pid

port            = 3306

socket          = /usr/local/mysql/tmp/mysql.sock

basedir    = /usr/local/mysql

datadir   = /data/dbdata

tmpdir   = /tmp

log-bin  = master-bin

log-bin-index   = master-bin.index

 

replicate-same-server-id = 0

auto_increment_increment = 2

auto_increment_offset = 1

 

relay-log = slave-relay-bin

relay-log-index = slave-relay-bin.index

 

server-id       = 1

 

重启mysqld

/etc/init.d/mysqld restart

查看二进制文件名与位置偏移值

mysql> show master status;

------------------- ---------- -------------- ------------------

| file              | position | binlog_do_db | binlog_ignore_db |

------------------- ---------- -------------- ------------------

| master-bin.000003 |      106 |              |                  |

------------------- ---------- -------------- ------------------

1 row in set (0.00 sec)

注意:

记录以上两个值,等会启动复制要用到

 

mysql(2)配置

创建账号

mysql> grant replication slave on *.* to 'repl'@'192.168.100.60' identified by '123456';

query ok, 0 rows affected (0.00 sec)

 

mysql> flush privileges;

query ok, 0 rows affected (0.00 sec)

 

mysql>

 

修改my.cnf

 

[mysqld]

user       = mysql

pid-file   = /var/run/mysqld/mysqld.pid

port            = 3306

socket          = /usr/local/mysql/tmp/mysql.sock

basedir    = /usr/local/mysql

datadir   = /data/dbdata

tmpdir   = /tmp

relay-log = slave-relay-bin

relay-log-index = slave-relay-bin.index

 

replicate-same-server-id = 0

auto_increment_increment = 2

auto_increment_offset = 2

 

log-bin  = master-bin

log-bin-index   = master-bin.index

 

server-id       = 2

 

重启mysqld

/etc/init.d/mysqld restart

查看二进制文件名与位置偏移值

mysql> show master status;

------------------- ---------- -------------- ------------------

| file              | position | binlog_do_db | binlog_ignore_db |

------------------- ---------- -------------- ------------------

| master-bin.000003 |      106 |              |                  |

------------------- ---------- -------------- ------------------

1 row in set (0.00 sec)

注意:

记录以上两个值,等会启动复制要用到

启动mysql(1) replication

mysql> change master to

    -> master_host = '192.168.100.61',

    -> master_port = 3306,

    -> master_user = 'repl',

    -> master_password = '123456',

    -> master_log_file = 'master-bin.000003',

    -> master_log_pos = 106;

query ok, 0 rows affected (0.18 sec)

 

mysql> start slave;

query ok, 0 rows affected (0.00 sec)

 

查看slave状态

mysql> show slave status\g;

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

               slave_io_state: waiting for master to send event

                  master_host: 192.168.100.61

                  master_user: repl

                  master_port: 3306

                connect_retry: 60

              master_log_file: master-bin.000003

          read_master_log_pos: 106

               relay_log_file: slave-relay-bin.000002

                relay_log_pos: 252

        relay_master_log_file: master-bin.000003

             slave_io_running: yes

            slave_sql_running: yes

              replicate_do_db:

          replicate_ignore_db:

           replicate_do_table:

       replicate_ignore_table:

      replicate_wild_do_table:

  replicate_wild_ignore_table:

                   last_errno: 0

                   last_error:

                 skip_counter: 0

          exec_master_log_pos: 106

              relay_log_space: 407

              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:

1 row in set (0.00 sec)

 

启动启动mysql(1)replication

 

mysql> change master to

    -> master_host = '192.168.100.60',

    -> master_port = 3306,

    -> master_user = 'repl',

    -> master_password = '123456',

    -> master_log_file = 'master-bin.000003',

    -> master_log_pos = 106;

query ok, 0 rows affected (0.11 sec)

 

mysql> start slave;

query ok, 0 rows affected (0.00 sec)

查看slave状态

mysql> show slave status\g;

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

               slave_io_state: waiting for master to send event

                  master_host: 192.168.100.60

                  master_user: repl

                  master_port: 3306

                connect_retry: 60

              master_log_file: master-bin.000003

          read_master_log_pos: 106

               relay_log_file: slave-relay-bin.000002

                relay_log_pos: 252

        relay_master_log_file: master-bin.000003

             slave_io_running: yes

            slave_sql_running: yes

              replicate_do_db:

          replicate_ignore_db:

           replicate_do_table:

       replicate_ignore_table:

      replicate_wild_do_table:

  replicate_wild_ignore_table:

                   last_errno: 0

                   last_error:

                 skip_counter: 0

          exec_master_log_pos: 106

              relay_log_space: 407

              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:

1 row in set (0.00 sec)

 

 

 

 

 

 

 

 

 

 

 

 

 

[mysqld]

user       = mysql

pid-file   = /var/run/mysqld/mysqld.pid

port            = 3306

socket          = /usr/local/mysql/tmp/mysql.sock

basedir    = /usr/local/mysql

datadir   = /data/dbdata

tmpdir   = /tmp

relay-log = slave-relay-bin

relay-log-index = slave-relay-bin.index

 

replicate-same-server-id = 0

auto_increment_increment = 2

auto_increment_offset = 1

 

log-bin  = master-bin

log-bin-index   = master-bin.index

 

mysql(1)

示例:在mysql(1)服务器创建example

mysql> create database example;

query ok, 1 row affected (0.00 sec)

 

mysql> show databases;

--------------------

| database           |

--------------------

| information_schema |

| example            |

| mysql              |

| test               |

--------------------

4 rows in set (0.00 sec)

 

查看mysql(2)

mysql> show databases;

--------------------

| database           |

--------------------

| information_schema |

| example            |

| mysql              |

| test               |

--------------------

4 rows in set (0.00 sec)

 

mysql(2)

示例:在mysql(2)服务器创建example1

 

mysql> create database example1;

query ok, 1 row affected (0.00 sec)

mysql> show databases;

--------------------

| database           |

--------------------

| information_schema |

| example            |

| example1           |

| mysql              |

| test               |

--------------------

5 rows in set (0.00 sec)

 

查看mysql(1)

mysql> show databases;

--------------------

| database           |

--------------------

| information_schema |

| example            |

| example1           |

| mysql              |

| test               |

--------------------

5 rows in set (0.00 sec)

 

测试成功

阅读(2976) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~
")); function link(t){ var href= $(t).attr('href'); href ="?url=" encodeuricomponent(location.href); $(t).attr('href',href); //setcookie("returnouturl", location.href, 60, "/"); }
网站地图