亚洲激情专区-91九色丨porny丨老师-久久久久久久女国产乱让韩-国产精品午夜小视频观看

溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

MySQL 5.5 主主復制搭建過程是怎樣的

發布時間:2021-11-16 15:47:36 來源:億速云 閱讀:155 作者:柒染 欄目:MySQL數據庫

MySQL 5.5 主主復制搭建過程是怎樣的,相信很多沒有經驗的人對此束手無策,為此本文總結了問題出現的原因和解決方法,通過這篇文章希望你能解決這個問題。

--節點1 IP 192.168.78.141  PORT 3306
--節點2 IP 192.168.78.137  PORT 5505

--配置節點1到節點2的復制
--編輯節點1的配置文件
[root@localhost install]# vim /etc/my.cnf
# Log
server-id = 100
log-bin = /log/binlog/mysql-bin

--在節點2安裝好MySQL軟件,安裝流程可以參考源碼安裝文章
http://blog.itpub.net/26506993/viewspace-2072859/

--在節點1,使用Xtrabackup創建完整備份
關于Xtrabackup,可參考
http://blog.itpub.net/26506993/viewspace-2087734/
http://blog.itpub.net/26506993/viewspace-2088737/

[root@localhost backup]# /install/percona/percona-xtrabackup-2.4.2-Linux-x86_64/bin/innobackupex  --defaults-file=/etc/my.cnf --stream=tar /tmp --user system --password 'Mysql#2015' | gzip -> 
/backup/xtra/xtra_fullbackup_20160501.tar.gz

--拷貝備份到節點2
[root@localhost backup]# scp /backup/xtra/xtra_fullbackup_20160501.tar.gz  root@192.168.78.137:/backup/20160501

解壓備份到數據文件目錄
[root@localhost 5505]# tar xivfz xtra_fullbackup_20160501.tar.gz -C /mysql_data/5505

在節點2上面需要安裝Xtraback
--使用Xtrabackup準備數據、應用日志,使數據文件達到一致性的狀態
[root@localhost bin]# ./innobackupex --defaults-file=/mysql_data/cnf/my.cnf  --apply-log /mysql_data/5505
.....
InnoDB: Doing recovery: scanned up to log sequence number 68405269 (0%)
InnoDB: Doing recovery: scanned up to log sequence number 68405269 (0%)
InnoDB: Database was not shutdown normally!
InnoDB: Starting crash recovery.
InnoDB: xtrabackup: Last MySQL binlog file position 414, file name /log/binlog/mysql-bin.000012
InnoDB: Removed temporary tablespace data file: "ibtmp1"
InnoDB: Creating shared tablespace for temporary tables
InnoDB: Setting file './ibtmp1' size to 12 MB. Physically writing the file full; Please wait ...
InnoDB: File './ibtmp1' size is now 12 MB.
InnoDB: 96 redo rollback segment(s) found. 1 redo rollback segment(s) are active.
InnoDB: 32 non-redo rollback segment(s) are active.
InnoDB: 5.7.11 started; log sequence number 68405269
xtrabackup: starting shutdown with innodb_fast_shutdown = 1
InnoDB: FTS optimize thread exiting.
InnoDB: Starting shutdown...
InnoDB: Shutdown completed; log sequence number 68405621
160430 23:51:25 completed OK!

--在節點1數據庫上面創建復制專用賬戶
mysql> grant replication slave on *.* to 'repl'@'192.168.78.%' identified by 'Mysql#2015';
Query OK, 0 rows affected (0.04 sec)

--配置節點2的配置文件
[root@localhost 5505]# vim /mysql_data/cnf/my.cnf
# Log
server-id = 200
log-bin = /mysql_log/binlog/mysql-bin
relay-log = /mysql_log/binlog/product-relay-bin
relay-log-index = /mysql_log/binlog/product-relay-index
binlog_cache_size = 32M
max_binlog_cache_size = 512M
max_binlog_size = 512M
binlog_format = MIXED

--啟動節點2的Mysql服務
[root@localhost bin]# /data/bin/mysqld_safe --defaults-file=/mysql_data/cnf/my.cnf &

--配置Slave節點復制環境
查詢Slave節點連接Master節點的二進制文件和位置
使用Xtrabackup備份時,在xtrabackup_binlog_info文件中會保存這部分信息
[root@localhost 5505]# more xtrabackup_binlog_info
mysql-bin.000012 414

--在節點2執行CHANGE MASTER語句
mysql> change master to
    -> master_host='192.168.78.141',
    -> master_port=3306,
    -> master_user='repl',
    -> master_password='Mysql#2015',
    -> master_log_file='mysql-bin.000012',
    -> master_log_pos=414;
Query OK, 0 rows affected (0.13 sec)

--啟動應用線程
mysql> start slave;

