日本不卡不码高清免费观看,久久国产精品久久w女人spa,黄色aa久久,三上悠亚国产精品一区二区三区

您的位置:首頁技術文章
文章詳情頁

mariadb的主從復制、主主復制、半同步復制配置詳解

瀏覽:309日期:2023-03-30 13:21:16

主從服務器的時間要同步,數據庫版本最好是一致的,以免造成函數處理、日志讀取、日志解析等發生異常。

以下三個主從復制的設置是獨立的。

注意防火墻和selinux的影響。

1、簡單主從復制的實現

(1)主服務器的配置

1)安裝mariadb-server

[root@localhost ~]# yum -y install mariadb-server

2)編輯/etc/my.cnf文件

[root@localhost ~]# vim /etc/my.cnf

    在[mysqld]段的最后添加以下內容

    skip_name_resolve = ON
    innodb_file_per_table = ON
    server-id = 1 (id號不能跟從服務器相同)
    log-bin = master-log (自定義二進制日志文件名)

3)授權可以復制本地數據庫信息的主機

[root@localhost ~]# systemctl start mariadb.service (啟動mariadb server)

[root@localhost ~]# mysql
 MariaDB [(none)]> grant replication slave,replication client on *.* to "repluser"@"10.1.51.%" identified by "replpasswd";
 MariaDB [(none)]> flush privileges;

MariaDB [(none)]> show master status\G (查看主服務器的狀態信息,在從服務器中要用到)
*************************** 1. row ***************************
   File: master-log.000003 (正在使用的二進制日志文件)
  Position: 497 (所處的位置)
 Binlog_Do_DB: 
Binlog_Ignore_DB:

(2)從服務器的配置

1)安裝mariadb-server

[root@localhost ~]# yum -y install mariadb-server

2)編輯/etc/my.cnf文件

[root@localhost ~]# vim /etc/my.cnf

    在[mysqld]段的最后添加以下內容

    skip_name_resolve = ON
    innodb_file_per_table = ON
    server-id = 2 (id號不能跟主服務器相同)
    relay-log = slave-log (自定義二進制日志文件名)

3)設置要從哪個主服務器的那個位置開始同步

[root@localhost ~]# systemctl start mariadb.service

[root@localhost ~]# mysql
 MariaDB [(none)]> change master to master_host="10.1.51.60",master_user="repluser",master_password="replpasswd",master_log_file="master-log.000003",master_log_pos=497;

MariaDB [(none)]> start slave; (啟動復制功能)
MariaDB [(none)]> show slave status\G (查看從服務器的狀態,下面顯示的是部分內容)
 Master_Host: 10.1.51.60
 Master_User: repluser
 Master_Port: 3306
 Connect_Retry: 60
 Master_Log_File: master-log.000003
 Read_Master_Log_Pos: 497
 Relay_Log_File: slave-log.000002
 Relay_Log_Pos: 530
 Relay_Master_Log_File: master-log.000003
 Slave_IO_Running: Yes 
 Slave_SQL_Running: Yes
 Master_Server_Id: 1

(3)測試

1)在主服務器導入事先準備好的數據庫

[root@localhost ~]# mysql < hellodb.sql

2)在從服務器查看是否同步

MariaDB [(none)]> show databases;
+--------------------+
| Database   |
+--------------------+
| information_schema |
| hellodb   |(數據庫已經同步)
| mysql    |
| performance_schema |
| test    |
+--------------------+
MariaDB [(none)]> use hellodb;
MariaDB [hellodb]> show tables; (hellodb數據庫的表也是同步的)
+-------------------+
| Tables_in_hellodb |
+-------------------+
| classes   |
| coc    |
| courses   |
| scores   |
| students   |
| teachers   |
| toc    |
+-------------------+

2、雙主復制的實現

(1)服務器1的配置

1)安裝mariadb-server

[root@localhost ~]# yum -y install mariadb-server

2)編輯/etc/my.cnf文件

[root@localhost ~]# vim /etc/my.cnf

    在[mysqld]段的最后添加以下內容

    skip_name_resolve = ON
    innodb_file_per_table = ON
    server-id = 1 (id號不能跟從服務器相同)
    log-bin = master-log (自定義主服務器的二進制日志文件名)
    relay-log = slave-log (自定義從服務器的二進制日志文件名)
    auto_increment_offset = 1
    auto_increment_increment = 2

