1. 程式人生 > >MySQL5.5.42 主從複製架構搭建

MySQL5.5.42 主從複製架構搭建

1、非同步複製構建

2、半同步複製構建

1、安裝相同mysql資料版本5.5.42
   

     192.168.56.101  master
     192.168.56.102  slave
     192.168.56.103  vhost

主庫配置:

2、在主庫上建立一個用作複製使用的賬戶repl,授予REPLICATION SLAVE許可權;

      同時授權限制從slave節點連線訪問。在master主機上執行:

     mysql>grant REPLICATION SLAVE on *.* to 'repl'@'192.168.56.102' identified by 'repl';
     mysql>grant REPLICATION SLAVE on *.* to 'repl'@'192.168.56.103' identified by 'repl';

3、修改master主機my.cnf配置檔案,開啟 BINLOG,並設定server-id的值。這兩個引數的修改需要重新啟動資料庫服務才生效。

vi my.cnf
[mysqld]
log-bin=/fsystem1/mylogbin/mysql-bin.log
server-id = 1

4、在master上設定讀鎖定有效,這是為了確保沒有資料庫操作,以便獲得一個一致性快照。

mysql> flush tables with read lock;
Query OK, 0 rows affected (0.00 sec)

5、從master獲取當前二進位制日誌名稱和偏移量值。這是為了在從資料庫啟動後,從這個點開始進行資料的恢復;

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

一致性備份:

cd /fsystem1/
tar -cvf data.tar data
scp data.tar  slave:/fsystem1/
scp data.tar  vhost:/fsystem1/

6、開鎖
mysql> unlock tables;
Query OK, 0 rows affected (0.00 sec)

從庫配置:


兩個從庫未開啟。將data.tar恢復到指定的路徑下:tar -xvf data.tar

7、配置從庫配置檔案,確保沒個節點的server-id不重複。

#on slave
vi my.cnf
[mysqld]
server-id = 2
#on vhost
vi my.cnf
[mysqld]
server-id = 3

8、在從庫上使用-skip-salve-start引數啟動,這樣不會立即啟動從資料庫上的複製程序,方便對從庫進一步配置。

    或者直接啟動 service mysql start

9、對slave庫做相應設定,指定複製使用者,主資料庫伺服器胡ip,埠,以及開始執行復制胡日誌檔案和位置等
      on slave/vhost執行:

mysql>
change master to
master_host='192.168.56.101',
master_port=3306,
master_user='repl',
master_password='repl',
master_log_file='mysql-bin.000001',
master_log_pos=107;

10、在從庫啟動slave IO執行緒。

mysql>start slave ;

mysql>show slave status \G;檢視slave相關資訊
mysql> show slave status \G;
*************************** 1. row ***************************
               Slave_IO_State: Connecting to master
                  Master_Host: 192.168.56.101
                  Master_User: repl
                  Master_Port: 3306
                Connect_Retry: 60
              Master_Log_File: mysql-bin.000001
          Read_Master_Log_Pos: 107
               Relay_Log_File: vhost-relay-bin.000001
                Relay_Log_Pos: 4
        Relay_Master_Log_File: mysql-bin.000001
             Slave_IO_Running: Connecting
            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: 107
              Relay_Log_Space: 107
              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: NULL
Master_SSL_Verify_Server_Cert: No
                Last_IO_Errno: 2003
                Last_IO_Error: error connecting to master '[email protected]:3306' - retry-time: 60  retries: 86400
               Last_SQL_Errno: 0
               Last_SQL_Error:
  Replicate_Ignore_Server_Ids:
             Master_Server_Id: 0
1 row in set (0.00 sec)

ERROR:
No query specified

mysql> show processlist \G;
*************************** 1. row ***************************
     Id: 1
   User: root
   Host: localhost
     db: NULL
Command: Query
   Time: 0
  State: NULL
   Info: show processlist
*************************** 2. row ***************************
     Id: 2
   User: system user
   Host:
     db: NULL
