群晖NAS内网穿透,出门在外也能访问

服务器端

下载frp安装包

https://github.com/fatedier/frp/releases
根据服务器和客户端系统平台下载不同程序,服务器端和客户端版本要一致,否则无法建立连接。

解压,其中的frps为frp的服务端,frpc为frp的客户端。

修改配置文件 frps.ini

[common]
bind_port = 7000

log_file = ./frps.log
log_level = info
log_max_days = 3

max_pool_count = 50
subdomain_host = xxx.com

启动

./frps -c ./frps.ini

群晖端

  1. 开启ssh

    控制面板->高级模式->终端机和SNMP->启用SSH功能

ssh登录到群晖

xshell使用管理员账号密码登录到群晖
执行sudo -i
输入密码切换到root用户

####下载并解压frp安装包
https://github.com/fatedier/frp/releases

修改配置 frpc.ini

[common]
[common]
server_addr = xxx.com
server_port = 7000
pool_count = 1

[ssh]
type = tcp
local_ip = 192.168.1.213
local_port = 22
remote_port = 6000

[nas]
type = tcp
local_port = 5000
remote_port = 5000
subdomain = nas

[web]
type = tcp
local_port = 80
remote_port = 80
subdomain = nas

[plex]
type = tcp
local_port = 32400
remote_port = 32400
subdomain = nas

[nas_Drive] 
type = tcp 
local_ip = 192.168.1.213 
local_port = 6690 
remote_port = 6690

[file_Manage]
type = tcp
local_ip = 192.168.1.213
local_port = 3362
remote_port = 3362

[file_Manage_1]
type = tcp
local_ip = 192.168.1.213
local_port = 3363
remote_port = 3363

启动客户端

.\frpc -c .\frpc.ini
输出下面启动成功

2019/03/23 19:59:43 [I] [proxy_manager.go:300] proxy removed: []
2019/03/23 19:59:43 [I] [proxy_manager.go:310] proxy added: [nas_Drive file_Manage file_Manage_1 ssh nas web plex]
2019/03/23 19:59:43 [I] [proxy_manager.go:333] visitor removed: []
2019/03/23 19:59:43 [I] [proxy_manager.go:342] visitor added: []
2019/03/23 19:59:44 [I] [control.go:246] [1cc1f382c2492b1f] login to server success, get run id [1cc1f382c2492b1f], server udp port [0]
2019/03/23 19:59:44 [I] [control.go:169] [1cc1f382c2492b1f] [nas] start proxy succes

然后访问http://你的域名:5000 ,就可以访问到群晖啦,客户端也可正常使用

为frp添加进程守护

访问因意外导致frp进程终止,我们写个脚本来监控frp运行

编写脚本 /root/frp-deamon.sh

#!/bin/sh
#添加本地执行路径
export LD_LIBRARY_PATH=~/frp_0.20.0_linux_amd64
while true; do
        server=`ps aux | grep frpc | grep -v grep`
        if [ ! "$server" ]; then
            nohup ./frpc -c ./frpc.ini &
        fi
        sleep 60
done

设置开机自启

群晖控制面板->计划任务->新增->触发的任务
命令里写
nohup bash /root/frp-deamon.sh >/dev/null 2>&1 &

发表评论

[/0o0] [..^v^..] [0_0] [T.T] [=3-❤] [❤.❤] [^v^] [-.0] [!- -] [=x=] [→_→] [><] 更多 »
昵称

抢沙发~