mysql 主主互备快速配置(备忘留存)

后续添加:

Keepalived 实现mysql故障迁移

heartbeat+DRBD+mysql高可用

MMM构建mysql高可用集群

  1. 配置环境

[[email protected]_1 ~]# uname -a  
Linux wdds_1 2.6.32-504.el6.x86_64 #1 SMP Wed Oct 15 04:27:16 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux[[email protected]_1 ~]# ifconfig eth0 |grep "inet addr:"    
          inet addr:10.0.0.61  Bcast:10.0.0.255  Mask:255.255.255.0

[[email protected]_2 ~]# ifconfig eth0|grep "inet addr:"  
          inet addr:10.0.0.62  Bcast:10.0.0.255  Mask:255.255.255.0

2.安装mysql

yum install mysql*

3、配置my.cnf文件

节点一:

[[email protected]_1 ~]# cat /etc/my.cnf    
[mysqld]    
datadir=/var/lib/mysql    
socket=/var/lib/mysql/mysql.sock    
user=mysql    
# Disabling symbolic-links is recommended to prevent assorted security risks    
symbolic-links=0

server-id = 1  
log-bin = mysql-relay-bin    
relay-log = mysql-relay-bin    
replicate-wild-ignore-table = mysql.%    
replicate-wild-ignore-table = test.%    
replicate-wild-ignore-table = information_schema.%

[mysqld_safe]  
log-error=/var/log/mysqld.log    
pid-file=/var/run/mysqld/mysqld.pid

节点二:

[[email protected]_2 ~]# cat /etc/my.cnf    
[mysqld]    
datadir=/var/lib/mysql    
socket=/var/lib/mysql/mysql.sock    
user=mysql    
# Disabling symbolic-links is recommended to prevent assorted security risks    
symbolic-links=0

server-id = 2  
log-bin = mysql-relay-bin    
relay-log = mysql-relay-bin    
replicate-wild-ignore-table = mysql.%    
replicate-wild-ignore-table = test.%    
replicate-wild-ignore-table = information_schema.%

[mysqld_safe]  
log-error=/var/log/mysqld.log    
pid-file=/var/run/mysqld/mysqld.pid

4、在同步之前,需要先手动同步数据库,保证数据库一致性

同步之前需要先锁表:

mysql> FLUSH TABLES WITH READ LOCK;  
Query OK, 0 rows affected (0.00 sec)

同步方法:

1)使用mysqldump工具导出,然后在导入到另一节点中

2)直接打包/var/lib/mysql 文件或其他mysql 的date文件(因这是测试 就直接打包了)

tar zcvf mysql.tar.gz /var/lib/mysql  然后scp到另一节点上。

5、在两个节点上分别创建复制的用户:

节点一:

mysql> grant replication slave on *.* to ‘repl_user‘@‘%‘ identified by ‘123.com‘;

mysql> show master status;  
+------------------------+----------+--------------+------------------+    
| File                   | Position | Binlog_Do_DB | Binlog_Ignore_DB |    
+------------------------+----------+--------------+------------------+    
| mysql-relay-bin.000004 |     1231 |              |                  |      
+------------------------+----------+--------------+------------------+
   
1 row in set (0.00 sec)

节点二:

mysql> grant replication slave on *.* to ‘repl_user‘@‘10.0.0.61‘ identified by ‘123.com‘;

mysql> show master status;  
+------------------------+----------+--------------+------------------+    
| File                   | Position | Binlog_Do_DB | Binlog_Ignore_DB |    
+------------------------+----------+--------------+------------------+    
| mysql-relay-bin.000002 |      480 |              |                  |    
+------------------------+----------+--------------+------------------+    
1 row in set (0.00 sec)

6、配置各自的主节点并:

节点一:

mysql> change master to  master_host=‘10.0.0.62‘, master_user=‘repl_user‘, master_password=‘123.com‘, master_log_file=‘mysql-relay-bin.000002‘, master_log_pos=480;

启动:mysql>start slave;

查看启动后的状态:

mysql> show slave status\G;    
*************************** 1. row ***************************    
               Slave_IO_State: Waiting for master to send event    
                  Master_Host: 10.0.0.62    
                  Master_User: repl_user    
                  Master_Port: 3306    
                Connect_Retry: 60    
              Master_Log_File: mysql-relay-bin.000002    
          Read_Master_Log_Pos: 480    
               Relay_Log_File: mysql-relay-bin.000002    
                Relay_Log_Pos: 367    
        Relay_Master_Log_File: mysql-relay-bin.000002    
            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: mysql.%,test.%,information_schema.%    
                   Last_Errno: 0    
                   Last_Error:    
                 Skip_Counter: 0    
          Exec_Master_Log_Pos: 480    
              Relay_Log_Space: 522    
              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> change master to  master_host=‘10.0.0.61‘, master_user=‘repl_user‘, master_password=‘123.com‘, master_log_file=‘mysql-relay-bin.000004‘, master_log_pos=480;

启动:mysql>start slave;

