Mysql+Mycat realizes database master-slave synchronization and separation of read and write


This article originated from the introduction of MySQL cluster high-availability architecture
to the architecture extension in the article. I wrote an article about MHA before. MySQL cluster high-availability architecture MHA


Mycat introduction


Official website: http://mycat.io/ 
E-book: http://mycat.io/document/Mycat_V1.6.0.pdf 
Book: http://blog.csdn.net/wind520/article/details/53213691

MyCAT adopts Java development to realize MySQL's open binary protocol and disguise itself as MySQL Server; applications only need to connect to MyCAT to execute SQL, and MyCAT distributes SQL to corresponding MySQL nodes according to the configured strategy.

What is MYCAT

  • A completely open source large database cluster for enterprise application development

  • Support transactions, ACID, and an enhanced database that can replace MySQL

  • An enterprise-level database that can be regarded as a MySQL cluster to replace the expensive Oracle cluster

  • A new SQL Server integrating memory caching technology, NoSQL technology, and HDFS big data

  • A new generation of enterprise-level database products that combine traditional databases and new distributed data warehouses

  • A novel database middleware product


Mycat overall architecture diagram

image



Mycat features introduction


  • Support SQL92 standard

  • Support common SQL syntax of MySQL, Oracle, DB2, SQL Server, PostgreSQL and other DBs

  • Comply with Mysql native protocol, cross-language, cross-platform, and cross-database general middleware agent.

  • Automatic failover based on heartbeat, read-write separation, MySQL master-slave, and galera cluster cluster.

  • Support Galera for MySQL cluster, Percona Cluster or MariaDB cluster

  • Based on Nio implementation, it effectively manages threads and solves high concurrency problems.

  • Supports multi-slice automatic routing and aggregation of data, commonly used aggregation functions such as sum, count, max, and cross-database paging.

  • Support global serial number, solve the problem of primary key generation under distributed.

  • Rich sharding rules, plug-in development, easy to expand.

  • Powerful web, command line monitoring.

  • The front-end is supported as a general proxy for MySQL, and the back-end JDBC mode supports Oracle, DB2, SQL Server, mongodb, and giant fir.

  • The cluster is based on ZooKeeper management, online upgrade, expansion, intelligent optimization, and big data processing (2.0 development version).




MySQL master-slave synchronization


This configuration will not be repeated here, you can refer to the previous article

The actual process of master-slave synchronization of MySQL database in Linux system


imageimageimage





Install Mycat service


The production environment is best to use the server alone for installation, and the test environment is installed on the main library

Need to install JAVA environment

[root@mysql-m ~]# java -version

java version "1.8.0_144"

Java(TM) SE Runtime Environment (build 1.8.0_144-b01)

Java HotSpot(TM) 64-Bit Server VM (build 25.144-b01, mixed mode)

image

Install Mycat service

[root@mysql-m local]# wget http://dl.mycat.io/1.6-RELEASE/Mycat-server-1.6-RELEASE-20161028204710-linux.tar.gz

[root@mysql-m local]# tar zxf Mycat-server-1.6-RELEASE-20161028204710-linux.tar.gz

[root@mysql-m local]# cd mycat/

[root@mysql-m mycat]# ll

total 24

drwxr-xr-x 2 root root 4096 Sep 23 19:13 bin

drwxrwxrwx 2 root root 4096 Mar  1  2016 catlet

drwxrwxrwx 4 root root 4096 Sep 23 19:13 conf

drwxr-xr-x 2 root root 4096 Sep 23 19:13 lib

drwxrwxrwx 2 root root 4096 Oct 28  2016 logs

-rwxrwxrwx 1 root root  217 Oct 28  2016 version.txt

[root@mysql-m mycat]# cat >>/etc/profile<<EOF

> export MYCAT_HOME=/usr/local/mycat

> export PATH=$PATH:$MYCAT_HOME/bin

> EOF

[root@mysql-m mycat]# source /etc/profile




配置Mycat服务


image

#以下四项取消注释,修改如下

<!--默认是65535 64K 用于sql解析时最大文本长度 -->

