Dedicated Linux server: Difference between revisions

From TF2 Classic Wiki
Jump to navigation Jump to search
(Port to using the new Metalink)
m (fixed headers)
Line 1: Line 1:
''Note: This was adapted and revised from a guide written by Raizo, the original of which can be found here: https://iraizo.github.io/tf2-classic-linux-server-tutorial/''
''Note: This was adapted and revised from a guide written by Raizo, the original of which can be found here: https://iraizo.github.io/tf2-classic-linux-server-tutorial/''


= Prerequisites =
== Prerequisites ==
* A Linux server running Ubuntu Server<sup>*</sup> on an x86_64 CPU. You cannot easily run SRCDS on any other architecture besides an x86_64 CPU. Box64/Box86 may work for ARM processors (e.g. Raspberry Pis) but that's complex, and not covered here.
* A Linux server running Ubuntu Server<sup>*</sup> on an x86_64 CPU. You cannot easily run SRCDS on any other architecture besides an x86_64 CPU. Box64/Box86 may work for ARM processors (e.g. Raspberry Pis) but that's complex, and not covered here.
* A SFTP/SSH client (PuTTY, Termius, FileZilla, MobaXterm)
* A SFTP/SSH client (PuTTY, Termius, FileZilla, MobaXterm)
Line 11: Line 11:
''*Ubuntu 20.04 LTS is the first Ubuntu version that starts to phase out many i386 libraries from Focal Fossa repos and future Ubuntu versions. Many Source games still rely on i386 libraries. While TF2C, Steam, and SteamCMD are known to work fine, it is possible other Source games and custom plugins and addons may or may not work properly without utilization of PPAs.
''*Ubuntu 20.04 LTS is the first Ubuntu version that starts to phase out many i386 libraries from Focal Fossa repos and future Ubuntu versions. Many Source games still rely on i386 libraries. While TF2C, Steam, and SteamCMD are known to work fine, it is possible other Source games and custom plugins and addons may or may not work properly without utilization of PPAs.
''
''
= Reading this article =
== 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 -->
This article has been written according to standard Linux terminal documentation syntax, meaning the following:
This article has been written according to standard Linux terminal documentation syntax, meaning the following:
Line 21: Line 21:
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.


= Creating a steam user for SteamCMD and Source SDK Base 2013 Dedicated Server =
== Creating a steam user for SteamCMD and Source SDK Base 2013 Dedicated Server ==
Pick a directory to install your server into. Industry standard is usually in <code>/opt</code>, but <code>/home</code> may be easier for you. If you want to use a directory in <code>/home</code>, omit the <code>-d</code> option as useradd will create a directory in <code>/home</code> with the user’s username, ours being <code>steam</code>. We’ll pick <code>/opt/tf2classic</code>.
Pick a directory to install your server into. Industry standard is usually in <code>/opt</code>, but <code>/home</code> may be easier for you. If you want to use a directory in <code>/home</code>, omit the <code>-d</code> option as useradd will create a directory in <code>/home</code> with the user’s username, ours being <code>steam</code>. We’ll pick <code>/opt/tf2classic</code>.


Line 34: Line 34:
<code>-m</code> creates a home directory for it, <code>-d /opt/tf2classic</code> specifies where our home directory will be, and <code>-s /usr/bin/bash</code> sets the shell to bash.
<code>-m</code> creates a home directory for it, <code>-d /opt/tf2classic</code> specifies where our home directory will be, and <code>-s /usr/bin/bash</code> sets the shell to bash.


= Installing Source SDK Base 2013 DS, SteamCMD, and dependencies =
== Installing Source SDK Base 2013 DS, SteamCMD, and dependencies ==
The SteamCMD package is in the multiverse repos. TF2Classic and SteamCMD require i386 (32-bit) libraries to function. You also need 7-Zip to extract TF2Classic.
The SteamCMD package is in the multiverse repos. TF2Classic and SteamCMD require i386 (32-bit) libraries to function. You also need 7-Zip to extract TF2Classic.