3)在服務器2上查看的master狀態

MariaDB [(none)]> show master status\G
*************************** 1. row ***************************
   File: master-log.000003
  Position: 422
 Binlog_Do_DB: 
Binlog_Ignore_DB:

4)啟動mariadb server并進行如下配置

[root@localhost ~]# systemctl start mariadb.service

[root@localhost ~]# mysql

 MariaDB [(none)]> grant replication slave,replication client on *.* to "repluser"@"10.1.51.%" identified by "replpasswd";

 MariaDB [(none)]> change master to master_host="10.1.51.50",master_user="repluser",master_password="replpasswd",master_log_file="master-log.000003",master_log_pos=422;

 MariaDB [(none)]> start slave;

 MariaDB [(none)]> SHOW SLAVE STATUS\G (僅是部分內容)
  Master_Host: 10.1.51.50
  Master_User: repluser
  Master_Port: 3306
  Connect_Retry: 60
  Master_Log_File: master-log.000003
  Read_Master_Log_Pos: 422
  Relay_Log_File: slave-log.000002
  Relay_Log_Pos: 530
  Relay_Master_Log_File: master-log.000003
  Slave_IO_Running: Yes
  Slave_SQL_Running: Yes
  Master_Server_Id: 2

(2)服務器2的配置

1)安裝mariadb-server

[root@localhost ~]# yum -y install mariadb-server

2)編輯/etc/my.cnf文件

[root@localhost ~]# vim /etc/my.cnf
    skip_name_resolve = ON
    innodb_file_per_table = ON
    server-id = 2
    relay-log = slave-log
    lob-bin = master-log
    auto_increment_offset = 2
    auto_increment_increment = 2

3)在服務器1查看master狀態

MariaDB [(none)]> show master status\G
*************************** 1. row ***************************
            File: master-log.000003
        Position: 245
    Binlog_Do_DB:
Binlog_Ignore_DB:

4)啟動mariadb server并配置

[root@localhost ~]# systemctl start mariadb.service

[root@localhost ~]# mysql

 MariaDB [(none)]> grant replication slave,replication client on *.* to "repluser"@"10.1.51.%" identified by "replpasswd";

 MariaDB [(none)]> change master to master_host="10.1.51.60",master_user="repluser",master_password="replpasswd",master_log_file="master-log.000003",master_log_pos=245;

 MariaDB [(none)]> start slave;

 MariaDB [(none)]> show slave status\G (僅是部分內容) 
  Master_Host: 10.1.51.60
  Master_User: repluser
  Master_Port: 3306
  Connect_Retry: 60
  Master_Log_File: master-log.000003
  Read_Master_Log_Pos: 422
  Relay_Log_File: slave-log.000003
  Relay_Log_Pos: 530
  Relay_Master_Log_File: master-log.000003
  Slave_IO_Running: Yes
  Slave_SQL_Running: Yes
  Master_Server_Id: 1

(3)測試

1)在任意一臺服務器上創建mydb數據庫

MariaDB [(none)]> create database mydb;

2)在另一臺服務器上查看

MariaDB [(none)]> show databases;
+--------------------+
| Database   |
+--------------------+
| information_schema |
| mydb    |
| mysql    |
| performance_schema |
| test    |
+--------------------+

3、半同步復制的實現

(1)在主服務器上的配置

1)安裝mariadb-server

[root@localhost ~]# yum -y install mariadb-server

2)編輯/etc/my.cnf

[root@localhost ~]# vim /etc/my.cnf
    skip_name_resolve = ON
    innodb_file_per_table = ON
    server-id = 1
    log-bin = master-log

3)授權可以復制本地數據庫信息的主機

[root@localhost ~]# systemctl start mariadb.service (啟動mariadb server)

[root@localhost ~]# mysql
 MariaDB [(none)]> grant replication slave,replication client on *.* to "repluser"@"10.1.51.%" identified by "replpasswd";
 MariaDB [(none)]> flush privileges;

