简体   繁体   中英

MySQL-proxy and basic failover (detect state)

I have just installed mysql proxy 0.8.2, and started playing with it. I am using it together with two MySQL 5.5 servers, listening on 3306, the proxy is running on 4040. Oh, and OS is Win 7 32-bit.

My problem is that that the mysql proxy checking the state of the servers doesn't seem like it should.

I start up the script, and it runs as it should. But when I shutdown the primary server, the script doesn't seem to recognize that - it still tries to connect to it...

Version information

mysql-proxy 0.8.2
chassis: mysql-proxy 0.8.2
glib2: 2.16.6
libevent: 1.4.12-stable
LUA: Lua 5.1.2
package.path: C:\ProgramX86\dev\mysql-proxy\lib\mysql-proxy\lua\?.lua
package.cpath: C:\ProgramX86\dev\mysql-proxy\bin\lua-?.dll
-- modules
proxy: 0.8.2*

My config

[mysql-proxy]
proxy-address = :4040
proxy-backend-addresses = 10.3.0.9:3306,192.168.4.100:3306
proxy-lua-script = C:/ProgramX86/dev/mysql-proxy/failover3.lua
daemon = true

Failover lua script

function connect_server()
    if proxy.global.backends[1].state == proxy.BACKEND_STATE_DOWN then
        proxy.connection.backend_ndx = 2
    else
        proxy.connection.backend_ndx = 1
    end
    print ("s Connecting: " .. proxy.global.backends[proxy.connection.backend_ndx].dst.name)
end 

function read_query(packet)
    if proxy.global.backends[1].state == proxy.BACKEND_STATE_DOWN then
        proxy.connection.backend_ndx = 2
    else
        proxy.connection.backend_ndx = 1
    end
    print ("q Connecting: " .. proxy.global.backends[proxy.connection.backend_ndx].dst.name)
end

It's because proxy.global.backends[1].state is still proxy.BACKEND_STATE_UP when the primary server is shut down. Someone said it will take 3 minutes to wait the back end response, instead of watching Mysql service all the time. I am trying to find a better way to solve the problem.

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