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

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

Mariadb數據庫主從復制同步配置過程實例

瀏覽:685日期:2023-03-30 13:21:07
目錄
  • 一、環境規劃
  • 二、Mariadb的主從復制介紹
    • 1.主從復制簡介
    • 2.半同步復制介紹
    • 3.主從復制原理圖
  • 三、安裝Mariadb
    • 1.配置yum倉庫
    • 2.檢查yum倉庫
    • 3.安裝mariadb
    • 4.啟動mariadb服務
    • 5.從節點安裝mariadb
  • 四、mariadb主庫配置
    • 1.mariadb的初始化
    • 2.修改主庫配置文件
    • 3.重啟mariadb服務
  • 五、mariadb從庫配置
    • 1.修改從庫node01節點的server.cnf文件
    • 2.修改從庫node02節點的server.cnf文件
    • 3.重啟node01和node02的mariadb服務
  • 六、查看mariadb主庫狀態
    • 1.創建數據庫用戶
    • 2.查看數據庫用戶信息
    • 3.查看主庫狀態
    • 4.查看mysql-bin日志文件
    • 5.gtid查詢
  • 七、啟動從庫
    • 1.從庫設置主庫的gtid
    • 2.連接主庫
    • 3.啟動從庫
    • 4.查詢從庫狀態
  • 八、測試主從同步
    • 1.主庫寫入數據
    • 2.主庫查看數據表
    • 3.從庫查看數據表

一、環境規劃

hostnameIP地址系統版本角色master192.168.3.171centos 7.6主節點node01192.168.3.172centos 7.6從節點node02192.168.3.173centos 7.6從節點

二、Mariadb的主從復制介紹

1.主從復制簡介

主從同步使得數據可以從一個數據庫服務器復制到其他服務器上,在復制數據時,一個服務器充當主服務器(master),其余的服務器充當從服務器(slave)。

2.半同步復制介紹

半同步復制是解決主庫數據掛掉,從庫數據不一致的問題。 解決方法:半同步復制,半同步復制場景中,master會監視所有的slave,確保其中至少一臺數據完全同步成功,master才會返回客戶端信息,此數據寫成功。

3.主從復制原理圖

三、安裝Mariadb

1.配置yum倉庫

3個節點都安裝Mariadb數據庫

[root@master yum.repos.d]# cat mariadb.repo # MariaDB 10.6 CentOS repository list - created 2021-12-27 11:21 UTC# https://mariadb.org/download/[mariadb]name = MariaDBbaseurl = https://mirrors.ustc.edu.cn/mariadb/yum/10.6/centos7-amd64gpgkey=https://mirrors.ustc.edu.cn/mariadb/yum/RPM-GPG-KEY-MariaDBgpgcheck=0
 sed -i "s#//mirrors.xtom.com.hk#//mirrors.ustc.edu.cn#g" /etc/yum.repos.d/mariadb.repo

2.檢查yum倉庫

[root@master yum.repos.d]# yum repolist allLoaded plugins: fastestmirrorLoading mirror speeds from cached hostfilerepo id  repo name statusmariadb  MariaDB   enabled: 96repolist: 96

3.安裝mariadb

yum -y install mariadb-server

4.啟動mariadb服務

[root@master yum.repos.d]# systemctl start mariadb[root@master yum.repos.d]# systemctl enable  mariadbCreated symlink from /etc/systemd/system/multi-user.target.wants/mariadb.service to /usr/lib/systemd/system/mariadb.service.[root@master yum.repos.d]# 

5.從節點安裝mariadb

如上步驟安裝即可。

四、mariadb主庫配置

1.mariadb的初始化

