Home  >  Article  >  Database  >  SSH Tunnel Memcached

SSH Tunnel Memcached

WBOY
WBOYOriginal
2016-06-07 16:26:06885browse

最近一台服务器放进了移动机房,需要访问原电信机房一台Memcached服务器,Memcached服务是以内网形式启动。 依靠google大神,搜索出解决思路,在本地起一个SSH链接,通过本地一个端口实现对另外机器的映射或者叫做转发。 上周本来已经搞定,本周突发灵异事件

最近一台服务器放进了移动机房,需要访问原电信机房一台Memcached服务器,Memcached服务是以内网形式启动。

依靠google大神,搜索出解决思路,在本地起一个SSH链接,通过本地一个端口实现对另外机器的映射或者叫做转发。

上周本来已经搞定,本周突发灵异事件,竟然不管了,最后百般尝试,完成结果如下:

移动机器IP:220.xxx.xxx.xxx 电信机器IP:155.xxx.xxx.xxx

在移动机器上执行:

shell > ssh -N -f -L 11211:192.168.0.xxx:11211 root@155.xxx.xxx.xxx

11211:192.168.0.xxx:11211,格式为:本地端口:memcache启动的IP:端口 这里没有用RSA认证,就直接输入密码。-N 是不需要shell,-f 是程序后台执行,其他参数参见ssh --help。

shell > ps aux

可以看见进程已经在了,下面开始测试代码。

>>> import memcache
>>> mc = memcache.Client(['127.0.0.1:11211'],debug=True)
>>> print mc.get('name')
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn