使用MySQL设置MaxScale读/写分离路由

时间:2015-11-28 23:36:45

标签: mysql database-replication maxscale

我正在尝试使用MySQL设置MaxScale读/写拆分路由。

我的流浪汉设置如下:

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

设置mysql复制的配置程序取自this article。我已经验证复制功能正常,maxscale实例可以连接到两个mysql实例中的每一个。

当我尝试连接到拆分路由器时出现以下错误消息:

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.

任何有关解决问题的帮助,甚至指向我可以调查为什么找不到合适的候选人的地方都非常感谢。

1 个答案:

答案 0 :(得分:0)

对我来说,最重要的信息丢失了或太抽象了(如何真正配置数据库服务器)。

当我遇到此类问题时,从站未正确配置为从站(意味着未设置主站)。 执行时会发生什么:

show slave status

可能是您错过了执行https://mariadb.com/kb/en/library/change-master-to/