久久久久久久视色,久久电影免费精品,中文亚洲欧美乱码在线观看,在线免费播放AV片

<center id="vfaef"><input id="vfaef"><table id="vfaef"></table></input></center>

    <p id="vfaef"><kbd id="vfaef"></kbd></p>

    
    
    <pre id="vfaef"><u id="vfaef"></u></pre>

      <thead id="vfaef"><input id="vfaef"></input></thead>

    1. 站長資訊網(wǎng)
      最全最豐富的資訊網(wǎng)站

      歸納整理之MySQL基于GTID主從搭建

      本篇文章給大家?guī)砹岁P于mysql的相關知識,主要介紹了MySQL基于GTID主從搭建,文章首先通過xtarbackup來同步數(shù)據(jù)展開文章內(nèi)容詳情,感興趣的小伙伴可以參考一下。

      歸納整理之MySQL基于GTID主從搭建

      推薦學習:mysql視頻教程

      用xtarbackup來同步數(shù)據(jù),然后基于GTID來設置主從。

      一、用xtarbackup備份數(shù)據(jù)庫

      1.1 優(yōu)勢

      使用xtarbackup來做主從的前期準備是因為xtarbackup備份數(shù)據(jù)和恢復數(shù)據(jù)都很快,特別適合數(shù)據(jù)量很大的數(shù)據(jù)庫備份,而且它的安裝非常的簡單,使用也很簡單….(巴拉巴拉,廢話編不出來了)。

      1.2 安裝

      具體版本根據(jù)自己的具體情況來選擇。就下面這幾步就安裝好了,是不是非常簡單…..

      # rpm -Uvh https://www.percona.com/redir/downloads/percona-release/redhat/percona-release-0.1-3.noarch.rpm # yum list | grep percona # yum -y install perl perl-devel libaio libaio-devel perl-Time-HiRes perl-DBD-MySQL  # rpm -Uvh ftp://rpmfind.net/linux/epel/6/x86_64/libev-4.03-3.el6.x86_64.rpm # yum install percona-xtrabackup –y

      1.3 使用

      1.3.1 普通備份

      innobackupex --defaults-file=/etc/my.cnf --user=root --password=123456 /data/backupMysql/

      1.3.2 tar備份

      (1)、備份到本地

      # 不壓縮 innobackupex --defaults-file=/etc/my.cnf --user=root --password=123456 --stream=tar /data/backupMysql/>/data/mysql.tar  # 壓縮 innobackupex --defaults-file=/etc/my.cnf --user=root --password=123456 --stream=tar /data/backupMysql/ | gzip >/data/mysql.tar.gz

      (2)、備份到遠程

      # 不壓縮 innobackupex --defaults-file=/etc/my.cnf --user=root --password=123456 --stream=tar /data/backupMysql/ | ssh root@192.168.1.7  "cat - >/data/mysql.tar  # 壓縮 innobackupex --defaults-file=/etc/my.cnf --user=root --password=123456 --stream=tar /data/backupMysql/ | | ssh root@192.168.1.7  "gzip >/data/mysql.tar.gz

      (3)、解壓方式

      # 未經(jīng)過壓縮的文件解壓 tar xvf mysql.tar -C /data  # 壓縮過的文件解壓 tar zxvf mysql.tar.gz -C /data

      1.3.3 xbstream備份

      (1)、備份到本地

      # 不壓縮 innobackupex --defaults-file=/etc/my.cnf --user=root --password=123456 --stream=xbstream /data/backupMysql/>/data/mysql.xbstream  # 壓縮 innobackupex --defaults-file=/etc/my.cnf --user=root --password=123456 --stream=xbstream --compress /data/backupMysql/ >/data/mysql_compress.xbstream

      (2)、備份要遠程

      # 不壓縮 innobackupex --defaults-file=/etc/my.cnf --user=root --password=123456 --stream=xbstream /data/backupMysql/| ssh root@192.168.1.7 "xbstream -x -C /backup/stream"  # 壓縮 innobackupex --defaults-file=/etc/my.cnf --user=root --password=123456 --stream=xbstream --compress /data/backupMysql/ | ssh root@192.168.1.7 "xbstream -x -C /backup/stream"

      (3)、解壓方式

      #### 未壓縮的 xbstream -x < mysql.xbstream -C /data  #### 壓縮過的 # 1、先解壓xbstream xbstream -x < mysql_compress.xbstream -C /data # 2、再解壓qp壓縮格式 for bf in `find . -iname "*.qp"`; do qpress -d $bf $(dirname $bf) && rm $bf; done  注:如果xtrabackup版本大于2.1.4,可以直接通過以下方式解壓第二步。 innobackupex --decompress /data

      1.3.4 恢復

      先將原備份壓縮包解壓到一個目錄,然后執(zhí)行下面語句恢復。

      innobackupex --defaults-file=/etc/my.cnf --user=root --password=123456 --copy-back /var/lib/mysql/backup/

      注:在做備份,解壓,恢復的過程中可以借助分屏工具,我喜歡用screen。

      二、基于GTID做數(shù)據(jù)同步

      2.1 GTID的概念

      • 1、全局事務標識:global transaction identifiers。
      • 2、GTID是一個事務一一對應,并且全局唯一ID。
      • 3、一個GTID在一個服務器上只執(zhí)行一次,避免重復執(zhí)行導致數(shù)據(jù)混亂或者主從不一致。
      • 4、GTID用來代替?zhèn)鹘y(tǒng)復制方法,不再使用MASTER_LOG_FILE+MASTER_LOG_POS開啟復制。而是使用MASTER_AUTO_POSTION=1的方式開始復制。
      • 5、MySQL-5.6.5開始支持的,MySQL-5.6.10后開始完善。
      • 6、在傳統(tǒng)的slave端,binlog是不用開啟的,但是在GTID中slave端的binlog是必須開啟的,目的是記錄執(zhí)行過的GTID(強制)。

      2.2 GTID的組成

      GTID = source_id:transaction_id source_id:用于鑒別原服務器,即mysql服務器唯一的的server_uuid,由于GTID會傳遞到slave,所以也可以理解為源ID。

      transaction_id:為當前服務器上已提交事務的一個序列號,通常從1開始自增長的序列,一個數(shù)值對應一個事務。

      示例: 3E11FA47-71CA-11E1-9E33-C80AA9429562:23 前面的一串為服務器的server_uuid,即3E11FA47-71CA-11E1-9E33-C80AA9429562,后面的23為transaction_id

      2.3 GTID的原理

      1、當一個事務在主庫端執(zhí)行并提交時,產(chǎn)生GTID,一同記錄到binlog日志中。

      2、binlog傳輸?shù)絪lave,并存儲到slave的relaylog后,讀取這個GTID的這個值設置gtid_next變量,即告訴Slave,下一個要執(zhí)行的GTID值。

      3、sql線程從relay log中獲取GTID,然后對比slave端的binlog是否有該GTID。

      4、如果有記錄,說明該GTID的事務已經(jīng)執(zhí)行,slave會忽略。

      5、如果沒有記錄,slave就會執(zhí)行該GTID事務,并記錄該GTID到自身的binlog,在讀取執(zhí)行事務前會先檢查其他session持有該GTID,確保不被重復執(zhí)行。

      6、在解析過程中會判斷是否有主鍵,如果沒有就用二級索引,如果沒有就用全部掃描。

      2.4 GTID的優(yōu)勢

      • 1、更簡單的實現(xiàn)failover,不用以前那樣在需要找log_file和log_pos。
      • 2、更簡單的搭建主從復制。
      • 3、比傳統(tǒng)的復制更加安全。
      • 4、GTID是連續(xù)的沒有空洞的,保證數(shù)據(jù)的一致性,零丟失。

      2.5 具體搭建過程

      對于GTID的配置,主要修改配置文件中與GTID特性相關的幾個重要參數(shù),mysql版本建議mysql-5.6.5版本以上。

      2.5.1 開啟主(master)Gtid

      其主要配置如下:

      [mysqld] #GTID: server_id=135                #服務器id gtid_mode=on                 #開啟gtid模式 enforce_gtid_consistency=on  #強制gtid一致性,開啟后對于特定create table不被支持  #binlog log_bin=master-binlog log-slave-updates=1     binlog_format=row            #強烈建議,其他格式可能造成數(shù)據(jù)不一致  #relay log skip_slave_start=1

      2.5.2 在master上進行數(shù)據(jù)備份

      innobackupex --defaults-file=/etc/my.cnf --user=root --password=123456 --stream=tar /data/backupMysql/ | | ssh root@192.168.1.7  "gzip >/data/mysql.tar.gz

      2.5.3 解壓備份的數(shù)據(jù)

      tar zxvf /data/mysql.tar.gz -C /data/baskup

      2.5.4 配置slave的配置文件

      [mysqld] #GTID: gtid_mode=on enforce_gtid_consistency=on server_id=143  #binlog log-bin=slave-binlog log-slave-updates=1 binlog_format=row      #強烈建議,其他格式可能造成數(shù)據(jù)不一致  #relay log skip_slave_start=1

      2.5.5 恢復數(shù)據(jù)

      innobackupex --defaults-file=/etc/my.cnf --user=root --password=123456 --copy-back /data/backup

      2.5.6 獲取GTID節(jié)點

      more /data/backup/2018-02-08_15-03-18/xtrabackup_binlog_info

      2.5.7 配置主從

      (1)、在master上授權

      grant replication slave on *.* to slaveuser@'192.168.1.7'  identified by "c2xhdmV1c2Vy";

      (2)、在slave上配置

      stop slave; SET GLOBAL gtid_purged="c5b5ffe7-ce66-11e7-9a19-00163e00013d:1-515758"; CHANGE MASTER TO MASTER_HOST='192.168.1.6',MASTER_PORT=3306,MASTER_USER='slaveuser',MASTER_PASSWORD='c2xhdmV1c2Vy',MASTER_AUTO_POSITION=1; start slave;

      2.6 已運行經(jīng)典復制mysql服務器轉(zhuǎn)向GTID復制

      • a、按本文2.5.2描述配置參數(shù)文件;
      • b、所有服務器設置global.read_only參數(shù),等待主從服務器同步完畢; mysql> SET @@global.read_only = ON;
      • c、依次重啟主從服務器;
      • d、使用change master 更新主從配置;mysql> CHANGE MASTER TO > MASTER_HOST = host, > MASTER_PORT = port, > MASTER_USER = user, > MASTER_PASSWORD = password, > MASTER_AUTO_POSITION = 1;
      • e、從庫開啟復制 mysql> START SLAVE; f、驗證主從復制

      推薦學習:mysql視頻教程

      贊(0)
      分享到: 更多 (0)
      網(wǎng)站地圖   滬ICP備18035694號-2    滬公網(wǎng)安備31011702889846號