[root@master ~]# mariadb-secure-installation NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!In order to log into MariaDB to secure it, we"ll need the currentpassword for the root user. If you"ve just installed MariaDB, andhaven"t set the root password yet, you should just press enter here.Enter current password for root (enter for none): OK, successfully used password, moving on...Setting the root password or using the unix_socket ensures that nobodycan log into the MariaDB root user without the proper authorisation.You already have your root account protected, so you can safely answer "n".Switch to unix_socket authentication [Y/n] n ... skipping.You already have your root account protected, so you can safely answer "n".Change the root password? [Y/n] n ... skipping.By default, a MariaDB installation has an anonymous user, allowing anyoneto log into MariaDB without having to have a user account created forthem.  This is intended only for testing, and to make the installationgo a bit smoother.  You should remove them before moving into aproduction environment.Remove anonymous users? [Y/n] y ... Success!Normally, root should only be allowed to connect from "localhost".  Thisensures that someone cannot guess at the root password from the network.Disallow root login remotely? [Y/n] n ... skipping.By default, MariaDB comes with a database named "test" that anyone canaccess.  This is also intended only for testing, and should be removedbefore moving into a production environment.Remove test database and access to it? [Y/n] y - Dropping test database... ... Success! - Removing privileges on test database... ... Success!Reloading the privilege tables will ensure that all changes made so farwill take effect immediately.Reload privilege tables now? [Y/n] y ... Success!Cleaning up...All done!  If you"ve completed all of the above steps, your MariaDBinstallation should now be secure.Thanks for using MariaDB![root@master ~]# 

2.修改主庫配置文件

[root@master ~]# grep -Ev "^$|^#" /etc/my.cnf.d/server.cnf[server][mysqld]character-set-server=utf8collation-server=utf8_general_ciserver_id = 12    #  一組主從組里的每個id必須是唯一值。推薦用ip位數log-bin= mysql-bin # 二進制日志,后面指定存放位置。如果只是指定名字,默認存放在/var/lib/mysql下lower_case_table_names=1 # 不區分大小寫binlog-format=ROW    # 二進制日志文件格式log-slave-updates=True    # slave更新是否記入日志sync-master-info=1    # 值為1確保信息不會丟失slave-parallel-threads=3 #同時啟動多少個復制線程,最多與要復制的數據庫數量相等即可binlog-checksum=CRC32    # 效驗碼master-verify-checksum=1    # 啟動主服務器效驗slave-sql-verify-checksum=1   # 啟動從服務器效驗[galera][embedded][mariadb][mariadb-10.6][root@master ~]# 

3.重啟mariadb服務

[root@master ~]# systemctl restart mariadb[root@master ~]# 

五、mariadb從庫配置

1.修改從庫node01節點的server.cnf文件

[root@node01 ~]# cat  /etc/my.cnf.d/server.cnf## These groups are read by MariaDB server.# Use it for options that only the server (but not clients) should see## See the examples of server my.cnf files in /usr/share/mysql/## this is read by the standalone daemon and embedded servers[server]# this is only for the mysqld standalone daemon[mysqld]character-set-server=utf8collation-server=utf8_general_ciserver_id=15#log-bin= mysql-bin #log-bin是二進制文件relay_log = relay-bin    # 中繼日志, 后面指定存放位置。如果只是指定名字,默認存放在/var/lib/mysql下lower_case_table_names=1## * Galera-related settings#[galera]# Mandatory settings#wsrep_on=ON#wsrep_provider=#wsrep_cluster_address=#binlog_format=row#default_storage_engine=InnoDB#innodb_autoinc_lock_mode=2## Allow server to accept connections on all interfaces.##bind-address=0.0.0.0## Optional setting#wsrep_slave_threads=1#innodb_flush_log_at_trx_commit=0# this is only for embedded server[embedded]# This group is only read by MariaDB servers, not by MySQL.# If you use the same .cnf file for MySQL and MariaDB,# you can put MariaDB-only options here[mariadb]# This group is only read by MariaDB-10.6 servers.# If you use the same .cnf file for MariaDB of different versions,# use this group for options that older servers don"t understand[mariadb-10.6]

2.修改從庫node02節點的server.cnf文件

