Home Database Mysql Tutorial 集群之MYsql主从服务之引伸出Mysql互为主从(环形结构)外加简单实_MySQL

集群之MYsql主从服务之引伸出Mysql互为主从(环形结构)外加简单实_MySQL

Jun 01, 2016 pm 01:11 PM

Mysql集群

备注:

本人资历很浅,说的不对话,万望各位前辈不要计较,
另关于环形的问题,我在后面的评论给予回复,
其实环形,解决多地域问题比较好的选择
关于配置步骤我重新整理了一下(主从AND环形)的配置步骤
在我博客中,有兴趣的朋友可以看一下,

http://my.oschina.net/u/1246814/blog/267518

多谢大家的指导.

比如 我有主的1台mysql服务器,俩从服务服务器   外加一个负载均衡器(如果把负载均衡器非常简单的来说话其实就DNS的转发,非常简单来说,其实 IP的轮换嘛)

我读数据的也就(查询)数据 也就(Select)语句时候,我只是在 仨台从服务器中读取数据

主服务器负责(增,删,改)这个一系列操作

顺便唠叨一下, 为啥 Select 我们建仨服务器或者多个呢?

因为距统计,大概B/S架构70%以上的操作都是以查为主(说白了就是展示嘛)

我们执行了DML语句那么负载均衡器,

就会把请求转发到主mysql服务器上,

这里有个问题?

我们已经向主服务器插入数据,或者删除数据,或者更新了数据,

那么是不是意味从服务里数据也应该发生变化呢

是的,从服务器肯定要发生变化的,不然就出现问题,

比如说,我删除了一个用户,

我查询一下被删除的用户, 丫的发现这个用户压根就没被删除,这不是搞笑了嘛,

那么就有了主从配置一说

 主从原理:mysql中有一种日志叫做bin日志(二进制日志),
       这个日志会记录下所有对MYSQL进行修改的SQL语句。当向主服务器执行SQL语句时,这条SQL语句会被传递到从服务器上再执行一遍。

说白了,就是Bin日志记录下Dml语句,直接到从服务器执行执行一遍相同的Dml操作,这个方式是以二进制,所有效率很好

至于什么时候用主从

1. 备份(如果数据库出现问题,马上再顶上)

2.优化(分流 读写分离) 

Look看图

集群之MYsql主从服务之引伸出Mysql互为主从(环形结构)外加简单实_MySQL

如果是Dml语句其实也可以直接访问主数据库,不必经过负载均衡器,那么这块从

话说回来哈, 负载均衡其实说白了吧,就是dns轮换,IP轮换嘛

如果可以话,其实我们自己也可以相对简单实现的,但这要分情况哈,

我提一个思路, 以MVC为例子 我粗狂简单的举一下列子,

1.在父类Model中对用户请求的sql语句进行分类。

1.1dml语句(update,insert,delelte)
1.2select语句
1.3dcl语句(数据控制语句)
1.4dtl语句(数据事务语句 )
1.5ddl语句(数据定义语句 )

2.我就以常用的dml 与select 语句为列子并拿3个台mysql服务器1台主mysql 2台从Mysql  与Linux系统为例子

  对用户请求数据库的Sql指令进行进行统一分类,管理

主服务器IP: 192.168.0.1

从服务器IP: 192.168.0.2

从服务器IP: 192.168.0.2

3. 对用sql指令分析

  如果是dml直接连接  192.168.0.1这台服务器

   如果是select语句 怎么办呢?

 1.我们首先要确定一个件事情要判断两台从服务器的负载大小

我们肯定要把请求发到负载比较小的服务器上是吧

那么我用socket用连接分别连接两台服务器,搞个类似远程控制客服端,

并利用top指令,对两台服务器的CPU内存等一些负载数据进行获取,

然后通过一些计算与比较最后把查询请求连接其中一个从服务器上。

然后就over
回归正题

关于Mysql环形结构也就mysql服务器互相为主从关系

虽然根据有关平台统计,B/S架构的平台70%以上都是都Select为主

那么如果我这个平台,就是(增,删,该)非常多,非常频繁怎么办呢?

如果是主从配置,那么我处理dml语句的就一台服务器,这不够嘛,这样主从服务器的缺点就暴露出来了

那么mysql的环形结构配置就能解决这样类似问题 

原理也是利用bin日志来做

现在3个mysql服务器

我们随便向其中任何一台服务服务器执行dml语句,

那么Bin日志记录下Dml语句,

直接到其他服务器执行执行一遍相同的Dml语句操作

look图

集群之MYsql主从服务之引伸出Mysql互为主从(环形结构)外加简单实_MySQL


完结


Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

Java Tutorial
1662
14
PHP Tutorial
1261
29
C# Tutorial
1234
24
When might a full table scan be faster than using an index in MySQL? When might a full table scan be faster than using an index in MySQL? Apr 09, 2025 am 12:05 AM

Full table scanning may be faster in MySQL than using indexes. Specific cases include: 1) the data volume is small; 2) when the query returns a large amount of data; 3) when the index column is not highly selective; 4) when the complex query. By analyzing query plans, optimizing indexes, avoiding over-index and regularly maintaining tables, you can make the best choices in practical applications.

Can I install mysql on Windows 7 Can I install mysql on Windows 7 Apr 08, 2025 pm 03:21 PM

Yes, MySQL can be installed on Windows 7, and although Microsoft has stopped supporting Windows 7, MySQL is still compatible with it. However, the following points should be noted during the installation process: Download the MySQL installer for Windows. Select the appropriate version of MySQL (community or enterprise). Select the appropriate installation directory and character set during the installation process. Set the root user password and keep it properly. Connect to the database for testing. Note the compatibility and security issues on Windows 7, and it is recommended to upgrade to a supported operating system.

Can mysql and mariadb coexist Can mysql and mariadb coexist Apr 08, 2025 pm 02:27 PM

MySQL and MariaDB can coexist, but need to be configured with caution. The key is to allocate different port numbers and data directories to each database, and adjust parameters such as memory allocation and cache size. Connection pooling, application configuration, and version differences also need to be considered and need to be carefully tested and planned to avoid pitfalls. Running two databases simultaneously can cause performance problems in situations where resources are limited.

MySQL: Simple Concepts for Easy Learning MySQL: Simple Concepts for Easy Learning Apr 10, 2025 am 09:29 AM

MySQL is an open source relational database management system. 1) Create database and tables: Use the CREATEDATABASE and CREATETABLE commands. 2) Basic operations: INSERT, UPDATE, DELETE and SELECT. 3) Advanced operations: JOIN, subquery and transaction processing. 4) Debugging skills: Check syntax, data type and permissions. 5) Optimization suggestions: Use indexes, avoid SELECT* and use transactions.

RDS MySQL integration with Redshift zero ETL RDS MySQL integration with Redshift zero ETL Apr 08, 2025 pm 07:06 PM

Data Integration Simplification: AmazonRDSMySQL and Redshift's zero ETL integration Efficient data integration is at the heart of a data-driven organization. Traditional ETL (extract, convert, load) processes are complex and time-consuming, especially when integrating databases (such as AmazonRDSMySQL) with data warehouses (such as Redshift). However, AWS provides zero ETL integration solutions that have completely changed this situation, providing a simplified, near-real-time solution for data migration from RDSMySQL to Redshift. This article will dive into RDSMySQL zero ETL integration with Redshift, explaining how it works and the advantages it brings to data engineers and developers.

Laravel Eloquent ORM in Bangla partial model search) Laravel Eloquent ORM in Bangla partial model search) Apr 08, 2025 pm 02:06 PM

LaravelEloquent Model Retrieval: Easily obtaining database data EloquentORM provides a concise and easy-to-understand way to operate the database. This article will introduce various Eloquent model search techniques in detail to help you obtain data from the database efficiently. 1. Get all records. Use the all() method to get all records in the database table: useApp\Models\Post;$posts=Post::all(); This will return a collection. You can access data using foreach loop or other collection methods: foreach($postsas$post){echo$post->

The relationship between mysql user and database The relationship between mysql user and database Apr 08, 2025 pm 07:15 PM

In MySQL database, the relationship between the user and the database is defined by permissions and tables. The user has a username and password to access the database. Permissions are granted through the GRANT command, while the table is created by the CREATE TABLE command. To establish a relationship between a user and a database, you need to create a database, create a user, and then grant permissions.

MySQL: The Ease of Data Management for Beginners MySQL: The Ease of Data Management for Beginners Apr 09, 2025 am 12:07 AM

MySQL is suitable for beginners because it is simple to install, powerful and easy to manage data. 1. Simple installation and configuration, suitable for a variety of operating systems. 2. Support basic operations such as creating databases and tables, inserting, querying, updating and deleting data. 3. Provide advanced functions such as JOIN operations and subqueries. 4. Performance can be improved through indexing, query optimization and table partitioning. 5. Support backup, recovery and security measures to ensure data security and consistency.

See all articles