Line 64: Line 64:
Give it a few, and when it’s finished we can run <code>exit</code>.
Give it a few, and when it’s finished we can run <code>exit</code>.


= Downloading TF2 Classic =
== Downloading TF2 Classic ==
The fastest way to download TF2Classic is to use a command-line download manager called Aria2 in combination with a "Metalink" which downloads from many mirrors at once.
The fastest way to download TF2Classic is to use a command-line download manager called Aria2 in combination with a "Metalink" which downloads from many mirrors at once.


Line 81: Line 81:
<code>mv tf2classic /opt/tf2classic/server/</code>
<code>mv tf2classic /opt/tf2classic/server/</code>


= Server Configuration =
== Server Configuration ==
Generate your server config(s) on [https://cfg.tf/ cfg.tf].
Generate your server config(s) on [https://cfg.tf/ cfg.tf].


Line 92: Line 92:
And merge the <code>cfg</code> folder with <code>/opt/tf2classic/server/tf2classic/cfg/</code>.
And merge the <code>cfg</code> folder with <code>/opt/tf2classic/server/tf2classic/cfg/</code>.


= Creating the server script =
== Creating the server script ==
Change into the server directory with:
Change into the server directory with:


Line 115: Line 115:
</code>
</code>


= Create symlinks to missing shared objects. =
== Create symlinks to missing shared objects. ==
Valve changed some shared object file names in the SDK and the objects we’re given have not adapted to the new names. Since these are simply renames, we can symlink them.
Valve changed some shared object file names in the SDK and the objects we’re given have not adapted to the new names. Since these are simply renames, we can symlink them.
'''Your server will not start without doing this.'''
'''Your server will not start without doing this.'''
Line 149: Line 149:
</code>
</code>


= Running the server =
== Running the server ==
Finally, all you need to do to start the server is run <code>./runserver.sh</code>!
Finally, all you need to do to start the server is run <code>./runserver.sh</code>!



Revision as of 11:23, 5 June 2022

Note: This was adapted and revised from a guide written by Raizo, the original of which can be found here: https://iraizo.github.io/tf2-classic-linux-server-tutorial/

Prerequisites

  • A Linux server running Ubuntu Server* on an x86_64 CPU. You cannot easily run SRCDS on any other architecture besides an x86_64 CPU. Box64/Box86 may work for ARM processors (e.g. Raspberry Pis) but that's complex, and not covered here.
  • A SFTP/SSH client (PuTTY, Termius, FileZilla, MobaXterm)
  • At least 16GB of free storage
  • A minimum of a 10Mbps upload speed if you intend on hosting a server over the Internet. No need to worry for LAN servers.

This guide was written for and tested on Ubuntu Server 20.04 LTS, however any Debian-based distro should work similarly and fine using this guide.

*Ubuntu 20.04 LTS is the first Ubuntu version that starts to phase out many i386 libraries from Focal Fossa repos and future Ubuntu versions. Many Source games still rely on i386 libraries. While TF2C, Steam, and SteamCMD are known to work fine, it is possible other Source games and custom plugins and addons may or may not work properly without utilization of PPAs.

Reading this article

This article has been written according to standard Linux terminal documentation syntax, meaning the following:

A command prefixed by # (a hashtag) is meant to be run as root. In this article, we're assuming that you're using a VPS and logged in as the root account to start with.

A command prefixed by $ (a dollar sign) is meant to be run as a regular user without root permissions.

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.

Creating a steam user for SteamCMD and Source SDK Base 2013 Dedicated Server

Pick a directory to install your server into. Industry standard is usually in /opt, but /home may be easier for you. If you want to use a directory in /home, omit the -d option as useradd will create a directory in /home with the user’s username, ours being steam. We’ll pick /opt/tf2classic.

Create a user with that home directory and give it a strong password:

# useradd -m -d /opt/tf2classic -s /usr/bin/bash steam

# passwd steam

-m creates a home directory for it, -d /opt/tf2classic specifies where our home directory will be, and -s /usr/bin/bash sets the shell to bash.

Installing Source SDK Base 2013 DS, SteamCMD, and dependencies

The SteamCMD package is in the multiverse repos. TF2Classic and SteamCMD require i386 (32-bit) libraries to function. You also need 7-Zip to extract TF2Classic.

# add-apt-repository multiverse

# dpkg --add-architecture i386

# apt update

Install SteamCMD, 7-Zip, and miscellaneous packages that we'll be using.

# apt install steamcmd 7zip aria2 tilde lib32z1 libncurses5:i386 libbz2-1.0:i386 lib32gcc1-s1 lib32stdc++6 libtinfo5:i386 libcurl3-gnutls:i386 libsdl2-2.0-0:i386 libcurl4-gnutls-dev libcurl4-gnutls-dev:i386

Login to the steam user you created:

# su - steam

Run steamcmd and let it update. When it’s finished updating and displays a prompt, login anonymously by typing and running: login anonymous

We will set a directory to install Source SDK Base 2013 DS to. Run force_install_dir /opt/tf2classic/server in SteamCMD to choose the directory for the server to install into. This path can be anything, just make sure you have access to it.

Then run app_update 244310 validate in SteamCMD to install Source SDK Base 2013 DS.

Give it a few, and when it’s finished we can run exit.

Downloading TF2 Classic

The fastest way to download TF2Classic is to use a command-line download manager called Aria2 in combination with a "Metalink" which downloads from many mirrors at once.

Run:

aria2c --bt-hash-check-seed=false --seed-time=0 https://wiki.tf2classic.com/misc/tf2classic-latest.meta4

It may produce some harmless errors in case any of the mirrors in the Metalink are currently inactive, but it will download the tf2classic.zip file rapidly, and it will automatically verify that the downloaded file isn't corrupted.

Extract the downloaded file by running 7zz x tf2classic.zip

Then finally move the directory into your SDK 2013 MP folder:

mv tf2classic /opt/tf2classic/server/

Server Configuration

Generate your server config(s) on cfg.tf.

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).

Upload the generated ZIP file to your server using SFTP, unzip the folder using:

7zz x <archive>.zip

And merge the cfg folder with /opt/tf2classic/server/tf2classic/cfg/.

Creating the server script

Change into the server directory with:

$ cd /opt/tf2classic/server/

Create a script to run the server with one simple command. Use any text editor of your choice to create runserver.sh where srcds_run is located. For the sake of those unfamiliar with terminal text editing, we'll be using Tilde. Run:

$ tilde runserver.sh

Fill it with this line (you may be able to paste using Ctrl-Shift-V):

./srcds_run -console -game tf2classic +map pl_upward +maxplayers 24

Feel free to change the map and maxplayers. There are more arguments, but we’ll keep it basic.

Save the file by clicking "File" -> "Exit", and confirming to save your changes. You can also press Ctrl-Q to accomplish this with your keyboard alone, if mouse inputs aren't passed through.

Now, make the script executable with:

$ chmod +x runserver.sh

Create symlinks to missing shared objects.

Valve changed some shared object file names in the SDK and the objects we’re given have not adapted to the new names. Since these are simply renames, we can symlink them. Your server will not start without doing this.

Enter the bin directory by typing, exactly:

cd bin

Run the following commands to create the symlinks in the bin folder:

$ ln -s datacache_srv.so datacache.so

$ ln -s dedicated_srv.so dedicated.so

$ ln -s engine_srv.so engine.so

$ ln -s materialsystem_srv.so materialsystem.so

$ ln -s replay_srv.so replay.so

$ ln -s scenefilecache_srv.so scenefilecache.so

$ ln -s shaderapiempty_srv.so shaderapiempty.so

$ ln -s studiorender_srv.so studiorender.so

$ ln -s vphysics_srv.so vphysics.so

$ ln -s soundemittersystem_srv.so soundemittersystem.so

Running the server

Finally, all you need to do to start the server is run ./runserver.sh!

If you want it to run even after closing the terminal window, run nohup ./runserver.sh & followed by disown

More advanced users will likely want to run it using GNU Screen, or using a systemd service, which will be documented here eventually.