[root@node02 ~]# cat  /etc/my.cnf.d/server.cnf## These groups are read by MariaDB server.# Use it for options that only the server (but not clients) should see## See the examples of server my.cnf files in /usr/share/mysql/## this is read by the standalone daemon and embedded servers[server]# this is only for the mysqld standalone daemon[mysqld]character-set-server=utf8collation-server=utf8_general_ciserver_id=16#log-bin= mysql-bin #log-bin是二進制文件relay_log = relay-bin    # 中繼日志, 后面指定存放位置。如果只是指定名字,默認存放在/var/lib/mysql下lower_case_table_names=1## * Galera-related settings#[galera]# Mandatory settings#wsrep_on=ON#wsrep_provider=#wsrep_cluster_address=#binlog_format=row#default_storage_engine=InnoDB#innodb_autoinc_lock_mode=2## Allow server to accept connections on all interfaces.##bind-address=0.0.0.0## Optional setting#wsrep_slave_threads=1#innodb_flush_log_at_trx_commit=0# this is only for embedded server[embedded]# This group is only read by MariaDB servers, not by MySQL.# If you use the same .cnf file for MySQL and MariaDB,# you can put MariaDB-only options here[mariadb]# This group is only read by MariaDB-10.6 servers.# If you use the same .cnf file for MariaDB of different versions,# use this group for options that older servers don"t understand[mariadb-10.6]

3.重啟node01和node02的mariadb服務

systemctl restart mariadb

六、查看mariadb主庫狀態

1.創建數據庫用戶

MariaDB [(none)]>  grant replication slave, replication client on *.* to "redhat"@"%"  identified by "admin";Query OK, 0 rows affected (0.025 sec)MariaDB [(none)]> flush privileges;Query OK, 0 rows affected (0.000 sec)

2.查看數據庫用戶信息

MariaDB [(none)]> select user,password,host from mysql.user;+-------------+-------------------------------------------+-----------+| User| Password  | Host      |+-------------+-------------------------------------------+-----------+| mariadb.sys |   | localhost || root| invalid   | localhost || mysql       | invalid   | localhost || redhat      | *4ACFE3202A5FF5CF467898FC58AAB1D615029441 | % |+-------------+-------------------------------------------+-----------+4 rows in set (0.002 sec)MariaDB [(none)]> 

3.查看主庫狀態

MariaDB [(none)]> show master status;+------------------+----------+--------------+------------------+| File     | Position | Binlog_Do_DB | Binlog_Ignore_DB |+------------------+----------+--------------+------------------+| mysql-bin.000002 |      659 |      |  |+------------------+----------+--------------+------------------+1 row in set (0.000 sec)MariaDB [(none)]> 

4.查看mysql-bin日志文件

[root@master ~]#  ll /var/lib/mysql/mysql-bin.index -rw-rw----. 1 mysql mysql 38 Nov 23 23:31 /var/lib/mysql/mysql-bin.index[root@master ~]# cat  /var/lib/mysql/mysql-bin.index ./mysql-bin.000001./mysql-bin.000002

5.gtid查詢

MariaDB [(none)]> select binlog_gtid_pos("mysql-bin.000002",659);+-----------------------------------------+| binlog_gtid_pos("mysql-bin.000002",659) |+-----------------------------------------+| 0-12-2  |+-----------------------------------------+1 row in set (0.000 sec)MariaDB [(none)]> 

七、啟動從庫

1.從庫設置主庫的gtid

MariaDB [(none)]>  set global gtid_slave_pos="0-12-2";Query OK, 0 rows affected (0.080 sec)

2.連接主庫

MariaDB [(none)]>  change master to master_host="192.168.3.171",master_user="redhat",master_password="admin",master_use_gtid=slave_pos;Query OK, 0 rows affected (0.182 sec)

3.啟動從庫

MariaDB [(none)]>  start slave;Query OK, 0 rows affected (0.123 sec)

