|
本帖最后由 276080758 于 2024-1-3 21:39 编辑
转载自:https://www.anidays.com/2024/75/
最近博主在玩Proxmox Virtual Environment(PVE)的All in boom,发现只要PVE里面装了Windows系统然后开了显卡(GPU)直通,通过远控软件(向日葵)链接Windows的话,没法设置分辨率,直接是640X480,根本没法用,但是通过自带的远程桌面链接分辨率又是没有问题的,所以本文主要阐述如何通过FRP内网穿透实现随时链接。
测试环境:
客户端:Windows 10 X64 专业版
服务器:Centos 7 X64 2009
Windows防火墙已打开端口和远程连接
一、服务器安装FRP
1、首先你需要一台有固定公网的服务器,速度不能太差,可以自己买个VPS,美西、阿里云、腾讯云都可以,hostloc.com里面很多介绍。
2、我们去frp的官网下载最新稳定版,https://github.com/fatedier/frp/releases,本文服务器端采用Centos7,所以下载frp_0.53.2_linux_amd64.tar.gz最新的版本。
3、在/usr/local下新建frp文件夹,解压刚才下载的压缩包,将下面两个文件使用WinSCP上传到VPS服务器的frp:
当然,你也可以自己在其他地方新建文件夹。注意文件夹拥有者及组,都要选root,因为后面SSH登录服务器执行命令的用户名就是root,如果后面程序无法启动,可以检查下是不是这里出错了。
上传的文件注意修改权限:
4、然后我们修改frps.toml,来配置连接端口。
以文本打开,直接修改为:
- bindPort = 8500
- auth.token = "QWER654321"
复制代码 第一个是frp服务基本端口,端口号这个可以根据自身情况修改。最后一个相当于登录密码,防止瞎猫碰上死耗子,QWER654321请自行修改。
改好后我们还要在防火墙中放行8500、8600端口,8500是FRP服务端口,要和上面配置文件匹配;8600是后面我们用来转发指定Windows远程桌面连接的端口,当然也可以自己改个其他的。我为了方便起见,选用了宝塔BT服务器面板,在面板里面找到安全,在右边填上端口,点击放行,8700不用放行,那是我搞其他服务用的。
5、现在我们要临时运行下frp看有没有报错,执行:
- cd /usr/local/frp //你自己的安装位置
- ./frps -c ./frps.toml
复制代码 返回
- [root@wiki-hk-web frp]# ./frps -c ./frps.toml
- 2023/11/26 22:19:07 [I] [root.go:102] frps uses config file: ./frps.toml
- 2023/11/26 22:19:08 [I] [service.go:200] frps tcp listen on 0.0.0.0:8500
- 2023/11/26 22:19:08 [I] [root.go:111] frps started successfully
复制代码 OK,配置没有问题,Ctrl+C结束运行,那么设置下让他自启动吧。
首先在VPS安装systemd、nano:
- yum install systemd
- yum install nano
复制代码 生成服务文件:
- sudo nano /etc/systemd/system/frps.service
复制代码 粘贴以下文件:
- [Unit]
- # 服务名称,可自定义
- Description = frp server
- After = network.target syslog.target
- Wants = network.target
- [Service]
- Type = simple
- # 启动frps的命令,需修改为您的frps的安装路径
- ExecStart = /usr/local/frp/frps -c /usr/local/frp/frps.toml
- [Install]
- WantedBy = multi-user.target
复制代码 然后使用Ctrl+O保存,Ctrl+X退出,设置开机启动:
- sudo systemctl enable frps
复制代码 后面可以通过以下命令管理frp:
- # 启动frp
- sudo systemctl start frps
- # 停止frp
- sudo systemctl stop frps
- # 重启frp
- sudo systemctl restart frps
- # 查看frp状态
- sudo systemctl status frps
复制代码
二、Windows安装FRP
1、我们去frp的官网下载最新稳定版,https://github.com/fatedier/frp/releases,展开多余版本,下载frp_0.53.2_windows_amd64.zip版本。
2、在C盘新建FRP文件夹,把压缩包以下文件放进去:
编辑frpc.toml文件,在里面写入
- serverAddr = "VPS的IP"
- serverPort = 8500
- auth.token = "QWER654321"
- [RDP]
- name = "WIN RDP"
- type = "tcp"
- localPort = 3389
- remote_port = 8600
复制代码 注意remote_port端口改成上面你VPS里匹配的。
3、测试
需要在防火墙内勾上远程桌面、远程桌面(webSocket),专用和公用网络都要。实在不会的建议关闭防火墙,用360安全卫士代替防火墙。记得把FRP添加到白名单。
电脑的远程进行设置里面也要勾上。
我们进入c:\FRP,在空白处按住shift键,然后鼠标右键,选择在此处打开 Powershell 窗口,输入:
返回
- PS C:\frp> .\frpc.exe -c frpc.toml
- 2024/01/02 22:17:56 [I] [root.go:139] start frpc service for config file [frpc.toml]
- 2024/01/02 22:17:56 [I] [service.go:299] [fd3b689ca607***] login to server success, get run id [fd3b689ca60***]
复制代码 OK,连接成功,直接关了窗口就是结束运行。
4、配置开机启动
总体思路是通过WinSW把FRP注册成服务来达到开机启动,现在先下载WinSW,https://github.com/winsw/winsw/releases,选择最新的稳定版WinSW v2.12.0,我是Win10,所以选择WinSW.NET461.exe,Win7可以选择WinSW.NET2.exe;还有配置文件sample-minimal.xml,全部下载到刚才C盘的FRP文件夹下,重命名为winsw.exe和winsw.xml。记事本打开winsw.xml,在最后写入以下内容:
- <!--
- This is an example of a minimal Windows Service Wrapper configuration, which includes only mandatory options.
-
- This configuration file should be placed near the WinSW executable, the name should be the same.
- E.g. for myapp.exe the configuration file name should be myapp.xml
-
- You can find more information about the configuration options here: https://github.com/kohsuke/winsw/blob/master/doc/xmlConfigFile.md
- Full example: https://github.com/kohsuke/winsw/blob/master/examples/sample-allOptions.xml
- -->
- <service>
- <id>FRP</id>
- <name>FRP</name>
- <description>FRP内网穿透自启动服务</description>
- <executable>frpc.exe</executable>
- <arguments>-c frpc.toml</arguments>
- <onfailure action="restart" delay="120 sec"/>
- <onfailure action="restart" delay="360 sec"/>
- <logmode>reset</logmode>
- </service>
复制代码 保存后,在FRP文件夹空白处打开Powershell 窗口,输入以下内容安装服务:
然后输入以下内容启动服务
期间如果弹出 UAC 点击允许即可,这样 frp 就被安装成系统服务在后台默默运行了。
Windows服务中可以看到已注册、已运行。
至此,我们就可以通过远程桌面连接中输入VPS的IP:8600来连接了。
参考文献:
https://sspai.com/post/60852
https://www.anidays.com/2023/74/
|
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有账号?立即注册
×
|