`

Mysql5.5.10互为主从复制配置

 
阅读更多

MySQL-master1:192.168.0.128
MySQL-master2:192.168.0.129
OS版本:CentOS 5.4
MySQL版本:5.5.10

一、MySQL master-master配置

1、修改MySQL配置文件
  两台MySQL均如要开启binlog日志功能,开启方法:在MySQL-master1  配置文件/etc/my.cnf的[MySQLd]段中加上
  
log-bin=mysql -bin  
server-id = 1
#binlog-do-db=radius  
binlog-ignore-db=mysql ,test   
log-slave-updates  
slave-skip-errors=all  
sync_binlog=1  
auto_increment_increment=2  
auto_increment_offset=1 

在MySQL-master2  配置文件/etc/my.cnf的[MySQLd]段中加上
  
log-bin=mysql -bin  
server-id  = 2  
log-slave-updates  
slave-skip-errors=all  
sync_binlog=1  
auto_increment_increment=2  
auto_increment_offset=2 

将两个配置文件保存,分别重启mysql 服务器
binlog-do-db=database   是要记录日志的数据库;
binlog-ignore-db        是不要记录日志的数据库名,多个数据库中间用逗号(,)隔开;

2、将192.168.0.128设为192.168.0.129的主服务器

在192.168.0.128上新建授权用户
MySQL> grant replication slave on *.* to ‘replication’@'%’ identified by ‘replication’;
Query OK, 0 rows affected (0.00 sec) 
MySQL>flush privileges;
Query OK, 0 rows affected (0.00 sec)
MySQL> show master status;
+——————+———-+————–+——————+

| File             | Position | Binlog_Do_DB | Binlog_Ignore_DB |

+——————+———-+————–+——————+

| MySQL-bin.000003 |      374 |              |                  |

+——————+———-+————–+——————+
1 row in set (0.00 sec)  

在192.168.0.129将192.168.0.128为自己的主服务器
MySQL> change master to master_host=’192.168.0.128′,master_user=’replication’,master_password=’replication’,master_log_file=’MySQL-bin.000003′,master_log_pos=374;

Query OK, 0 rows affected (0.05 sec)  
MySQL> start slave;
Query OK, 0 rows affected (0.00 sec)  
MySQL> show slave status\G;
*************************** 1. row ***************************

             Slave_IO_State: Waiting for master to send event
                Master_Host: 192.168.0.128
                Master_User: replication
                Master_Port: 3306
              Connect_Retry: 60
            Master_Log_File: MySQL-bin.000003
        Read_Master_Log_Pos: 374
             Relay_Log_File: MySQL-master2-relay-bin.000002
              Relay_Log_Pos: 235
      Relay_Master_Log_File: MySQL-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: 374
            Relay_Log_Space: 235
            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
1 row in set (0.00 sec)
红色标注部分为192.168.0.128主机中show master status命令结果中的file postion两个值

3、将192.168.0.129设为192.168.0.128的主服务器

在192.168.0.129上新建授权用户
MySQL> grant replication slave on *.* to ‘replication’@'%’ identified by ‘replication’;
Query OK, 0 rows affected (0.00 sec)
 
MySQL>flush privileges;
Query OK, 0 rows affected (0.00 sec)
MySQL> show master status;
+——————+———-+————–+——————+

| File             | Position | Binlog_Do_DB | Binlog_Ignore_DB |

+——————+———-+————–+——————+

| MySQL-bin.000003 |      374 |              |                  |

+——————+———-+————–+——————+
1 row in set (0.00 sec)
在192.168.0.128将192.168.0.129为自己的主服务器
MySQL> change master to master_host=’192.168.0.129′,master_user=’replication’,master_password=’replication’,master_log_file=’MySQL-bin.000003′,master_log_pos=374;
Query OK, 0 rows affected (0.05 sec)  
MySQL> start slave;
Query OK, 0 rows affected (0.00 sec)  
MySQL> show slave status\G;
*************************** 1. row ***************************

             Slave_IO_State: Waiting for master to send event
                Master_Host: 192.168.0.129
                Master_User: replication
                Master_Port: 3306
              Connect_Retry: 60
            Master_Log_File: MySQL-bin.000003
        Read_Master_Log_Pos: 374
             Relay_Log_File: MySQL-master2-relay-bin.000002
              Relay_Log_Pos: 235
      Relay_Master_Log_File: MySQL-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: 374
            Relay_Log_Space: 235
            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
1 row in set (0.00 sec)

mysql 配置文件my.cnf中   
log-slave-updates  表示如果一个MASTER挂掉的话,另外一个马上接管。
sync_binlog=1
auto_increment_increment=2
auto_increment_offset=1   指的是服务器频繁的刷新日志。这个保证了在其中一台挂掉的话,日志刷新到另外一台。从而保证了数据的同步 。
如果主数据库有数据的话,数据库锁表操作,不让数据再进行写入动作。
mysql > FLUSH TABLES WITH READ LOCK ;
看主数据库的状态
mysql > show master status;
把主服务器数据文件复制到从服务器,最好先用tar处理一下
取消主数据库锁定
mysql >UNLOCK TABLES;

分享到:
评论

相关推荐

    mysql5.5.10安装手册

    mysql5.5.10安装文档。比较详细,后面附了一部分错误解决方案

    mysql 5.5.10(源码)

    ySQL是一个小型关系型数据库管理系统,开发者为瑞典MySQL AB公司。在2008年1月16号被Sun公司收购。而2009年,SUN又被Oracle收购。MySQL是一种关联数据库管理系统,关联数据库将数据保存在不同的表中,而不是将所有...

    mysql-5.5.10-winx64.msi

    MySQL(官方发音为/maɪ ˌɛskjuːˈɛl/“My S-Q-L”,但也经常被错误读作/maɪ ˈsiːkwəl/“My Sequel”)原本是一个开放源码的关系数据库管理系统,原开发者为瑞典的MySQL AB公司,该公司于2008年被昇阳微系统...

    mysql-5.5.10.tar.gz

    MySQL :: The world's most popular open source database

    php-5.5.10环境自搭建iis+php+mysql

    php-5.5.10环境自搭建iis+php+mysql

    MySQL-【5.5.10-win32】免安装精简版.7z

    支持高级特性,适度精简,适合部署发布用.内置2个账号 帐号root 密码空 帐号heminghui 密码1987413 端口:55555 精心制作的批处理。还有各个ini也保留了,方便不同的场景

    64位apache+mysql+php5.5.10+memcache

    mysql 太大 我给删掉了, PHP 5.5.10自己 一直用 ,不喜欢集成环境的朋友可以下载安装,还有memcacheadmin。

    MySQL-server-5.5.10-1.linux2.6.x86_64.rpm

    MySQL-server-5.5.10-1.linux2.6.x86_64 Linux 安装包

    itext5.5.10生成PDF

    itext5.5.10生成PDF。itext5.5.10生成PDF。itext5.5.10生成PDF。itext5.5.10生成PDF。

    itextpdf-5.5.10

    itextpdf-5.5.10、源码、帮助文档,开发工具jar包;实现pdf和数字签名必备

    itextpdf-5.5.10.jar

    itext jar包 版本 5.5.10

    MySQL-client-5.5.10-1.rhel5.x86_64.rpm

    MySQL-client-5.5.10-1.rhel5.x86_64.rpm

    mysql-5.6.10.tar.gz

    MySQL Community Server 5.6.10 source code版本 Generic Linux (Architecture Independent), Compressed TAR Archive 这个是依赖linux的mysql共通版,tar压缩包

    itext5-5.5.10

    版本号:5.5.10。通过iText不仅可以生成PDF或rtf的文档,而且可以将XML、Html文件转化为PDF文件。 iText的安装:下载iText.jar文件后,只需要在系统的CLASSPATH中加入iText.jar的路径,在程序中就可以使用iText类库了...

    php-5.5.10-Win32-VC11-x64.zip

    php-5.5.10-Win32-VC11-x64.zip

    itextsharp-all-5.5.10.tar

    C#读取PDF文本内容时,引用iTextSharp会显示iTextSharp.text.pdf中不存在类型或命名空间名parser,原因是iTextSharp版本过低,...本文件为5.5.10版,可解决这个问题。 引用itextsharp-dll-core中的itextsharp-dll即可。

    itextsharp-all-5.5.10

    一个不错的操作PDF的类

    php-5.5.10-nts-Win32-VC11-x64.zip

    php-5.5.10-nts-Win32-VC11-x64.zip

    mysql5.5-10 win part 09

    mysql-5.5.10-win32.part01.rar 到 mysql-5.5.10-win32.part09.rar

    mysql5.5-10 win part 01

    mysql-5.5.10-win32.part01.rar 到 mysql-5.5.10-win32.part09.rar

Global site tag (gtag.js) - Google Analytics