Proxy local mysql socket over the network

As an user of OpenVZ it's often my task to migrate database driven web applications to separate environments. In recent versions of OpenVZ, bind mounting of sockets between virtual environments is prohibited. I had to find a way to proxy local connections to /var/run/mysqld/mysqld.sock to the remote mysql server.

First I've created a mysql user and group:

addgroup --system mysql
adduser --system --home /var/run/mysqld --ingroup mysql mysql

Then I've installed and configured the excellent socat utility using launchtool.

db.vz is the address remote database host in the following executable launchtool configuration script

#!/usr/bin/launchtool -C
tag = mysql-proxy
daemon = yes
user = mysql
command = socat UNIX-LISTEN:/var/run/mysqld/mysqld.sock,fork,mode=0666 TCP:db.vz:3306,forever
start dir = /var/run/mysqld
wait times = 5
infinite runs = yes
stats = yes
launchtool output = syslog:mysql-proxy,LOG_DAEMON,LOG_INFO
launchtool errors = syslog:mysql-proxy,LOG_DAEMON,LOG_ERR
command output = syslog:mysql-proxy,LOG_DAEMON,LOG_INFO
command errors = syslog:mysql-proxy,LOG_DAEMON,LOG_ERR

Update: this method seems reliable but rather slow when an application continously creates lots of connections - like does PHP

Linkbacks

Use the following URL for manually sending trackbacks: http://rigo.info/lib/plugins/linkback/exe/trackback.php/en:blog:proxy_local_mysql_socket_over_the_network
en/blog/proxy_local_mysql_socket_over_the_network.txt · Utolsó módosítás: 2009-09-05 00:00 (külső szerkesztés)
CC Attribution-Noncommercial-Share Alike 4.0 International
www.chimeric.de Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0