Command: Connect
   Time: 114
  State: Connecting to master
   Info: NULL
*************************** 3. row ***************************
     Id: 3
   User: system user
   Host:
     db: NULL
Command: Connect
   Time: 114
  State: Slave has read all relay log; waiting for the slave I/O thread to update it
   Info: NULL
3 rows in set (0.00 sec)

ERROR:
No query specified

原因是由於master防火牆沒有關閉。


配置半同步複製(在非同步複製基礎上配置)

mysql> select @@have_dynamic_loading ;
+------------------------+
| @@have_dynamic_loading |
+------------------------+
| YES                    |
+------------------------+
1 row in set (0.00 sec)

[[email protected] plugin]# pwd
/mysql/mysql-5.5.42/lib/plugin
[[email protected] plugin]# ls -l | grep semisync_
-rwxr-xr-x. 1 root mysql 170522 Jan  7  2015 semisync_master.so
-rwxr-xr-x. 1 root mysql  88911 Jan  7  2015 semisync_slave.so

1、在主庫上安裝semisync_master.so,從庫上安裝semisync_slave.so
     語句成分是固定的。

MySQL>install plugin rpl_semi_sync_master SONAME 'semisync_master.so';
mysql>install plugin rpl_semi_sync_slave SONAME 'semisync_slave.so';

mysql> select * from mysql.plugin;
+---------------------+-------------------+
| name                | dl                |
+---------------------+-------------------+
| rpl_semi_sync_slave | semisync_slave.so |
+---------------------+-------------------+
1 row in set (0.00 sec)
mysql> select * from mysql.plugin;
+----------------------+--------------------+
| name                 | dl                 |
+----------------------+--------------------+
| rpl_semi_sync_master | semisync_master.so |
+----------------------+--------------------+
1 row in set (0.00 sec)


2、安裝完成後,需要開啟半同步複製開關,預設是關閉的。

mysql>set global rpl_semi_sync_master_enabled=1;
mysql>set global rpl_semi_sync_master_timeout=30000;
mysql> show status like '%semi_sync%';
+--------------------------------------------+-------+
| Variable_name                              | Value |
+--------------------------------------------+-------+
| Rpl_semi_sync_master_clients               | 0     |
| Rpl_semi_sync_master_net_avg_wait_time     | 0     |
| Rpl_semi_sync_master_net_wait_time         | 0     |
| Rpl_semi_sync_master_net_waits             | 0     |
| Rpl_semi_sync_master_no_times              | 0     |
| Rpl_semi_sync_master_no_tx                 | 0     |
| Rpl_semi_sync_master_status                | ON    |
| Rpl_semi_sync_master_timefunc_failures     | 0     |
| Rpl_semi_sync_master_tx_avg_wait_time      | 0     |
| Rpl_semi_sync_master_tx_wait_time          | 0     |
| Rpl_semi_sync_master_tx_waits              | 0     |
| Rpl_semi_sync_master_wait_pos_backtraverse | 0     |
| Rpl_semi_sync_master_wait_sessions         | 0     |
| Rpl_semi_sync_master_yes_tx                | 0     |
+--------------------------------------------+-------+
14 rows in set (0.00 sec)

由於是在非同步複製的基礎上配置的,需要重新啟動從庫的I/O執行緒。

mysql> show status like '%semi_sync%';
+----------------------------+-------+
| Variable_name              | Value |
+----------------------------+-------+
| Rpl_semi_sync_slave_status | OFF   |
+----------------------------+-------+
1 row in set (0.00 sec)
mysql>set global rpl_semi_sync_slave_enabled=1;

mysql>stop slave IO_THREAD ;start slave IO_THREAD;

配置完成。
mysql> show status like '%semi_sync%';
+----------------------------+-------+
| Variable_name              | Value |
+----------------------------+-------+
| Rpl_semi_sync_slave_status | ON    |----半同步複製開啟。
+----------------------------+-------+
1 row in set (0.00 sec)