--查看同步狀態
mysql> show slave status\G
*************************** 1. row ***************************
               Slave_IO_State: Waiting for master to send event
                  Master_Host: 192.168.78.141
                  Master_User: repl
                  Master_Port: 3306
                Connect_Retry: 60
              Master_Log_File: mysql-bin.000013
          Read_Master_Log_Pos: 341
               Relay_Log_File: product-relay-bin.000003
                Relay_Log_Pos: 487
        Relay_Master_Log_File: mysql-bin.000013
             Slave_IO_Running: Yes
            Slave_SQL_Running: Yes

--搭建節點2到節點1的復制
--在節店1的配置文件中,增加中繼日志的設置
[root@localhost log]# vim /etc/my.cnf
relay-log = /log/binlog/product-relay-bin
relay-log-index = /log/binlog/product-relay-index

--重啟節點1的數據庫
[root@localhost tmp]# /software/bin/mysqladmin -usystem -p'system' shutdown
160512 02:47:54 mysqld_safe mysqld from pid file /var/run/mysqld/mysqld.pid ended
[1]+  Done                    /software/bin/mysqld_safe --defaults-file=/etc/my.cnf  (wd: ~)
(wd now: /tmp)
[root@localhost tmp]# /software/bin/mysqld_safe --defaults-file=/etc/my.cnf &
[1] 40246
[root@localhost tmp]# 160512 02:48:13 mysqld_safe Logging to '/log/err.log'.
160512 02:48:13 mysqld_safe Starting mysqld daemon with databases from /data

mysql> show variables like 'relay_log%';
+-----------------------+---------------------------------+
| Variable_name         | Value                           |
+-----------------------+---------------------------------+
| relay_log             | /log/binlog/product-relay-bin   |
| relay_log_index       | /log/binlog/product-relay-index |
| relay_log_info_file   | relay-log.info                  |
| relay_log_purge       | ON                              |
| relay_log_recovery    | OFF                             |
| relay_log_space_limit | 0                               |
+-----------------------+---------------------------------+
6 rows in set (0.00 sec)

--在節點1上面增加全局只讀鎖,如果應用只連接到一個節點,如節點1,這一步可以忽略
mysql> flush tables with read lock;
Query OK, 0 rows affected (0.00 sec)

--查看節點2當前的日志名稱和位置,用于下面在節點1的change master to命令
mysql> show master status;
+------------------+----------+--------------+------------------+
| File             | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+------------------+----------+--------------+------------------+
| mysql-bin.000006 | 14078491 |              |                  |
+------------------+----------+--------------+------------------+
1 row in set (0.00 sec)

--在節點1執行CHANGE MASTER語句
mysql> change master to
    -> master_host='192.168.78.137',
    -> master_port=5505,
    -> master_user='repl',
    -> master_password='Mysql#2015',
    -> master_log_file='mysql-bin.000006',
    -> master_log_pos=14078491;
Query OK, 0 rows affected (0.13 sec)

--啟動應用線程
mysql> start slave;

--節點1釋放全局只讀鎖
mysql> unlock tables;
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.78.137
                  Master_User: repl
                  Master_Port: 5505
                Connect_Retry: 60
              Master_Log_File: mysql-bin.000006
          Read_Master_Log_Pos: 14078491
               Relay_Log_File: product-relay-bin.000002
                Relay_Log_Pos: 253
        Relay_Master_Log_File: mysql-bin.000006
             Slave_IO_Running: Yes
            Slave_SQL_Running: Yes

在兩個節點的配置文件中增加序列的相關參數,以避免生成的序列相同而產生沖突
--節點1

節點1上序列從1開始,增長值為2,即為奇數,如1、3、5

## set this to server-id value

auto_increment_offset = 1

## set this to the number of mysql servers

auto_increment_increment = 2


--節點2
節點2上序列從2開始,增長值為2,即為奇數,如2、4、6

## set this to server-id value

auto_increment_offset = 2

## set this to the number of mysql servers

auto_increment_increment = 2

看完上述內容,你們掌握MySQL 5.5 主主復制搭建過程是怎樣的的方法了嗎?如果還想學到更多技能或想了解更多相關內容,歡迎關注億速云行業資訊頻道,感謝各位的閱讀!

向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

石首市| 凤山市| 永济市| 孝昌县| 九龙坡区| 开远市| 渝北区| 黄骅市| 鄂托克旗| 广昌县| 方城县| 南丰县| 盐津县| 通榆县| 金湖县| 越西县| 丹东市| 甘洛县| 孝感市| 富平县| 博野县| 绩溪县| 门源| 修文县| 神池县| 辽阳县| 新民市| 珠海市| 容城县| 江城| 哈密市| 蓝山县| 鄂托克前旗| 仙居县| 河西区| 临沧市| 绥滨县| 丰宁| 政和县| 左贡县| 板桥市|