简体   繁体   中英

maxscale does not split select queries

I have 2 mariadb instances master and one slave. Replication is mixed . SLAVE lag is 0 Seconds_Behind_Master: 0 I have maxscale instance which have to split SELECT queries between master and slave but all SELECT queries are sent to master.

Could you help me to solve this issue?

Here is my maxscale.cnf

[maxscale]
threads=auto


[web1]
type=server
address=1.1.1.1
port=3306
protocol=MariaDBBackend

[web2]
type=server
address=1.1.1.2
port=3306
protocol=MariaDBBackend

[MariaDB-Monitor]
type=monitor
module=mariadbmon
servers=web1,web2
user=maxscale
password=XXXXXXXXX
monitor_interval=2000

[Read-Write-Service]
type=service
router=readwritesplit
max_slave_connections=1
servers=web1,web2
user=maxscale
password=XXXXXXX

[Read-Write-Listener]
type=listener
service=Read-Write-Service
protocol=MariaDBClient
port=4006

[MaxAdmin]
type=service
router=cli

[MaxAdmin-Unix-Listener]
type=listener
service=MaxAdmin
protocol=maxscaled
socket=default

[MaxAdmin-Inet-Listener]
type=listener
service=MaxAdmin
protocol=maxscaled
address=localhost
port=6603
Servers.
-------------------+-----------------+-------+-------------+--------------------
Server             | Address         | Port  | Connections | Status
-------------------+-----------------+-------+-------------+--------------------
web1               | 87.120.207.232  |  3306 |           0 | Slave of External Server, Running
web2               | 87.120.207.229  |  3306 |           2 | Master, Running
-------------------+-----------------+-------+-------------+--------------------

here is startup messages of maxscale

