简体   繁体   中英

Setting up MaxScale read/write split routing with MySQL

I am attempting to setup MaxScale read/write split routing with MySQL.

My vagrant setup is as follows:

Vagrant.configure(2) do |config|
  config.vm.box = "ubuntu/trusty64"

  config.vm.define 'maxscale' do |haproxy_instance|
    haproxy_instance.vm.provision "shell", path: 'provision_maxscale.sh'
    haproxy_instance.vm.network "forwarded_port", guest: 80, host: 9901
    haproxy_instance.vm.network "forwarded_port", guest: 3306, host: 9906
    haproxy_instance.vm.network 'private_network', ip: '192.168.50.101'
  end

  config.vm.define 'mysql-primary' do |mysql_primary_instance|
    mysql_primary_instance.vm.provision "shell", path: 'provision_mysql_primary.sh'
    mysql_primary_instance.vm.network "forwarded_port", guest: 3306, host: 9907
    mysql_primary_instance.vm.network 'private_network', ip: '192.168.50.100'
  end

  config.vm.define 'mysql-slave' do |mysql_slave_instance|
    mysql_slave_instance.vm.provision "shell", path: 'provision_mysql_primary.sh'
    mysql_slave_instance.vm.network "forwarded_port", guest: 3306, host: 9908
    mysql_slave_instance.vm.network 'private_network', ip: '192.168.50.99'
  end

end

provision_maxscale.sh :

wget https://downloads.mariadb.com/enterprise/pbc3-8y0m/generate/10.0/mariadb-enterprise-repository.deb
dpkg -i mariadb-enterprise-repository.deb
sudo apt-get update
sudo apt-get --force-yes --yes install maxscale

sudo systemctl start maxscale.service
cp /vagrant/maxscale.cnf /etc/maxscale.cnf
sudo systemctl start maxscale.service
sudo service maxscale stop
sudo service maxscale start

maxscale.cnf :

[maxscale]
threads=4

[qla]
type=filter
module=qlafilter
options=/tmp/QueryLog

[fetch]
type=filter
module=regexfilter
match=fetch
replace=select

[RW]
type=service
localhost_match_wildcard_host=1
router=readwritesplit
servers=server1,server2
user=lorefnon
passwd=password
max_slave_connections=100%
router_options=slave_selection_criteria=LEAST_CURRENT_OPERATIONS

[RR]
type=service
localhost_match_wildcard_host=1
router=readconnroute
router_options=synced
servers=server1,server2
user=lorefnon
passwd=password

[Debug Interface]
type=service
router=debugcli

[CLI]
type=service
router=cli

[RWlistener]
type=listener
service=RW
protocol=MySQLClient
# address=10.69.179.54
port=3307

[RRlistener]
type=listener
service=RR
protocol=MySQLClient
# address=10.69.179.54
port=3308

[Debug Listener]
type=listener
service=Debug Interface
protocol=telnetd
address=127.0.0.1
port=4442

[CLI Listener]
type=listener
service=CLI
protocol=maxscaled
address=127.0.0.1
port=6603

[server1]
type=server
address=192.168.50.100
port=3306
protocol=MySQLBackend

[server2]
type=server
address=192.168.50.99
port=3306
protocol=MySQLBackend

The provisioners for setting up mysql replications are taken from this article . And I have verified that replication is functional and the maxscale instance can connect to each of the two mysql instances.

The following error message appears when I try to connect to the split router:

mysql -u lorefnon -p -P3307 -h 127.0.0.1

-----------------------------------------------------------------------


MariaDB Corporation MaxScale    /var/log/maxscale/error1.log Sat Nov 28 11:38:02 2015
-----------------------------------------------------------------------
--- Logging is enabled.
2015-11-28 11:38:13   Error : Couldn't find suitable Master from 2 candidates.
2015-11-28 11:38:13   Error : Failed to create RW session.

Any help regarding figuring out the problem, or even pointing to where I can investigate why a suitable candidate is not being found is highly appreciated.

for me the most important information is missing or too abstract (how you really configured your database servers).

When I had these kind of issues the slave wasn't configured properly as slave (means no master was set). What happens when you execute:

show slave status

Could it be, that you missed to execute https://mariadb.com/kb/en/library/change-master-to/

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