Dedicated Linux server: Difference between revisions
Technochips (talk | contribs) (use pre instead of code, added instructions for manual installs) |
m (Added indention to the note. Removed "Note".) |
||
(15 intermediate revisions by 2 users not shown) | |||
Line 1: | Line 1: | ||
'' | :''This 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/'' | ||
== Prerequisites == | == Prerequisites == | ||
Line 7: | Line 7: | ||
* A minimum of a 10Mbps upload speed if you intend on hosting a server over the Internet. No need to worry for LAN servers. | * 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 22.04 LTS, however any Debian-based distro should work similarly and fine using this guide. | <sup>*</sup>'''Note''': This guide was written for and tested on Ubuntu Server 22.04 LTS, however any Debian-based distro should work similarly and fine using this guide. | ||
== 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 19: | Line 19: | ||
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 31: | Line 31: | ||
<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 45: | Line 45: | ||
# apt install steamcmd unzip aria2 tilde lib32z1 libncurses5:i386 libbz2-1.0:i386 lib32gcc-s1 lib32stdc++6 libtinfo5:i386 libcurl3-gnutls:i386 libsdl2-2.0-0:i386 libcurl4-gnutls-dev libcurl4-gnutls-dev:i386 | # apt install steamcmd unzip aria2 tilde lib32z1 libncurses5:i386 libbz2-1.0:i386 lib32gcc-s1 lib32stdc++6 libtinfo5:i386 libcurl3-gnutls:i386 libsdl2-2.0-0:i386 libcurl4-gnutls-dev libcurl4-gnutls-dev:i386 | ||
</pre> | </pre> | ||
''<sup>*</sup>'''Note''':See [https://developer.valvesoftware.com/wiki/SteamCMD#Package_From_Repositories|Valve Developer Wiki SteamCMD Repository Packages] if your distro is having issues getting steamcmd. | |||
'' | |||
Login to the steam user you created: | Login to the steam user you created: | ||
Line 50: | Line 52: | ||
<pre># su - steam</pre> | <pre># su - steam</pre> | ||
Run <code>steamcmd</code> and let it update. When it’s finished updating and displays | Run <code>steamcmd</code> and let it update. When it’s finished updating and displays the main SteamCMD shell, run <code>force_install_dir /opt/tf2classic/server</code> to choose the directory for the Source SDK Base 2013 Dedicated server to install into. This path can be anything, just make sure you have access to it. | ||
Login anonymously by typing and running: <code>login anonymous</code> | |||
Then run <code>app_update 244310 validate</code> in SteamCMD to install Source SDK Base 2013 DS. | Then run <code>app_update 244310 validate</code> in SteamCMD to install Source SDK Base 2013 DS. | ||
Line 76: | Line 77: | ||
<pre>mv tf2classic /opt/tf2classic/server/</pre> | <pre>mv tf2classic /opt/tf2classic/server/</pre> | ||
== 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 87: | Line 88: | ||
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>. | ||
= | === 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 144: | Line 122: | ||
== Running the server == | == Running the server == | ||
=== Creating the server script === | |||
Change into the server directory with: | |||
<pre>$ cd /opt/tf2classic/server/</pre> | |||
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 nano. Run: | |||
<pre>$ nano runserver.sh</pre> | |||
Fill it with this line (you may be able to paste using <code>Shift+Insert</code>): | |||
<pre>./srcds_run -console -game tf2classic +map pl_upward +maxplayers 24</pre> | |||
Feel free to change the map and maxplayers. There are more arguments, but we’ll keep it basic. | |||
Save the file by clicking <code>CRTL+X</code>, and then <code>Y</code> to write your changes. | |||
Now, make the script executable with: | |||
<pre> | |||
$ chmod +x runserver.sh | |||
</pre> | |||
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>! | ||
If you want it to run even after closing the terminal window, run <code>nohup ./runserver.sh &</code> followed by <code>disown</code> | If you want it to run even after closing the terminal window, run <code>nohup ./runserver.sh &</code> followed by <code>disown</code> | ||
=== Systemd & Crontab for automated start, restart and updating === | |||
For easier automation of server restarts, updating, and booting alongside the system, you may use systemd, which is the default init system for most modern Linux distros and cronjobs. | |||
Create file <code>ssdk2013mp-update</code> and fill in the following | |||
<pre> | |||
@ShutdownOnFailedCommand 1 //set to 0 if updating multiple servers at once | |||
@NoPromptForPassword 1 | |||
login anonymous | |||
app_update 244310 | |||
quit | |||
</pre> | |||
Make it executable with <code>chmod +x ssdk2013mp-update</code> | |||
This script will update the underlying Source SDK 2013 MP Dedicated Server, you may execute it by itself, but in this case we will use it for automatic updates. | |||
Next, create a service file in <code>/etc/systemd/system/</code> | |||
Example <code>tf2classic.service</code>: | |||
<pre> | |||
[Unit] | |||
Description=TF2Classic | |||
After=network-online.target | |||
Wants=network-online.target | |||
[Service] | |||
Type=forking | |||
User=steam | |||
WorkingDirectory=/home/tf2classic | |||
RemainAfterExit=yes | |||
ExecStartPre=/usr/games/steamcmd +runscript /opt/tf2classic/ssdkb2013mp-update | |||
ExecStartPre=/opt/tf2classic/TF2CDownloaderLinux --update | |||
ExecStart=/opt/tf2classic/server/srcds_run -console -game tf2classic +map tr_walkway_fastcat_v1 -port 27020 +maxplayers 32 +sv_setsteamaccount XXXXXXX | |||
TimeoutStartSec=infinity | |||
Restart=always | |||
[Install] | |||
WantedBy=multi-user.target | |||
</pre> | |||
Then, enable the service to start with the init system: | |||
<pre> | |||
# systemctl enable tf2classic.service | |||
</pre> | |||
Next, switch to the <code>root</code> user using <code>sudo su</code> and execute <code>crontab -e</code>. This is where you can set cronjobs, include something like the following: | |||
<pre> | |||
# Restart and update check for TF2Classic every day at 4 AM. | |||
0 4 * * * systemctl restart tf2classic.service | |||
</pre> | |||
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>. | |||
=== Systemd manual start, stop, restart/update === | |||
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. | |||
<pre> | |||
# systemctl restart tf2classic # in case you need to restart manually or to grab updates!! | |||
# systemctl stop tf2classic # in case you need to stop the server manually | |||
# systemctl start tf2classic # in case you need to start the server manually | |||
# systemctl disable tf2classic # in case you need to stop the server from booting as your system initializes | |||
# systemctl enable tf2classic # in case you need to start the server to boot as your system initializes | |||
</pre> | |||
''</br>See also [[Dedicated_Linux_server_extras|Dedicated Linux Server Extras]].'' | |||
[[Category:Guides]] | [[Category:Guides]] |
Latest revision as of 12:53, 23 April 2024
- This 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/
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.
*Note: This guide was written for and tested on Ubuntu Server 22.04 LTS, however any Debian-based distro should work similarly and fine using this guide.
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, and miscellaneous packages that we'll be using.
# apt install steamcmd unzip aria2 tilde lib32z1 libncurses5:i386 libbz2-1.0:i386 lib32gcc-s1 lib32stdc++6 libtinfo5:i386 libcurl3-gnutls:i386 libsdl2-2.0-0:i386 libcurl4-gnutls-dev libcurl4-gnutls-dev:i386
*Note:See Developer Wiki SteamCMD Repository Packages if your distro is having issues getting steamcmd.
Login to the steam user you created:
# su - steam
Run steamcmd
and let it update. When it’s finished updating and displays the main SteamCMD shell, run force_install_dir /opt/tf2classic/server
to choose the directory for the Source SDK Base 2013 Dedicated server to install into. This path can be anything, just make sure you have access to it.
Login anonymously by typing and running: login anonymous
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 TF2CDownloader.
Run:
$ wget https://github.com/tf2classic/TF2CDownloader/releases/latest/download/TF2CDownloaderLinux $ chmod +x ./TF2CDownloaderLinux $ ./TF2CDownloaderLinux
And follow the prompts.
You'll need to move the extracted 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:
unzip <archive>.zip
And merge the cfg
folder with /opt/tf2classic/server/tf2classic/cfg/
.
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
If you've manually installed TF2 Classic instead of using the automatic installer, make sure to symlink these files too, inside TF2 Classic's bin folder:
$ cd ../tf2classic/bin $ rm server_srv.so $ ln -s server.so server_srv.so
Running the server
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 nano. Run:
$ nano runserver.sh
Fill it with this line (you may be able to paste using Shift+Insert
):
./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 CRTL+X
, and then Y
to write your changes.
Now, make the script executable with:
$ chmod +x runserver.sh
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
Systemd & Crontab for automated start, restart and updating
For easier automation of server restarts, updating, and booting alongside the system, you may use systemd, which is the default init system for most modern Linux distros and cronjobs.
Create file ssdk2013mp-update
and fill in the following
@ShutdownOnFailedCommand 1 //set to 0 if updating multiple servers at once @NoPromptForPassword 1 login anonymous app_update 244310 quit
Make it executable with chmod +x ssdk2013mp-update
This script will update the underlying Source SDK 2013 MP Dedicated Server, you may execute it by itself, but in this case we will use it for automatic updates.
Next, create a service file in /etc/systemd/system/
Example tf2classic.service
:
[Unit] Description=TF2Classic After=network-online.target Wants=network-online.target [Service] Type=forking User=steam WorkingDirectory=/home/tf2classic RemainAfterExit=yes ExecStartPre=/usr/games/steamcmd +runscript /opt/tf2classic/ssdkb2013mp-update ExecStartPre=/opt/tf2classic/TF2CDownloaderLinux --update ExecStart=/opt/tf2classic/server/srcds_run -console -game tf2classic +map tr_walkway_fastcat_v1 -port 27020 +maxplayers 32 +sv_setsteamaccount XXXXXXX TimeoutStartSec=infinity Restart=always [Install] WantedBy=multi-user.target
Then, enable the service to start with the init system:
# systemctl enable tf2classic.service
Next, switch to the root
user using sudo su
and execute crontab -e
. This is where you can set cronjobs, include something like the following:
# Restart and update check for TF2Classic every day at 4 AM. 0 4 * * * systemctl restart tf2classic.service
You may create as many services as you have TF2C servers but remember to name the service files uniquely, enable them in systemctl
, and add them to the crontab
.
Systemd manual start, stop, restart/update
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.
# systemctl restart tf2classic # in case you need to restart manually or to grab updates!! # systemctl stop tf2classic # in case you need to stop the server manually # systemctl start tf2classic # in case you need to start the server manually # systemctl disable tf2classic # in case you need to stop the server from booting as your system initializes # systemctl enable tf2classic # in case you need to start the server to boot as your system initializes
See also Dedicated Linux Server Extras.