> For the complete documentation index, see [llms.txt](https://docs.clore.ai/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.clore.ai/guides/guides_v2-zh/you-xi-yu-chuan-liu/sunshine-moonlight.md).

# Sunshine + Moonlight 远程游戏

在 Clore.ai 的 GPU 驱动服务器上，使用 Sunshine（主机端）和 Moonlight（客户端）以接近零延迟远程串流并游玩 PC 游戏。

{% hint style="info" %}
**Sunshine** 是一个开源、自托管的游戏串流服务器，GitHub 星标超过 20,000。 **Moonlight** 是连接到它的免费开源客户端。两者结合后可与 GeForce NOW 竞争——而成本只是其一小部分。
{% endhint %}

***

## 什么是 Sunshine + Moonlight？

**Sunshine** 是原始 Moonlight/GameStream 技术栈的一个分支，现在已完全独立，并由 LizardByte 积极维护。它会捕获你的 GPU 输出，使用 H.264/H.265/AV1 实时编码，并以超低延迟通过网络串流。

**Moonlight** 是可用于 Windows、macOS、Linux、Android、iOS、Raspberry Pi，甚至部分智能电视的客户端应用。

### 为什么在 Clore.ai 上使用它？

* **租用高端 GPU** （RTX 4090、A100 等）按现货价格
* **串流 AAA 游戏** 从云端到任何设备——甚至是一台便宜的笔记本电脑
* **无需 GeForce NOW 订阅** 你就能控制硬件
* **游戏 Mod 制作、AI 辅助游玩**，或在强大硬件上进行游戏开发测试

***

## 前提条件

| 要求            | 详情                           |
| ------------- | ---------------------------- |
| Clore.ai 账户   | 在 CLORE 余额充足的情况下             |
| GPU 服务器       | 优先使用 NVIDIA GPU（用于 NVENC 编码） |
| Moonlight 客户端 | 已安装在你的本地设备上                  |
| SSH 访问        | 用于初始设置                       |

***

## 第 1 步：在 Clore.ai 上租用 GPU 服务器

1. 前往 [clore.ai](https://clore.ai) → **市场**
2. 筛选条件 **GPU 类型**：建议使用 RTX 3080 或更高配置进行 1080p/60fps 串流
3. 查找带有端口 **22**, **47990**，以及 **48010** 可用
4. 选择一台服务器并继续下单

{% hint style="warning" %}
**端口要求**：Sunshine 需要端口 47990（HTTPS Web UI）和 48010（串流）。下单前，请确保这些端口已列在服务器的可用端口中。
{% endhint %}

### 串流推荐 GPU

| 分辨率   | 目标 FPS  | 最低 GPU          |
| ----- | ------- | --------------- |
| 1080p | 60 fps  | RTX 3060        |
| 1440p | 60 fps  | RTX 3080        |
| 4K    | 60 fps  | RTX 3090 / 4080 |
| 1080p | 120 fps | RTX 4070+       |

***

## 第 2 步：通过 Docker 部署 Sunshine

### Docker Compose（推荐）

创建一个文件 `docker-compose.yml`:

```yaml
version: "3.8"

services:
  sunshine:
    image: lizardbyte/sunshine:latest
    container_name: sunshine
    restart: unless-stopped
    privileged: true
    network_mode: host
    environment:
      - PUID=1000
      - PGID=1000
      - TZ=UTC
      - SUNSHINE_USERNAME=admin
      - SUNSHINE_PASSWORD=your_secure_password
    volumes:
      - ./sunshine-config:/config
      - /tmp/.X11-unix:/tmp/.X11-unix:rw
      - /dev/dri:/dev/dri
    devices:
      - /dev/dri:/dev/dri
    deploy:
      resources:
        reservations:
          devices:
            - driver: nvidia
              count: all
              capabilities: [gpu]
```

### 启动容器

```bash
# 拉取并启动
docker compose up -d

# 检查日志
docker compose logs -f sunshine

# 验证它正在运行
docker ps | grep sunshine
```

{% hint style="success" %}
**首次启动**：Sunshine 初始化大约需要 30 秒。在继续之前，请查看日志中是否出现“Sunshine started successfully”。
{% endhint %}

### 单条 Docker 命令（快速开始）

```bash
docker run -d \\
  --name sunshine \\
  --restart unless-stopped \
  --privileged \
  --network host \
  -e SUNSHINE_USERNAME=admin \\
  -e SUNSHINE_PASSWORD=changeme \\
  -v $(pwd)/sunshine-config:/config \\
  -v /tmp/.X11-unix:/tmp/.X11-unix \\
  --device /dev/dri:/dev/dri \\
  --gpus all \\
  lizardbyte/sunshine:latest
```

***

## 第 3 步：配置 Sunshine Web UI

1. 打开浏览器并访问：

   ```
   https://<your-clore-server-ip>:47990
   ```
2. 接受自签名证书警告
3. 使用你设置的凭据登录（`admin` / `your_secure_password`)

{% hint style="warning" %}
**仅限 HTTPS**：Sunshine 的 Web UI 运行在 HTTPS 上。浏览器会显示证书警告——这是正常的。点击“高级”→“继续”即可继续。
{% endhint %}

### Web UI 部分

| 部分        | 用途                |
| --------- | ----------------- |
| **PIN 码** | 与 Moonlight 客户端配对 |
| **应用程序**  | 定义可串流的应用/游戏       |
| **配置**    | 编码器、分辨率、比特率设置     |
| **日志**    | 调试串流问题            |

***

## 第 4 步：配置编码设置

访问 **配置** → **视频** 在 Web UI 中：

### Clore.ai 推荐设置

```
# 编码器
encoder: nvenc          # 使用 NVIDIA 硬件编码

# 分辨率
resolution_width: 1920
resolution_height: 1080

# 帧率
fps: 60

# 比特率
bitrate: 50000          # 1080p60 时 50 Mbps — 画质极佳

# H.265（压缩更好，若客户端支持则使用）
codec: hevc
```

{% hint style="info" %}
**NVENC 与 VAAPI**：在 Clore.ai 的 NVIDIA 服务器上，始终使用 `nvenc` 编码器。它将编码卸载到 GPU 硬件上，释放 CPU 资源供游戏本身使用。
{% endhint %}

### 比特率指南

| 质量 | 分辨率     | 比特率       |
| -- | ------- | --------- |
| 好  | 1080p60 | 20 Mbps   |
| 很高 | 1080p60 | 35 Mbps   |
| 优秀 | 1080p60 | 50 Mbps   |
| 很高 | 1440p60 | 50 Mbps   |
| 优秀 | 4K60    | 100+ Mbps |

***

## 第 5 步：添加要串流的应用

在 Sunshine Web UI → **应用程序** → **添加新项**:

### 示例：桌面串流

```
名称：桌面
命令：（留空以使用完整桌面）
工作目录：/home/user
```

### 示例：Steam 游戏

```
名称：Steam 大屏幕模式
命令：steam -bigpicture
工作目录：/home/user
分离命令：（空）
```

### 示例：自定义游戏

```
名称：我的游戏
命令：/opt/games/mygame/start.sh
工作目录：/opt/games/mygame
图像：/opt/games/mygame/cover.png
```

***

## 第 6 步：设置虚拟显示器（无头服务器）

Clore.ai 服务器是无头的（没有物理显示器）。你需要一个虚拟显示器：

```bash
# 安装虚拟显示驱动
apt-get update && apt-get install -y xvfb x11vnc xfce4

# 创建虚拟显示器
Xvfb :1 -screen 0 1920x1080x24 &
export DISPLAY=:1

# 启动桌面环境
startxfce4 &
```

### 或者使用虚拟帧缓冲脚本

```bash
#!/bin/bash
# start-display.sh

export DISPLAY=:1

# 启动虚拟显示器
Xvfb :1 -screen 0 1920x1080x24 -ac +extension GLX +render -noreset &
sleep 2

# 启动窗口管理器
openbox &
sleep 1

# 启动 Sunshine
docker compose up -d sunshine
```

赋予可执行权限并运行：

```bash
chmod +x start-display.sh
./start-display.sh
```

{% hint style="info" %}
**没有显示器的 NVIDIA GPU**：将以下内容添加到你的 Sunshine 配置中，以便在没有物理显示器的情况下使用 GPU：

```bash
export __GL_SYNC_TO_VBLANK=0
export __GL_GSYNC_ALLOWED=0
```

{% endhint %}

***

## 第 7 步：连接 Moonlight 客户端

### 安装 Moonlight

| 平台           | 下载                                                       |
| ------------ | -------------------------------------------------------- |
| Windows      | [moonlight-stream.org](https://moonlight-stream.org)     |
| macOS        | Mac App Store 或 moonlight-stream.org                     |
| Linux        | `flatpak install flathub com.moonlight_stream.Moonlight` |
| Android      | Google Play 商店                                           |
| iOS          | App Store                                                |
| Raspberry Pi | `apt install moonlight-embedded`                         |

### 配对 Moonlight 与 Sunshine

1. 在你的本地设备上打开 Moonlight
2. 点击 **添加 PC** 并输入你的 Clore.ai 服务器 IP
3. Moonlight 会显示一个 **PIN 码**
4. 前往 Sunshine Web UI → **PIN 码** → 输入 PIN
5. 连接已建立！✅

### 获得最佳体验的 Moonlight 设置

```
分辨率：1920x1080
FPS：60
比特率：50 Mbps
视频编解码器：HEVC（H.265）
硬件解码：已启用
音频：立体声
```

***

## 第 8 步：端口转发参考

| 端口          | 协议  | 用途                   |
| ----------- | --- | -------------------- |
| 22          | TCP | SSH 管理               |
| 47984       | TCP | HTTPS（兼容 GameStream） |
| 47989       | TCP | HTTP（兼容 GameStream）  |
| 47990       | TCP | HTTPS Web UI         |
| 48010       | TCP | RTSP（流控制）            |
| 47998-48000 | UDP | 视频/音频串流              |
| 48010       | UDP | 视频串流                 |

{% hint style="warning" %}
**Clore.ai 端口映射**：下单服务器时，请确保端口 47990 和 48010 已包含在你的端口映射中。如果可能，串流用的 UDP 端口（47998-48000）也应可用。
{% endhint %}

***

## 故障排查

### Sunshine 无法启动

```bash
# 查看容器日志
docker logs sunshine --tail 50

# 常见修复：权限
chmod 777 /tmp/.X11-unix
xhost +local:docker
```

### 串流时黑屏

```bash
# 验证虚拟显示器正在运行
export DISPLAY=:1
xdpyinfo | grep dimensions

# 重启显示器
pkill Xvfb
Xvfb :1 -screen 0 1920x1080x24 &
```

### 高延迟

* 从 **Wi-Fi 切换到以太网** 在客户端一侧
* 降低 Moonlight 设置中的比特率
* 使用 **H.265** 而不是 H.264（在相同画质下压缩更好）
* 启用 **帧节奏** 在 Sunshine 配置中

### NVENC 错误：“未找到编码器”

```bash
# 验证 NVIDIA GPU 可访问
nvidia-smi

# 检查容器是否拥有 GPU 访问权限
docker exec sunshine nvidia-smi

# 如果没有，请使用 --gpus all 标志重新启动
docker stop sunshine && docker rm sunshine
# 重新使用 --gpus all 运行
```

### 身份验证/配对问题

```bash
# 重置 Sunshine 凭据
docker exec sunshine sunshine --creds admin newpassword

# 清除已配对客户端
rm -f ./sunshine-config/sunshine_state.json
docker restart sunshine
```

***

## 高级配置

### 多显示器支持

```yaml
# 在 Sunshine 配置（sunshine.conf）中
[video]
adapter_name = /dev/dri/card0
output_name = HDMI-A-1
```

### 通过网络传输音频

安装 PulseAudio 虚拟 sink：

```bash
apt-get install -y pulseaudio
pulseaudio --daemon
pactl load-module module-null-sink sink_name=virtual_sink
export PULSE_SERVER=unix:/run/user/1000/pulse/native
```

### 游戏控制器支持

Sunshine 支持虚拟手柄模拟。在配置中启用：

```yaml
[input]
gamepad = enabled
ds4_back_as_touchpad_click = disabled
```

### 局域网唤醒（用于常驻服务器）

```bash
# 即使未串流也保持服务器运行
docker update --restart=always sunshine
```

***

## 成本优化

### 计算你的串流成本

```
GPU 租用：$0.05–0.19/小时（RTX 3080）
存储：约 $0.01/小时（50GB SSD）
总计：约 $0.31–0.81/小时

对比 GeForce NOW：$9.99–$19.99/月（时长有限）
对比 Xbox Cloud Gaming：$14.99/月（游戏库有限）
```

### 省钱技巧

1. **抢占式实例**：在低峰时段使用最便宜的可用 GPU
2. **不玩游戏时暂停**：停止容器但保留卷
3. **预先安装游戏**：使用持久卷，这样你就不必每次重新下载
4. **自动关机**：添加脚本，在空闲后停止服务器

```bash
# 在 30 分钟没有 Moonlight 连接后自动关机
#!/bin/bash
while true; do
  connections=$(ss -tn | grep 47990 | wc -l)
  if [ "$connections" -eq 0 ]; then
    idle_count=$((idle_count + 1))
  else
    idle_count=0
  fi
  if [ "$idle_count" -ge 30 ]; then
    echo "30 分钟内无连接，正在关机"
    docker stop sunshine
    break
  fi
  sleep 60
done
```

***

## 安全最佳实践

{% hint style="danger" %}
**切勿在没有身份验证的情况下暴露 Sunshine！** 始终设置强密码，并考虑使用 VPN 或 SSH 隧道以获得额外安全性。
{% endhint %}

### SSH 隧道方法（最安全）

```bash
# 在你的本地机器上创建 SSH 隧道
ssh -L 47990:localhost:47990 \\
    -L 48010:localhost:48010 \\
    root@<clore-server-ip>

# 然后让 Moonlight 连接到 localhost 而不是服务器 IP
```

### 更改默认凭据

```bash
docker exec sunshine sunshine --creds admin 'Y0urStr0ngP@ssw0rd!'
```

### 按 IP 限制访问

在 Sunshine 配置中：

```
allowed_ips = 192.168.1.0/24,203.0.113.5
```

***

## 性能基准

| GPU      | 分辨率   | FPS | 延迟     | 编码器       |
| -------- | ----- | --- | ------ | --------- |
| RTX 3060 | 1080p | 60  | \~15ms | NVENC     |
| RTX 3080 | 1440p | 60  | \~12ms | NVENC     |
| RTX 4080 | 4K    | 60  | \~10ms | NVENC AV1 |
| RTX 4090 | 4K    | 120 | \~8ms  | NVENC AV1 |

*延迟是在 100 Mbps 本地网络连接下测得*

***

## 有用链接

* [Sunshine GitHub](https://github.com/LizardByte/Sunshine) — 2万+ 星标
* [Moonlight 官方网站](https://moonlight-stream.org)
* [Sunshine 文档](https://docs.lizardbyte.dev/projects/sunshine)
* [LizardByte Discord](https://discord.gg/lizardbyte)
* [Clore.ai 市场](https://clore.ai)

***

## 总结

| 步骤 | 操作                                   |
| -- | ------------------------------------ |
| 1  | 租用带有 22、47990、48010 端口的 GPU 服务器      |
| 2  | 部署 `lizardbyte/sunshine` 通过 Docker   |
| 3  | 通过以下地址的 Web 界面配置： `https://IP:47990` |
| 4  | 设置 NVENC 编码器，50 Mbps 码率              |
| 5  | 创建虚拟显示器（Xvfb）                        |
| 6  | 在本地安装 Moonlight 客户端                  |
| 7  | 使用 PIN 码配对                           |
| 8  | 开始串流并畅玩游戏！🎮                         |

在 Clore.ai 上使用 Sunshine + Moonlight，你将获得堪比任何商业服务的云游戏体验——同时完全掌控你的硬件和游戏。无需订阅，没有限制，也没有上限。

***

## Clore.ai GPU 推荐

| 使用场景           | 推荐 GPU         | Clore.ai 预计成本     |
| -------------- | -------------- | ----------------- |
| 1080p/60fps 串流 | RTX 3090（24GB） | $0.07–0.21/gpu/hr |
| 4K/高刷新率串流      | RTX 4090（24GB） | $0.14–0.42/gpu/hr |
| 3A 游戏 + 串流     | RTX 4090（24GB） | $0.14–0.42/gpu/hr |

> 💡 本指南中的所有示例都可以部署在 [Clore.ai](https://clore.ai/marketplace) GPU 服务器上。浏览可用 GPU 并按小时租用——无需承诺，拥有完整 root 访问权限。


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.clore.ai/guides/guides_v2-zh/you-xi-yu-chuan-liu/sunshine-moonlight.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
