单节点数据库的弊病
- 大型互联网程序用户群体庞大,所以架构必须要特殊设计
- 单节点的数据库无法满足性能上的要求
- 单节点的数据库没有冗余设计,无法满足高可用
单节点MySQL的性能瓶领颈
2016年春节微信红包巨大业务量,数据库承受巨大负载
常见MySQL集群方案
mysql 集群方案介绍,建议使用pxc,因为弱一致性会有问题,比如说a节点数据库显示我购买成功,b 节点数据库显示没有成功,这就麻烦了,pxc 方案是在全部节点都写入成功之后才会告诉你成功,是可读可写双向同步的,但是replication是单向的,不同节点的数据库之间都会开放端口进行通讯,如果从防火墙的这个端口关闭,pxc就不会同步成功,也不会返给你成功了。
Replication
- 速度快,但仅能保证弱一致性,适用于保存价值不高的数据,比如日志、帖子、新闻等。
- 采用master-slave结构,在master写入会同步到slave,能从slave读出;但在slave写入无法同步到master。
- 采用异步复制,master写入成功就向客户端返回成功,但是同步slave可能失败,会造成无法从slave读出的结果。
PXC (Percona XtraDB Cluster)
- 速度慢,但能保证强一致性,适用于保存价值较高的数据,比如订单、客户、支付等。
- 数据同步是双向的,在任一节点写入数据,都会同步到其他所有节点,在任何节点上都能同时读写。
- 采用同步复制,向任一节点写入数据,只有所有节点都同步成功后,才会向客户端返回成功。事务在所有节点要么同时提交,要么不提交。
建议PXC使用PerconaServer (MySQL改进版,性能提升很大)
PXC的数据强一致性
同步复制,事务在所有集群节点要么同时提交,要么不提交 Replication采用异步复制,无法保证数据的一致性
PXC集群安装介绍
在Docker中安装PXC集群,使用Docker仓库中的PXC官方镜像:https://hub.docker.com/r/percona/percona-xtradb-cluster
1、从docker官方仓库中拉下PXC镜像:
docker pull percona/percona-xtradb-cluster
或者本地安装
docker load < /home/soft/pxc.tar.gz
安装完成:
[root@localhost ~]# docker pull percona/percona-xtradb-cluster Using default tag: latest Trying to pull repository docker.io/percona/percona-xtradb-cluster ... latest: Pulling from docker.io/percona/percona-xtradb-cluster ff144d3c0ab1: Pull complete eafdff1524b5: Pull complete c281665399a2: Pull complete c27d896755b2: Pull complete c43c51f1cccf: Pull complete 6eb96f41c54d: Pull complete 4966940ec632: Pull complete 2bafadcea292: Pull complete 3c2c0e21b695: Pull complete 52a8c2e9228e: Pull complete f3f28eb1ce04: Pull complete d301ece75f56: Pull complete 3d24904bec3c: Pull complete 1053c2982c37: Pull complete Digest: sha256:17c64dacbb9b62bd0904b4ff80dd5973b2d2d931ede2474170cbd642601383bd Status: Downloaded newer image for docker.io/percona/percona-xtradb-cluster:latest [root@localhost ~]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE docker.io/percona/percona-xtradb-cluster latest 70b3670450ef 2 months ago 408 MB
2、重命名镜像:(名称太长,重命名一下)
docker tag percona/percona-xtradb-cluster:latest pxc
然后原来的镜像就可以删除掉了
[root@localhost ~]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE docker.io/percona/percona-xtradb-cluster latest 70b3670450ef 2 months ago 408 MB pxc latest 70b3670450ef 2 months ago 408 MB docker.io/java latest d23bdf5b1b1b 2 years ago 643 MB [root@localhost ~]# docker rmi docker.io/percona/percona-xtradb-cluster Untagged: docker.io/percona/percona-xtradb-cluster:latest Untagged: docker.io/percona/percona-xtradb-cluster@sha256:17c64dacbb9b62bd0904b4ff80dd5973b2d2d931ede2474170cbd642601383bd [root@localhost ~]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE pxc latest 70b3670450ef 2 months ago 408 MB docker.io/java latest d23bdf5b1b1b 2 years ago 643 MBDocker部署Mysql集群的实现
扫一扫手机访问