Mar  4 13:56:47 qwe maxscale[12932]: syslog logging is enabled.
Mar  4 13:56:47 qwe maxscale[12932]: maxlog logging is enabled.
Mar  4 13:56:47 qwe maxscale[12932]: Using up to 4.67GiB of memory for query classifier cache
Mar  4 13:56:47 qwe maxscale[12932]: Working directory: /var/log/maxscale
Mar  4 13:56:47 qwe maxscale[12932]: The collection of SQLite memory allocation statistics turned off.
Mar  4 13:56:47 qwe maxscale[12932]: Threading mode of SQLite set to Multi-thread.
Mar  4 13:56:47 qwe maxscale[12932]: MariaDB MaxScale 2.4.7 started (Commit: f576680ed9062222f23ec9e6a3f0b23174ed0535)
Mar  4 13:56:47 qwe maxscale[12932]: MaxScale is running in process 12932
Mar  4 13:56:47 qwe maxscale[12932]: Configuration file: /etc/maxscale.cnf
Mar  4 13:56:47 qwe maxscale[12932]: Log directory: /var/log/maxscale
Mar  4 13:56:47 qwe maxscale[12932]: Data directory: /var/lib/maxscale
Mar  4 13:56:47 qwe maxscale[12932]: Module directory: /usr/lib64/maxscale
Mar  4 13:56:47 qwe maxscale[12932]: Service cache: /var/cache/maxscale
Mar  4 13:56:47 qwe maxscale[12932]: Worker message queue size: 1.00MiB
Mar  4 13:56:47 qwe maxscale[12932]: No query classifier specified, using default 'qc_sqlite'.
Mar  4 13:56:47 qwe maxscale[12932]: Loaded module qc_sqlite: V1.0.0 from /usr/lib64/maxscale/libqc_sqlite.so
Mar  4 13:56:47 qwe maxscale[12932]: Query classification results are cached and reused. Memory used per thread: 299.04MiB
Mar  4 13:56:47 qwe maxscale[12932]: The systemd watchdog is Enabled. Internal timeout = 30s
Mar  4 13:56:47 qwe maxscale[12932]: Loading /etc/maxscale.cnf.
Mar  4 13:56:47 qwe maxscale[12932]: /etc/maxscale.cnf.d does not exist, not reading.
Mar  4 13:56:47 qwe maxscale[12932]: Loaded module maxscaled: V2.0.0 from /usr/lib64/maxscale/libmaxscaled.so
Mar  4 13:56:47 qwe maxscale[12932]: [cli] THE 'cli' MODULE AND 'maxadmin' ARE DEPRECATED: Use 'maxctrl' instead
Mar  4 13:56:47 qwe maxscale[12932]: Loaded module cli: V1.0.0 from /usr/lib64/maxscale/libcli.so
Mar  4 13:56:47 qwe maxscale[12932]: Loaded module MariaDBClient: V1.1.0 from /usr/lib64/maxscale/libmariadbclient.so
Mar  4 13:56:47 qwe maxscale[12932]: [readwritesplit] Initializing statement-based read/write split router module.
Mar  4 13:56:47 qwe maxscale[12932]: Loaded module readwritesplit: V1.1.0 from /usr/lib64/maxscale/libreadwritesplit.so
Mar  4 13:56:47 qwe maxscale[12932]: [mariadbmon] Initialise the MariaDB Monitor module.
Mar  4 13:56:47 qwe maxscale[12932]: Loaded module mariadbmon: V1.5.0 from /usr/lib64/maxscale/libmariadbmon.so
Mar  4 13:56:47 qwe maxscale[12932]: Loaded module MariaDBBackend: V2.0.0 from /usr/lib64/maxscale/libmariadbbackend.so
Mar  4 13:56:47 qwe maxscale[12932]: Loaded module mariadbbackendauth: V1.0.0 from /usr/lib64/maxscale/libmariadbbackendauth.so
Mar  4 13:56:47 qwe maxscale[12932]: Encrypted password file /var/lib/maxscale/.secrets can't be accessed (No such file or directory). Password encryption is not used.
Mar  4 13:56:47 qwe maxscale[12932]: Loaded module MaxAdminAuth: V2.1.0 from /usr/lib64/maxscale/libmaxadminauth.so
Mar  4 13:56:47 qwe maxscale[12932]: Loaded module mariadbauth: V1.1.0 from /usr/lib64/maxscale/libmariadbauth.so
Mar  4 13:56:47 qwe maxscale[12932]: Started REST API on [127.0.0.1]:8989
Mar  4 13:56:47 qwe maxscale[12932]: MaxScale started with 16 worker threads, each with a stack size of 8388608 bytes.
Mar  4 13:56:47 qwe maxscale[12932]: Starting a total of 2 services...
Mar  4 13:56:47 qwe maxscale[12932]: Server 'web1' version: 10.4.12-MariaDB-log
Mar  4 13:56:47 qwe maxscale[12932]: Server 'web2' version: 10.2.31-MariaDB-log
Mar  4 13:56:47 qwe maxscale[12932]: [MariaDBAuth] [Read-Write-Service] Loaded 46 MySQL users for listener 'Read-Write-Listener' from server 'web1' with checksum 0x7605b1f5.
Mar  4 13:56:47 qwe maxscale[12932]: Listening for connections at [::]:4006
Mar  4 13:56:47 qwe maxscale[12932]: Service 'Read-Write-Service' started (1/2)
Mar  4 13:56:47 qwe maxscale[12932]: Listening for connections at [localhost]:6603
Mar  4 13:56:47 qwe maxscale[12932]: Listening for connections at [/var/run/maxscale/maxadmin.sock]:0
Mar  4 13:56:47 qwe maxscale[12932]: Service 'MaxAdmin' started (2/2)
Mar  4 13:56:47 qwe maxscale[12932]: Loaded server states from journal file: /var/lib/maxscale/MariaDB-Monitor/monitor.dat
Mar  4 13:56:47 qwe systemd: Started MariaDB MaxScale Database Proxy.

Try adding assume_unique_hostnames=false to the MariaDB-Monitor section. This should cause the slave server to be properly detected (goes into Slave, Running state) after which reads can be routed to it.

If the status is correct but reads are still not routed to it, add log_info=true under the [maxscale] section to enable verbose logging. This will tell you why the queries are not routed to the slaves. One of the most common reasons that reads aren't routed to slaves is that they are done inside a transaction so that might be a good thing to check first.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM