Skip to content

Commit 2b4688a

Browse files
committed
add moonlight-10054-fix
1 parent 84d63eb commit 2b4688a

File tree

1 file changed

+151
-0
lines changed

1 file changed

+151
-0
lines changed

content/posts/moonlight-10054-fix.md

Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
1+
---
2+
title: 记一次 Moonlight 10054 错误的解决经历
3+
date: 2023-12-29
4+
description: "记一次 Moonlight 10054 错误的解决经历"
5+
layout: post
6+
7+
tags:
8+
- 串流
9+
- Sunshine
10+
- Moonlight
11+
categories:
12+
- Linux
13+
- 串流
14+
lightgallery: true
15+
16+
toc:
17+
auto: true
18+
---
19+
20+
## 1. 起因
21+
22+
最近看到很多 Linux 平铺窗口管理器的视频,总觉得很炫酷,体内的折腾之心在沸腾,于是就打起了体验(~~折腾~~)平铺窗口的想法,看到这里各位看官肯定要说:这和 `Moonlight` 串流有啥关系,标题党!辣鸡!
23+
24+
_哈哈,各位别急,且听我慢慢道来_
25+
26+
首先,我主力的生产系统是 Windows ,我不想在 Windows 下开发,所以 Windows 平铺窗口就 pass 掉了,只能转向 Linux,正好公司一台 `Exsi` 主机还剩很多资源,并且还有一块 `GTX 1060` 的显卡可以用来直通加速,那不正好创建一个带显卡的虚拟机,运行 Linux 桌面,然后我再远程串流这台虚拟机不就行了吗,那串流体验最好的自然是 Moonlight 了, 诶,你看,这不就关联大了吗!
27+
28+
## 2. 环境
29+
30+
好吧,废话少说,我描述一下我的环境,我要远程串流的是一台 `Exsi` 创建的虚拟机,参数如下:
31+
32+
| 项目 || 备注 |
33+
| --- | --- | --- |
34+
| 系统 | Arch Linux | |
35+
| CPU | 8 vCPU | 宿主机 CPU 为 AMD Ryzen Threadripper 1950X |
36+
| RAM | 8GB | |
37+
| GPU | NVIDIA GeForce GTX 1060 6GB | 显卡直通 |
38+
| 显示器 || |
39+
| 远程串流服务 | [Sunshine v0.21.0](https://github.com/LizardByte/Sunshine) | |
40+
| 显示服务 | X11 | |
41+
| 窗口管理器 | [awesome](https://awesomewm.org/download/) | |
42+
| Windows 客户端 | Moonlight-qt | |
43+
44+
### 2.1 串流设置
45+
46+
按照 [官网headless系统设置](https://docs.lizardbyte.dev/projects/sunshine/en/latest/about/guides/linux/headless_ssh.html) 的指引,我安装好了 `nvidia` 的专有驱动,驱动能成功识别显卡,设置好了一个虚拟显示器并且成功运行了 `Xorg`
47+
48+
![image.png](https://img.linkzz.eu.org/main/images/2023/12/6a94fb1e495e0fc2ed5d7f4ca50a6953.png)
49+
50+
## 3. 排查
51+
52+
`x11vnc` 可以访问桌面,并且 `awesome` 工作正常,`rustdesk` 可以访问并且能开启硬件编码。
53+
54+
![image.png](https://img.linkzz.eu.org/main/images/2023/12/dacb17272df216d17a54faba327fc616.png)
55+
56+
唯独 `sunshine` 连接不上,启动日志显示硬件编码工作正常
57+
58+
![image.png](https://img.linkzz.eu.org/main/images/2023/12/89cbdf1362de2e5a05ece963169e603c.png)
59+
60+
Moonlight客户端可以正常添加和配对串流主机,但在启动【Desktop】串流之后总会报错:
61+
62+
```text
63+
启动 RTSP handshake 失败: 错误 10054
64+
检查防火墙和端口转发规则: TCP 48010,UDP 48000,UDP 48010
65+
```
66+
67+
按照以上提示检测端口连通性,因为我和串流主机都在内网环境,我的客户端是 Windows 系统,防火墙已经关掉了,而串流的 Archlinux 是没有装防火墙服务的,所以不存在防火墙挡掉端口的问题,果然,使用 `nc` 测试端口连通:
68+
69+
```bash
70+
~ nc -v 10.1.1.63 48010
71+
Connection to 10.1.1.63 48010 port [tcp/*] succeeded!
72+
```
73+
74+
UDP 的端口只有在串流的过程中才会打开监听,所以没法直接测试,但是通过手动端口监听测试也证明 UDP 端口也是没有被防火墙挡掉的。
75+
76+
```bash
77+
# 服务端监听 udp 48010
78+
~ nc -lu -p 48010
79+
80+
# 客户端连接
81+
~ nc -uv 10.1.1.63 48010
82+
Connection to 10.1.1.63 48010 port [udp/*] succeeded!
83+
```
84+
85+
查看 sunshine 的详细连接日志发现执行 desktop 之后 sunshine 接收到了一个 rtsp 的 Request,sequence 是1,之后就客户端就退出报错了。
86+
87+
```log
88+
[2023:12:29:17:03:29]: Debug: ------ h264 ------
89+
[2023:12:29:17:03:29]: Debug: PASSED: supported
90+
[2023:12:29:17:03:29]: Debug: REF_FRAMES_RESTRICT: unsupported
91+
[2023:12:29:17:03:29]: Debug: CBR: supported
92+
[2023:12:29:17:03:29]: Debug: DYNAMIC_RANGE: unsupported
93+
[2023:12:29:17:03:29]: Debug: VUI_PARAMETERS: supported
94+
[2023:12:29:17:03:29]: Debug: -------------------
95+
[2023:12:29:17:03:29]: Info: Found H.264 encoder: h264_nvenc [nvenc]
96+
[2023:12:29:17:03:29]: Debug: ------ hevc ------
97+
[2023:12:29:17:03:29]: Debug: PASSED: supported
98+
[2023:12:29:17:03:29]: Debug: REF_FRAMES_RESTRICT: unsupported
99+
[2023:12:29:17:03:29]: Debug: CBR: supported
100+
[2023:12:29:17:03:29]: Debug: DYNAMIC_RANGE: unsupported
101+
[2023:12:29:17:03:29]: Debug: VUI_PARAMETERS: supported
102+
[2023:12:29:17:03:29]: Debug: -------------------
103+
[2023:12:29:17:03:29]: Info: Found HEVC encoder: hevc_nvenc [nvenc]
104+
[2023:12:29:17:03:29]: Debug: /CN=NVIDIA GameStream Client -- verified
105+
[2023:12:29:17:03:29]: Debug: TUNNEL :: HTTPS
106+
[2023:12:29:17:03:29]: Debug: METHOD :: GET
107+
[2023:12:29:17:03:29]: Debug: DESTINATION :: /serverinfo
108+
[2023:12:29:17:03:29]: Debug: User-Agent -- Mozilla/5.0
109+
[2023:12:29:17:03:29]: Debug: Accept-Language -- zh-CN,en,*
110+
[2023:12:29:17:03:29]: Debug: Accept-Encoding -- gzip, deflate
111+
[2023:12:29:17:03:29]: Debug: Connection -- Keep-Alive
112+
[2023:12:29:17:03:29]: Debug: Host -- 10.1.1.63:47984
113+
[2023:12:29:17:03:29]: Debug: [--]
114+
[2023:12:29:17:03:29]: Debug: uuid -- d63f79a098fb43e199209d93b001b333
115+
[2023:12:29:17:03:29]: Debug: uniqueid -- 0123456789ABCDEF
116+
[2023:12:29:17:03:29]: Debug: [--]
117+
[2023:12:29:17:03:29]: Debug: handle_read(): Handle read of size: 93 bytes
118+
[2023:12:29:17:03:29]: Debug: handle_payload(): Handle read of size: 0 bytes
119+
[2023:12:29:17:03:29]: Debug: type [REQUEST]
120+
[2023:12:29:17:03:29]: Debug: sequence number [1]
121+
[2023:12:29:17:03:29]: Debug: protocol :: RTSP/1.0
122+
[2023:12:29:17:03:29]: Debug: payload ::
123+
[2023:12:29:17:03:29]: Debug: command :: OPTIONS
124+
[2023:12:29:17:03:29]: Debug: target :: rtsp://10.1.1.63:48010
125+
[2023:12:29:17:03:29]: Debug: CSeq :: 1
126+
[2023:12:29:17:03:29]: Debug: X-GS-ClientVersion :: 14
127+
[2023:12:29:17:03:29]: Debug: Host :: 10.1.1.63
128+
[2023:12:29:17:03:29]: Debug: ---Begin MessageBuffer---
129+
OPTIONS
130+
---End MessageBuffer---
131+
[2023:12:29:17:03:29]: Debug: ---Begin Response---
132+
RTSP/1.0 200 OK
133+
CSeq: 1
134+
135+
136+
137+
---End Response---
138+
[2023:12:29:17:03:32]: Debug: TUNNEL :: NONE
139+
```
140+
141+
这就是问题的所在,说明客户端很可能没收到这个Sequence为1的应答,导致双方连接不上,并不是因为硬件编码的问题,也不是防火墙的问题,更不是 `X11` 显示系统的问题。
142+
143+
那是什么问题呢,我看着 `RTSP` 陷入了沉思,联想到各大网络直播多是使用的 `RTSP` 协议推流,该不会是 IT 禁用了该协议吧,**果然,公司上班时间是无法观看直播网站的,直播推流的流也是拉取不到的!**
144+
145+
事已至此,一切都真相大白了,**公司用的是深信服的网络行为管理,老板为了省钱IT是外包的,一周来一次,平时接触不到,没想到这个策略的设置如此简单粗暴,内网的RTSP协议都给禁掉了,那开发如果用到该协议推流,我估计光是排查问题就得浪费半天时间吧,哎,结合到最近各大互联网公司频发的运维事故我只想说:降本增效害死人!**
146+
147+
## 4. 解决问题
148+
149+
既然知道问题发生的原因了,解决就好办了,既然直连的 `RTSP` 协议不行,我通过 VPN 开个隧道总可以了吧。果然,通过 wireguard 建立隧道之后一切问题解决,串流成功,不得不感叹 Moolight 和 Sunshine 项目做的真是完美,低延迟,高性能,画质还不差,体验秒杀前面的 VNC 和 rustdesk,接下来继续我的平铺窗口管理器之旅了,Awesome !
150+
151+
![image.png](https://img.linkzz.eu.org/main/images/2023/12/f3eddc820e2eb71018cff4b5991799db.png)

0 commit comments

Comments
 (0)