OpenVZ Forum


Home » General » Support » WIKI - Shared webhosting - problem with mysql socket
WIKI - Shared webhosting - problem with mysql socket [message #23167] Wed, 14 November 2007 07:15 Go to next message
tauren is currently offline  tauren
Messages: 7
Registered: November 2007
Junior Member
I have a VE running only MySQL. I've shared the mysql.socket file with another VE that is running a web server by following the instructions at: http://wiki.openvz.org/Shared_webhosting

Everything works nicely. I can run the standard mysql client in the webserver VE and connect to the mysql VE. It appears to the webserver VE that mysql is running on localhost.

However, if mysql is restarted, then I get this error when trying to connect from the webserver VE:

ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (111)

If I go and recreate the link to mysql.sock, then it works again.

Any idea how I can get around this? I don't want to manually have to recreate this link for every VE each time mysql is restarted. And since the restart is in a VE, I don't know how I would automate it either to make the changes in host.

Is this the expected behavior? From the wiki page, it seems like there shouldn't be an issue. But maybe the author hadn't tested this scenario.

Thanks!
Tauren
Re: WIKI - Shared webhosting - problem with mysql socket [message #23269 is a reply to message #23167] Thu, 15 November 2007 06:56 Go to previous messageGo to next message
curx
Messages: 739
Registered: February 2006
Location: Nürnberg, Germany
Senior Member

Hi,

you must relink the mysql.sock on every restart the VE, because it's a hard not a soft link.

You can experience with the vz mount/unmount scripts to set a hard link from VE to another one.



Re: WIKI - Shared webhosting - problem with mysql socket [message #23281 is a reply to message #23269] Thu, 15 November 2007 08:32 Go to previous messageGo to next message
tauren is currently offline  tauren
Messages: 7
Registered: November 2007
Junior Member
curx wrote on Thu, 15 November 2007 01:56

Hi,

you must relink the mysql.sock on every restart the VE, because it's a hard not a soft link.

You can experience with the vz mount/unmount scripts to set a hard link from VE to another one.




Thanks, that helps for VE startup/shutdown. But the hard link is lost even if mysql is restarted within the mysql VE. A "service mysqld restart" removes the mysql.sock and creates a new one, thus losing the hard link.

As ToyKeeper suggested on freenode #openvz, a cron job could run every minute to see if the mysql.sock file has changed. If it has, then all hard links could be recreated. But that is more of a hack that a real solution. It may have to do though, as I haven't come up with a real solution yet. If there are any ideas, I'm all ears.

BTW, I updated the WIKI to mention this behavior.

Tauren




Re: WIKI - Shared webhosting - problem with mysql socket [message #23305 is a reply to message #23281] Thu, 15 November 2007 12:10 Go to previous messageGo to next message
curx
Messages: 739
Registered: February 2006
Location: Nürnberg, Germany
Senior Member

Hi,

1) ssh connection VE -> VE0

A wrapper, when restarting a mysql-server in VE, a predefined ssh connetion to VE0, maybe different port , which invoke the ln sequence.

* setup a nonpasswd ssh connection with authorizeds_keys
* maybe start a non-sshd-port sshd (port 22!) daemon on VE0, with sshd_option
"PermitRootLogin forced-commands-only"

and a ssh connection like:

VE# ssh -p <PORT> root@<VE0_IP_or_NAME> 'ln /var/lib/vz/root/<VEID_mysqld>/var/run/mysql/mysql.sock /var/lib/vz/root/<VEID_NON_mysqld>/var/run/mysql/mysql.sock'

2) setup a shared folder with mount -o bind ...

3) setup mysqld with connection settings and limit the IP, which can connect to mysqld with iptables or tcpd-wrapper

Re: WIKI - Shared webhosting - problem with mysql socket [message #23367 is a reply to message #23305] Fri, 16 November 2007 01:58 Go to previous messageGo to next message
tauren is currently offline  tauren
Messages: 7
Registered: November 2007
Junior Member
Thanks curx,

Those are some great ideas. I have created a script to relink the sockets. It can be run manually or via a cron job. I've added it to the wiki if anyone is interested:

http://wiki.openvz.org/Shared_webhosting

Thanks again,
Tauren

curx wrote on Thu, 15 November 2007 07:10

Hi,

1) ssh connection VE -> VE0

A wrapper, when restarting a mysql-server in VE, a predefined ssh connetion to VE0, maybe different port , which invoke the ln sequence.

* setup a nonpasswd ssh connection with authorizeds_keys
* maybe start a non-sshd-port sshd (port 22!) daemon on VE0, with sshd_option
"PermitRootLogin forced-commands-only"

and a ssh connection like:

VE# ssh -p <PORT> root@<VE0_IP_or_NAME> 'ln /var/lib/vz/root/<VEID_mysqld>/var/run/mysql/mysql.sock /var/lib/vz/root/<VEID_NON_mysqld>/var/run/mysql/mysql.sock'

2) setup a shared folder with mount -o bind ...

3) setup mysqld with connection settings and limit the IP, which can connect to mysqld with iptables or tcpd-wrapper




Re: WIKI - Shared webhosting - problem with mysql socket [message #30182 is a reply to message #23367] Wed, 14 May 2008 18:12 Go to previous message
sudhaker is currently offline  sudhaker
Messages: 8
Registered: February 2008
Junior Member
It can't be any simpler than this.


Cheers,
Sudhaker
http://sudhaker.com

[Updated on: Wed, 14 May 2008 18:12]

Report message to a moderator

Previous Topic: HN-based firewall dns problems
Next Topic: Why CentOS 5 VE templates not official
Goto Forum:
  


Current Time: Tue Nov 19 01:13:54 GMT 2024

Total time taken to generate the page: 0.02978 seconds