本文主要給大家介紹多種MySQL復(fù)制方法詳解,其所涉及的東西,從理論知識(shí)來獲悉,有很多書籍、文獻(xiàn)可供大家參考,從現(xiàn)實(shí)意義角度出發(fā),創(chuàng)新互聯(lián)累計(jì)多年的實(shí)踐經(jīng)驗(yàn)可分享給大家。
站在用戶的角度思考問題,與客戶深入溝通,找到湘潭縣網(wǎng)站設(shè)計(jì)與湘潭縣網(wǎng)站推廣的解決方案,憑借多年的經(jīng)驗(yàn),讓設(shè)計(jì)與互聯(lián)網(wǎng)技術(shù)結(jié)合,創(chuàng)造個(gè)性化、用戶體驗(yàn)好的作品,建站類型包括:網(wǎng)站建設(shè)、成都做網(wǎng)站、企業(yè)官網(wǎng)、英文網(wǎng)站、手機(jī)端網(wǎng)站、網(wǎng)站推廣、申請(qǐng)域名、網(wǎng)絡(luò)空間、企業(yè)郵箱。業(yè)務(wù)覆蓋湘潭縣地區(qū)。MySQL復(fù)制主要是把寫操作發(fā)送給主節(jié)點(diǎn)、讀操作發(fā)送給從節(jié)點(diǎn),每個(gè)節(jié)點(diǎn)都有相關(guān)的數(shù)據(jù)集;從服務(wù)專門啟動(dòng)一個(gè)線程,把自己扮演成為客戶端,通過MySQL協(xié)議向MySQL主節(jié)點(diǎn)請(qǐng)求讀取二進(jìn)制日志文件中的事件,隨后主節(jié)點(diǎn)將會(huì)檢查自己二進(jìn)制日志中的事件并發(fā)送給從節(jié)點(diǎn),從節(jié)點(diǎn)收到后先保存在自己的中繼日志中,每讀取到一個(gè)事件都會(huì)在中繼中保存下來
復(fù)制中用到的線程名稱:
從節(jié)點(diǎn):
I/O Thread:從主節(jié)點(diǎn)請(qǐng)求二進(jìn)制事件,并保存于中繼日志中
SQL Thread:從中繼日志中讀取二進(jìn)制日志事件,在本地完成重放
主節(jié)點(diǎn):
dump Thread:為每個(gè)從節(jié)點(diǎn)的I/O Thread啟動(dòng)一個(gè)dump Thread,用于向其發(fā)送二進(jìn)制日志事件
復(fù)制的功用:
1、實(shí)現(xiàn)數(shù)據(jù)分布的目的
2、主要能夠完成寫操作的負(fù)載均衡效果
3、能夠?qū)崿F(xiàn)備份的效果(當(dāng)主云服務(wù)器掛了,備節(jié)點(diǎn)可以當(dāng)主節(jié)點(diǎn))
4、可以實(shí)現(xiàn)高可用和故障切換
5、可以在從節(jié)點(diǎn)上為Mysql做升級(jí)測(cè)試
MySQL復(fù)制的方式:主從復(fù)制、主主復(fù)制、半同步復(fù)制、過濾復(fù)制、SSL復(fù)制
一、實(shí)現(xiàn)主從復(fù)制:
準(zhǔn)備環(huán)境
虛擬機(jī)1:Master節(jié)點(diǎn)(主節(jié)點(diǎn)) | IP:192.168.1.108 |
虛擬機(jī)2:Slave節(jié)點(diǎn)(從節(jié)點(diǎn)) | IP:192.168.1.109 |
1、部署Master節(jié)點(diǎn)
(1)、安裝mariadb服務(wù)
[root@node0 ~]# yum install mariadb-server -y(2)編輯其配置文件
[root@node0 ~]# vim /etc/my.cnf ##mariadb配置文件路徑 [mysqld] log_bin=mysql-bin ##開啟二進(jìn)制日志功能 server-id=1 ##定義唯一Server-id innodb_file_per_table = ON skip_name_resolve = ON ##禁止反解主機(jī)名 [root@node0 ~]# systemctl start mariadb.service ##啟動(dòng)mariadb服務(wù) MariaDB [(none)]> show global variables like "server_id"; ##查看其server-id server_id 1 MariaDB [(none)]> show global variables like "log_bin"; ##查看其二進(jìn)制日志是否開啟 log_bin ON MariaDB [(none)]> show master status; ##查看正在使用的二進(jìn)制日志文件 mysql-bin.000002 245 | MariaDB [(none)]> grant replication slave,replication client on *.* to 'repluser'@'192.168.%.%' identified by 'replpass'; ##創(chuàng)建具有復(fù)制權(quán)限的用戶 MariaDB [(none)]> flush privileges;2、部署Slave節(jié)點(diǎn)
(1)安裝mariadb服務(wù)
[root@node1 ~]# yum install mariadb-server -y(2)編輯其配置文件
[root@node1 ~]# vim /etc/my.cnf [mysqld] relay-log=relay-log ##啟用中繼日志 server-id=2 ##定義唯一Server-id;此Server-id一定不能和Master的上的Server-id相同 innodb_file_per_table = ON skip_name_resolve = ON [root@node1 ~]# systemctl start mariadb.service MariaDB [(none)]> show global variables like "relay_log"; ##查看中繼日志是否啟用 relay_log relay-log MariaDB [(none)]> show global variables like "server_id"; ##查看其server-i server_id 2(3)使用具有復(fù)制權(quán)限的用戶賬號(hào)連接至主服務(wù)器上,并啟動(dòng)復(fù)制線程
MariaDB [(none)]> change master to master_host='192.168.1.108',master_user='repluser',master_password='replpass',master_log_file='mysql-bin.000002',master_log_pos=245; ## master_host:指明主節(jié)點(diǎn)的IP地址 ## master_user、master_password:指明具有復(fù)制權(quán)限的用戶賬號(hào) ## master_log_file:指明主節(jié)點(diǎn)正在使用的二進(jìn)制日志; ## master_log_pos:指明二進(jìn)制日志的position MariaDB [(none)]> start slave; ##啟動(dòng)復(fù)制線程 MariaDB [(none)]> show slave status\G; ##查看復(fù)制線程的狀態(tài)信息 Slave_IO_Running: Yes Slave_SQL_Running: Yes3、測(cè)試主從服務(wù)器是否實(shí)現(xiàn)復(fù)制功能
(1)在Master節(jié)點(diǎn)上查看一次數(shù)據(jù)庫(kù)
MariaDB [(none)]> show databases; +--------------------+ | Database +--------------------+ | information_schema | lweim | mysql | performance_schema | test +--------------------+(2)在Slave上查看一次數(shù)據(jù)庫(kù)
MariaDB [(none)]> show databases; +--------------------+ | Database +--------------------+ | information_schema | mysql | performance_schema | testdb +--------------------+(3)在Master節(jié)點(diǎn)上創(chuàng)建一個(gè)名為“MaGeRepo”的數(shù)據(jù)庫(kù),并在Slave節(jié)點(diǎn)上查看
MariaDB [(none)]> create database MaGeRepo; ##在主節(jié)點(diǎn)上創(chuàng)建數(shù)據(jù)庫(kù)“MaGeRepo” Query OK, 1 row affected (0.00 sec) MariaDB [(none)]> show databases; ##在從節(jié)點(diǎn)上查看數(shù)據(jù)庫(kù) +--------------------+ | Database +--------------------+ | information_schema | MaGeRepo | mysql | performance_schema | testdb +--------------------在主從復(fù)制架構(gòu)中應(yīng)該注意的問題:
1、在Master節(jié)點(diǎn)上的參數(shù)
sync_binlog=ON sync_master_info=ON 如果用的是InnoDB存儲(chǔ)引擎,以下兩項(xiàng)也要開啟 innodb_flush_log_at_tx_commit = ON ##刷寫日志 innodb_support_xa = ON ##是否讓innodb支持分布式事務(wù)
2、在Slave節(jié)點(diǎn)上的參數(shù)
skip_slave_start = OFF ##是否自動(dòng)啟動(dòng)事務(wù)線程 sync_relay_log = ON sync_relay_log_info = ON二、實(shí)現(xiàn)主主復(fù)制
準(zhǔn)備環(huán)境
虛擬機(jī)1:Master節(jié)點(diǎn)(主節(jié)點(diǎn)) | IP:192.168.1.108 |
虛擬機(jī)2:Master節(jié)點(diǎn)(主節(jié)點(diǎn)) | IP:192.168.1.109 |
1、部署虛擬機(jī)1
(1)安裝mariadb服務(wù)
[root@node0 ~]# yum install mariadb-server -y(2)編輯其配置文件
[root@node0 ~]# vim /etc/my.cnf log_bin=mysql-bin relay-log=relay-log ##啟用中繼日志 server-id=1 innodb_file_per_table = ON [root@node0 ~]# systemctl start mariadb.service MariaDB [(none)]> show global variables like "%log%"; relay_log relay-log log_bin ON MariaDB [(none)]> show master status; mysql-bin.000003 245 MariaDB [(none)]> grant replication slave,replication client on *.* to 'repluser'@'192.168.%.%' identified by 'replpass';2、部署虛擬機(jī)2
(1)安裝mariadb服務(wù)
[root@node1 ~]# yum install mariadb-server -y(2)編輯配置文件
[root@node1 ~]# vim /etc/my.cnf [mysqld] relay-log=relay-log log_bin=mysql-bin ##啟用二進(jìn)制日志 server-id=2 innodb_file_per_table = ON skip_name_resolve = ON [root@node1 ~]# systemctl start mariadb.service MariaDB [(none)]> show master status; mysql-bin.000003 245 MariaDB [(none)]> grant replication slave,replication client on *.* to 'repluser'@'192.168.%.%' identified by 'replpass'; ##創(chuàng)建具有復(fù)制權(quán)限的用戶賬號(hào)3、兩個(gè)節(jié)點(diǎn)分別使用雙方創(chuàng)建的用戶連到對(duì)方的服務(wù)器上,并啟動(dòng)復(fù)制線程
(1)讓虛擬機(jī)1連接至虛擬機(jī)2
MariaDB [(none)]> change master to master_host='192.168.1.109',master_user='repluser',master_password='replpass',master_log_file='mysql-bin.000003',master_log_pos=245; MariaDB [(none)]> flush privileges; MariaDB [(none)]> start slave;(2)讓虛擬機(jī)2連接至虛擬機(jī)1
MariaDB [(none)]> change master to master_host='192.168.1.108',master_user='repluser',master_password='replpass',master_log_file='mysql-bin.000003',master_log_pos=245; MariaDB [(none)]> flush privileges; MariaDB [(none)]> start slave;4、測(cè)試主主復(fù)制模型
(1)在分別查看虛擬機(jī)1和虛擬機(jī)2的數(shù)據(jù)庫(kù)
MariaDB [(none)]> show databases; ##查看虛擬機(jī)1的數(shù)據(jù)庫(kù) +-------------------- | Database +--------------------+ | information_schema | mysql | performance_schema | test +--------------------+ MariaDB [(none)]> show databases; ##查看虛擬機(jī)2的數(shù)據(jù)庫(kù) +--------------------+ | Database +--------------------+ | information_schema | mysql | performance_schema | testdb +--------------------+(2)在虛擬機(jī)1上添加“LweimRepo"數(shù)據(jù)庫(kù),在虛擬機(jī)2上添加“WzxRepo”數(shù)據(jù)庫(kù)
MariaDB [(none)]> create database LweimRepo; ##虛擬機(jī)1 Query OK, 1 row affected (0.00 sec) MariaDB [(none)]> flush privileges; MariaDB [(none)]> create database WzxRepo; ##虛擬機(jī)2 Query OK, 1 row affected (0.00 sec) MariaDB [(none)]> flush privileges;(3)再次查看兩個(gè)節(jié)點(diǎn)的數(shù)據(jù)庫(kù)
MariaDB [(none)]> show databases; ##查看虛擬機(jī)1 +--------------------+ | Database +--------------------+ | information_schema | LweimRepo | WzxRepo | mysql | performance_schema | test +--------------------+ MariaDB [(none)]> show databases; ##查看虛擬機(jī)2 +--------------------+ | Database +--------------------+ | information_schema | LweimRepo | WzxRepo | mysql | performance_schema | testdb +--------------------+三、實(shí)現(xiàn)半同步復(fù)制:當(dāng)master節(jié)點(diǎn)有多個(gè)slave節(jié)點(diǎn)時(shí),只需要有一個(gè)slave節(jié)點(diǎn)復(fù)制完成之后并響應(yīng)給master節(jié)點(diǎn),隨后master節(jié)點(diǎn)響應(yīng)客戶端
準(zhǔn)備環(huán)境
虛擬機(jī)1:Master節(jié)點(diǎn)(主節(jié)點(diǎn)) | IP:192.168.1.108 |
虛擬機(jī)2:Slave節(jié)點(diǎn)(從節(jié)點(diǎn)) | IP:192.168.1.109 |
1、給master節(jié)點(diǎn)安裝插件“semisync_master.so”
MariaDB [(none)]> install plugin rpl_semi_sync_master soname 'semisync_master.so'; MariaDB [(none)]> show global variables like "%semi%"; +------------------------------------+-------+ | Variable_name Value +------------------------------------+-------+ | rpl_semi_sync_master_enabled OFF ##是否啟用半同步復(fù)制的主節(jié)點(diǎn),需把它設(shè)置為ON | rpl_semi_sync_master_timeout 10000 ##等待slave的響應(yīng)時(shí)長(zhǎng),單位為毫秒,默認(rèn)為10s | rpl_semi_sync_master_trace_level 32 ##跟蹤節(jié)點(diǎn)32,默認(rèn)值就好,不建議更改 | rpl_semi_sync_master_wait_no_slave ON ##當(dāng)沒有slave節(jié)點(diǎn)時(shí)是否等待 +------------------------------------+-------+ MariaDB [(none)]> set global rpl_semi_sync_master_enabled=1; ##“rpl_semi_sync_master_enabled”更改為“ON”2、在Slave節(jié)點(diǎn)上安裝“semisync_slave.so”
MariaDB [(none)]> install plugin rpl_semi_sync_slave soname 'semisync_slave.so'; MariaDB [(none)]> set global rpl_semi_sync_slave_enabled=1; ##啟用半同步復(fù)制的slave節(jié)點(diǎn) MariaDB [(none)]> show global variables like "%semi%"; +---------------------------------+-------+ | Variable_name Value +---------------------------------+-------+ | rpl_semi_sync_slave_enabled ON ##是否啟用半同步復(fù)制的slav節(jié)點(diǎn) | rpl_semi_sync_slave_trace_level 32 +---------------------------------+-------+3、實(shí)現(xiàn)主從復(fù)制
4、在Master節(jié)點(diǎn)上查看是否增加slave節(jié)點(diǎn)
MariaDB [(none)]> show global status like "%semi%"; +--------------------------------------------+-------+ | Variable_name Value +--------------------------------------------+-------+ | Rpl_semi_sync_master_clients 1 ##已經(jīng)連接Slave節(jié)點(diǎn)的個(gè)數(shù) | 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 1 | Rpl_semi_sync_master_no_tx 2 | 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 +--------------------------------------------+--- ----5、在Master節(jié)點(diǎn)上創(chuàng)建數(shù)據(jù)庫(kù)“GunDuZi,并在Slave節(jié)點(diǎn)上查看
MariaDB [(none)]> create database GunDuZi; MariaDB [(none)]> show global status like "%semi%"; +--------------------------------------------+-------+ | Variable_name Value +--------------------------------------------+-------+ | Rpl_semi_sync_master_clients 1 | Rpl_semi_sync_master_net_avg_wait_time 8147 | Rpl_semi_sync_master_net_wait_time 8147 | Rpl_semi_sync_master_net_waits 1 | Rpl_semi_sync_master_no_times 1 | Rpl_semi_sync_master_no_tx 2 | Rpl_semi_sync_master_status ON | Rpl_semi_sync_master_timefunc_failures 0 | Rpl_semi_sync_master_tx_avg_wait_time 9388 | Rpl_semi_sync_master_tx_wait_time 9388 | Rpl_semi_sync_master_tx_waits 1 | Rpl_semi_sync_master_wait_pos_backtraverse 0 | Rpl_semi_sync_master_wait_sessions 0 | Rpl_semi_sync_master_yes_tx 1 +--------------------------------------------+------- MariaDB [(none)]> show databases; +--------------------+ | Database +--------------------+ | information_schema | GunDuZi | mysql | performance_schema | test +--------------------+ ##注意:一定要先安裝插件,在實(shí)現(xiàn)主從復(fù)制四、實(shí)現(xiàn)過濾復(fù)制:讓從節(jié)點(diǎn)指定復(fù)制數(shù)據(jù)庫(kù)或復(fù)制數(shù)據(jù)庫(kù)中指定的表
準(zhǔn)備環(huán)境
虛擬機(jī)1:Master節(jié)點(diǎn)(主節(jié)點(diǎn)) | IP:192.168.1.108 |
虛擬機(jī)2:Slave節(jié)點(diǎn)(從節(jié)點(diǎn)) | IP:192.168.1.109 |
1、實(shí)現(xiàn)主從復(fù)制
2、指定Slave節(jié)點(diǎn)需要復(fù)制的數(shù)據(jù)庫(kù)為“wtcdb”
MariaDB [wxpp]> set global replicate_do_db=wtcdb; MariaDB [wxpp]> show global variables like "replicate%"; +----------------------------------+-----------+ | Variable_name Value +----------------------------------+-----------+ | replicate_annotate_row_events OFF | replicate_do_db wtcdb ##僅復(fù)制那些數(shù)據(jù)庫(kù) | replicate_do_table ##僅復(fù)制那些數(shù)據(jù)庫(kù)中的表 | replicate_events_marked_for_skip replicate | replicate_ignore_db ##忽略的數(shù)據(jù)庫(kù)(不復(fù)制的數(shù)據(jù)庫(kù)) | replicate_ignore_table ##忽略的表(不復(fù)制的表) | replicate_wild_do_table ##可以使用通配符來指定需要復(fù)制的數(shù)據(jù)庫(kù) | replicate_wild_ignore_table +----------------------------------+-----------+3、查看Slave節(jié)點(diǎn)上的數(shù)據(jù)庫(kù)
MariaDB [(none)]> show databases; +--------------------+ | Database +--------------------+ | information_schema | mysql | performance_schema | test | wxpp +--------------------+4、在Master節(jié)點(diǎn)上創(chuàng)建“l(fā)weimdb”、“wzxdb”、“wtcdb”三個(gè)數(shù)據(jù)庫(kù)
MariaDB [(none)]> create database lweimdb; Query OK, 1 row affected (0.01 sec) MariaDB [(none)]> create database wzxdb; Query OK, 1 row affected (0.00 sec) MariaDB [(none)]> create database wtcdb; Query OK, 1 row affected (0.00 sec) MariaDB [(none)]> flush privileges; Query OK, 0 rows affected (0.00 sec) MariaDB [(none)]> show databases; +--------------------+ | Database +--------------------+ | information_schema | lweimdb | mysql | performance_schema | test | wtcdb | wxpp | wzxdb +--------------------+5、再一次查看Slave節(jié)點(diǎn)上的數(shù)據(jù)庫(kù),是否只復(fù)制了“wtcdb”數(shù)據(jù)庫(kù)
MariaDB [(none)]> show databases; +--------------------+ | Database +--------------------+ | information_schema | mysql | performance_schema | test | wtcdb | wxpp +--------------------+五、實(shí)現(xiàn)SSL復(fù)制
準(zhǔn)備環(huán)境
虛擬機(jī)1:Master節(jié)點(diǎn)(主節(jié)點(diǎn)) | IP:192.168.1.108 |
虛擬機(jī)2:Slave節(jié)點(diǎn)(從節(jié)點(diǎn)) | IP:192.168.1.109 |
虛擬機(jī)3:CA機(jī)構(gòu)(簽署主從節(jié)點(diǎn)證書) | IP:192.168.1.110 |
1、部署虛擬機(jī)3
(1)創(chuàng)建CA證書秘鑰
[root@localhost CA]# (umask 077;openssl genrsa -out ./private/cakey.pem 1024)(2)讓CA自簽證書
[root@localhost CA]# openssl req -new -x509 -key ./private/cakey.pem -out cacert.pem -days 365 [root@localhost CA]# touch serial index.txt ##創(chuàng)建所需要的文件 [root@localhost CA]# echo 01 > serial ##生成證書序列號(hào)2、Master節(jié)點(diǎn)創(chuàng)建證書,并讓CA機(jī)構(gòu)簽署
[root@node0 ssl]# (umask 077; openssl genrsa -out master.key 1024) ##Master節(jié)點(diǎn)生成秘鑰 [root@node0 ssl]# openssl req -new -key master.key -out master.csr -days 365 ##生成需要簽署的證書 [root@localhost CA]# openssl ca -in /tmp/master.csr -out master.crt -days 365 ##讓CA簽署證書 [root@node0 ssl]# chmod 600 * ##更改權(quán)限為600 [root@node0 ssl]# chown mysql.mysql -R ssl/* ##更改文件屬主屬組為mysql [root@node0 ssl]# ll total 12 -rw------- 1 mysql mysql 1046 Jun 9 20:49 cacert.pem -rw------- 1 mysql mysql 3202 Jun 9 20:43 master.crt -rw------- 1 mysql mysql 887 Jun 9 20:35 master.key3、配置Master節(jié)點(diǎn)的配置文件,并創(chuàng)建具有復(fù)制權(quán)限的用戶
[root@node0 ~]# vim /etc/my.cnf ssl ##開啟sll功能 ssl_ca=/var/lib/mysql/ssl/cacert.pem ##指明CA機(jī)構(gòu)證書路徑 ssl_cert=/var/lib/mysql/ssl/master.crt ##指明Master節(jié)點(diǎn)的證書路徑 ssl_key=/var/lib/mysql/ssl/master.key ##指明Master節(jié)點(diǎn)的秘鑰路徑 [root@node0 ~]# systemctl start mariadb.service MariaDB [(none)]> show global variables like "%ssl%"; ##查看是否啟用ssl +---------------+-------------------------------+ | Variable_name | Value +---------------+-------------------------------+ | have_openssl | YES | have_ssl | YES | ssl_ca | /var/lib/mysql/ssl/cacert.pem | ssl_capath | ssl_cert | /var/lib/mysql/ssl/master.crt | ssl_cipher | ssl_key | /var/lib/mysql/ssl/master.key +---------------+-------------------------------+ MariaDB [(none)]> grant replication slave,replication client on *.* to 'repluser'@'192.168.%.%' identified by 'replpass' require ssl;4、將Master節(jié)點(diǎn)上的證書發(fā)送給Slave,修改其配置文件,連接至Master節(jié)點(diǎn)并啟動(dòng)復(fù)制線程
[root@node0 ~]# scp ssl/* root@192.168.1.109:/var/lib/mysql/ ##要確保發(fā)送的文件屬組屬主為“mysql” root@192.168.1.109's password: cacert.pem 100% 1046 1.0KB/s 00:00 master.crt 100% 3206 3.1KB/s 00:00 master.key 100% 887 0.9KB/s 00:00 [root@node1 ~]# vim /etc/my.cnf ssl ssl_ca=/var/lib/mysql/cacert.pem ssl_cert=/var/lib/mysql/master.crt ssl_key=/var/lib/mysql/master.key [root@node1 ~]# systemctl start mariadb.service MariaDB [(none)]> show global variables like '%ssl%'; ##從節(jié)點(diǎn)上的SSL的功能已經(jīng)開啟 +---------------+---------------------------+ | Variable_name | Value +---------------+---------------------------+ | have_openssl | YES | have_ssl | YES | ssl_ca | /var/lib/mysql/cacert.pem | ssl_capath | | ssl_cert | /var/lib/mysql/master.crt | ssl_cipher | | ssl_key | /var/lib/mysql/master.key +---------------+---------------------------+ MariaDB [(none)]> change master to master_host='192.168.1.108',master_user='repluser',master_password='replpass',master_log_file='mysql-bin.000003',master_log_pos=245,master_ssl=1,master_ssl_ca='/var/lib/mysql/cacert.pem',master_ssl_cert='/var/lib/mysql/master.crt',master_ssl_key='/var/lib/mysql/master.key'; ## master_ssl:?jiǎn)⒂胹sl功能 ## master_ssl_ca:指明CA證書路徑 ## master_ssl_cert:指明Master節(jié)點(diǎn)證書路徑 ## master_ssl_key:指明Master節(jié)點(diǎn)秘鑰路徑 MariaDB [(none)]> start slave; ##啟動(dòng)復(fù)制線程 MariaDB [(none)]> show slave status\G; ##查看復(fù)制線程相關(guān)信息 Slave_IO_Running: Yes Slave_SQL_Running: Yes Master_SSL_Allowed: Yes ##要確保這三項(xiàng)都為“YES” Master_SSL_CA_File: /var/lib/mysql/cacert.pem Master_SSL_Cert: /var/lib/mysql/master.crt Master_SSL_Key: /var/lib/mysql/master.key5、分別查看Master節(jié)點(diǎn)和Slave節(jié)點(diǎn)上的數(shù)據(jù)庫(kù)
MariaDB [(none)]> show databases; ##查看Master節(jié)點(diǎn) +--------------------+ | Database +--------------------+ | information_schema | mysql | performance_schema | ssl | test +--------------------+ MariaDB [(none)]> show databases; ##查看Slave節(jié)點(diǎn) +--------------------+ | Database +--------------------+ | information_schema | mysql | performance_schema | test +--------------------+6、在Master節(jié)點(diǎn)上創(chuàng)建"LweimRepo”、“HjRepo”、“WzxRepo”,隨后再到Slave節(jié)點(diǎn)上查看
MariaDB [(none)]> create database LweimRepo; Query OK, 1 row affected (0.00 sec) MariaDB [(none)]> create database HjRepo; Query OK, 1 row affected (0.00 sec) MariaDB [(none)]> create database WzxRepo; Query OK, 1 row affected (0.04 sec) MariaDB [(none)]> show databases; ##在Slave節(jié)點(diǎn)上查看 +--------------------+ | Database +--------------------+ | information_schema | HjRepo | LweimRepo | WzxRepo | mysql | performance_schema | test +--------------------+問題小結(jié):
1、當(dāng)Slave節(jié)點(diǎn)連接至Master節(jié)點(diǎn)時(shí),一定要指明Master節(jié)點(diǎn)當(dāng)前使用的二進(jìn)制日志以及pos
2、在使用SSL復(fù)制時(shí),要確保秘鑰、證書文件的權(quán)限以及屬主屬組
3、當(dāng)生成證書時(shí),三臺(tái)虛擬機(jī)的國(guó)家、省份、公司名稱必須要一樣
看了以上介紹多種MySQL復(fù)制方法詳解,希望能給大家在實(shí)際運(yùn)用中帶來一定的幫助。本文由于篇幅有限,難免會(huì)有不足和需要補(bǔ)充的地方,大家可以繼續(xù)關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊板塊,會(huì)定期給大家更新行業(yè)新聞和知識(shí),如有需要更加專業(yè)的解答,可在官網(wǎng)聯(lián)系我們的24小時(shí)售前售后,隨時(shí)幫您解答問題的。
另外有需要云服務(wù)器可以了解下創(chuàng)新互聯(lián)cdcxhl.cn,海內(nèi)外云服務(wù)器15元起步,三天無理由+7*72小時(shí)售后在線,公司持有idc許可證,提供“云服務(wù)器、裸金屬服務(wù)器、高防服務(wù)器、香港服務(wù)器、美國(guó)服務(wù)器、虛擬主機(jī)、免備案服務(wù)器”等云主機(jī)租用服務(wù)以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡(jiǎn)單易用、服務(wù)可用性高、性價(jià)比高”等特點(diǎn)與優(yōu)勢(shì),專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應(yīng)用場(chǎng)景需求。
網(wǎng)頁(yè)名稱:多種MySQL復(fù)制方法詳解-創(chuàng)新互聯(lián)
分享鏈接:http://aaarwkj.com/article22/gjjcc.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供商城網(wǎng)站、云服務(wù)器、手機(jī)網(wǎng)站建設(shè)、網(wǎng)站設(shè)計(jì)公司、ChatGPT、外貿(mào)建站
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容