Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Configuration and use of mysqlroute

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

MySQL Router is a lightweight MySQL middleware officially launched by MySQL. It is a lightweight agent between application client and dbserver. It can detect, analyze and forward queries to backend database instances and return the results to client. It is an alternative to mysql-proxy. But there is a difference between mysql-proxy and mysql-proxy. mysqlroute uses two ports for read and write separation

Default port number Description 7001 Default is read/write port mode = read-write By default, the first master database is the write master database. When the first master database is DOWN, the second database is promoted to the master database. If the first one does not have problems, the second one will not be used. Can be used as high availability 7002 Default is read port If set later, poll according to the set list

After MySQL Router receives the request of the front-end application program, it distinguishes between reading and writing according to different ports, sends all writes and queries connected to the read-write port to the master library, and sends queries connected to the read-only port to multiple slave libraries in a polling manner, thus realizing the purpose of separating reading and writing. The results of the read and write are passed to MySQL Router, which returns them to the client application.

I understand that mysql-proxy is used in the same way as connecting a single database, while mysql route is to concentrate the reading and writing of multiple hosts together, and separate the reading and writing. When using it, the program still needs to be changed. Specific performance tests will be tested slowly in the following articles

Installation can be done in a variety of ways, because I chose binary packages for testing

Installation package download:

http://dev.mysql.com/downloads/router/

Documents:

http://downloads.mysql.com/docs/mysql-router-en.pdf

I chose binary installation:

The system is centos7-1604-mini

1. download

cd /usr/local/ && wget -c https://dev.mysql.com/get/Downloads/MySQL-Router/mysql-router-2.0.4-linux-glibc2.12-x86-64bit.tar.gz

cd /usr/local/ && tar -zxvf mysql-router-2.0.4-linux-glibc2.12-x86-64bit.tar.gz

ln -s mysql-router-2.0.4-linux-glibc2.12-x86-64bit/ mysql-router

2. Create necessary files, copy configuration files

mkdir /etc/mysql-route/

mkdir /var/log/mysql-route

chown mysql:mysql /var/log/mysql-route

cp /usr/local/mysql-router/share/doc/mysqlrouter/sample_mysqlrouter.ini /etc/mysql-route/mysqlrouter.conf

mysqlrouter.conf modification

[DEFAULT]logging_folder = /var/log/mysql-route

plugin_folder = /usr/local/mysql-router/lib/mysqlrouter

config_folder = /etc/mysql-route

runtime_folder = /var/run/ [logger]level = INFO

#Primary node failover configuration

[routing:basic_failover]

#Write node address

bind_address=0.0.0.0

#Write Node Port

bind_port = 7001

#mode, read and write

mode = read-write

#By default, the first master database is the write master database. When the first master database is DOWN, the second database is promoted to master database.

destinations = 192.168.10.191:3306

#Configuration from Node Load Balancer

[routing:balancing]

#Bind IP address

bind_address=0.0.0.0

#listening port bind_port = 7002

#Connection timeout

connect_timeout = 3

#Maximum number of connections

max_connections = 1024

#Backend server address. Default Read Polling

destinations = 192.168.10.192:3306,192.168.10.191:3306

#Mode: Read or Write

mode = read-only

[keepalive]interval = 60

8. Start mysqlrouter

mysqlrouter --config /usr/local/mysqlrouter/etc/mysqlrouter.conf &

Testing connects mysql libraries through mysqlrouter, a middleware

mysql -h227.0.0.1 -uappuser -p123456 -e"show databases;" -P7001

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report