mysql> show status like '%semi_sync%';
+--------------------------------------------+-------+
| Variable_name                              | Value |
+--------------------------------------------+-------+
| Rpl_semi_sync_master_clients               | 2     |------------從庫數量
| Rpl_semi_sync_master_net_avg_wait_time     | 0     |
| Rpl_semi_sync_master_net_wait_time         | 0     |
| Rpl_semi_sync_master_net_waits             | 0     |
| Rpl_semi_sync_master_no_times              | 0     |
| Rpl_semi_sync_master_no_tx                 | 0     |
| Rpl_semi_sync_master_status                | ON    |----半同步複製開啟。
| Rpl_semi_sync_master_timefunc_failures     | 0     |
| Rpl_semi_sync_master_tx_avg_wait_time      | 0     |
| Rpl_semi_sync_master_tx_wait_time          | 0     |
| Rpl_semi_sync_master_tx_waits              | 0     |
| Rpl_semi_sync_master_wait_pos_backtraverse | 0     |
| Rpl_semi_sync_master_wait_sessions         | 0     |
| Rpl_semi_sync_master_yes_tx                | 0     |
+--------------------------------------------+-------+
14 rows in set (0.00 sec)






相關推薦

MySQL5.5.42 主從複製架構搭建

1、非同步複製構建 2、半同步複製構建 1、安裝相同mysql資料版本5.5.42          192.168.56.101  master      192.168.56.102  slave      192.168.56.103  vhost 主庫配置: 2

linux 下Redis 5.0主從複製(一主二從)的搭建

文件結構如下:   一、環境說明: 作用 IP地址 埠 作業系統版本 安裝目錄 主庫 172.16.10.80 6379 Redhat 6.7

MySQL5.7.17主從複製搭建(一主一從)教程詳解

mysql> stop slave; #暫停從庫 mysql>CHANGE MASTER TO MASTER_HOST='192.168.0.120',MASTER_USER='repl', MASTER_PASSWORD='[email protected]',MASTER_LOG_

linux redhat6.5中 用LAMP架構搭建安裝 論壇

用LAMP架構搭建安裝 論壇LAMP指的Linux(操作系統)、ApacheHTTP 服務器,MySQL(有時也指MariaDB,數據庫軟件) 和PHP(有時也是指Perl或Python) 的第一個字母,一般用來建立web 服務器。本文中使用renhat6.5 APACHE+Mysql +PHP 開源論壇 搭

Centos7安裝MySQL5.7和主從複製配置

一:MySQL安裝 1、下載tar包,這裡使用wget從官網下載 wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.22-linux-glibc2.12-x86_64.tar.gz 2、將mysql安裝

linux centos下mysql資料庫的主從複製環境搭建

有兩臺MySQL資料庫伺服器Master和slave,Master為主伺服器,slave為從伺服器,初始狀態時,Master和slave中的資料資訊相同,當Master中的資料發生變化時,slave也跟著發生相應的變化,使得master和slave的資料資訊同步,達到備份的目的。 原理圖如下:

mysql5.1.73 主從複製的設定套路

2、修改主伺服器master:    #vi /etc/my.cnf   [client] #password       = your_password port    

MongoDB 主從複製搭建

一、Mongodb複製集簡介 什麼是複製集? 複製集(Replica Sets)是額外的資料副本,是跨多個伺服器同步資料的過程,複製集提供了冗餘並增加了資料可用性,通過複製集可以對硬體故障和中斷的服務進行恢復。 MongoDB複製集原理: mongodb

MySQL-主從複製搭建從資料庫

上一遍我們成功搭建了MySQL-3380作為主從複製架構中的主資料庫,該資料庫我們用於寫資料。那麼接下來我們將搭建MySQL-3381作為從資料庫,用於讀資料。 我們嘗試裝機msi安裝程式,會發現彈出如下的彈出框。這個表示使用安裝器是無法安裝多例項的,只能手動安裝。