MariaDB [(none)]> show master status\G (查看主服務器的狀態信息,在從服務器中要用到)
*************************** 1. row ***************************
   File: master-log.000003 (正在使用的二進制日志文件)
  Position: 245 (所處的位置)
 Binlog_Do_DB: 
Binlog_Ignore_DB:

4)安裝rpl semi sync_master插件,并啟用

[root@localhost ~]# mysql

MariaDB [(none)]> install plugin rpl_semi_sync_master soname "semisync_master.so";
MariaDB [(none)]> set global rpl_semi_sync_master_enabled = ON;

補充:

MariaDB [(none)]> show plugins;(可查看插件是否激活)
MariaDB [(none)]> show global variables like "rpl_semi%";(可查看安裝的插件是否啟用)
MariaDB [(none)]> show global status like "%semi%";(可查看從服務器的個數,此時是0個)

(2)從服務器的配置

1)安裝mariadb-server

[root@localhost ~]# yum -y install mariadb-server

2)編輯/etc/my.cnf文件

[root@localhost ~]# vim /etc/my.cnf

    在[mysqld]段的最后添加以下內容

    skip_name_resolve = ON
    innodb_file_per_table = ON
    server-id = 2 (id號不能跟主服務器相同)
    relay-log = slave-log (自定義二進制日志文件名)

3)設置要從哪個主服務器的那個位置開始同步

[root@localhost ~]# systemctl start mariadb.service

[root@localhost ~]# mysql

 MariaDB [(none)]> change master to master_host="10.1.51.60",master_user="repluser",master_password="replpasswd",master_log_file="master-log.000003",master_log_pos=245;

4)安裝rpl semi sync_slave插件并啟用

[root@localhost ~]# mysql 

 MariaDB [(none)]> install plugin rpl_semi_sync_slave soname "semisync_slave.so";
 MariaDB [(none)]> set global rpl_semi_sync_slave_enabled = ON;
 MariaDB [(none)]> start slave;

完成上面配置后,可以在主服務器上查看半同步復制的相關信息,命令如下:

MariaDB [(none)]> show global status like "%semi%";
 Rpl_semi_sync_master_clients 1 (從服務器有一臺)

(3)測試

測試以個人實際情況而定
1)在主服務器上導入事先準備好的數據庫hellodb.sql

MariaDB [hellodb]> source /root/hellodb.sql;

2)在主服務器上查看半同步復制的狀態

MariaDB [hellodb]> show master status;
+-------------------+----------+--------------+------------------+
| File    | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+-------------------+----------+--------------+------------------+
| master-log.000003 |  8102 |    |     |
+-------------------+----------+--------------+------------------+

MariaDB [hellodb]> show global status like "%semi%";
+--------------------------------------------+-------+
| Variable_name| Value |
+--------------------------------------------+-------+
| Rpl_semi_sync_master_clients    | 1  |
| Rpl_semi_sync_master_net_avg_wait_time  | 1684 |
| Rpl_semi_sync_master_net_wait_time   | 60630 |
| Rpl_semi_sync_master_net_waits    | 36 |
| Rpl_semi_sync_master_no_times    | 1  |
| Rpl_semi_sync_master_no_tx     | 1  |
| Rpl_semi_sync_master_status    | ON |
| Rpl_semi_sync_master_timefunc_failures  | 0  |
| Rpl_semi_sync_master_tx_avg_wait_time  | 1884 |
| Rpl_semi_sync_master_tx_wait_time   | 65965 |
| Rpl_semi_sync_master_tx_waits    | 35 |
| Rpl_semi_sync_master_wait_pos_backtraverse | 0  |
| Rpl_semi_sync_master_wait_sessions   | 0  |
| Rpl_semi_sync_master_yes_tx    | 35 |
+--------------------------------------------+-------+

3)在從服務器上查看是否同步

MariaDB [(none)]> show databases;
MariaDB [(none)]> use hellodb;
MariaDB [hellodb]> select * from students;

補充:基于上面的半同步復制配置復制的過濾器,復制過濾最好在從服務器上設置,步驟如下

(1)從服務器的配置

1)關閉mariadb server

[root@localhost ~]# systemctl stop mariadb.service

