Unreal Engine 像素流送在 g4dn 上实现容器化部署实践(一)

0
0
{"value":"Unreal Engine/ 虚幻引擎(以下简称UE)是 Epic Games 公司的游戏引擎产品,Epic Games 使用该引擎开发了 “堡垒之夜”, “战争机器”等多款游戏,该引擎也被众多游戏开发商、工作室采用,如 “最终幻想7重制版:Intergrade”, “荣誉勋章:超越巅峰”, “绝地求生”等游戏, 除了游戏以外UE引擎还被用于广泛用于影视、建筑、数字孪生领域。\n\n本系列文章将会分为 2 个篇章来系统地介绍 UE4 像素流送在 Amazon g4dn 实例上的容器化部署方案, 在第 1 章我们会从头讲解如何在 g4dn 实例上安装并编译 UE4 项目,构建docker 镜像, 并且通过 docker-compose 实现多项目共享 Nvidia Tesla T4 GPU 进行像素流推送。第 2 章我们会讲解如何在 Amazon Elastic Kuberntes Service 上使用 g4dn 部署一套可弹性伸缩的 UE4 像素推流平台。\n\n本文分为如下几个部分:\n\n1. 安装 UE 4.27, 创建像素流送演示项目\n2. 使用 g4dn 实例 Linux 环境编译 UE4 演示项目,构建演示项目的 docker image\n3. 在 g4dn 实例上使用 docker-compose 部署 STUN/TURN 服务器, Signaling Server, UE4 演示项目\n4. 通过浏览器/移动终端访问 UE4 演示项目\n\n### **1. 安装UE 4.27, 创建像素流送演示项目**\n\n在开始之前,我们必须做好如下几件准备工作。\n\n- 请准备 Epic Games 官方用户账号, Github 账号, 下载 UE4 和 UE4 container 需要这些账号。\n- 创建 g4dn 类型创建 Windows EC2 实例, 安装 UE4,并创建像素流送演示项目(可选)。\n- 创建 g4dn Linux EC2 实例,编译演示项目,构建 docker image\n\n#### **1.1 创建 g4dn.xlarge windows 主机**\n\n- “应用程序和操作系统映像”选择 Microsoft Windows Server 2019 Base/Microsoft Windows Server 2019 with NVIDIA GRID Driver \n- “”实例类型””从默认 micro 修改为 g4dn.xlarge\n- 设置密钥对,不然无法获取 Windows 管理员密码\n- 网络设置为公有子网,分配公有IP\n- 选择自动创建新安全组\n- 存储设置为 100GB\n\n以上配置完了后,请核对摘要信息,并点击启动实例:\n\n![image.png](https://dev-media.amazoncloud.cn/df63b67caceb49258f007951b15419c7_image.png)\n\n#### **1.2 连接 Windows 主机,安装 Amazon CLI 命令行工具, Nvidia Grid Driver**\n\n选择实例,点击连接,点击 RDP 客户端, 上传自己的私钥后就可以看见 windows 连接密码\n\n![image.png](https://dev-media.amazoncloud.cn/d55adf450d024a71a2d6f18ef4c6a685_image.png)\n\n使用 RDP 客户端连接 EC2 实例,作者使用的是 Microsoft Remote Desktop on Mac.\n\nWindows server 自带的 IE 有很多限制,所以我们首先使用 Powershell 安装 chrome 浏览器。\n\n```\\n\$Path = \$env:TEMP; \$Installer = \\"chrome_installer.exe\\"; Invoke-WebRequest \\"http://dl.google.com/chrome/install/375.126/chrome_installer.exe\\" -OutFile \$Path\\\\\$Installer; Start-Process -FilePath \$Path\\\\\$Installer -Args \\"/silent /install\\" -Verb RunAs -Wait; Remove-Item \$Path\\\\\$Installer\\n```\n\n![image.png](https://dev-media.amazoncloud.cn/74bf4aabe67b437989df87a7b357666f_image.png)\n\n安装完后桌面会出现 chrome 图标\n\n复制以下 PowerShell 代码下载 Nvida Grid Driver\n\n```\\n\$Bucket = \\"ec2-windows-nvidia-drivers\\"\\n\$KeyPrefix = \\"latest\\"\\n\$LocalPath = \\"\$home\\\\Desktop\\\\NVIDIA\\"\\n\$Objects = Get-S3Object -BucketName \$Bucket -KeyPrefix \$KeyPrefix -Region us-east-1\\nforeach (\$Object in \$Objects) {\\n \$LocalFileName = \$Object.Key\\n if (\$LocalFileName -ne '' -and \$Object.Size -ne 0) {\\n \$LocalFilePath = Join-Path \$LocalPath \$LocalFileName\\n Copy-S3Object -BucketName \$Bucket -Key \$Object.Key -LocalFile \$LocalFilePath -Region us-east-1\\n }\\n}\\n```\n\n运行完成后会在桌面生成一个 NVIDIA 目录,里面有 2 个 exe 文件,我们选择运行\n\n511.65_grid_win10_win11_server2016_server2019_server2022_64bit_aws_swl.exe 即可完成驱动安装\n\n![image.png](https://dev-media.amazoncloud.cn/8db0cfe7b89b43559314f207de76cdd1_image.png)\n\n#### **1.3 安装UE4, 创建演示项目**\n\n首先在 Epic Game 官网下载 Epic Games Launche, 通过 Launcher 可以安装各个版本的 Unreal Engine,我们这里安装的版本是 4.27.2。\n\n项目选择”游戏”, 模版选”“第一人称”, 取名为” MyFirstPersonProject ” , 选择蓝图,创建该项目 ws\n\n![image.png](https://dev-media.amazoncloud.cn/71df1b910bbe4014ab65e5017fc7cac6_image.png)\n\n![image.png](https://dev-media.amazoncloud.cn/419b9ce38735413bb4899059b6f950cb_image.png)\n\n选择蓝图,取名为” MyFirstPersonProject ” (请注意不要使用中文),创建项目即可\n\n![image.png](https://dev-media.amazoncloud.cn/4e43c9fdeae34536b6d8f8113510a96d_image.png)\n\n![image.png](https://dev-media.amazoncloud.cn/34d212b1d5ec4b22aacbd0eab05eb93e_image.png)\n\n启用项目, 然后点击编辑>插件\n\n![image.png](https://dev-media.amazoncloud.cn/b24aa439fdc14648ab704f299608236d_image.png)\n\n选择” Graphics ” 启用 Pixel Streaming 插件,并重启编辑器\n\n![image.png](https://dev-media.amazoncloud.cn/7ce9947490b64ae1ab0a068624348de8_image.png)\n\n测试\n\n![image.png](https://dev-media.amazoncloud.cn/83f40acf9c8e4df7a975fb19ab4cd000_image.png)\n\n### **2. 在 g4dn Linux EC2 上编译演示项目并构建 docker image**\n\n#### **2.1 创建一台 g4dn.xlarge Linux EC2 实例**\n\n注意系统映像请选择 Deep Learning Base AMI , 这样需要的 Nvidia CUDA, Nvidia-Docker 都已经自动安装好了\n\n![image.png](https://dev-media.amazoncloud.cn/65cddf3cc38740e99ad8b21dfe8df08a_image.png)\n\n摘要如下:\n\n![image.png](https://dev-media.amazoncloud.cn/9c7cf2e1368d43ec8d4cc2d9ade3488c_image.png)\n\n使用 nivida-sim 检查驱动\n\n![image.png](https://dev-media.amazoncloud.cn/34308476457b4ab4b2ea73fd1a53cd8d_image.png)\n\n#### **2.2 在 Epic Games 网站上关联 GitHub 账号**\n\nEpic Games 提供官方的基础镜像 ,但是需要使用者加入 Epic Games github 组织, 具体详细的操作方法请参考 [Epic Games 官方文档](https://www.unrealengine.com/zh-CN/ue4-on-github?lang=zh-CN&sessionInvalidated=true)\n\n登录到Epic Games 网站\n\n![image.png](https://dev-media.amazoncloud.cn/892598f095cd44078712d7ceaf422e19_image.png)\n\n在 Epic Games 网站关联你的 github 账号\n\n![image.png](https://dev-media.amazoncloud.cn/7d41531034e54412aa0b30e295e06a38_image.png)\n\n成功后即可访问 Epic Games 的私有仓库\n\n![image.png](https://dev-media.amazoncloud.cn/d0ab25c5a4a143f4ab335f3f2e287715_image.png)\n\n#### **2.3 编译演示项目、构建docker image**\n\n```\\n#使用github ACCESS_TOKEN登陆ghcr.io仓库\\necho <github ACCESS_TOKEN> | docker login ghcr.io -u <github 账号邮箱> --password-stdin\\n\\n#测试是否可以正常访问Epic Games 基础container image\\ndocker pull ghcr.io/epicgames/unreal-engine:dev-4.27\\n```\n\n在 g4dn EC2 实例上克隆 github 代码仓库,里面包含了 Dockerfile, docker-compose.yml, tools.sh\n\n```\\ngit clone https://github.com/stevensu1977/UE4-PixelStreaming-Container.git\\n```\n\n查看 docker file\n\n```\\n# ---------------------------------------------------------------------------\\n# Copyright (c) 2022 Su Wei/wsuam@amazon.com and/or its affiliates. All rights reserved.\\n# MIT License\\n# Permission is hereby granted, free of charge, to any person obtaining a copy\\n# of this software and associated documentation files (the \\"Software\\"), to deal\\n# in the Software without restriction, including without limitation the rights\\n# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\\n# copies of the Software, and to permit persons to whom the Software is\\n# furnished to do so, subject to the following conditions:\\n#\\n# The above copyright notice and this permission notice shall be included in all\\n# copies or substantial portions of the Software.\\n#\\n# THE SOFTWARE IS PROVIDED \\"AS IS\\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\\n# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\\n# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\\n# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\\n# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\\n# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\\n# SOFTWARE.\\n# ---------------------------------------------------------------------------\\n\\n# Perform the build in an Unreal Engine container image that includes the Engine Tools and Pixel Streaming for Linux\\nFROM ghcr.io/epicgames/unreal-engine:dev-4.27 as builder\\n\\n# Clone the source code for the example Unreal project\\nRUN mkdir /tmp/github\\nRUN git clone --progress --depth=1 'https://github.com/stevensu1977/UE4-PixelStreaming-demo.git' /tmp/github\\nRUN mv /tmp/github/FirstPersonProject/* /tmp/project\\n\\n\\n# Package the example Unreal project\\nRUN /home/ue4/UnrealEngine/Engine/Build/BatchFiles/RunUAT.sh BuildCookRun \\\\\\n -clientconfig=Development -serverconfig=Development \\\\\\n -project=/tmp/project/FirstPersonProject.uproject \\\\\\n -utf8output -nodebuginfo -allmaps -noP4 -cook -build -stage -prereqs -pak -archive \\\\\\n -archivedirectory=/tmp/project/dist \\\\\\n -platform=Linux\\n\\n# Copy the packaged project into the Pixel Streaming runtime image\\nFROM ghcr.io/epicgames/unreal-engine:runtime-pixel-streaming\\nCOPY --from=builder --chown=ue4:ue4 /tmp/project/dist/LinuxNoEditor /home/ue4/project\\n\\n\\n# Set the project as the container's entrypoint\\nENTRYPOINT [\\"/home/ue4/project/FirstPersonProject.sh\\", \\"-RenderOffscreen\\", \\"-RenderOffscreen\\", \\"-AllowPixelStreamingCommands\\" ,\\"-PixelStreamingHideCursor\\" ,\\"-PixelStreamingWebRTCMaxFps=30\\", \\"-PixelStreamingWebRTCDisableReceiveAudio\\",\\"-FullStdOutLogOutput\\", \\"-ForceRes\\", \\"-ResX=1920\\", \\"-ResY=1080\\"]\\n```\n\n使用 tools.sh 构建 docker 镜像\n\n#代码仓库提供了一个辅助工具 tools.sh 也可以使用它来构建、启动、停止 docker-compose\n#使用./tools build 脚本会生成一个” pixelstreaming-demo ”的 docker image.\n./tools.sh build\n\n![image.png](https://dev-media.amazoncloud.cn/f983f5b130044e4dbee4498b28ebc0b6_image.png)\n\n### **3. 编写 docker-compose 文件**\n在步骤 2 我们成功的构建了演示项目的 docker 镜像 , 接下来我们会使用 docker-compose 根据官方像素流送架构来编排 TURN/STUN server, signalling server, 演示项目,实现一键启动。\n\nEpic Games 官方像素流送架构参考图:\n\n![image.png](https://dev-media.amazoncloud.cn/0d41ac9a7dac4360bbc1713a0545b157_image.png)\n\n3.1 docker-compose 版本需要 1.27 以上才支持 nvidia GPU ,首先安装 docker-compose 1.29.2\n\n```\\nsudo curl -L \\"https://github.com/docker/compose/releases/download/1.29.2/docker-compose-\$(uname -s)-\$(uname -m)\\" -o /usr/local/bin/docker-compose\\n```\n\n查看代码仓库的 docker-compose.yml\n\n```\\nversion: \\"3\\"\\nservices:\\n \\n # The WebRTC TURN server (note that you will need TCP and UDP ports 3478 and 49152-65535 exposed for TURN relaying to function correctly)\\n turnserver:\\n image: \\"coturn/coturn:4.5.2\\"\\n network_mode: \\"host\\"\\n command: [\\"-a\\", \\"-v\\", \\"-n\\", \\"-u\\", \\"user:password\\", \\"-p\\", \\"\${TURN_PORT}\\", \\"-r\\", \\"default-realm\\", \\"--no-dtls\\", \\"--no-tls\\"]\\n \\n # The Cirrus signalling server\\n signalling:\\n image: \\"ghcr.io/epicgames/pixel-streaming-signalling-server:4.27\\"\\n network_mode: \\"host\\"\\n command:\\n - \\"--publicIp=\${PUBLIC_IP}\\"\\n - \\"--HttpPort=\${HTTP_PORT}\\"\\n - \\"--StreamerPort=\${STREAMER_PORT}\\"\\n - >-\\n --peerConnectionOptions={\\n \\"iceServers\\":[\\n {\\n \\"urls\\": [\\"turn:\${PUBLIC_IP}:\${TURN_PORT}\\"],\\n \\"username\\": \\"user\\",\\n \\"credential\\": \\"password\\"\\n }\\n ]\\n \${EXTRA_PEERCONNECTION_OPTIONS}\\n }\\n depends_on:\\n - turnserver\\n \\n # The Pixel Streaming demo project\\n project:\\n image: \\"pixelstreaming-demo\\"\\n network_mode: \\"host\\"\\n command:\\n - \\"-PixelStreamingURL=ws://127.0.0.1:\${STREAMER_PORT}\\"\\n \\n depends_on:\\n - signalling\\n \\n deploy:\\n resources:\\n reservations:\\n devices:\\n - driver: nvidia\\n capabilities: [gpu]\\n count: 1\\n```\n\n### **4. 测试**\n通过代码仓库的 tools.sh 可以启动多个监听不同端口的演示项目\n\n启动演示项目,命令会输出访问端口\n\n```./tools.sh start ```\n\n![image.png](https://dev-media.amazoncloud.cn/649c12194a3949d7b34c2d28f6901d6f_image.png)\n\n通过电脑浏览器和手机可以正常访问\n\n![image.png](https://dev-media.amazoncloud.cn/a6028a9ef2d24ad98c9f0d8c4f3e74fc_image.png)\n\n![image.png](https://dev-media.amazoncloud.cn/c7ef418e32db489384b56ab4dde890e6_image.png)\n\n启动多个游戏\n\n```\\nPROJECT_NAME=\\"DEMO01\\" ./tools.sh start 10001 3578 8888\\nPROJECT_NAME=\\"DEMO02\\" ./tools.sh start 10002 3579 8889\\nPROJECT_NAME=\\"DEMO03\\" ./tools.sh start 10003 3580 8899\\n```\n\n如果启动成功会出现以下信息,通过显示的地址/端口使用浏览器访问即可\n\n![image.png](https://dev-media.amazoncloud.cn/a7dc29ead5594bfa8e21d1bd3d70b7d0_image.png)\n\n使用 nvidia-smi 查看 GPU 信息, 会显示 3 个进程已经共享 GPU\n\n![image.png](https://dev-media.amazoncloud.cn/65e54b8e6b414f48aa887e872dd2a3ac_image.png)\n\n停止游戏演示\n\n```\\n#单游戏实例\\n./tools.sh stop\\n\\n#多游戏实例\\nPROJECT_NAME=\\"DEMO01\\" ./tools.sh stop\\nPROJECT_NAME=\\"DEMO02\\" ./tools.sh stop\\nPROJECT_NAME=\\"DEMO03\\" ./tools.sh stop\\n```\n\n### **5.总结**\n\n本文详细地介绍了如何在亚马逊云上使用 EC2 g4dn 实例实现 UE4 项目的编译,打包,并且通过 docker-compose 进行本地化部署,在下一个章节我们将会介绍如何在 [Amazon Elastic Kubernetes Service](https://aws.amazon.com/cn/eks/?trk=cndc-detail)(EKS)上部署 UE4 像素流推送平台。\n\n### **参考文档、资源**\n\n- [Unreal Engine 官方像素流送文档](https://docs.unrealengine.com/4.27/en-US/SharingAndReleasing/PixelStreaming/)\n- [docker-compose 配置文档](https://docs.docker.com/compose/)\n- [Amazon EC2 G4 文档](https://aws.amazon.com/cn/ec2/instance-types/g4/)\n\n### **本篇作者**\n\n![image.png](https://dev-media.amazoncloud.cn/df1c858dc9964a4ea00ea2e5058c6364_image.png)\n\n#### **粟伟**\n\nAmazon 资深解决方案架构师,专注游戏行业, 开源项目爱好者,致力于云原生应用推广、落地。具有 15 年以上的信息技术行业专业经验,担任过高级软件工程师,系统架构师等职位,在加入 Amazon 之前曾就职于 Bea, Oracle, IBM 等公司。\n\n![image.png](https://dev-media.amazoncloud.cn/53fb5ae12787406ab27f4515a658ad75_image.png)\n\n#### **贺杨**\n\nAmazon 解决方案架构师,具备 17 年 IT 专业服务经验,工作中担任过研发、开发经理、解决方案架构师等多种角色。在加入 Amazon 前,拥有多年外企研发和售前架构经验,在传统企业架构和中间件解决方案有深入的理解和丰富的实践经验。\n\n![image.png](https://dev-media.amazoncloud.cn/b592160284df41468faa946d94d83c1e_image.png)\n\n#### **白鹤**\n\n教授级高级工程师,亚马逊云科技媒体行业资深解决方案架构师,重点从事融合媒体系统、内容制作平台、超高清编码云原生能力等方面架构设计工作,在围绕媒体数字化转型的多个领域有丰富的实践经验。","render":"<p>Unreal Engine/ 虚幻引擎(以下简称UE)是 Epic Games 公司的游戏引擎产品,Epic Games 使用该引擎开发了 “堡垒之夜”, “战争机器”等多款游戏,该引擎也被众多游戏开发商、工作室采用,如 “最终幻想7重制版:Intergrade”, “荣誉勋章:超越巅峰”, “绝地求生”等游戏, 除了游戏以外UE引擎还被用于广泛用于影视、建筑、数字孪生领域。</p>\n<p>本系列文章将会分为 2 个篇章来系统地介绍 UE4 像素流送在 Amazon g4dn 实例上的容器化部署方案, 在第 1 章我们会从头讲解如何在 g4dn 实例上安装并编译 UE4 项目,构建docker 镜像, 并且通过 docker-compose 实现多项目共享 Nvidia Tesla T4 GPU 进行像素流推送。第 2 章我们会讲解如何在 Amazon Elastic Kuberntes Service 上使用 g4dn 部署一套可弹性伸缩的 UE4 像素推流平台。</p>\n<p>本文分为如下几个部分:</p>\n<ol>\\n<li>安装 UE 4.27, 创建像素流送演示项目</li>\n<li>使用 g4dn 实例 Linux 环境编译 UE4 演示项目,构建演示项目的 docker image</li>\n<li>在 g4dn 实例上使用 docker-compose 部署 STUN/TURN 服务器, Signaling Server, UE4 演示项目</li>\n<li>通过浏览器/移动终端访问 UE4 演示项目</li>\n</ol>\\n<h3><a id=\\"1_UE_427__11\\"></a><strong>1. 安装UE 4.27, 创建像素流送演示项目</strong></h3>\\n<p>在开始之前,我们必须做好如下几件准备工作。</p>\n<ul>\\n<li>请准备 Epic Games 官方用户账号, Github 账号, 下载 UE4 和 UE4 container 需要这些账号。</li>\n<li>创建 g4dn 类型创建 Windows EC2 实例, 安装 UE4,并创建像素流送演示项目(可选)。</li>\n<li>创建 g4dn Linux EC2 实例,编译演示项目,构建 docker image</li>\n</ul>\\n<h4><a id=\\"11__g4dnxlarge_windows__19\\"></a><strong>1.1 创建 g4dn.xlarge windows 主机</strong></h4>\\n<ul>\\n<li>“应用程序和操作系统映像”选择 Microsoft Windows Server 2019 Base/Microsoft Windows Server 2019 with NVIDIA GRID Driver</li>\n<li>“”实例类型””从默认 micro 修改为 g4dn.xlarge</li>\n<li>设置密钥对,不然无法获取 Windows 管理员密码</li>\n<li>网络设置为公有子网,分配公有IP</li>\n<li>选择自动创建新安全组</li>\n<li>存储设置为 100GB</li>\n</ul>\\n<p>以上配置完了后,请核对摘要信息,并点击启动实例:</p>\n<p><img src=\\"https://dev-media.amazoncloud.cn/df63b67caceb49258f007951b15419c7_image.png\\" alt=\\"image.png\\" /></p>\n<h4><a id=\\"12__Windows__Amazon_CLI__Nvidia_Grid_Driver_32\\"></a><strong>1.2 连接 Windows 主机,安装 Amazon CLI 命令行工具, Nvidia Grid Driver</strong></h4>\\n<p>选择实例,点击连接,点击 RDP 客户端, 上传自己的私钥后就可以看见 windows 连接密码</p>\n<p><img src=\\"https://dev-media.amazoncloud.cn/d55adf450d024a71a2d6f18ef4c6a685_image.png\\" alt=\\"image.png\\" /></p>\n<p>使用 RDP 客户端连接 EC2 实例,作者使用的是 Microsoft Remote Desktop on Mac.</p>\n<p>Windows server 自带的 IE 有很多限制,所以我们首先使用 Powershell 安装 chrome 浏览器。</p>\n<pre><code class=\\"lang-\\">\$Path = \$env:TEMP; \$Installer = &quot;chrome_installer.exe&quot;; Invoke-WebRequest &quot;http://dl.google.com/chrome/install/375.126/chrome_installer.exe&quot; -OutFile \$Path\\\\\$Installer; Start-Process -FilePath \$Path\\\\\$Installer -Args &quot;/silent /install&quot; -Verb RunAs -Wait; Remove-Item \$Path\\\\\$Installer\\n</code></pre>\\n<p><img src=\\"https://dev-media.amazoncloud.cn/74bf4aabe67b437989df87a7b357666f_image.png\\" alt=\\"image.png\\" /></p>\n<p>安装完后桌面会出现 chrome 图标</p>\n<p>复制以下 PowerShell 代码下载 Nvida Grid Driver</p>\n<pre><code class=\\"lang-\\">\$Bucket = &quot;ec2-windows-nvidia-drivers&quot;\\n\$KeyPrefix = &quot;latest&quot;\\n\$LocalPath = &quot;\$home\\\\Desktop\\\\NVIDIA&quot;\\n\$Objects = Get-S3Object -BucketName \$Bucket -KeyPrefix \$KeyPrefix -Region us-east-1\\nforeach (\$Object in \$Objects) {\\n \$LocalFileName = \$Object.Key\\n if (\$LocalFileName -ne '' -and \$Object.Size -ne 0) {\\n \$LocalFilePath = Join-Path \$LocalPath \$LocalFileName\\n Copy-S3Object -BucketName \$Bucket -Key \$Object.Key -LocalFile \$LocalFilePath -Region us-east-1\\n }\\n}\\n</code></pre>\\n<p>运行完成后会在桌面生成一个 NVIDIA 目录,里面有 2 个 exe 文件,我们选择运行</p>\n<p>511.65_grid_win10_win11_server2016_server2019_server2022_64bit_aws_swl.exe 即可完成驱动安装</p>\n<p><img src=\\"https://dev-media.amazoncloud.cn/8db0cfe7b89b43559314f207de76cdd1_image.png\\" alt=\\"image.png\\" /></p>\n<h4><a id=\\"13_UE4__72\\"></a><strong>1.3 安装UE4, 创建演示项目</strong></h4>\\n<p>首先在 Epic Game 官网下载 Epic Games Launche, 通过 Launcher 可以安装各个版本的 Unreal Engine,我们这里安装的版本是 4.27.2。</p>\n<p>项目选择”游戏”, 模版选”“第一人称”, 取名为” MyFirstPersonProject ” , 选择蓝图,创建该项目 ws</p>\n<p><img src=\\"https://dev-media.amazoncloud.cn/71df1b910bbe4014ab65e5017fc7cac6_image.png\\" alt=\\"image.png\\" /></p>\n<p><img src=\\"https://dev-media.amazoncloud.cn/419b9ce38735413bb4899059b6f950cb_image.png\\" alt=\\"image.png\\" /></p>\n<p>选择蓝图,取名为” MyFirstPersonProject ” (请注意不要使用中文),创建项目即可</p>\n<p><img src=\\"https://dev-media.amazoncloud.cn/4e43c9fdeae34536b6d8f8113510a96d_image.png\\" alt=\\"image.png\\" /></p>\n<p><img src=\\"https://dev-media.amazoncloud.cn/34d212b1d5ec4b22aacbd0eab05eb93e_image.png\\" alt=\\"image.png\\" /></p>\n<p>启用项目, 然后点击编辑&gt;插件</p>\n<p><img src=\\"https://dev-media.amazoncloud.cn/b24aa439fdc14648ab704f299608236d_image.png\\" alt=\\"image.png\\" /></p>\n<p>选择” Graphics ” 启用 Pixel Streaming 插件,并重启编辑器</p>\n<p><img src=\\"https://dev-media.amazoncloud.cn/7ce9947490b64ae1ab0a068624348de8_image.png\\" alt=\\"image.png\\" /></p>\n<p>测试</p>\n<p><img src=\\"https://dev-media.amazoncloud.cn/83f40acf9c8e4df7a975fb19ab4cd000_image.png\\" alt=\\"image.png\\" /></p>\n<h3><a id=\\"2__g4dn_Linux_EC2__docker_image_100\\"></a><strong>2. 在 g4dn Linux EC2 上编译演示项目并构建 docker image</strong></h3>\\n<h4><a id=\\"21__g4dnxlarge_Linux_EC2__102\\"></a><strong>2.1 创建一台 g4dn.xlarge Linux EC2 实例</strong></h4>\\n<p>注意系统映像请选择 Deep Learning Base AMI , 这样需要的 Nvidia CUDA, Nvidia-Docker 都已经自动安装好了</p>\n<p><img src=\\"https://dev-media.amazoncloud.cn/65cddf3cc38740e99ad8b21dfe8df08a_image.png\\" alt=\\"image.png\\" /></p>\n<p>摘要如下:</p>\n<p><img src=\\"https://dev-media.amazoncloud.cn/9c7cf2e1368d43ec8d4cc2d9ade3488c_image.png\\" alt=\\"image.png\\" /></p>\n<p>使用 nivida-sim 检查驱动</p>\n<p><img src=\\"https://dev-media.amazoncloud.cn/34308476457b4ab4b2ea73fd1a53cd8d_image.png\\" alt=\\"image.png\\" /></p>\n<h4><a id=\\"22__Epic_Games__GitHub__116\\"></a><strong>2.2 在 Epic Games 网站上关联 GitHub 账号</strong></h4>\\n<p>Epic Games 提供官方的基础镜像 ,但是需要使用者加入 Epic Games github 组织, 具体详细的操作方法请参考 <a href=\\"https://www.unrealengine.com/zh-CN/ue4-on-github?lang=zh-CN&amp;sessionInvalidated=true\\" target=\\"_blank\\">Epic Games 官方文档</a></p>\\n<p>登录到Epic Games 网站</p>\n<p><img src=\\"https://dev-media.amazoncloud.cn/892598f095cd44078712d7ceaf422e19_image.png\\" alt=\\"image.png\\" /></p>\n<p>在 Epic Games 网站关联你的 github 账号</p>\n<p><img src=\\"https://dev-media.amazoncloud.cn/7d41531034e54412aa0b30e295e06a38_image.png\\" alt=\\"image.png\\" /></p>\n<p>成功后即可访问 Epic Games 的私有仓库</p>\n<p><img src=\\"https://dev-media.amazoncloud.cn/d0ab25c5a4a143f4ab335f3f2e287715_image.png\\" alt=\\"image.png\\" /></p>\n<h4><a id=\\"23_docker_image_132\\"></a><strong>2.3 编译演示项目、构建docker image</strong></h4>\\n<pre><code class=\\"lang-\\">#使用github ACCESS_TOKEN登陆ghcr.io仓库\\necho &lt;github ACCESS_TOKEN&gt; | docker login ghcr.io -u &lt;github 账号邮箱&gt; --password-stdin\\n\\n#测试是否可以正常访问Epic Games 基础container image\\ndocker pull ghcr.io/epicgames/unreal-engine:dev-4.27\\n</code></pre>\\n<p>在 g4dn EC2 实例上克隆 github 代码仓库,里面包含了 Dockerfile, docker-compose.yml, tools.sh</p>\n<pre><code class=\\"lang-\\">git clone https://github.com/stevensu1977/UE4-PixelStreaming-Container.git\\n</code></pre>\\n<p>查看 docker file</p>\n<pre><code class=\\"lang-\\"># ---------------------------------------------------------------------------\\n# Copyright (c) 2022 Su Wei/wsuam@amazon.com and/or its affiliates. All rights reserved.\\n# MIT License\\n# Permission is hereby granted, free of charge, to any person obtaining a copy\\n# of this software and associated documentation files (the &quot;Software&quot;), to deal\\n# in the Software without restriction, including without limitation the rights\\n# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\\n# copies of the Software, and to permit persons to whom the Software is\\n# furnished to do so, subject to the following conditions:\\n#\\n# The above copyright notice and this permission notice shall be included in all\\n# copies or substantial portions of the Software.\\n#\\n# THE SOFTWARE IS PROVIDED &quot;AS IS&quot;, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\\n# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\\n# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\\n# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\\n# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\\n# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\\n# SOFTWARE.\\n# ---------------------------------------------------------------------------\\n\\n# Perform the build in an Unreal Engine container image that includes the Engine Tools and Pixel Streaming for Linux\\nFROM ghcr.io/epicgames/unreal-engine:dev-4.27 as builder\\n\\n# Clone the source code for the example Unreal project\\nRUN mkdir /tmp/github\\nRUN git clone --progress --depth=1 'https://github.com/stevensu1977/UE4-PixelStreaming-demo.git' /tmp/github\\nRUN mv /tmp/github/FirstPersonProject/* /tmp/project\\n\\n\\n# Package the example Unreal project\\nRUN /home/ue4/UnrealEngine/Engine/Build/BatchFiles/RunUAT.sh BuildCookRun \\\\\\n -clientconfig=Development -serverconfig=Development \\\\\\n -project=/tmp/project/FirstPersonProject.uproject \\\\\\n -utf8output -nodebuginfo -allmaps -noP4 -cook -build -stage -prereqs -pak -archive \\\\\\n -archivedirectory=/tmp/project/dist \\\\\\n -platform=Linux\\n\\n# Copy the packaged project into the Pixel Streaming runtime image\\nFROM ghcr.io/epicgames/unreal-engine:runtime-pixel-streaming\\nCOPY --from=builder --chown=ue4:ue4 /tmp/project/dist/LinuxNoEditor /home/ue4/project\\n\\n\\n# Set the project as the container's entrypoint\\nENTRYPOINT [&quot;/home/ue4/project/FirstPersonProject.sh&quot;, &quot;-RenderOffscreen&quot;, &quot;-RenderOffscreen&quot;, &quot;-AllowPixelStreamingCommands&quot; ,&quot;-PixelStreamingHideCursor&quot; ,&quot;-PixelStreamingWebRTCMaxFps=30&quot;, &quot;-PixelStreamingWebRTCDisableReceiveAudio&quot;,&quot;-FullStdOutLogOutput&quot;, &quot;-ForceRes&quot;, &quot;-ResX=1920&quot;, &quot;-ResY=1080&quot;]\\n</code></pre>\\n<p>使用 tools.sh 构建 docker 镜像</p>\n<p>#代码仓库提供了一个辅助工具 tools.sh 也可以使用它来构建、启动、停止 docker-compose<br />\\n#使用./tools build 脚本会生成一个” pixelstreaming-demo ”的 docker image.<br />\\n./tools.sh build</p>\n<p><img src=\\"https://dev-media.amazoncloud.cn/f983f5b130044e4dbee4498b28ebc0b6_image.png\\" alt=\\"image.png\\" /></p>\n<h3><a id=\\"3__dockercompose__207\\"></a><strong>3. 编写 docker-compose 文件</strong></h3>\\n<p>在步骤 2 我们成功的构建了演示项目的 docker 镜像 , 接下来我们会使用 docker-compose 根据官方像素流送架构来编排 TURN/STUN server, signalling server, 演示项目,实现一键启动。</p>\n<p>Epic Games 官方像素流送架构参考图:</p>\n<p><img src=\\"https://dev-media.amazoncloud.cn/0d41ac9a7dac4360bbc1713a0545b157_image.png\\" alt=\\"image.png\\" /></p>\n<p>3.1 docker-compose 版本需要 1.27 以上才支持 nvidia GPU ,首先安装 docker-compose 1.29.2</p>\n<pre><code class=\\"lang-\\">sudo curl -L &quot;https://github.com/docker/compose/releases/download/1.29.2/docker-compose-\$(uname -s)-\$(uname -m)&quot; -o /usr/local/bin/docker-compose\\n</code></pre>\\n<p>查看代码仓库的 docker-compose.yml</p>\n<pre><code class=\\"lang-\\">version: &quot;3&quot;\\nservices:\\n \\n # The WebRTC TURN server (note that you will need TCP and UDP ports 3478 and 49152-65535 exposed for TURN relaying to function correctly)\\n turnserver:\\n image: &quot;coturn/coturn:4.5.2&quot;\\n network_mode: &quot;host&quot;\\n command: [&quot;-a&quot;, &quot;-v&quot;, &quot;-n&quot;, &quot;-u&quot;, &quot;user:password&quot;, &quot;-p&quot;, &quot;\${TURN_PORT}&quot;, &quot;-r&quot;, &quot;default-realm&quot;, &quot;--no-dtls&quot;, &quot;--no-tls&quot;]\\n \\n # The Cirrus signalling server\\n signalling:\\n image: &quot;ghcr.io/epicgames/pixel-streaming-signalling-server:4.27&quot;\\n network_mode: &quot;host&quot;\\n command:\\n - &quot;--publicIp=\${PUBLIC_IP}&quot;\\n - &quot;--HttpPort=\${HTTP_PORT}&quot;\\n - &quot;--StreamerPort=\${STREAMER_PORT}&quot;\\n - &gt;-\\n --peerConnectionOptions={\\n &quot;iceServers&quot;:[\\n {\\n &quot;urls&quot;: [&quot;turn:\${PUBLIC_IP}:\${TURN_PORT}&quot;],\\n &quot;username&quot;: &quot;user&quot;,\\n &quot;credential&quot;: &quot;password&quot;\\n }\\n ]\\n \${EXTRA_PEERCONNECTION_OPTIONS}\\n }\\n depends_on:\\n - turnserver\\n \\n # The Pixel Streaming demo project\\n project:\\n image: &quot;pixelstreaming-demo&quot;\\n network_mode: &quot;host&quot;\\n command:\\n - &quot;-PixelStreamingURL=ws://127.0.0.1:\${STREAMER_PORT}&quot;\\n \\n depends_on:\\n - signalling\\n \\n deploy:\\n resources:\\n reservations:\\n devices:\\n - driver: nvidia\\n capabilities: [gpu]\\n count: 1\\n</code></pre>\\n<h3><a id=\\"4__273\\"></a><strong>4. 测试</strong></h3>\\n<p>通过代码仓库的 tools.sh 可以启动多个监听不同端口的演示项目</p>\n<p>启动演示项目,命令会输出访问端口</p>\n<p><code>./tools.sh start </code></p>\\n<p><img src=\\"https://dev-media.amazoncloud.cn/649c12194a3949d7b34c2d28f6901d6f_image.png\\" alt=\\"image.png\\" /></p>\n<p>通过电脑浏览器和手机可以正常访问</p>\n<p><img src=\\"https://dev-media.amazoncloud.cn/a6028a9ef2d24ad98c9f0d8c4f3e74fc_image.png\\" alt=\\"image.png\\" /></p>\n<p><img src=\\"https://dev-media.amazoncloud.cn/c7ef418e32db489384b56ab4dde890e6_image.png\\" alt=\\"image.png\\" /></p>\n<p>启动多个游戏</p>\n<pre><code class=\\"lang-\\">PROJECT_NAME=&quot;DEMO01&quot; ./tools.sh start 10001 3578 8888\\nPROJECT_NAME=&quot;DEMO02&quot; ./tools.sh start 10002 3579 8889\\nPROJECT_NAME=&quot;DEMO03&quot; ./tools.sh start 10003 3580 8899\\n</code></pre>\\n<p>如果启动成功会出现以下信息,通过显示的地址/端口使用浏览器访问即可</p>\n<p><img src=\\"https://dev-media.amazoncloud.cn/a7dc29ead5594bfa8e21d1bd3d70b7d0_image.png\\" alt=\\"image.png\\" /></p>\n<p>使用 nvidia-smi 查看 GPU 信息, 会显示 3 个进程已经共享 GPU</p>\n<p><img src=\\"https://dev-media.amazoncloud.cn/65e54b8e6b414f48aa887e872dd2a3ac_image.png\\" alt=\\"image.png\\" /></p>\n<p>停止游戏演示</p>\n<pre><code class=\\"lang-\\">#单游戏实例\\n./tools.sh stop\\n\\n#多游戏实例\\nPROJECT_NAME=&quot;DEMO01&quot; ./tools.sh stop\\nPROJECT_NAME=&quot;DEMO02&quot; ./tools.sh stop\\nPROJECT_NAME=&quot;DEMO03&quot; ./tools.sh stop\\n</code></pre>\\n<h3><a id=\\"5_316\\"></a><strong>5.总结</strong></h3>\\n<p>本文详细地介绍了如何在亚马逊云上使用 EC2 g4dn 实例实现 UE4 项目的编译,打包,并且通过 docker-compose 进行本地化部署,在下一个章节我们将会介绍如何在 Amazon Elastic Kubernetes Service(EKS)上部署 UE4 像素流推送平台。</p>\n<h3><a id=\\"_320\\"></a><strong>参考文档、资源</strong></h3>\\n<ul>\\n<li><a href=\\"https://docs.unrealengine.com/4.27/en-US/SharingAndReleasing/PixelStreaming/\\" target=\\"_blank\\">Unreal Engine 官方像素流送文档</a></li>\\n<li><a href=\\"https://docs.docker.com/compose/\\" target=\\"_blank\\">docker-compose 配置文档</a></li>\\n<li><a href=\\"https://aws.amazon.com/cn/ec2/instance-types/g4/\\" target=\\"_blank\\">Amazon EC2 G4 文档</a></li>\\n</ul>\n<h3><a id=\\"_326\\"></a><strong>本篇作者</strong></h3>\\n<p><img src=\\"https://dev-media.amazoncloud.cn/df1c858dc9964a4ea00ea2e5058c6364_image.png\\" alt=\\"image.png\\" /></p>\n<h4><a id=\\"_330\\"></a><strong>粟伟</strong></h4>\\n<p>Amazon 资深解决方案架构师,专注游戏行业, 开源项目爱好者,致力于云原生应用推广、落地。具有 15 年以上的信息技术行业专业经验,担任过高级软件工程师,系统架构师等职位,在加入 Amazon 之前曾就职于 Bea, Oracle, IBM 等公司。</p>\n<p><img src=\\"https://dev-media.amazoncloud.cn/53fb5ae12787406ab27f4515a658ad75_image.png\\" alt=\\"image.png\\" /></p>\n<h4><a id=\\"_336\\"></a><strong>贺杨</strong></h4>\\n<p>Amazon 解决方案架构师,具备 17 年 IT 专业服务经验,工作中担任过研发、开发经理、解决方案架构师等多种角色。在加入 Amazon 前,拥有多年外企研发和售前架构经验,在传统企业架构和中间件解决方案有深入的理解和丰富的实践经验。</p>\n<p><img src=\\"https://dev-media.amazoncloud.cn/b592160284df41468faa946d94d83c1e_image.png\\" alt=\\"image.png\\" /></p>\n<h4><a id=\\"_342\\"></a><strong>白鹤</strong></h4>\\n<p>教授级高级工程师,亚马逊云科技媒体行业资深解决方案架构师,重点从事融合媒体系统、内容制作平台、超高清编码云原生能力等方面架构设计工作,在围绕媒体数字化转型的多个领域有丰富的实践经验。</p>\n"}
目录
亚马逊云科技解决方案 基于行业客户应用场景及技术领域的解决方案
联系亚马逊云科技专家
亚马逊云科技解决方案
基于行业客户应用场景及技术领域的解决方案
联系专家
0
目录
关闭