使用阿里云服务器为我的小伙伴们创建游戏服务器~

简介: steamCMD在linux上可以很方便的创建游戏服务器文件,只需要按照步骤安装和配置,之后启动服务器脚本就可以开启服务器了,1核2G的服务器,我们俩人玩了三个小时,之后开始变得不流畅起来,所以要想保障体验的话最好是2核4G的服务器估计能满足正常的时间分布。

Valheim server on Linux
Here is a step-by-step guide for setting up a Valheim server on Linux. Having done it twice now I thought it would be a good idea to capture this somewhere so that next time I don't have to look any of this up again.

The only assumptions being made here is that your server is running Ubuntu of some semi-recent version and a basic understanding of Linux.

SteamCMD
The SteamCMD utility from Valve will help us install the gamefiles on the server. Follow the instructions on the wiki to get it up and running.

Valheim
Now that SteamCMD is available, we can use it to download the gamefiles to the server.

steamcmd +login anonymous +force_install_dir

/home/steam/.steam/steamapps/common/valheim +app_update 896660 validate +exit

Some things to note here:

I've forced the install directory to something without spaces or other special crap in the name. This will make setting up systemd easier later.
896660 is the steam identifier for Valheim.
You can re-use this command later when you need to update the gamefiles when the devs release an update.
For quick re-use, create an sh file and put the command in there. I've named my update_game.sh, mark the file as executable and you're all set.

There are some last changes before we can run the server.

Valheim server configuration
There is not a lot to change but it's a requirement if you want to set up things correctly. Browse to the folder where you installed the game and look for a file called start_server.sh. As instructed in the file, make a copy of it (for simplicity I've named mine start_valheim.sh). Here's what mine looks like:

export TERM=xterm
export templdpath=$LD_LIBRARY_PATH
export LD_LIBRARY_PATH=./linux64:$LD_LIBRARY_PATH
export SteamAppId=892970

echo "Starting server PRESS CTRL-C to exit"

./valheim_server.x86_64 -name "Helheim" -port 2456 -world "Dedicated" -password "..."
export LD_LIBRARY_PATH=$templdpath

I've added an additional export at the top (found after a bunch of searching for specific problems) to prevent some warnings and errors while the game starts. You could maybe get by without it, it'll depend on the rest of your system. If you see weird stuff in the game output, it's worth a shot.

Update the value for the -name argument to something you nice and of course set the -password value. Make sure it is longer than 5 characters and is not your server name.

Port configuration
This step will depend on your network infrastructure, I'm running my server on the Azure cloud platform which has its own way of configuring ports for VMs. Your setup is probably different but the gist of all of it is that you need op open the port range 2456-2458 for incoming traffic.

Running the server
It's tempting now to just run the > start_valheim.sh> file and start gaming but that comes with a drawback. When you close your SSH session, your server will stop. To fix that we'll use systemd to run the gameserver for us (and even try to restart it should it for some
reason crash or shut down).

Here is the config file I'm using:

[Unit]
Description=Valheim service
Wants=network.target
After=syslog.target network-online.target

[Service]
Type=simple
Restart=on-failure
RestartSec=10
User=steam
WorkingDirectory=/home/steam/.steam/steamapps/common/valheim/
ExecStart=/bin/sh /home/steam/.steam/steamapps/common/valheim/start_valheim.sh

[Install]
WantedBy=multi-user.target
If you've stuck with the same names for files and directories you can copy-paste this into a file called valheim.service and roll with that, or change it, if needed.

Given the systemd config file above, we can now hand this over to systemd to hand off the running and monitoring of the server. First step is to install the service file.

