最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

mariadb的主從復(fù)制、主主復(fù)制、半同步復(fù)制配置詳解

 更新時間:2016年11月21日 08:51:28   作者:運維部落  
這篇文章主要詳細(xì)介紹了mariadb的主從復(fù)制、主主復(fù)制、半同步復(fù)制的概念和方法,有需要的小伙伴可以參考下

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

以下三個主從復(fù)制的設(shè)置是獨立的。

注意防火墻和selinux的影響。

1、簡單主從復(fù)制的實現(xiàn)

(1)主服務(wù)器的配置

1)安裝mariadb-server

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

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

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

    在[mysqld]段的最后添加以下內(nèi)容

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

3)授權(quán)可以復(fù)制本地數(shù)據(jù)庫信息的主機

[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 (查看主服務(wù)器的狀態(tài)信息,在從服務(wù)器中要用到)
*************************** 1. row ***************************
   File: master-log.000003 (正在使用的二進制日志文件)
  Position: 497 (所處的位置)
 Binlog_Do_DB: 
Binlog_Ignore_DB:

(2)從服務(wù)器的配置

1)安裝mariadb-server

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

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

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

    在[mysqld]段的最后添加以下內(nèi)容

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

3)設(shè)置要從哪個主服務(wù)器的那個位置開始同步

[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; (啟動復(fù)制功能)
MariaDB [(none)]> show slave status\G (查看從服務(wù)器的狀態(tài),下面顯示的是部分內(nèi)容)
 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)在主服務(wù)器導(dǎo)入事先準(zhǔn)備好的數(shù)據(jù)庫

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

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

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

2、雙主復(fù)制的實現(xiàn)

(1)服務(wù)器1的配置

1)安裝mariadb-server

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

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

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

    在[mysqld]段的最后添加以下內(nèi)容

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

3)在服務(wù)器2上查看的master狀態(tài)

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 (僅是部分內(nèi)容)
  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)服務(wù)器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)在服務(wù)器1查看master狀態(tài)

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 (僅是部分內(nèi)容) 
  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)在任意一臺服務(wù)器上創(chuàng)建mydb數(shù)據(jù)庫

MariaDB [(none)]> create database mydb;

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

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

3、半同步復(fù)制的實現(xiàn)

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

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)授權(quán)可以復(fù)制本地數(shù)據(jù)庫信息的主機

[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 (查看主服務(wù)器的狀態(tài)信息,在從服務(wù)器中要用到)
*************************** 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%';(可查看從服務(wù)器的個數(shù),此時是0個)

(2)從服務(wù)器的配置

1)安裝mariadb-server

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

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

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

    在[mysqld]段的最后添加以下內(nèi)容

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

3)設(shè)置要從哪個主服務(wù)器的那個位置開始同步

[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;

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

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

(3)測試

測試以個人實際情況而定
1)在主服務(wù)器上導(dǎo)入事先準(zhǔn)備好的數(shù)據(jù)庫hellodb.sql

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

2)在主服務(wù)器上查看半同步復(fù)制的狀態(tài)

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)在從服務(wù)器上查看是否同步

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

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

(1)從服務(wù)器的配置

1)關(guān)閉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 (只復(fù)制mydb數(shù)據(jù)庫的內(nèi)容)

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

    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后,半同步復(fù)制功能將被關(guān)閉,因此要重新啟動

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;(需先關(guān)閉從服務(wù)器復(fù)制功能再重啟)
MariaDB [(none)]> start slave;

(2)測試

1)主服務(wù)器上的hellodb數(shù)據(jù)庫創(chuàng)建一個新表semitable

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

2)在從服務(wù)器上查看hellodb數(shù)據(jù)庫是否有semitable

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

3)在主服務(wù)器上創(chuàng)建mydb數(shù)據(jù)庫,并為其創(chuàng)建一個tbl1表

MariaDB [hellodb]> create database mydb;

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

MariaDB [hellodb]> use mydb;
MariaDB [mydb]> show tables; (可以查看到)
+----------------+
| Tables_in_mydb |
+----------------+
| tbl1   |
+----------------+

