User:Webb/New linux server: Difference between revisions
From TF2 Classified Wiki
More actions
No edit summary |
No edit summary |
||
| Line 1: | Line 1: | ||
:''This is a WIP updated version of the Linux dedicated server article. I want to ask for feedback before moving out of my user namespace. The original article was adapted and revised from a guide written by Raizo, the original of which can be found here: https://blog.raizo.dev/posts/tf2-classic-linux-server-tutorial/'' | :''This is a WIP updated version of the Linux dedicated server article. I want to ask for feedback before moving out of my user namespace. The original article was adapted and revised from a guide written by Raizo, the original of which can be found here: https://blog.raizo.dev/posts/tf2-classic-linux-server-tutorial/'' | ||
== Reading this article == | |||
<!-- Originally from https://wiki.teamfortress.com/wiki/Linux_dedicated_server#Reading_this_article --> | <!-- Originally from https://wiki.teamfortress.com/wiki/Linux_dedicated_server#Reading_this_article --> | ||
A command prefixed by <code>#</code> is meant to be run as '''root'''. | A command prefixed by <code>#</code> is meant to be run as '''root'''. | ||
| Line 22: | Line 11: | ||
Some commands are listed in-line with the rest of a paragraph and lack this symbol, in which case you should run the command as whichever account you're currently logged in with. | Some commands are listed in-line with the rest of a paragraph and lack this symbol, in which case you should run the command as whichever account you're currently logged in with. | ||
== | == Prerequisites == | ||
* A Linux server running Ubuntu Server<sup>*</sup> on an x86_64 CPU<sup>**</sup> with root access | |||
* At least 20GB of free storage | |||
* A minimum of a 10Mbps upload speed if you intend on hosting a server over the Internet, more will be needed if you host custom content | |||
* ''Optional'': An SSH/SFTP client if doing remote access/file management | |||
<sup>*</sup> This guide was written for and tested on Ubuntu Server 24.04 LTS Minimal. Other distros may use different package names and conventions. | |||
< | <sup>**</sup> Using an x86 compatibility layer like Box86 for another architecture is unsupported and may not work. | ||
</ | == Preparing for install === | ||
=== Dependencies === | |||
We'll need to install some required packages and tools for our server to work, as well as for installation. | |||
Since the legacy TF2C branch, Source SDK, and SteamCMD are built for 32-bit, we'll need to enable 32-bit packages. We'll also add the <code>multiverse</code> repository which has SteamCMD. | |||
<pre> | <pre> | ||
| Line 44: | Line 36: | ||
</pre> | </pre> | ||
Next, we'll install the <code>dialog</code> package so the Steam Subscriber Agreement dialog works, and then the rest of the packages we need. | |||
<pre> | <pre> | ||
| Line 50: | Line 42: | ||
# apt install steamcmd p7zip aria2 tilde lib32z1 libbz2-1.0:i386 lib32gcc-s1 lib32stdc++6 libcurl3-gnutls:i386 libsdl2-2.0-0:i386 wget | # apt install steamcmd p7zip aria2 tilde lib32z1 libbz2-1.0:i386 lib32gcc-s1 lib32stdc++6 libcurl3-gnutls:i386 libsdl2-2.0-0:i386 wget | ||
</pre> | </pre> | ||
If your version of Ubuntu doesn't come with a text editor, you may install one now. For this guide we'll use <code>nano</code>. | If your version of Ubuntu doesn't come with a text editor, you may install one now. For this guide we'll use <code>nano</code>. | ||
<pre># apt install nano</pre> | <pre># apt install nano</pre> | ||
=== Creating a user for the server === | |||
Pick a directory to install your server into. Many put it under a directory in <code>/opt</code>, but for this guide we'll be using <code>/home/srcds</code>. | |||
Create a disabled user with the home directory: | |||
<pre> | |||
# useradd -s /bin/false -mr srcds | |||
</pre> | |||
<code>-m</code> creates a home directory for the new user, <code>-r</code> specifies that it's a system account that will not have a password, and <code>-s /bin/false</code> prevents the account from having a default shell. | |||
=== Installing Source SDK Base 2013 Dedicated Server (SDK 2013) === | |||
Switch to the new <code>srcds</code> user you made, and run SteamCMD. | Switch to the new <code>srcds</code> user you made, and run SteamCMD. | ||
| Line 66: | Line 70: | ||
</pre> | </pre> | ||
You should be dropped into a SteamCMD shell. We can install the SDK now. Note that <code>force_install_dir</code> must be ran before <code>login anonymous</code>. | You should be dropped into a SteamCMD shell. We can install the SDK 2013 now. Note that <code>force_install_dir</code> must be ran before <code>login anonymous</code>. | ||
<pre> | <pre> | ||
| Line 79: | Line 83: | ||
== Installing TF2C == | == Installing TF2C == | ||
We'll be downloading the archived verison of TF2C. You | We'll be downloading the archived verison of TF2C, since it's unlikely to get updates. You have the option of using TF2CDownloader, but we won't cover it here. | ||
<pre> | <pre> | ||
| Line 90: | Line 94: | ||
This will downloaded the latest archive of TF2C, create its directory, and extract it. If extraction succeeds it will delete tf2classic.zip. | This will downloaded the latest archive of TF2C, create its directory, and extract it. If extraction succeeds it will delete tf2classic.zip. | ||
=== | === Symlinking improperly named shared objects === | ||
Valve changed some shared object file names in the SDK | Valve changed some shared object file names in the SDK, but the objects included with our install of SDK 2013 have not adopted the new names. | ||
We'll also do the same for TF2C's <code>server_srv.so</code> and SDK's < | Since these are simply renames, we can symlink them. We'll also do the same for TF2C's <code>server_srv.so</code> and SDK's <code>steamclient.so</code>. | ||
'''Your server will not start without doing this.''' | |||
Run the following commands to create the symlinks in the bin folder: | Run the following commands to create the symlinks in the bin folder: | ||
| Line 133: | Line 138: | ||
== Server Configuration == | == Server Configuration == | ||
For a basic, private server, you should only need to set a password in < | For a basic, private server, you should only need to set a password in <code>sdk/tf2classic/cfg/server.cfg</code> by appending the file with <code>sv_password yourpassword</code>. | ||
You can also make it LAN-only by appending < | You can also make it LAN-only by appending <code>sv_lan 1</code> in the same file. | ||
If you want a more complicated | If you want a more complicated setup, consider using [https://cfg.tf/ cfg.tf]. If you don't need this you can skip to the next section. | ||
Make sure the server type is set to “Internet and LAN” if you want players outside your LAN to be able to join (you may need to port forward if you’re on consumer broadband or open ports on your firewall). | Make sure the server type is set to “Internet and LAN” if you want players outside your LAN to be able to join (you may need to port forward if you’re on consumer broadband or open ports on your firewall). | ||
| Line 153: | Line 158: | ||
</pre> | </pre> | ||
== | == Managing the server via Systemd == | ||
Systemd is a program that will automatically handle things like logging, restarts, and starting your server when your machine boots. We'll use this to run our server, instead of manually running commands. | Systemd is a program that will automatically handle things like logging, restarts, and starting your server when your machine boots. We'll use this to run our server, instead of manually running commands. | ||
| Line 159: | Line 164: | ||
=== Creating an SDK 2013 update script === | === Creating an SDK 2013 update script === | ||
We're going to create a script that will update | We're going to create a script that will update SDK 2013 for us instead of typing it out manually each time. Later, we'll optionally use this script to check and update SDK 2013 on our server automatically when the server starts. | ||
First, let's create a directory for the script. | First, let's create a directory for the script. | ||
| Line 188: | Line 193: | ||
=== Creating a service file === | === Creating a service file === | ||
Create a service file in <code>/etc/systemd/system/</code> as root. | Create a service file in <code>/etc/systemd/system/</code> as root. For this guide we'll use <code>/etc/systemd/system/tf2c.service</code>. | ||
<pre> | <pre> | ||
[Unit] | [Unit] | ||
| Line 214: | Line 218: | ||
</pre> | </pre> | ||
Then, enable the service to start with Systemd. | Then, enable the service to start with Systemd on boot. | ||
<pre> | <pre> | ||
| Line 222: | Line 226: | ||
=== Automatic restarts using crontab === | === Automatic restarts using crontab === | ||
As root, execute <code>crontab -e</code>. This will open a special file where you can set cronjobs. For example, adding the following line will restart your game server every day at 04:00: | As root, execute <code>crontab -e</code>. This will open a special file in your editor where you can set cronjobs. For example, adding the following line will restart your game server every day at 04:00: | ||
<pre> | <pre> | ||
| Line 230: | Line 234: | ||
You may create as many services as you have TF2C servers but remember to name the service files uniquely, enable them in <code>systemctl</code>, and add them to the <code>crontab</code>. When updating service files, remember to run <code>systemctl daemon-reload</code> before restarting the service. | You may create as many services as you have TF2C servers but remember to name the service files uniquely, enable them in <code>systemctl</code>, and add them to the <code>crontab</code>. When updating service files, remember to run <code>systemctl daemon-reload</code> before restarting the service. | ||
=== | === Manually managing services === | ||
If you don't wish to use the service files above to automatically boot servers, or you need to perform these actions for maintenance: you may issue commands to manually ''start'', ''stop'', ''restart'', or ''update'' the server(s) through systemd. | If you don't wish to use the service files above to automatically boot servers, or you need to perform these actions for maintenance: you may issue commands to manually ''start'', ''stop'', ''restart'', or ''update'' the server(s) through systemd. | ||