MySQL 8.0 MICは高いクラスタ構築が可能です。



mysql 8.0がもたらす新しい特性は、MySQLshellと結合し、第三者の中間部品を必要とせず、自動的に利用可能な高いクラスタを構築する。
mysql 8.0は新しい製品として内蔵されているmysq-inodb-cluster(MIC)の高い利用可能なクラスタの技術は確かに驚くべきであり、MySQLshellと組み合わせてクラスタの迅速な配置を実施することができ、MySQL-routeは急速な切り替えを実現し、読み書き分離技術を内蔵し、負荷均衡技術を備えています。結合しますが、実際の効果はどうですか?検証が必要です。
クラスタ配置
1.1設置環境
オペレーティングシステム:Linux、バージョン:CentOS-7-x 86
メディアの準備:なし
環境整理
yumリリースプロセス
[root@bug ~]# ps -ef|grep yum
root     22481  1694  5 17:23 ?        00:00:03 /usr/bin/python /usr/share/PackageKit/helpers/yum/yumBackend.py get-updates none
root     22591 22507  1 17:24 pts/0    00:00:00 grep --color=auto yum
[root@bug ~]# kill -9 22481
余分なシステムがあるかどうかチェックしてください。あればアンインストールします。
[root@bug ~]# rpm -qa|grep mairadb
[root@bug ~]# rpm -qa|grep mysql
防火壁を閉鎖する
[root@bug ~]# systemctl status firewalld.service
● firewalld.service - firewalld - dynamic firewall daemon
   Loaded: loaded (/usr/lib/systemd/system/firewalld.service; enabled; vendor preset: enabled)
   Active: inactive (dead) 
 
selinuxをオフにして、システムを再起動したら有効です。
[root@bug selinux]# vi /etc/selinux/config
SELINUX=disabled
[root@bug selinux]# reboot
 
1.2 MySQL 8.0をインストールする
[root@bug ~]# yum install -y wget https://repo.mysql.com//mysql80-community-release-el7-1.noarch.rpm
[root@bug ~]# yum list|grep mysql
[root@bug ~]# yum install -y mysql-community-client.x86_64 mysql-router.x86_64 mysql-shell.x86_64 
YUMソースのインストール方式を採用して、総ダウンロード量は約400 Mで、
 
1.3自動クラスタ配置
展開ノード1
[root@bug ~]# mysqlsh

 MySQL  JS >  dba.deploySandboxInstance(3310); 
A new MySQL sandbox instance will be created on this host in 
/root/mysql-sandboxes/3310

Warning: Sandbox instances are only suitable for deploying and 
running on your local machine for testing purposes and are not 
accessible from external networks.

Please enter a MySQL root password for the new instance: ******
Deploying new MySQL instance...

Instance localhost:3310 successfully deployed and started.
Use shell.connect('root@localhost:3310'); to connect to the instance.
最初のノードの配置が完了し、ポートは3310に設定され、ログインアカウントはroot@localhostパスワード ******
 
ローカル認証を使用して、データベースのインスタンスに登録し、検証を行う。
[root@bug ~]# mysql -uroot -porange -S /root/mysql-sandboxes/3310/sandboxdata/mysqld.sock
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
  
同様の方法で、ノード2、ノード3が展開される。
MySQL  JS >  dba.deploySandboxInstance(3320); 

MySQL  JS > dba.deploySandboxInstance(3330);
 
1.4クラスタを作成する
この実験は簡単に局所クラスタを作成するためのものです。
 MySQL  JS >  \connect root@localhost:3310 
Creating a session to 'root@localhost:3310'

*****************************************************
MySQL localhost:3310 ssl JS > var cluster=dba.createCluster('test') A new InnoDB cluster will be created on instance 'root@localhost:3310'. ********************************************************* 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.
クラスタシステムはすでに作成されました。最後の行:At least 3 instances are need for the cluster to be able to withstand up to one server failure.ヒントは、少なくとも3つの例が必要であり、これにより、ノード2,3をクラスタに追加することができる。
 
