首頁>Club>
2
回覆列表
  • 1 # 手機使用者51977825032

    光憑這句話,看不出來MGR的意思。但是,在這句話前面就應該曾經把這個簡稱的全名寫出來過。可以自己去查檢視。

  • 2 # 愛可生雲資料庫

    MySQL Group Replication(下簡稱MGR)準確來說是官方推出的高知可用解決方案,基於原生複製技術,並以外掛的方式提供。

    1、使用前,關掉防火牆,包括 selinux,firewalld,或者 MySQL 企業版的firewall(如果用了企業版的話)2、兩臺機器:(4 臺 MySQL 例項)192.168.2.219 centos-ytt57-1 3311/3312192.168.2.229 centos-ytt57-2 3311/33123、安裝 MySQL(兩臺都裝), MySQL Shell(任意一臺), mysqlrouter(任意一臺,官方建議和應用程式裝在一個伺服器上)yum install mysql-community-server mysql-shell mysql-router-community

    4、搭建 InnoDB-Cluster(兩臺都裝)

    1. 配置檔案如下:shell>vi /etc/my.cnfmaster-info-repository=tablerelay-log-info-repository=tablegtid_mode=ONenforce_gtid_consistency=ONbinlog_checksum=NONElog_slave_updates=ONbinlog_format=ROWtransaction_write_set_extraction=XXHASH642. 系統 HOSTS 配置(兩臺都配)

    shell>vi /etc/hosts

    127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4

    ::1 localhost localhost.localdomain localhost6 localhost6.localdomain6

    192.168.2.219 centos-ytt57-2

    192.168.2.229 centos-ytt57-3

    用 MySQL coalesce 函式確認下 report-host 是否設定正確(root@localhost) : [(none)] >SELECT coalesce(@@report_host, @@hostname) as r;+----------------+| r |+----------------+| centos-ytt57-1 |+----------------+1 row in set (0.00 sec)

    3. 建立管理員使用者搭建 GROUP REPLICATION (四個節點都要)

    create user root identified by "Root@123";grant all on *.* to root with grant option;flush privileges;

    4. MySQLsh 連線其中一臺節點:

    [root@centos-ytt57-1 mysql]# mysqlsh root@localhost:3321

    5. 檢查配置正確性:(如果這裡不顯示 OK,把對應的引數加到配置檔案重啟 MySQL 再次檢查)dba.checkInstanceConfiguration("root@centos-ytt57-2:3311");dba.checkInstanceConfiguration("root@centos-ytt57-2:3312");dba.checkInstanceConfiguration("root@centos-ytt57-3:3311");dba.checkInstanceConfiguration("root@centos-ytt57-3:3312");mysqlsh 執行檢測

    [root@centos-ytt57-1 mysql]# mysqlsh --log-level=8 root@localhost:3311

    MySQL localhost:3311 ssl JS > dba.checkInstanceConfiguration("root@centos-ytt57-2:3311")

    {

    "status": "ok"

    }

    6. 建立叢集,節點 1 上建立。(結果顯示 Cluster successfully created 表示成功)

    MySQL localhost:3311 ssl JS > var cluster = dba.createCluster("ytt_mgr");

    Cluster successfully created. Use Cluster.addInstance() to add MySQL instances.

    At least 3 instances are needed for the cluster to be able to withstand up to

    one server failure.

    7. 新增節點 2,3,4(全部顯示 OK,表示新增成功)MySQL localhost:3311 ssl JS > cluster.addInstance("root@centos-ytt57-2:3312");MySQL localhost:3311 ssl JS > cluster.addInstance("root@centos-ytt57-3:3311");MySQL localhost:3311 ssl JS > cluster.addInstance("root@centos-ytt57-3:3312");

    8. 檢視拓撲圖:(describe 簡單資訊,status 詳細描述)

    MySQL localhost:3311 ssl JS > cluster.describe()

    {

    "clusterName": "ytt_mgr",

    "defaultReplicaSet": {

    "name": "default",

    "topology": [

    {

    "address": "centos-ytt57-2:3311",

    "label": "centos-ytt57-2:3311",

    "role": "HA",

    "version": "8.0.17"

    },

    {

    "address": "centos-ytt57-2:3312",

    "label": "centos-ytt57-2:3312",

    "role": "HA",

    "version": "8.0.17"

    },

    {

    "address": "centos-ytt57-3:3311",

    "label": "centos-ytt57-3:3311",

    "role": "HA",

    "version": "8.0.17"

    },

    {

    "address": "centos-ytt57-3:3312",

    "label": "centos-ytt57-3:3312",

    "role": "HA",

    "version": "8.0.17"

    }

    ],

    "topologyMode": "Single-Primary"

    }

    }

    MySQL localhost:3311 ssl JS > cluster.status()

    "clusterName": "ytt_mgr",

    "defaultReplicaSet": {

    "name": "default",

    "primary": "centos-ytt57-2:3311",

    "ssl": "REQUIRED",

    "status": "OK",

    "statusText": "Cluster is ONLINE and can tolerate up to ONE failure.",

    "topology": {

    "centos-ytt57-2:3311": {

    "address": "centos-ytt57-2:3311",

    "mode": "R/W",

    "readReplicas": {},

    "role": "HA",

    "status": "ONLINE",

    "version": "8.0.17"

    },

    "centos-ytt57-2:3312": {

    "address": "centos-ytt57-2:3312",

    "mode": "R/O",

    "readReplicas": {},

    "role": "HA",

    "status": "ONLINE",

    "version": "8.0.17"

    },

    "centos-ytt57-3:3311": {

    "address": "centos-ytt57-3:3311",

    "mode": "R/O",

    "readReplicas": {},

    "role": "HA",

    "status": "ONLINE",

    "version": "8.0.17"

    },

    "centos-ytt57-3:3312": {

    "address": "centos-ytt57-3:3312",

    "mode": "R/O",

    "readReplicas": {},

    "role": "HA",

    "status": "ONLINE",

    "version": "8.0.17"

    }

    },

    "topologyMode": "Single-Primary"

    },

    "groupInformationSourceMember": "centos-ytt57-2:3311"

    9. 簡單測試下資料是否同步

    (root@localhost) : [(none)] >create database ytt;

    Query OK, 1 row affected (0.03 sec)

    (root@localhost) : [(none)] >use ytt;

    Database changed

    (root@localhost) : [ytt] >create table p1(id int primary key, log_time datetime);

    Query OK, 0 rows affected (0.08 sec)

    (root@localhost) : [ytt] >insert into p1 values (1,now());

    Query OK, 1 row affected (0.04 sec)

    (root@localhost) : [ytt] >show master status;

    +---------------+----------+--------------+------------------+-------------------------------------------+

    | File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |

    +---------------+----------+--------------+------------------+-------------------------------------------+

    | mysql0.000001 | 25496 | | | 6c7bb9db-b759-11e9-a9c0-0800276cf0fc:1-41 |

    +---------------+----------+--------------+------------------+-------------------------------------------+

    1 row in set (0.00 sec)

    檢視其他三個節點

    (root@localhost) : [ytt] >show tables;

    +---------------+

    | Tables_in_ytt |

    +---------------+

    | p1 |

    +---------------+

    1 row in set (0.00 sec)

    (root@localhost) : [ytt] >select * from p1;

    +----+---------------------+

    | id | log_time |

    +----+---------------------+

    | 1 | 2019-08-05 16:44:20 |

    +----+---------------------+

    1 row in set (0.00 sec)

    停掉主節點:[root@centos-ytt57-2 mysql0]# systemctl stop mysqld@0

    現在檢視,主節點已經變為本機 3312節點"centos-ytt57-2:3312": { "address": "centos-ytt57-2:3312", "mode": "R/W", "readReplicas": {}, "role": "HA", "status": "ONLINE"}

    10. 報錯處理

    錯誤日誌裡顯示2019-08-05T09:01:35.125591Z 0 [ERROR] Plugin group_replication reported: "The group name option is mandatory"2019-08-05T09:01:35.125622Z 0 [ERROR] Plugin group_replication reported: "Unable to start Group Replication on boot"

    同時用 cluster.rescan() 掃描,發現The instance "centos-ytt57-2:3311" is no longer part of the ReplicaSet.

    重新加入此節點到叢集:cluster.rejoinInstance("centos-ytt57-2:3311")

    再次執行cluster.status()檢視叢集狀態:"status": "OK",11. 移除和加入cluster.removeInstance("centos-ytt57-3:3312");The instance "centos-ytt57-3:3312" was successfully removed from the cluster.cluster.addInstance("centos-ytt57-3:3312");The instance "centos-ytt57-3:3312" was successfully added to the cluster.

    12. 用 mysqlrouter 生成連線 MGR 相關資訊。涉及到兩個使用者:--user=mysqlrouter 是使用mysqlrouter的系統使用者自動建立的MySQL 使用者是用來與MGR通訊的使用者。如果想檢視這個使用者的使用者名稱以及密碼,就加上--force-password-validation,不過一般也沒有必要檢視。

  • 中秋節和大豐收的關聯?
  • 茶館結尾部分?