4.查詢從庫狀態

MariaDB [(none)]> show  slave status\G*************************** 1. row ***************************Slave_IO_State: Waiting for master to send event   Master_Host: 192.168.3.171   Master_User: redhat   Master_Port: 3306 Connect_Retry: 60       Master_Log_File: mysql-bin.000002   Read_Master_Log_Pos: 1450Relay_Log_File: relay-bin.000002 Relay_Log_Pos: 1461 Relay_Master_Log_File: mysql-bin.000002      Slave_IO_Running: Yes     Slave_SQL_Running: Yes       Replicate_Do_DB:    Replicate_Ignore_DB:     Replicate_Do_Table: Replicate_Ignore_Table:        Replicate_Wild_Do_Table:    Replicate_Wild_Ignore_Table:     Last_Errno: 0    Last_Error:   Skip_Counter: 0   Exec_Master_Log_Pos: 1450       Relay_Log_Space: 1764       Until_Condition: NoneUntil_Log_File:  Until_Log_Pos: 0    Master_SSL_Allowed: No    Master_SSL_CA_File:     Master_SSL_CA_Path:        Master_SSL_Cert:      Master_SSL_Cipher: Master_SSL_Key:  Seconds_Behind_Master: 0 Master_SSL_Verify_Server_Cert: No Last_IO_Errno: 0 Last_IO_Error: Last_SQL_Errno: 0Last_SQL_Error:    Replicate_Ignore_Server_Ids:       Master_Server_Id: 12Master_SSL_Crl:     Master_SSL_Crlpath:     Using_Gtid: Slave_Pos   Gtid_IO_Pos: 0-12-7       Replicate_Do_Domain_Ids:    Replicate_Ignore_Domain_Ids:  Parallel_Mode: optimistic     SQL_Delay: 0   SQL_Remaining_Delay: NULL       Slave_SQL_Running_State: Slave has read all relay log; waiting for more updates      Slave_DDL_Groups: 3Slave_Non_Transactional_Groups: 2    Slave_Transactional_Groups: 01 row in set (0.000 sec)MariaDB [(none)]> 

八、測試主從同步

1.主庫寫入數據

MariaDB [(none)]> create database school;Query OK, 1 row affected (0.001 sec)MariaDB [(none)]> use school;Database changedMariaDB [school]> CREATE TABLE IF NOT EXISTS `student`(    ->    `id` INT UNSIGNED AUTO_INCREMENT,    ->    `name` VARCHAR(100) NOT NULL,    ->    `gender` TINYINT NOT NULL,    ->    `age` INT UNSIGNED,    ->    `class` INT UNSIGNED,    ->      `course` VARCHAR(100) NOT NULL,    ->     `grade` INT UNSIGNED,    ->    PRIMARY KEY ( `id` )    -> )ENGINE=InnoDB DEFAULT CHARSET=utf8;Query OK, 0 rows affected (0.206 sec)MariaDB [school]> insert into student ( name, gender, age, class, Course, grade ) values ( "高峰", "0", "22", "4", "英語", "100"), ( "陳林", "1", "15", "5", "化學", "99" );Query OK, 2 rows affected (0.012 sec)Records: 2  Duplicates: 0  Warnings: 0MariaDB [school]> insert into student ( name, gender, age, class, course, grade ) values  ( "王明", "0", "16", "2", "數學", "88"),  ( "萬易", "0", "17", "4", "地理", "79" ), ( "李依依", "1", "17", "3", "語文",  "90"  ) ;Query OK, 3 rows affected (0.017 sec)Records: 3  Duplicates: 0  Warnings: 0

2.主庫查看數據表

