Mycat中介軟體實現Percona Cluster讀寫分離
Mycat實現讀寫分離架構圖:
Mycat主從自動切換架構圖:
Mycat下載地址:http://dl.mycat.io/1.6.7.3/20190828135747/Mycat-server-1.6.7.3-release-20190828135747-linux.tar.gz
Percona-XtraDB-Cluster下載地址:https://www.percona.com/downloads/Percona-XtraDB-Cluster-57/LATEST/
Percona-XtraBackup下載地址: https://www.percona.com/downloads/Percona-XtraBackup-2.4/LATEST/
yum倉庫地址:https://www.percona.com/downloads/percona-release/redhat/
1.下載,安裝Percona-XtraDB-Cluster(三臺都需要裝)
[root@k8s01 ~]# rpm -ivh https://www.percona.com/redir/downloads/percona-release/redhat/1.0-13/percona-release-1.0-13.noarch.rpm
[root@k8s01 ~]# yum repolist
[root@k8s01 ~]# rpm -ivh percona-xtrabackup-24-2.4.13-1.el7.x86_64.rpm
[root@k8s01 ~]# yum install Percona-XtraDB-Cluster-57 -y
2.修改配置,啟動服務(k8s01節點)
[root@k8s01 ~]# vim /etc/percona-xtradb-cluster.conf.d/mysqld.cnf
log-bin=k8s01-bin
log-bin-index=k8s01-bin-index
[root@k8s01 ~]# vim /etc/percona-xtradb-cluster.conf.d/wsrep.cnf
[mysqld]
wsrep_provider=/usr/lib64/galera3/libgalera_smm.so
wsrep_cluster_address=gcomm://192.168.54.129,192.168.54.130,192.168.54.128
binlog_format=ROW
default_storage_engine=InnoDB
wsrep_slave_threads= 8
wsrep_log_conflicts
innodb_autoinc_lock_mode=2
wsrep_node_address=192.168.54.128 --三個節點值不一樣
wsrep_cluster_name=mycluster
wsrep_node_name=k8s01
pxc_strict_mode=ENFORCING
wsrep_sst_method=xtrabackup-v2
wsrep_sst_auth="sstuser:s3cretPass"
[root@k8s01 ~]# mysql_install_db --defaults-file=/etc/percona-xtradb-cluster.cnf --datadir=/var/lib/mysql --初使化資料
[root@k8s01 ~]# systemctl start
mysql@bootstrap.service --第一次啟動,不需要同步資料
[root@k8s01 ~]# ps -ef | grep mysql
root 60672 54285 0 14:56 pts/1 00:00:00 tailf /var/log/mysqld.log
root 66031 1 0 15:03 ? 00:00:00 /bin/sh /usr/bin/mysqld_safe --basedir=/usr --wsrep-new-cluster
mysql 66568 66031 6 15:03 ? 00:00:01 /usr/sbin/mysqld --basedir=/usr --datadir=/var/lib/mysql --plugin-dir=/usr/lib64/mysql/plugin --user=mysql --wsrep-provider=/usr/lib64/galera3/libgalera_smm.so --wsrep-new-cluster --log-error=
/var/log/mysqld.log --pid-file=/var/run/mysqld/mysqld.pid --socket=/var/lib/mysql/mysql.sock --wsrep_start_position=00000000-0000-0000-0000-000000000000:-1root 66763 33815 0 15:04 pts/0 00:00:00 grep --color=auto mysql
# Password set for user 'root@localhost' at 2019-11-15 14:40:31
ya;-t*taM8T< --mysql登陸密碼
[root@k8s01 ~]# mysql -u root -p'ya;-t*taM8T<'
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 13
Server version: 5.7.27-30-57-log
Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.
affiliates. Other names may be trademarks of their respective owners.
Query OK, 0 rows affected, 1 warning (0.02 sec)
Query OK, 0 rows affected (0.00 sec)
Bye
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 16
Server version: 5.7.27-30-57-log Percona XtraDB Cluster (GPL), Release rel30, Revision 64987d4, WSREP version 31.39, wsrep_31.39
Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.
affiliates. Other names may be trademarks of their respective owners.
Query OK, 0 rows affected, 1 warning (0.05 sec)
Query OK, 0 rows affected (0.01 sec)
Bye
[root@k8s01 ~]#
3.修改配置,啟動服務(k8s02節點)
[root@k8s02 ~]# vim /etc/percona-xtradb-cluster.conf.d/mysqld.cnf
log-bin=k8s01-bin
log-bin-index=k8s01-bin-index
[root@k8s02 ~]# vim /etc/percona-xtradb-cluster.conf.d/wsrep.cnf
[mysqld]
wsrep_provider=/usr/lib64/galera3/libgalera_smm.so
wsrep_cluster_address=gcomm://192.168.54.128,192.168.54.129,192.168.54.130
binlog_format=ROW
default_storage_engine=InnoDB
wsrep_slave_threads= 8
wsrep_log_conflicts
innodb_autoinc_lock_mode=2
wsrep_node_address=192.168.54.129
wsrep_cluster_name=mycluster
wsrep_node_name=k8s02
pxc_strict_mode=ENFORCING
wsrep_sst_method=xtrabackup-v2
wsrep_sst_auth="sstuser:s3cretPass"
[root@k8s02 ~]# systemctl start mysql
4.修改配置,啟動服務(k8s03節點)
[root@k8s03 ~]# vim /etc/percona-xtradb-cluster.conf.d/mysqld.cnf
log-bin=k8s01-bin
log-bin-index=k8s01-bin-index
[root@k8s03 ~]# vim /etc/percona-xtradb-cluster.conf.d/wsrep.cnf
[mysqld]
wsrep_provider=/usr/lib64/galera3/libgalera_smm.so
default_storage_engine=InnoDB
wsrep_slave_threads= 8
wsrep_log_conflicts
innodb_autoinc_lock_mode=2
wsrep_node_address=192.168.54.130
wsrep_cluster_name=mycluster
wsrep_node_name=k8s03
pxc_strict_mode=ENFORCING
wsrep_sst_method=xtrabackup-v2
wsrep_sst_auth="sstuser:s3cretPass"
[root@k8s03 ~]# systemctl start mysql
5.測試Percona-XtraDB-Cluster叢集資料同步
k8s01節點:
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 22
Server version: 5.7.27-30-57-log Percona XtraDB Cluster (GPL), Release rel30, Revision 64987d4, WSREP version 31.39, wsrep_31.39
Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.
affiliates. Other names may be trademarks of their respective owners.
Query OK, 1 row affected (0.01 sec)
Database changed
mysql> create table t (a int primary key,b int);
Query OK, 0 rows affected (0.02 sec)
Query OK, 2 rows affected (0.02 sec)
Records: 2 Duplicates: 0 Warnings: 0
+---+------+
| a | b |
+---+------+
| 1 | 2 |
| 2 | 3 |
+---+------+
2 rows in set (0.00 sec)
Bye
[root@k8s01 ~]#
k8s02節點:
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 12
Server version: 5.7.27-30-57-log Percona XtraDB Cluster (GPL), Release rel30, Revision 64987d4, WSREP version 31.39, wsrep_31.39
Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.
affiliates. Other names may be trademarks of their respective owners.
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
mysql> select * from t;
+---+------+
| a | b |
+---+------+
| 1 | 2 |
| 2 | 3 |
+---+------+
2 rows in set (0.01 sec)
Bye
[root@k8s02 ~]#
6.下載,安裝Mycat中介軟體
[root@[root@k8s01 soft]# rpm -ivh jdk-8u221-linux-x64.rpm
warning: jdk-8u221-linux-x64.rpm: Header V3 RSA/SHA256 Signature, key ID ec551f03: NOKEY
Preparing... ################################# [100%]
Updating / installing...
1:jdk1.8-2000:1.8.0_221-fcs ################################# [100%]
Unpacking JAR files...
tools.jar...
plugin.jar...
javaws.jar...
deploy.jar...
rt.jar...
jsse.jar...
charsets.jar...
localedata.jar...
[root@k8s01 soft]# tar xvf Mycat-server-1.6.7.3-release-20190828135747-linux.tar.gz -C /usr/local/
[root@k8s01 soft]# cd /usr/local/mycat/conf/
[root@k8s01 conf]# vim schema.xml
[root@k8s01 conf]# vim server.xml
<property name="password">System135</property>
<property name="schemas">hubei</property>
[root@k8s01 conf]# ../bin/mycat restart
Stopping Mycat-server...
Mycat-server was not running.
Starting Mycat-server...
[root@k8s01 conf]# netstat -antulp | grep 9066
tcp6 0 0 :::9066 :::* LISTEN 100087/java
[root@k8s01 conf]#
7.使用Mycat驗證讀,寫資料
(1).檢視管理埠服務
(2).檢視資料,如果想要看負載均衡效果,必須退出終端,再登陸。
(3).k8s01節點寫入資料,k8s02和k8s03讀資料
8.k8s01節點當機後,k8s02節點負責寫入資料,k8s03讀資料
[root@k8s01 conf]# systemctl stop mysql@bootstrap.service
[root@k8s01 conf]# netstat -antulp | grep 3306
tcp6 0 0 10.4.132.50:60568 10.4.132.42:3306 ESTABLISHED 100087/java
tcp6 0 0 10.4.132.50:51072 10.4.132.66:3306 ESTABLISHED 100087/java
[root@k8s01 conf]# ps -ef | grep mysqld
root 115559 33815 0 16:58 pts/0 00:00:00 grep --color=auto mysqld
(2).寫入節點是k8s02,讀節點是k8s03
錯誤處理:
(1).Mysql沒有初使化資料
2019-11-15T06:33:04.385584Z 0 [Warning] Failed to open optimizer cost constant tables
2019-11-15T06:33:04.385659Z 0 [ERROR] Fatal error: Can't open and lock privilege tables: Table 'mysql.user' doesn't exist
2019-11-15T06:33:04.385668Z 0 [ERROR] Fatal error: Failed to initialize ACL/grant/time zones structures or failed to remove temporary table files.
2019-11-15T06:33:04.385687Z 0 [ERROR] Aborting
解決方法:
[root@k8s01 conf]# mysql_install_db --defaults-file=/etc/percona-xtradb-cluster.cnf --datadir=/var/lib/mysql --需要初使化資料
(2).第一個節點第一次啟動必須要建立新的叢集
2019-11-15T06:41:35.761089Z 0 [Note] WSREP: Current view of cluster as seen by this node
view ((empty))
2019-11-15T06:41:35.761280Z 0 [ERROR] WSREP: failed to open gcomm backend connection: 110: failed to reach primary view (pc.wait_prim_timeout): 110 (Connection timed out)
at gcomm/src/pc.cpp:connect():159
2019-11-15T06:41:35.761309Z 0 [ERROR] WSREP: gcs/src/gcs_core.cpp:gcs_core_open():209: Failed to open backend connection: -110 (Connection timed out)
2019-11-15T06:41:35.761583Z 0 [ERROR] WSREP: gcs/src/gcs.cpp:gcs_open():1514: Failed to open channel 'pxc_1' at 'gcomm://192.168.54.128,192.168.54.129,192.168.54.130': -110 (Connection timed out)
2019-11-15T06:41:35.761597Z 0 [ERROR] WSREP: gcs connect failed: Connection timed out
2019-11-15T06:41:35.761600Z 0 [ERROR] WSREP: Provider/Node (gcomm://192.168.54.128,192.168.54.129,192.168.54.130) failed to establish connection with cluster (reason: 7)
2019-11-15T06:41:35.761603Z 0 [ERROR] Aborting
解決方法:
(3).沒有建立wsrep.cnf使用者名稱
2019-11-15T07:27:59.158666Z 0 [ERROR] WSREP: Command did not run: wsrep_sst_xtrabackup-v2 --role 'donor' --address '192.168.54.129:4444/xtrabackup_sst//1' --socket '/var/lib/mysql/mysql.sock' --datadir '/var/lib/mysql/' --defaults-file '/etc/my.cnf' --defaults-group-suf
fix '' --mysqld-version '5.7.27-30-57' '' --gtid '19a21dce-0776-11ea-8879-92a989219bb1:2'2019-11-15T07:27:59.159302Z 0 [Warning] WSREP: Protocol violation. JOIN message sender 0.0 (k8s01) is not in state transfer (SYNCED). Message ignored.
2019-11-15T07:27:59.159405Z 5 [Note] WSREP: Synchronized with group, ready for connections
解決方法:
[root@k8s01 conf]# grep sst /etc/percona-xtradb-cluster.conf.d/wsrep.cnf
wsrep_sst_method=xtrabackup-v2
wsrep_sst_auth="sstuser:s3cretPass"
[root@k8s01 conf]#
Query OK, 0 rows affected, 1 warning (0.05 sec)
Query OK, 0 rows affected (0.01 sec)
mysql> exit
Bye
[root@k8s01 ~]#
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/25854343/viewspace-2663927/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- Mycat中介軟體實現Mysql主從讀寫分離MySql
- MySQL cetus 中介軟體 讀寫分離MySql
- 資料庫中介軟體sharding-jdbc實現讀寫分離資料庫JDBC
- MyCat 讀寫分離 資料庫分庫分表 中介軟體 安裝部署,及簡單使用資料庫
- Mycat實現mysql的負載均衡讀寫分離MySql負載
- MyCat分庫分表、讀寫分離
- MySQL中介軟體之ProxySQL(3):初試讀寫分離MySql
- 使用proxysql 1.4.14中介軟體實現mysql 5.7.26主從的讀寫分離MySql
- Mycat2+Mysql一主一從實現讀寫分離配置MySql
- CentOS7系統下使用Mycat實現mysql讀寫分離部署CentOSMySql
- Mycat中介軟體實現Mysql資料分片(上篇)MySql
- Mycat中介軟體實現Mysql資料分片( 下篇)MySql
- 分散式資料庫中介軟體 MyCat | 分庫分表實踐分散式資料庫
- ProxySQL實現MySQL讀寫分離MySql
- ShardingSphere(七) 讀寫分離配置,實現分庫讀寫操作
- 【Mongo】Mongo讀寫分離的實現Go
- Docker實現Mariadb分庫分表、讀寫分離Docker
- Mycat讀寫分離、主從切換、分庫分表的操作記錄
- PostgreSQL+Pgpool實現HA讀寫分離SQL
- docker+atlas+mysql實現讀寫分離DockerMySql
- Kubernetes 中實現 MySQL 的讀寫分離MySql
- 位元組面試:什麼是讀寫分離?讀寫分離的底層如何實現?面試
- docker+mysql叢集+讀寫分離+mycat管理+垂直分庫+負載均衡DockerMySql負載
- Spring Aop實現資料庫讀寫分離Spring資料庫
- ProxySQL實現Mysql讀寫分離 - 部署手冊MySql
- SpringBoot 專案優雅實現讀寫分離Spring Boot
- 搭建MySQL主從實現Django讀寫分離MySqlDjango
- MHA+ProxySQL實現讀寫分離高可用SQL
- Mysql讀寫分離叢集的搭建且與MyCat進行整合MySql
- 搭建基於springmvc,ibatis的工程實現讀寫分離,配置分離SpringMVCBAT
- 博學谷 - mysql資料庫效能優化筆記05 - 讀寫分離中介軟體MaxScaleMySql資料庫優化筆記
- 基於Sharding-Jdbc 實現的讀寫分離實現JDBC
- 安裝Centos7 、 Mysql8 叢集,實現讀寫分離 高可用(五)-- MyCat配置詳解CentOSMySql
- ShardingSphere + Mysql,實現分庫分表、讀寫分離,並整合 SpringBootMySqlSpring Boot
- 分庫分表(6)--- SpringBoot+ShardingSphere實現分表+ 讀寫分離Spring Boot
- redis客戶端實現高可用讀寫分離Redis客戶端
- StoneDB 讀寫分離實踐方案
- MySQL-SpringBoot整合JPA實現資料讀寫分離MySqlSpring Boot