MySQL  localhost:3310 ssl  JS > cluster.addInstance( 'root@localhost:3320')

The instance 'root@localhost:3320' was successfully added to the cluster.


 MySQL  localhost:3310 ssl  JS > cluster.addInstance( 'root@localhost:3330') 

The instance 'root@localhost:3330' was successfully added to the cluster.

クラスタ状態を確認
MySQL  localhost:3310 ssl  JS > dba.getCluster().status()
{
    "clusterName": "test", 
    "defaultReplicaSet": {
        "name": "default", 
        "primary": "localhost:3310", 
        "ssl": "REQUIRED", 
        "status": "OK", 
        "statusText": "Cluster is ONLINE and can tolerate up to ONE failure.", 
        "topology": {
            "localhost:3310": {
                "address": "localhost:3310", 
                "mode": "R/W", 
                "readReplicas": {}, 
                "role": "HA", 
                "status": "ONLINE"
            }, 
            "localhost:3320": {
                "address": "localhost:3320", 
                "mode": "R/O", 
                "readReplicas": {}, 
                "role": "HA", 
                "status": "ONLINE"
            }, 
            "localhost:3330": {
                "address": "localhost:3330", 
                "mode": "R/O", 
                "readReplicas": {}, 
                "role": "HA", 
                "status": "ONLINE"
            }
        }
    }, 
    "groupInformationSourceMember": "mysql://root@localhost:3310"
}
  
簡単に三つのノードを含むクラスタが作成されました。データ同期が完了し、読み書き分離などの機能が可能です。例えば、現在3310ポートの状態は「R/W」であり、同時にreadとwrite、3320と3330の状態は「R/O」で、読み取り専用モードです。
 
1.5中間部品の配置
このときのクラスタの高い利用可能性はまだ完全ではなく、MySQL-routerがクラスタと外部とのドッキングを完了するために必要であり、自動切替、フェイルオーバなどの機能を実現する。
MySQL-routerの役割はkeepalived類のミドルウェアに似ています。ホストが故障した場合、アプリケーションは自動的に他のインスタンスに切り替わります。
[root@bug ~]#  mysqlrouter --bootstrap root@localhost:3310 --user=mysqlrouter
Please enter MySQL password for root: *****

Bootstrapping system MySQL Router instance...
Checking for old Router accounts
Creating account mysql_router2_j05xzi45m81x@'%'
MySQL Router  has now been configured for the InnoDB cluster 'test'.

The following connection information can be used to connect to the cluster.

Classic MySQL protocol connections to cluster 'test':
- Read/Write Connections: localhost:6446
- Read/Only Connections: localhost:6447
X protocol connections to cluster 'test':
- Read/Write Connections: localhost:64460
- Read/Only Connections: localhost:64470

Existing configurations backed up to '/etc/mysqlrouter/mysqlrouter.conf.bak'
[root@bug ~]# mysqlrouter&
[1] 25602
[root@bug ~]#  ps -ef|grep router
mysqlro+ 25602 22507  8 19:35 pts/0    00:00:01 mysqlrouter
root     25619 22507  0 19:36 pts/0    00:00:00 grep --color=auto router

  
MySQL-routerのインストール効果を検証します。
MySQL-routerのデフォルト設定では、
ホストポート:6446
ライブラリポート:6447
[root@bug ~]#  mysql -uroot -h 127.0.0.1 -P 6446 -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
********************************************************8
mysql> 
MySQL-router構成が完了したことを証明します。
 
 1.6クラスタ効果を検証する
1,routerを通じて同時に三つのノードに登録して、ポート番号を確認します。
2,ノード1でデータを構築し、ノード2,3のビュー状態でデータの同期性を検証する。
3,ノード1(ホスト)がオフラインし、クラスタ状態とノード2、ノード3の状態を確認し、災害準備能力を検証する。
 
 
  
 
転載先:https://www.cnblogs.com/shc336/p/9537904.html