MariaDB [school]> select * from school.student;+----+-----------+--------+------+-------+--------+-------+| id | name      | gender | age  | class | course | grade |+----+-----------+--------+------+-------+--------+-------+|  1 | 高峰      |      0 |   22 |     4 | 英語   |   100 ||  2 | 陳林      |      1 |   15 |     5 | 化學   |    99 ||  3 | 王明      |      0 |   16 |     2 | 數學   |    88 ||  4 | 萬易      |      0 |   17 |     4 | 地理   |    79 ||  5 | 李依依    |      1 |   17 |     3 | 語文   |    90 |+----+-----------+--------+------+-------+--------+-------+5 rows in set (0.000 sec)MariaDB [school]> 

3.從庫查看數據表

[root@node01 ~]# hostnamenode01[root@node01 ~]# mariadbWelcome to the MariaDB monitor.  Commands end with ; or \g.Your MariaDB connection id is 12Server version: 10.6.11-MariaDB MariaDB ServerCopyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.Type "help;" or "\h" for help. Type "\c" to clear the current input statement.MariaDB [(none)]> select * from school.student;+----+-----------+--------+------+-------+--------+-------+| id | name      | gender | age  | class | course | grade |+----+-----------+--------+------+-------+--------+-------+|  1 | 高峰      |      0 |   22 |     4 | 英語   |   100 ||  2 | 陳林      |      1 |   15 |     5 | 化學   |    99 ||  3 | 王明      |      0 |   16 |     2 | 數學   |    88 ||  4 | 萬易      |      0 |   17 |     4 | 地理   |    79 ||  5 | 李依依    |      1 |   17 |     3 | 語文   |    90 |+----+-----------+--------+------+-------+--------+-------+5 rows in set (0.000 sec)MariaDB [(none)]> 

以上就是Mariadb數據庫主從復制同步配置過程實例的詳細內容,更多關于Mariadb主從復制同步配置的資料請關注其它相關文章!