CentOS6中MySql5.6資料庫主從複製/讀寫分離(二)

程式碼層面實現讀寫分離 在文章(一)中我們已經有了兩個資料庫而且已經實現了主從資料庫同步,接下來的問題就是在我們的業務程式碼裡面實現讀寫分離,假設我們使用的是主流的ssm的框架開發的web專案,這裡面我們需要多個數據源。 在此之前,我們在專案中一般會使用一

4.Redis主從複製叢集搭建步驟

本文主要介紹Redis主從複製的詳細配置步驟。 1.主-從模式; 2.主-從-從模式。 一、主-從模式 1.主從模式從結構上來看,其實就是擁有master和slave的redis叢集,其拓撲結構如圖所示: 注意:Redis叢集不用安

mysql 5.7 主從複製

mysql主從複製  首先這個密碼就搞得我很頭大  yum安裝的rpm包 系統自動完成初始化 預設密碼強度是strong 這個設定是真的坑 規則很嚴格 反正我試了各種辦法都不能滿足密碼要求  只能先用服務啟動時日誌裡給的初始密碼先登進去 然後修改規則 再執行mysql_s

5.redis主從複製

redis主從複製 什麼是主從複製? 主從複製,是用來建立一個和主資料庫(master)完全一樣的資料庫環境,稱為從資料庫(slave)。 主從複製的作用和使用場合一般有幾個: 一是容災恢復,主資料庫伺服器故障後,可迅速從從資料庫恢復。 二是讀寫分離、主資料庫主要做寫的操作,從資料庫做讀的操作。 主從複製應

Linux mariadb(Mysql)的主從複製架構

mysql的主從複製架構,需要準備兩臺機器,並且可以通訊,安裝好2個mysql,保持版本一致性 mysql -v 檢視資料庫版本1.準備主庫的配置檔案  /etc/my.cnf 寫入開啟主庫的引數[mysqld]# 標註 主庫的身份idserver-id=1# 那個binlog的檔名log-bin=

MyCat1.6+Mysql5.7的主從複製+讀寫分離

1.Mysql的主從複製前提準備工作及注意事項:a、主DB server和從DB server資料庫的版本一致b、主DB server和從DB server資料庫資料一致[ 這裡就會可以把主的備份在從上還原,也可以直接將主的資料目錄拷貝到從的相應資料目錄]c、主DB serv

centos7下配置mysql5.7.24主從複製

前置條件 準備兩臺伺服器(可以是虛擬機器),系統為centos7 此處演示的兩臺伺服器:192.168.8.134、192.168.8.135 第一步:安裝mysql5.7.24 先在兩臺伺服器上安裝mysql5.7.24,安裝可參考: 安裝成功後,啟動mysql。如果是虛擬機器的話,在一臺安裝好之

MySQL主從複製架構使用方法

一. 單個數據庫伺服器的缺點 資料庫伺服器存在單點問題 資料庫伺服器資源無法滿足增長的讀寫請求 高峰時資料庫連線數經常超過上限 二. 如何解決單點問題 增加額外的資料庫伺服器,組建資料庫叢集 同一叢集中的資料庫伺服器需要具有相同的資料 叢集中的任一伺服器宕機後,其它伺服器可以取代宕機伺服器 三.

mysql5.7的主從複製,基於GTID複製,並行複製,半同步複製

一 最簡單的AB主從複製 MySQL之間資料複製的基礎是二進位制日誌檔案(binary log file)。一臺MySQL資料庫一旦啟用二進位制日誌後,其作為master,它的資料庫中所有操作都會以“事件”的方式記錄在二進位制日誌中,其他資料庫作為slave通

MySQL主從複製架構

轉載於http://www.cnblogs.com/mindwind/p/4973635.html 原生複製架構 MySQL 的原生複製架構原理如上圖所示。從庫的 I/O Thread 執行緒負責不斷讀取主庫的 binlog 日誌檔案並寫入本地的 Relay l