Copy the file to /etc/systemd/system.
Activate the service so that systemd can start the service: sudo systemctl enable valheim (don't include the .service part here).
Start the service: sudo systemctl start valheim.
Check the server status and see if it's actually running: sudo systemctl status valheim.
If everything was set up correctly, the output of step 4 will show a line that looks something like this (truncated for brevity):

● valheim.service - Valheim service
    Loaded: loaded (/etc/systemd/system/valheim.service; enabled; vendor preset: enabled)
    Active: active (running)
journalctl -u valheim -n 20

Wrapping up
At this point you should be able to use the public IP of your server to start playing! I don't know much about the resources required to keep everthing running smoothly but I've been running a server on a fairly modest 2-core/8GB RAM Linux (Standard D2as_v4 on Azure) VM that can easily host a 4 player game.

Now go forth and play the viking game with your friends on your very own Valheim server!

Posted on 2021-09-12
Tagged Gaming, Linux

© 2022 harrewijnen.net

相关实践学习
借助OSS搭建在线教育视频课程分享网站
本教程介绍如何基于云服务器ECS和对象存储OSS,搭建一个在线教育视频课程分享网站。
7天玩转云服务器
云服务器ECS(Elastic Compute Service)是一种弹性可伸缩的计算服务,可降低 IT 成本,提升运维效率。本课程手把手带你了解ECS、掌握基本操作、动手实操快照管理、镜像管理等。了解产品详情: https://www.aliyun.com/product/ecs
相关文章
|
5天前
|
弹性计算 网络安全
阿里云国际OpenAPI多接口快速管理ECS服务器教程
阿里云国际OpenAPI多接口快速管理ECS服务器教程
|
3天前
|
弹性计算 开发框架 .NET
阿里云服务器购买教程及云服务器地域、实例、操作系统、带宽等参数选择指南
对于初次购买阿里云服务器的用户来说,想使用阿里云服务器搭建网站或者运行APP、小程序等项目,第一步就是要先购买阿里云服务器,下面小编以图文形式给大家介绍一下阿里云服务器的购买流程,以及购买过程中如何云服务器地域、实例、带宽等关键配置和选择这些参数的一些注意事项,以供参考。
|
4天前
|
存储 固态存储 安全
阿里云服务器X86计算架构解析与X86计算架构云服务器收费价格参考
阿里云服务器架构分为X86计算、Arm计算、高性能计算等多种架构,其中X86计算是用户选择最多的一种架构,本文将深入探讨阿里云X86计算架构的云服务器,包括其技术特性、适用场景、性能优势以及最新价格情况。
|
5天前
|
编解码 弹性计算 应用服务中间件
阿里云服务器Arm计算架构解析:Arm计算架构云服务器租用收费标准价格参考
阿里云服务器架构分为X86计算、Arm计算、高性能计算等多种架构,其中Arm计算架构以其低功耗、高效率的特点受到广泛关注。本文将深入解析阿里云Arm计算架构云服务器的技术特点、适用场景以及包年包月与按量付费的收费标准与最新活动价格情况,以供选择参考。
|
5天前
|
人工智能 运维 关系型数据库
携手UALink,阿里云磐久AI Infra 2.0服务器亮相2024 OCP全球峰会
阿里云服务器研发受邀和UALink联盟一起,在OCP全球峰会上重点阐述AI服务器Scale UP互连技术领域发展趋势
|
5天前
|
网络协议 安全 网络安全
阿里云国际修改域名绑定的DDoS高防服务器
阿里云国际修改域名绑定的DDoS高防服务器
|
5天前
|
SQL 安全 网络安全
阿里云高防服务器如何实现安全防护,以及如何接触安全防护
阿里云高防服务器如何实现安全防护,以及如何接触安全防护
|
5天前
|
安全 网络协议 网络安全
如何购买阿里云购买DDoS高防服务器?
如何购买阿里云购买DDoS高防服务器?
|
5天前
|
域名解析 弹性计算 缓存
阿里云国际云服务器全局流量分析功能详细介绍
阿里云国际云服务器全局流量分析功能详细介绍
|
5天前
|
Apache 数据中心 Windows
将网站迁移到阿里云Windows系统云服务器,访问该站点提示连接被拒绝,如何处理?
将网站迁移到阿里云Windows系统云服务器,访问该站点提示连接被拒绝,如何处理?