標簽: MariaDB
日本不卡不码高清免费观看,久久国产精品久久w女人spa,黄色aa久久,三上悠亚国产精品一区二区三区
日韩一二三区在线观看| 蜜臀av性久久久久蜜臀aⅴ四虎| 日韩精品久久久久久久软件91| 西西人体一区二区| 午夜在线播放视频欧美| 91精品福利| 亚洲欧美不卡| 亚洲精品在线二区| 91av一区| 开心激情综合| 伊人久久av| 日韩免费视频| 欧美成人午夜| 老鸭窝毛片一区二区三区| 亚洲综合小说| 樱桃成人精品视频在线播放| 性欧美xxxx免费岛国不卡电影| 红杏一区二区三区| 国产一区二区色噜噜| 久久精品网址| 成人污污视频| 亚洲天堂资源| 久久久精品久久久久久96 | 亚洲欧美日韩国产一区| 国产一区日韩欧美| 亚洲先锋成人| 精品1区2区3区4区| 久久精品免费一区二区三区| 日韩久久精品网| 欧美香蕉视频| 久久久一二三| 一区在线免费| 蜜臀久久99精品久久久画质超高清| 蜜桃视频一区二区三区在线观看| 蜜桃久久av一区| 日韩精品视频在线看| 国产亚洲字幕| 韩日一区二区| 999视频精品| 在线成人动漫av| 中文字幕系列一区| 蜜桃91丨九色丨蝌蚪91桃色| 亚洲欧美日韩国产综合精品二区 | 久久久久国产精品一区三寸| 日韩国产专区| 婷婷综合激情| 亚洲午夜国产成人| 国产午夜精品一区在线观看| 国产精品v一区二区三区| 免费在线亚洲欧美| 日韩在线精品| 亚洲免费网址| 日本午夜精品久久久久| 国产精品nxnn| 蜜桃av.网站在线观看| 日韩欧美中文| 99国产精品久久久久久久 | 欧美羞羞视频| 伊人久久亚洲热| 欧美一区久久| 成人国产综合| 国产精品毛片| 国产精品中文字幕亚洲欧美| 97人人精品| 亚洲国产日韩欧美在线| 综合一区av| 精品视频一区二区三区四区五区 | 国产乱人伦丫前精品视频| 成人精品动漫一区二区三区| 亚洲国产综合在线看不卡| 综合亚洲视频| 久久伊人国产| 亚洲精品成人| 国产精品亚洲四区在线观看| 久久蜜桃资源一区二区老牛| 视频一区二区中文字幕| 久久久久伊人| 黄色欧美日韩| 欧美日韩黄网站| 蜜桃成人精品| 综合在线一区| 日韩国产在线| 日韩av资源网| 久久精品国产亚洲夜色av网站| 一区二区电影| 一区二区三区四区日本视频| 日本中文字幕视频一区| 国产美女高潮在线观看| 亚洲色图网站| 亚洲综合电影| 欧美日韩亚洲一区| 亚洲女同中文字幕| 国产亚洲久久| 久久久久91| 国产区精品区| 黄色成人91| 精品三级国产| 亚洲图片久久| 久久中文视频| 日韩av午夜在线观看| 国产91久久精品一区二区| 国产精品三p一区二区| 尹人成人综合网| 国产一二在线播放| 日韩高清在线不卡| 婷婷综合激情| 天堂中文在线播放| 日韩av不卡一区二区| 久久久精品网| 麻豆精品在线| 日韩精品欧美精品| 午夜久久黄色| 中文在线中文资源| 国产伦精品一区二区三区在线播放| 亚洲男女自偷自拍| 伊人网在线播放| 国产精品2023| 日韩精品一级| 久久国产精品99国产| 久久精品国产亚洲夜色av网站| 国产精品丝袜在线播放| 综合激情网...| 亚洲午夜电影| 精品伊人久久久| 国产亚洲高清在线观看| 蜜臀av在线播放一区二区三区 | 国产亚洲精品美女久久久久久久久久| 夜久久久久久| 欧美国产91| 亚洲a在线视频| 国产精品毛片久久| 欧美a在线观看| 欧美日韩一视频区二区| 老司机久久99久久精品播放免费| 99精品电影| 日韩国产一区| 91日韩免费| 久久久亚洲欧洲日产| 国产精品传媒麻豆hd| 欧美日韩一区二区三区在线电影| 亚洲精品自拍| 亚洲精品成人一区| 亚洲一区二区日韩| 先锋亚洲精品| 在线国产日韩| 日欧美一区二区| 日韩国产一区二| 天堂av在线一区| 欧美国产91| 午夜亚洲精品| 美女网站久久| 亚洲欧美日韩一区在线观看| 日韩不卡免费高清视频| 最新中文字幕在线播放 | 国产精品成人一区二区不卡| 老司机精品视频网| 精品一区二区三区四区五区| 久久成人福利| 国产专区精品| 日本美女一区| 亚洲精品国产偷自在线观看| 五月天激情综合网| 国产麻豆久久| 久久精品青草| 黄色日韩在线| 91成人精品视频| 久久精品国产99久久| 免费一二一二在线视频| 岛国av免费在线观看| 久久亚洲黄色| 欧美日韩一区二区三区不卡视频 | 另类中文字幕国产精品| 99久久99久久精品国产片果冰| 欧美日韩国产高清电影| 99综合视频| 日本亚洲三级在线| 久久99久久人婷婷精品综合| 日韩av专区| 亚洲精品一二三区区别| 在线观看一区| 国产精品片aa在线观看| 成人污污视频| 美女网站一区| 日韩美女国产精品| 国产成人精品一区二区免费看京| 久久精品亚洲人成影院 | 国产99久久| 午夜久久av | 久久av影院| 1024精品一区二区三区| 中文在线日韩| 国产精品99久久免费| 丝袜美腿一区| 亚洲开心激情| 国产一区二区三区不卡视频网站| 久久精品影视| 青草国产精品久久久久久| 亚洲天堂av影院| 亚洲三级观看| 理论片午夜视频在线观看|