2)編輯/etc/my.cnf文件

[root@localhost ~]# vim /etc/my.cnf
 skip_name_resolve = ON
 innodb_file_per_table = ON
 server-id = 2
 relay-log = slave-log
 replicate-do-db = mydb (只復制mydb數據庫的內容)

補充:常用的過濾選項如下

    Replicate_Do_DB=
    Replicate_Ignore_DB=
    Replicate_Do_Table=
    Replicate_Ignore_Table=
    Replicate_Wild_Do_Table=
    Replicate_Wild_Ignore_Table=

3)重啟mariadb server

[root@localhost ~]# systemctl start mariadb.service

4)重啟mariadb server后,半同步復制功能將被關閉,因此要重新啟動

MariaDB [(none)]> show global variables like "%semi%";
+---------------------------------+-------+
| Variable_name     | Value |
+---------------------------------+-------+
| rpl_semi_sync_slave_enabled  | OFF |
| rpl_semi_sync_slave_trace_level | 32 |
+---------------------------------+-------+

MariaDB [(none)]> set global rpl_semi_sync_slave_enabled = ON;
MariaDB [(none)]> stop slave;(需先關閉從服務器復制功能再重啟)
MariaDB [(none)]> start slave;

(2)測試

1)主服務器上的hellodb數據庫創建一個新表semitable

MariaDB [hellodb]> create table semitable (id int);

2)在從服務器上查看hellodb數據庫是否有semitable

MariaDB [(none)]> use hellodb
MariaDB [hellodb]> show tables;(并沒有)
+-------------------+
| Tables_in_hellodb |
+-------------------+
| classes   |
| coc    |
| courses   |
| scores   |
| students   |
| teachers   |
| toc    |
+-------------------+

3)在主服務器上創建mydb數據庫,并為其創建一個tbl1表

MariaDB [hellodb]> create database mydb;

4)在從服務器上查看mydb數據庫的是否有tbl1表

