我打开了一个ssh tunel ,如本文所述:Zend_Db: How to connect to a MySQL database over SSH tunnel?
但现在我不知道我到底做了什么.这个命令会影响服务器上的任何东西吗?
我使用OSX Lion,服务器运行在Ubuntu11.10上.
我打开了一个ssh tunel ,如本文所述:Zend_Db: How to connect to a MySQL database over SSH tunnel?
但现在我不知道我到底做了什么.这个命令会影响服务器上的任何东西吗?
我使用OSX Lion,服务器运行在Ubuntu11.10上.
假设你运行了这个命令:ssh -f user@mysql-server.com -L 3306:mysql-server.com:3306 -N
,如你链接的帖子所述.
命令的分解:
ssh
:这是不言而喻的.调用ssh
. -f
:(摘自man ssh
页)
请求ssh在命令执行之前进入后台.
基本上,输入任何密码建立连接后,向后台发送ssh
;它会在localhost
向您返回shell提示,而不是让您登录到remote-host
.
user@mysql-server.com
:您要登录的远程服务器. -L 3306:mysql-server.com:3306
:这是有趣的一点.-L
(摘自man ssh
页):
[绑定地址:]端口:主机:主机端口
因此,-L 3306:mysql-server.com:3306
将local端口3306
绑定到主机mysql-server.com
上的remote port 3306
.
当您连接到local端口3306
时,连接将通过安全通道转发到mysql-server.com
.然后,remote host、mysql-server.com
连接到端口3306
上的mysql-server.com
.
-N
:不要执行命令.这对于"仅转发端口"(引用手册页)很有用.
这个命令会影响服务器上的任何东西吗?
是的,它在端口3306上的localhost和mysql-server.com之间建立连接.
我该如何关闭这条 tunel ...
如果你使用了-f
,你会注意到你打开的ssh
过程是在后台进行的.关闭它的更好方法是运行ps aux | grep 3306
,找到ssh -f ... -L 3306:mysql-server.com:3306 -N
中的pid
,然后运行kill <pid>
.(或者kill -9 <pid>
;我忘了kill
是否有效).这样做的好处很好,就是not次杀死所有其他ssh
次连接;如果你有不止一个,重新建立他们可以是一个轻微的...疼痛
... 因为现在我无法正确使用我的本地mysql.
This is because you've effectively "captured" the local mysql
process and forwarded any traffic that attempts to connect to it, off to the remote mysql
process. A much nicer solution would be to not use local port 3306 in the port-forward. Use something that's not used, like 33060. (Higher numbers are generally less used; it's pretty common to port-forward a combination like this: "2525->25", "8080->80", "33060->3306" or similar. Makes remembering slightly easier).
所以,如果使用ssh -f user@mysql-server.com -L 33060:mysql-server.com:3306 -N
,那么将Zend connect to mysql函数指向端口33060
上的localhost
,这将连接到端口3306
上的mysql-server.com
.显然,您仍然可以在端口3306
上连接到localhost
,因此您仍然可以使用本地mysql
服务器.