<property name="maxStringLiteralLength">65535</property>

<property name="sequnceHandlerType">0</property>

<property name="backSocketNoDelay">1</property>

<property name="frontSocketNoDelay">1</property>

<property name="processorExecutor">1</property>

image

配置schema.xml文件

image

image

主从服务器上配置读写的用户user并给以相应的权限


启动服务

image

image

登陆管理管理端口,查看是否有默认的逻辑数据库

image

查看数据读写入口

image

从上面可以看出数据写入与读取的入口在哪个库上




测试Mycat读写分离功能


接下来测试通过mycat来进行对主从数据库的读写操作

image

image

上面的数据是从逻辑数据库插入与查询的,接下来分别从主从库查看数据是否写入成功

image

imageimage

再次查看数据源的入口情况

image




Mycat性能监控


MYCAT监控

  • 支持对Mycat、Mysql性能监控

  • 支持对Mycat的JVM内存提供监控服务

  • 支持对线程的监控

  • 支持对操作系统的CPU、内存、磁盘、网络的监控


下载WEB管理端软件

wget https://github.com/MyCATApache/Mycat-download/blob/master/mycat-web-1.0/Mycat-web-1.0-SNAPSHOT-20160617163048-linux.tar.gz


需要安装zookeeper

[root@mysql-m local]# wget http://mirrors.hust.edu.cn/apache/zookeeper/zookeeper-3.4.6/zookeeper-3.4.6.tar.gz

[root@mysql-m local]# tar zxf zookeeper-3.4.6.tar.gz

[root@mysql-m local]# ln -s zookeeper-3.4.6 zookeeper

[root@mysql-m conf]# cp zoo_sample.cfg zoo.cfg

[root@mysql-m bin]# ./zkServer.sh start

JMX enabled by default

Using config: /usr/local/zookeeper/bin/../conf/zoo.cfg

Starting zookeeper ... STARTED

[root@mysql-m ~]# lsof -i :2181

COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME

java 3639 root 25u IPv6 19337 0t0 

TCP *:eforward (LISTEN)


安装WEB管理端

[root@mysql-m bin]# cd /usr/local/

[root@mysql-m local]# tar zxf Mycat-web-1.0-SNAPSHOT-20160617163048-linux.tar.gz

[root@mysql-m local]# cd mycat-web/mycat-web/WEB-INF/classes/

[root@mysql-m classes]# ll

total 28

drwxr-xr-x 3 root root 4096 Jun 17  2016 com

-rw-r--r-- 1 root root  367 Jun 17  2016 jdbc.properties

-rw-r--r-- 1 root root 4068 Jun 17  2016 log4j2.xml

drwxr-xr-x 3 root root 4096 Jun 17  2016 mybatis

-rw-r--r-- 1 root root  411 Jun 17  2016 mycat.properties

drwxr-xr-x 3 root root 4096 Jun 17  2016 org

drwxr-xr-x 2 root root 4096 Sep 26 00:21 spring

[root@mysql-m classes]# vim mycat.properties

#

#Mon Jan 16 15:37:36 CST 2012

show.period=3000000

zookeeper=10.0.0.11:2181 

[root@mysql-m mycat-web]# /usr/local/mycat-web/start.sh &

[1] 3684

[root@mysql-m mycat-web]# nohup: ignoring input and appending output to `nohup.out'

[root@mysql-m mycat-web]# lsof -i :8082

COMMAND  PID USER  FD  TYPE DEVICE SIZE/OFF NODE NAME

java 3685 root 122u IPv6 20997 0t0 TCP *:us-cli (LISTEN)

image

image

image

image



Recommended reading

Elaborately Organized|Public Account Article Directory

Introduction to Docker container technology (1)

Introduction to Docker container technology (2)

Process management tool Supervisor (book delivery activity)

Carefully organize|Empty the network disk and get on the car

"Golden three silver four" toss about the interview

Maybe these will be of interest to you? ?

Migrant Workers’ "Questions and Answers" column is open, welcome to tease


·end·



Guess you like

Origin blog.51cto.com/15127557/2668494