相關(guān)文章

  • 記一次mariadb數(shù)據(jù)庫無法連接

    記一次mariadb數(shù)據(jù)庫無法連接

    本文給大家分享的是一次mariadb數(shù)據(jù)庫無法連接的處理方法,主要是給大家簡單描述下處理的思路,希望對大家處理mariadb數(shù)據(jù)庫有所幫助。
    2016-10-10
  • 在Ubuntu系統(tǒng)中安裝MariaDB數(shù)據(jù)庫的教程

    在Ubuntu系統(tǒng)中安裝MariaDB數(shù)據(jù)庫的教程

    這篇文章主要介紹了在Ubuntu系統(tǒng)中安裝MariaDB數(shù)據(jù)庫的教程,同時也適用于其他Debian系的Linux系統(tǒng),需要的朋友可以參考下
    2015-06-06
  • MariaDB表表達(dá)式之公用表表達(dá)式(CTE)

    MariaDB表表達(dá)式之公用表表達(dá)式(CTE)

    公用表表達(dá)式(Common Table Expression)是SQL Server2005版本的引入的一個特性,CTE可以看組是一個臨時的結(jié)果集,下面這篇文章主要給大家介紹了關(guān)于MariaDB表表達(dá)式之公用表表達(dá)式(CTE)的相關(guān)資料,需要的朋友可以參考下
    2022-01-01
  • 淺談MySQL和mariadb區(qū)別

    淺談MySQL和mariadb區(qū)別

    MariaDB是MySQL源代碼的一個分支,在意識到Oracle會對MySQL許可做什么后分離了出來(MySQL先后被Sun、Oracle收購)。除了作為一個Mysql的“向下替代品”,MariaDB包括的一些新特性使它優(yōu)于MySQL。通過本篇文章給大家介紹MySQL和mariadb區(qū)別,需要的朋友可以參考下
    2015-09-09
  • MariaDB中1045權(quán)限錯誤導(dǎo)致拒絕用戶訪問的錯誤解決方法

    MariaDB中1045權(quán)限錯誤導(dǎo)致拒絕用戶訪問的錯誤解決方法

    這篇文章主要介紹了MariaDB中1045權(quán)限錯誤導(dǎo)致拒絕用戶訪問的錯誤解決方法,需要的朋友可以參考下
    2016-01-01
  • centos編譯安裝mariadb的詳細(xì)過程

    centos編譯安裝mariadb的詳細(xì)過程

    這篇文章主要介紹了centos編譯安裝mariadb的方法,主要包括安裝cmake環(huán)境及安裝mariadb的詳細(xì)過程,本文給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下的相關(guān)資料
    2022-08-08
  • Mac中MariaDB數(shù)據(jù)庫的安裝步驟

    Mac中MariaDB數(shù)據(jù)庫的安裝步驟

    大家都知道MariaDB數(shù)據(jù)庫管理系統(tǒng)是MySQL的一個分支,主要由開源社區(qū)在維護,采用GPL授權(quán)許可MariaDB的目的是完全兼容MySQL,包括API和命令行,使之能輕松成為MySQL的代替品。這篇文章我們將詳細(xì)介紹在Mac中安裝MariaDB數(shù)據(jù)庫的步驟,有需要可以參考學(xué)習(xí)。
    2016-09-09
  • MariaDB性能調(diào)優(yōu)工具mytop的使用詳解

    MariaDB性能調(diào)優(yōu)工具mytop的使用詳解

    這篇文章主要給大家介紹了關(guān)于MariaDB性能調(diào)優(yōu)工具mytop的使用,文中介紹的非常詳細(xì),對大家具有一定的參考價值,需要的朋友們下面來一起看看吧。
    2017-03-03
  • MariaDB數(shù)據(jù)庫的外鍵約束實例詳解

    MariaDB數(shù)據(jù)庫的外鍵約束實例詳解

    約束保證了數(shù)據(jù)的完整性和一致性。下面這篇文章主要給大家介紹了關(guān)于MariaDB數(shù)據(jù)庫的外鍵約束的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),需要的朋友可以參考借鑒,下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2018-09-09
  • debian10 mariadb安裝過程詳解

    debian10 mariadb安裝過程詳解

    這篇文章主要介紹了debian10 mariadb安裝過程詳解,本文給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2020-11-11

最新評論

报价| 周口市| 疏勒县| 哈尔滨市| 阜阳市| 边坝县| 钦州市| 浠水县| 镇远县| 富平县| 长沙市| 西林县| 灵山县| 徐州市| 津市市| 澄江县| 安顺市| 禄丰县| 新建县| 麻栗坡县| 响水县| 怀远县| 淳化县| 岱山县| 遂溪县| 克山县| 万州区| 原阳县| 舞钢市| 胶南市| 永胜县| 根河市| 汨罗市| 札达县| 浙江省| 兴和县| 郎溪县| 酒泉市| 江都市| 治县。| 大姚县|