V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
通过以下 Referral 链接购买 DigitalOcean 主机,你将可以帮助 V2EX 持续发展
DigitalOcean - SSD Cloud Servers
ikw
V2EX  ›  VPS

树莓派连 vps 对公网开放端口的问题

  •  
  •   ikw · Oct 13, 2016 · 814 views
    This topic created in 3485 days ago, the information mentioned may be changed or developed.

    场景是这样的,我在内网,也就是路由器下,树莓派跑着一个 aria2 服务

    然后我在公网有一台 vps ,我希望通过树莓派能连到这台 vps 后,我可以通过 vps 向树莓派下发下载任务。

    现在使用的方案:

    使用 ssh 代理中转:

    • 树莓派对 vps 正向代理:
    ssh -fNR vps_port:127.0.0.1:pi_port user@vps
    

    但是 vps_port 只能在 vps 本地访问到,已经试过在 vps_port 前加 vps 的 ip ,也是只能本地访问。

    • 所以在 vps 加反向代理:
    ssh -fNL *:remote_port:localhost:target_port localhost
    

    这样连接就正常了。

    • 考虑到 ssh 时间长了会断,又写了个脚本, 300 秒看一下,断了就再运行。

    看起来一切都正常了。

    但是,问题来了。

    晚上还是正常的东西,睡一晚上起来,端口就连不上了!

    所有东西看起来都很正常,调试我也不知道从哪里下手了。

    • 手动把树莓派上的 ssh 杀了,然后再启动,一切又正常了。

    这,我就有点不会了。有人对 ssh 代理比较了解的吗?

    求助!

    Supplement 1  ·  Oct 13, 2016

    用了 autossh 也会出问题。

    研究了一下,发现问题应该如下:

    • 假设树莓派使用 A 端口连接 vps 的 B 端口。
    • 在 vps 上 B 端口在一定时间以后,进入了 close_wait 状态,是 sshd 占用着这个端口。
    • 因为 B 端口被占用,所以树莓派这边做反向代理时,无法绑定到 B 端口上。

    不知道有没有人知道为什么会出现 close_wait 状态呢,而且这个 close_wait 占用了很长时间?

    8 replies    2016-10-15 15:41:03 +08:00
    cq65617875
        1
    cq65617875  
       Oct 13, 2016
    为何不考虑 VPN
    ikw
        2
    ikw  
    OP
       Oct 13, 2016
    @cq65617875 树莓派只能单向连 vps ,如果用 vpn 的话,要怎么设置呢?
    roychan
        3
    roychan  
       Oct 13, 2016
    用 autossh ,设置 'ServerAliveInterval' 参数。
    roychan
        4
    roychan  
       Oct 13, 2016
    准确地说是:用 autossh ,并设置 'ServerAliveInterval' 参数。
    ikw
        5
    ikw  
    OP
       Oct 13, 2016
    @roychan 好东西!我试一下,明天早上看看效果,先谢谢了!
    roychan
        6
    roychan  
       Oct 14, 2016
    你有设置那个参数吗?
    ikw
        7
    ikw  
    OP
       Oct 14, 2016
    @roychan Ops ,自己查了一下 autossh ,把这个参数给忘了,我的锅,今晚再试试!
    ikw
        8
    ikw  
    OP
       Oct 15, 2016
    @roychan 太感谢了,加了参数之后果然可以用了!
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   5412 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 38ms · UTC 08:27 · PVG 16:27 · LAX 01:27 · JFK 04:27
    ♥ Do have faith in what you're doing.