Docker Compose builds mycat read-write separation

illustrate

Continuing from [Part 1] Docker Compose builds mysql master-slave replication , this article introduces how to build `mycat middleware`, and use `mycat` to do `read-write separation`.

Configuration file and document address: [mycat-rw](http://git.oschina.net/wangjingj/mycat-rw)

system environment

  • docker 1.12.3

  • mysql5.7.17

  • deepin 15.3 desktop version (this does not matter, because we use docker)

  • mycat1.6

Key points

  • See the detailed introduction of the previous article

  • Expose `mysql` `mycat` port number for easy management

  • This article starts directly from `docker-compose.yml`

docker-compose.yml文件

For convenience, let's post them all together.

Docker Compose builds mycat read-write separation

Docker Compose builds mycat read-write separation

Docker Compose builds mycat read-write separation

Docker Compose builds mycat read-write separation

mycat configuration

This is just a successful configuration, please refer to the mycat authoritative guide for detailed configuration rules.

  • schema.xml placement

Docker Compose builds mycat read-write separation

  • server.xml configuration

Docker Compose builds mycat read-write separation

Docker Compose builds mycat read-write separation

Docker Compose builds mycat read-write separation

  • log4j2.xml configuration

This changes the log level to debug, which is convenient for us to observe the test.

  • mycat的Dockerfile

Docker Compose builds mycat read-write separation

start up

Run in the `docker-compose.yml` file directory

Docker Compose builds mycat read-write separation

If there is no image file corresponding to the container, `docker-compose` will automatically build the image.

Command to build images manually using `docker-compose`: `docker-compose build mycat`

If the command is executed successfully, the containers mycat, m1, s1, and s2 have been started successfully.

Let's take a look with `docker ps -a`.

Docker Compose builds mycat read-write separation

test

  • Enter the mycat client

Docker Compose builds mycat read-write separation

  • execute select statement

Because the master-slave replication test has been done in the previous article, we will not repeat this place. We directly execute the `select` statement to see if the read-write separation has been achieved.

Docker Compose builds mycat read-write separation

Result set:

Docker Compose builds mycat read-write separation

Then we open mycat's log mycat.log to see

Docker Compose builds mycat read-write separation

Pay attention to the places marked in the picture.

Well, from the log we can see that the `select` statement we executed was executed from the library s1.

  • Execute the insert statement

Docker Compose builds mycat read-write separation

Open the log mycat.log of mycat and take a look

Docker Compose builds mycat read-write separation

This time we found that executing the `insert` statement is the main library m1.

Summarize

In short, an instance of using `mycat middleware` to build mysql 1 master 2 slave master-slave replication and read-write separation is completed.

It is very simple to say why `mycat database middleware` is used, because it basically has no impact on developers and will not invade into the code.

If you support it, please like it, if you don't like it, please give it a thumbs up.

A little bit every day, grow a little bit more.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325525907&siteId=291194637