在快速发展的游戏行业中,游戏服务器的部署和维护一直是开发团队面临的重要挑战。随着容器技术的成熟,将Unreal Engine专用服务器容器化部署到Amazon GameLift,已经成为一种高效且可靠的解决方案。这种方案不仅简化了部署流程,还提供了更好的资源隔离和扩展性能。
本文将手把手带你了解如何使用Amazon GameLift的容器化Fleet来部署和管理Unreal Engine 5(UE5) 的经典Demo游戏 —— Lyra Game的专用服务器。
通过容器部署方式,您可以实现更一致的运行环境、更快的上线速度,以及自动扩展等运维优势。同时,借助Amazon GameLift提供的会话管理、自动伸缩和监控告警等功能,开发团队可以更轻松地保障游戏服务的稳定性和玩家体验。值得一提的是,Amazon GameLift现已支持基于Graviton3的实例,带来更高性价比。
本文将带你完成将UE5专用服务器部署到Graviton架构容器Fleet的完整流程。
环境准备
1.您可参阅博客《Unreal Engine 5结合Amazon GameLift在Graviton3上的实践》,熟悉UE5的Linux Arm包的构建。
2.准备一台Amazon EC2,配置为R7g.4xlarge,操作系统为Amazon Linux2023。
3.在Amazon EC2上安装Docker。
《Unreal Engine 5结合Amazon GameLift在Graviton3上的实践》
https://aws.amazon.com/cn/blogs/china/unreal-engine-5-combined-with-amazon-gamelift-on-graviton3/
环境部署
编译适合Amazon GameLift
Managed Container的游戏包
目前Amazon GameLift Managed Container的SDK版本为5.2.0+,所以需要重新基于5.2.0版本进行构建游戏包。
1.将以下版本重新进行编译:
Amazon GameLift-Cpp-ServerSDK-5.2.0sudo yum install git docker -ygit clone https://github.com/aws/amazon-gamelift-toolkit.git cd amazon-gamelift-toolkit/building-gamelift-server-sdk-for-unreal-engine-and-amazon-linux
左右滑动查看完整示意
2.Dockerfile请使用以下内容。
FROM public.ecr.aws/amazonlinux/amazonlinux:latest as build-server# Install dependenciesRUN yum install -y gcc-c++ gdb cmake3 git wget openssl openssl-devel tar perl sudo
# Install correct OpenSSL version. NOTE: You might need to change this based on your Unreal Engine 5 version and the OpenSSL version it utilizesRUN wget https://github.com/openssl/openssl/archive/refs/tags/OpenSSL_1_1_1t.tar.gz && \tar -xzvf OpenSSL_1_1_1t.tar.gz && \cd openssl-OpenSSL_1_1_1t/ && \./config && \sudo make install && \mkdir lib && \cp libssl.so.1.1 /lib && \cp libcrypto.so.1.1 /lib
RUN export LD_LIBRARY_PATH=/usr/local/lib:/usr/local/lib64 && \openssl version && \cd ..
# Copy the Open SSL files to binaries folderRUN mkdir /binaries && \cp ./openssl-OpenSSL_1_1_1t/libssl.so.1.1 /binaries/ && \cp ./openssl-OpenSSL_1_1_1t/libcrypto.so.1.1 /binaries/
# Download and build the GameLift Server SDK (NOTE: You might need to change this to download a different SDK version)RUN echo "Download and unzip GameLift Server SDK 5.2.0" && \mkdir SDK && cd SDK && \wget https://gamelift-server-sdk-release.s3.us-west-2.amazonaws.com/cpp/GameLift-Cpp-ServerSDK-5.2.0.zip && \unzip GameLift-Cpp-ServerSDK-5.2.0.zip && \echo "Build the GameLift server SDK" && \mkdir cmake-build && \export OPENSSL_ROOT_DIR=/openssl-OpenSSL_1_1_1t/ && \export OPENSSL_LIBRARIES=/openssl-OpenSSL_1_1_1t/lib/ && \cmake -G "Unix Makefiles" -DBUILD_FOR_UNREAL=1 -DCMAKE_BUILD_TYPE=Release -S . -B ./cmake-build && \cmake --build cmake-build --target all && \cd ./cmake-build/prefix/ && \echo "Copying files over to binaries folder" && \cp -r ./lib/* /binaries/ && \echo "copying over headers (these are already provided by the GameLift Unreal Plugin so you don't need them with that)" && \mkdir /binaries/include && \cp -r ./include/* /binaries/include/
# Copy the binaries only to a clean setup for copying to local system after buildFROM scratch AS server COPY --from=build-server /binaries/ / ENTRYPOINT [ "/GameLiftSampleServer" ]
左右滑动查看完整示意
3.执行命令,获取编译包。
sudo ./buildbinaries.sh
左右滑动查看完整示意
4.在官方网站下载5.2.0的Unreal Engine Plugin文件至Windows机器上。删除原有C:\Unreal Projects\LyraStarterGame\Plugins下GameLiftServerSDK Plugin文件,并将最新Plugin文件拷贝进去。
官方网站:
https://gamelift-server-sdk-release.s3.us-west-2.amazonaws.com/unreal/GameLift-Cpp-ServerSDK-UnrealPlugin-5.2.0.zip
5.将编译好的文件存放到以下文件夹,如果文件夹不存在,请自行创建。
LyraStarterGame\Plugins\GameLiftServerSDK\ThirdParty\GameLiftServerSDK\LinuxArm64\x86_64-unknown-linux-gnu
6.将Project重新Build Solution后,打开UE Editor,Cook Development Server。
构建镜像
1.首先在Amazon ECR上创建存储容器镜像。
aws ecr create-repository --repository-name gamelift-ue5-arm64
左右滑动查看完整示意
2.然后将已经打好的Linux Arm64的包上传至上面创建的Amazon EC2。
3.解压linuxarm64.zip的打包后,在文件目录下创建Dockerfile文件。
cd linuxarm64
cat << 'EOF' > DockerfileFROM amazonlinux:2023
# Create a working directoryWORKDIR /app
# Copy all files from current directory to containerCOPY . .
# Make the shell script executableRUN chmod +x LyraServer-Arm64.sh
# Set the entrypointENTRYPOINT ["./LyraServer-Arm64.sh"]EOF
左右滑动查看完整示意
4.打包镜像,并且push至Amazon ECR上。
docker build -t gamelift-ue5-arm64 .docker tag gamelift-ue5-arm64:latest {accountid}.dkr.ecr.{region}.amazonaws.com/gamelift-ue5-arm64:latestaws ecr get-login-password --region ap-northeast-1 | docker login --username AWS --password-stdin {accountid}.dkr.ecr.{region}.amazonaws.comdocker push {accountid}.dkr.ecr.{region}.amazonaws.com/gamelift-ue5-arm64:latest
左右滑动查看完整示意
配置Amazon GameLift
Container group definitions
Amazon GameLift的Container group definitions是一个配置蓝图,用于定义如何将容器化游戏服务器部署到容器机群中,包含游戏服务器容器和支持容器的配置信息。它支持两种类型:GAME_SERVER和PER_INSTANCE,可以指定内存、CPU等资源限制,并且允许维护多个版本。
GAME_SERVER容器组用于运行游戏服务器应用程序,是托管游戏会话和玩家的必需组件。它可以在Fleet实例中复制多份,复制数量取决于软件的计算需求和实例可用资源。
PER_INSTANCE容器组是可选的,用于在每个Fleet实例上运行额外的支持软件,比如监控或后台服务。游戏服务器软件不直接依赖于PER_INSTANCE组中的进程。
本文主要是测试Game Server的内容,首先创建Group Definitions。
打开亚马逊云科技管理控制台。
创建Amazon GameLift Container Group Definition完成。
配置Amazon GameLift
Managed Container Fleet
依据上面的Amazon GameLift Container Definition Group来创建Amazon GameLift Managed Container Fleet,打开亚马逊云科技管理控制台。
1.因为在Fleet中需要将日志保存到Amazon S3中,所以需要创建Fleet Role绑定到Amazon GameLift Fleet。
2.创建日志存储桶,命名格式为gamelift-*。
3.创建Fleet,并选择日志存储方式为到Amazon S3中。
选择C7g实例。
Review,然后提交创建。
等待几分钟之后,可以看到Container Fleet的状态变为Active。
同时在日志中可以发现以下日志信息,表示Amazon GameLift初始化成功。
连接测试
创建GameSession
1.使用以下Amazon CLI命令来创建Game Session。
aws gamelift create-game-session \ --fleet-id <containerfleet-id> \ --maximum-player-session-count 2
左右滑动查看完整示意
2.使用命令连接Game Session,注意IP和端口请根据上图内容进行替换。
LyraClient.exe <IP>:32806 -WINDOWED -ResX=800 -ResY=450
左右滑动查看完整示意
至此,使用Graviton容器的方式来部署UE5的专用服务器流程已经完毕。
总结
通过将UE5专用服务器容器化并部署到Amazon GameLift的容器化Fleet,开发团队能够实现高效灵活的游戏服务器管理。
本文详细介绍了从环境准备到构建镜像及配置Amazon GameLift容器Fleet的完整流程,涵盖以下关键点:
环境准备:了解构建UE5 Linux Arm包的要求,并配置适合的Amazon EC2实例和Docker环境。
游戏包编译:通过安装必要的依赖项和使用Amazon GameLift Server SDK,成功编译适合Amazon GameLift容器的游戏包。
镜像构建与推送:创建Amazon ECR仓库,构建Docker镜像并将其推送至Amazon ECR,实现游戏服务器的容器化。
Fleet配置:配置Container Group Definitions和容器Fleet,确保游戏服务器能够在亚马逊云科技环境中高效运行。
连接测试:通过创建Game Session并连接客户端,验证服务器部署的成功性。
这种容器化部署方案不仅简化了游戏服务器的管理流程,还提供了更好的资源利用率和扩展能力,使开发团队能够专注于提升玩家体验。借助Amazon GameLift强大的功能,团队可以更轻松地维护游戏服务质量,保障稳定的在线游戏体验。
本篇作者
郭俊龙
亚马逊云科技解决方案架构师,主要负责游戏行业客户解决方案设计,比较擅长云原生微服务以及大数据方案设计和实践。
星标不迷路,开发更极速!
关注后记得星标「亚马逊云开发者」
听说,点完下面4个按钮
就不会碰到bug了!
点击阅读原文查看博客!获得更详细内容!