MariaDB [hellodb]> use mydb;
MariaDB [mydb]> show tables; (可以查看到)
+----------------+
| Tables_in_mydb |
+----------------+
| tbl1   |
+----------------+
標簽: MariaDB
相關文章:
日本不卡不码高清免费观看,久久国产精品久久w女人spa,黄色aa久久,三上悠亚国产精品一区二区三区
国产亚洲一卡2卡3卡4卡新区| 蜜桃久久av一区| 日本v片在线高清不卡在线观看| 国产精品普通话对白| av不卡在线看| 老牛影视一区二区三区| 中文不卡在线| 欧美有码在线| 久久一区国产| 天堂√8在线中文| 夜鲁夜鲁夜鲁视频在线播放| 性感美女一区二区在线观看| 欧美影院三区| 久久一级电影| 日韩午夜电影| 亚洲乱亚洲高清| 国产剧情一区| 在线中文字幕播放| 今天的高清视频免费播放成人| 黄色欧美日韩| 涩涩涩久久久成人精品| 国产精品欧美一区二区三区不卡 | 国产精品xxxav免费视频| 免费在线观看一区| 伊人久久av| 国产亚洲激情| 日韩欧美在线精品| 精品丝袜久久| 欧美日韩国产一区二区三区不卡| 免费精品视频| 国产一卡不卡| av一区在线| 亚洲人成网站在线在线观看| 国产精品麻豆成人av电影艾秋| 国产一区二区三区国产精品| 久久国产成人午夜av影院宅| 蜜臀国产一区二区三区在线播放| 国产一区 二区| 久久久蜜桃一区二区人| 日韩影院精彩在线| 美女高潮久久久| 国产欧美一区二区三区精品酒店| 红桃视频亚洲| 你懂的国产精品| 香蕉久久精品| 欧美性www| 久久国产中文字幕| 人人精品久久| 欧美日韩尤物久久| 亚洲v天堂v手机在线| 国产精品久久久久久久久妇女| 亚洲国产日韩欧美在线| 国产亚洲第一伦理第一区| 麻豆精品蜜桃| 91精品一区| 欧美日中文字幕| 91在线成人| 香蕉人人精品| 麻豆极品一区二区三区| 国产毛片久久| 国产精品伦理久久久久久| 亚洲婷婷丁香| 久久九九99| 久久精品凹凸全集| 欧美日韩四区| 成人在线黄色| 日韩精品视频中文字幕| 99久久亚洲精品| 国产精品毛片视频| 日韩中文字幕不卡| 日韩大片免费观看| 日韩欧美中文字幕在线视频| 久久一区二区三区喷水| 久久精品国内一区二区三区| 一区二区三区网站| 欧美亚洲国产精品久久| 九九九精品视频| 婷婷五月色综合香五月| 国产中文一区| 精品国产亚洲一区二区三区大结局| 亚洲欧美日韩专区| se01亚洲视频 | 欧美激情一区| 一区二区亚洲视频| 亚洲手机视频| 精品久久不卡| 亚洲精品少妇| 日韩午夜免费| 久久国产日韩| 91嫩草亚洲精品| 国产日韩欧美一区二区三区| 免费日韩精品中文字幕视频在线| 欧美片第1页| 精品久久99| 国产调教精品| 蜜桃av一区二区在线观看| 激情视频一区二区三区| 在线天堂资源www在线污| 欧美91在线| 国产精品最新| 日韩和欧美一区二区三区| 精品1区2区3区4区| 日本久久成人网| 国产suv精品一区二区四区视频| 欧美一区自拍| 日韩欧美高清一区二区三区| 在线视频免费在线观看一区二区| 韩国精品主播一区二区在线观看| 精品国产精品国产偷麻豆| 青草国产精品| 亚洲2区在线| 亚洲色图网站| 亚洲一区二区免费在线观看| 中文精品视频| 亚洲精品1区2区| 国内亚洲精品| 亚洲国内精品| 免费视频国产一区| 久久久噜噜噜| 视频一区中文| 蜜臀久久99精品久久一区二区| 99热国内精品| 女人天堂亚洲aⅴ在线观看| 欧美1区免费| 欧美日韩中文一区二区| 黄色不卡一区| 视频一区二区中文字幕| 鲁大师影院一区二区三区| 在线一区欧美| 在线免费观看亚洲| 综合色一区二区| 日本va欧美va瓶| 国产精品丝袜在线播放| 久久精品人人| 国产欧美一区二区三区精品酒店| 天堂8中文在线最新版在线| 亚洲成av在线| 99亚洲视频| 日韩综合一区二区| 日韩精品视频在线看| 国产欧美久久一区二区三区| 国产精区一区二区| 四季av一区二区凹凸精品| 国产网站在线| 欧美一区三区| 亚洲最大av| 国产精品99久久免费| 国产成人免费av一区二区午夜| 国产夫妻在线| 午夜久久免费观看| 亚洲欧美视频| 欧美三区不卡| 国产aa精品| 国产精品99免费看| 视频在线在亚洲| 日本欧美一区二区| 久久亚洲国产精品尤物| 欧美三级精品| 免费人成在线不卡| 国产精品久久久久毛片大屁完整版| 麻豆久久一区| 欧美日韩激情| 91成人在线精品视频| 狠狠久久伊人中文字幕| 久久国产亚洲| 日本亚洲欧美天堂免费| 麻豆91小视频| 亚洲激情久久| 国产日产精品_国产精品毛片 | 久久免费大视频| 亚洲欧美在线专区| 国产中文欧美日韩在线| 激情久久久久久| 少妇高潮一区二区三区99| 国产精品二区不卡| 久久亚洲欧美| 免费日韩一区二区三区| 日韩一区二区三区免费播放| 久久香蕉精品| 色婷婷色综合| 免费人成黄页网站在线一区二区| 国产精品一二| 黄色不卡一区| 国产精选一区| 99综合视频| 精品免费视频| 综合激情网站| 中文在线资源| 欧美在线日韩| 激情欧美一区| 久久精品国产999大香线蕉| 亚洲深夜av| 美女在线视频一区| 丝袜a∨在线一区二区三区不卡| 精品在线网站观看| 综合激情五月婷婷| 91精品一区国产高清在线gif| 欧美午夜三级| 日韩视频一区| 国产suv精品一区二区四区视频 |