mysql> show slave status\G;  
*************************** 1. row ***************************    
               Slave_IO_State: Waiting for master to send event    
                  Master_Host: 10.0.0.61    
                  Master_User: repl_user    
                  Master_Port: 3306    
                Connect_Retry: 60    
              Master_Log_File: mysql-relay-bin.000004    
          Read_Master_Log_Pos: 1231    
               Relay_Log_File: mysql-relay-bin.000004    
                Relay_Log_Pos: 1227    
        Relay_Master_Log_File: mysql-relay-bin.000004    
             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: mysql.%,test.%,information_schema.%    
                   Last_Errno: 0    
                   Last_Error:    
                 Skip_Counter: 0    
          Exec_Master_Log_Pos: 1231    
              Relay_Log_Space: 1488    
              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.01 sec)

7、测试:分别在两个节点上创建数据库 或表,在另一个节点上查看是否已经创建。

创建一个数据库   create database test100 character set utf8;

查看数据库 show databases;

时间: 2024-10-07 06:15:49

mysql 主主互备快速配置(备忘留存)的相关文章

mysql主主互备模式配置

本文为南非蚂蚁的书籍<循序渐进linux-第二版>-8.3.5的读笔记 mysql双主互备架构图 mysql主主互备模式配置 环境: DB1:主服务器  centos6.6  mysql5.1.73 IP:10.24.24.111 DB2:从服务器  centos6.6  mysql5.1.73 IP:10.24.24.112 mysql VIP:10.24.24.112 ---------------------------------------- centos6.x安装mysql # y

配置MySQL实现主主互备模式并利用keepalived实现双主高可用

每台主机均需安装keepalived,mysql,安装过程这里不多介绍,不懂的可自行百度. 本次配置的环境为 DB1:192.168.31.190                DB2:192.168.31.184        MySQL VIP:192.168.31.189 1.修改MySQL配置文件 首先修改DB1的/etc/my.cnf配置文件,在"[mysqld]"段中添加一下内容: server-id = 1 log-bin=mysql-bin relay-log = my

MySQL双主互备模式架构

MySql双主互备架构模式 操作系统 CentOS 6.3 MySql版本 mysql-5.0.56 keepalived keepalived-1.1.19.tar.gz Master DB1配置文件 修改MySql 配置文件  /etc/my.cnf 增加以下段落 [mysqld] server-id=1    节点标示 log-bin=mysql-bin   开启mysql的binlog日志功能 relay-log = mysql-relay-bin  用来定义日志文件命名格式 repli

MySQL主主互备结合keepalived实现高可用

试验环境: master:192.168.1.210(CentOS6.5) slave:192.168.1.211(CentOS6.5) VIP:192.168.1.208 MySQL主主互备模式配置 step1:Master服务的/etc/my.cnf配置 [mysqld] basedir = /usr/local/mysql datadir = /var/lib/mysql port = 3306 socket = /var/lib/mysql/mysql.sock server_id = 

MySQL主主互备模式(Keepalived)

MySQL双主-高可用 单台数据库实例安装 请参考:二进制包安装MySQL 资源规划 主机名 os 版本 MySQL 版本 主机 IP MySQL VIP db01.lyk.com centos 6.4 mysql-5.6.21-linux-glibc2.5-x86_64 172.31.30.12 172.31.30.222 db02.lyk.com centos 6.4 mysql-5.6.21-linux-glibc2.5-x86_64 172.31.30.11 3.修改MySQL配置文件

mysql主主互备架构

企业级mysql集群具备高可用,可扩展性,易管理,低成本的特点.mysql主主互备就是企业中常用的一个解决方案.在这种架构中,虽然互为主从,但同一时刻只有一台mysql 可读写,一台mysqk只能进行读操作 1.配置 环境: DB1(master)  mysql-5.1.73-3.el6_5.x86_64   192.168.32.130 DB2 (slave)    mysql-5.1.73-3.el6_5.x86_64    192.168.32.129 mysql vip : 192.16

mysql主主互备+原来mysql主从架构

接http://wsw26.blog.51cto.com/1442148/1749125我这个A已做了BC的主架构上增加一台D的虚拟机(同一个环境),我的目的是D和A主主互备,BC继续做A的从,既是D<-->A-->BC这样架构(类似级联的) 准备工作:(1)D的IP是192.168.0.190,A的IP是192.168.0.8,B的IP是192.168.0.140,C的IP是192.168.0.141(2)将A的mysql备份的sql通过scp传去D那里再从D那里新建对应的数据库名字后

MariaDB、MySQL双主互备模型同步数据

MySQL双主互备即两台MySQL服务器同时是主服务器,而同时又是对方的从服务器,这样可以分担主服务器的一部分写请求,因为如果是单主模型的话数据写入只能写入在一台MySQL服务器,而双主模型则可同时写在两台服务器上,有效加快了写入的速度,而且还能提供数据的备份功能. 环境如下: server1:CentOS 6.5 x86_64 mariadb 10.0.10 IP:192.168.10.204 server2:CentOS 6.5 x86_64 mariadb 10.0.10  IP:192.

mysql双主互备

一.安装mysql 各种方式太多了 二.摘录自:https://linux.cn/thread-14135-1-1.html 1)首先在DB1上my.cnf 中[mysqld] 字段中添加如下内容:server-id = 1 //数据库ID号, 为1时表示为Master,其中master_id必须为1到232–1之间的一个正整数值;log-bin=mysql-bin //启用二进制日志: relay-log=mysql-relay-bin  //用来定义relay-log日志文件命名格式repl