mysql-proxy-discuss team mailing list archive
-
mysql-proxy-discuss team
-
Mailing list archive
-
Message #00053
Re: Choose which server to connect to
Ok, let's restart from scratch:
A client wants to connect to its mysql server. So he puts sql.client1.com.
Let's say sql.client1.com is a CNAME to mysqlproxy.master.com OR a 'A' to mysql.proxy.ip.address .
Another client would have the same configuration: sql.client2.com -> mysqlproxy.master.com (or mysql.proxy.ip.address).
With a consequence, all clients requests are "redirected" to the proxy.
Now, I still want different mysql server for my clients. For exemple:
sql.client1.private.master.com
sql.client2.private.master.com
To do that, I would like to know if mysql proxy is able to tell me from which ip or address it has been called by. (sorry if the sentence is not correct)
In other words, I would like the proxy to tell me:
"Somebody called me using sql.client1.com" -> I would know it's client1's request, and I redirect it to sql.client1.private.master.com (or the equivalent ip)
"Somebody called me using sql.client2.com" -> I would know it's client1's request, and I redirect it to sql.client2.private.master.com (or the equivalent ip)
Eventually, the question is:
Is mysqlproxy able to tell me the destination address of the requests, ie sql.client{1,2}.com ?
Thanks a lot for reading and trying to understand !
Mysqlproxy is one of my last chances :D
Best regards,
Pierre
----- Mail Original -----
De: "Joshua Zhu" <zhuzhaoyuan@xxxxxxxxx>
À: "Pierre" <mail@xxxxxxxx>
Cc: mysql-proxy-discuss@xxxxxxxxxxxxxxxxxxx
Envoyé: Mercredi 11 Février 2009 03h02:57 GMT +01:00 Amsterdam / Berlin / Berne / Rome / Stockholm / Vienne
Objet: Re: [Mysql-proxy-discuss] Choose which server to connect to
On Tue, Feb 10, 2009 at 6:06 PM, Pierre < mail@xxxxxxxx > wrote:
Hum...
I think we misunderstood a bit.
Oops...
In fact, I don't really want to know what is the address of the client,
but to which server the client made his connection.
In fact, I want each client to enter a different server adress:
sqlserver1.dom.tld
sqlserver2.dom.tld
sqlserver3.dom.tld
...
all sqlserverX.dom.tld are redirected to the proxy,
but the proxy redirect the queries according to the address it has been called from.
Sorry, I'm not quite following you here. What do you mean by "redirected to the proxy"? Are sqlserver*.dom.tld _real_ hosts, or just entries in /etc/hosts like this?
host-ip-of-mysql-proxy sqlserver1.dom.tld sqlserver2.dom.tld sqlserver3.dom.tld
For instance, if a client tries to connect to sqlserver1.dom.tld, mysqlproxy will redirect the query to 192.168.0.1.
Another one wants to connect to sqlserver2.dom.tld, he will be redirected to 192.168.0.2, through mysql proxy.
Eventually, sqlserverX.dom.tld is always the adress of the mysql proxy.
----- Mail Original -----
De: "Joshua Zhu" < zhuzhaoyuan@xxxxxxxxx >
À: "Pierre" < mail@xxxxxxxx >
Cc: mysql-proxy-discuss@xxxxxxxxxxxxxxxxxxx
Envoyé: Mardi 10 Février 2009 09h26:20 GMT +01:00 Amsterdam / Berlin / Berne / Rome / Stockholm / Vienne
Objet: Re: [Mysql-proxy-discuss] Choose which server to connect to
Hi Pierre,
I guess the script may look like this:
--
-- redirect-by-client-address.lua
-- author: Joshua Zhu (zhuzhaoyuan AT gmail.com )
--
local string = require("string")
local is_debug = true
local cli_svr_map
function get_server(client)
if not cli_svr_map then
-- Initializing
-- Note: You should modify the client IPs and the backend addresses below!
cli_svr_map = {
["192.168.0.189"] = {
address = " 192.168.0.192:3306 ",
backend_ndx = -1 },
["192.168.0.192"] = {
address = " 192.168.0.189:3306 ",
backend_ndx = -1 },
}
for _, v in pairs(cli_svr_map) do
for i = 1, #proxy.global.backends do
local backend = proxy.global.backends[i]
if v.address == backend.address then
v.backend_ndx = i
break
end
end
end
if is_debug then
print("map table:")
for k, v in pairs(cli_svr_map) do
print(" [" .. k .. "] = {" .. v.address .. ", " .. v.backend_ndx .. "}")
end
end
end
local host = string.match(client, "([^:]+):")
if cli_svr_map[host] then
return cli_svr_map[host].backend_ndx
end
return -1
end
function connect_server()
if is_debug then
print("[connect_server] " .. proxy.connection.client.address)
print("we have " .. #proxy.global.backends .. " backends:")
for i = 1, #proxy.global.backends do
local backend = proxy.global.backends[i]
print(" [" .. i .. "].connected_clients = " .. backend.connected_clients)
print(" [" .. i .. "].address = " .. backend.address)
print(" [" .. i .. "].state = " .. backend.state)
print(" [" .. i .. "].type = " .. backend.type)
print(" [" .. i .. "].uuid = " .. (backend.uuid or "(nil)"))
end
end
local index = get_server(proxy.connection.client.address)
if index > 0 and index <= #proxy.global.backends then
if proxy.global.backends[index].state ~= proxy.BACKEND_STATE_DOWN then
if is_debug then
print("redirect the client to backends[" .. proxy.global.backends[index].address .. "]")
end
proxy.connection.backend_ndx = index
end
end
end
Cheers!
--
Joshua Zhu
http://blog.zhuzhaoyuan.com
--
Joshua Zhu
http://blog.zhuzhaoyuan.com
Follow ups
References