Difference between revisions of "Linux dedicated server"

From Team Fortress Wiki
Jump to: navigation, search
(Updated for SteamCMD and to match a lot of the Windows changes)
Line 2: Line 2:
 
{{ambox | type = notice | image = Ambox_notice.png | contents = '''hldsupdatetool''' no longer works. Please download and use the '''[https://developer.valvesoftware.com/wiki/SteamCMD SteamCMD]'''.}}
 
{{ambox | type = notice | image = Ambox_notice.png | contents = '''hldsupdatetool''' no longer works. Please download and use the '''[https://developer.valvesoftware.com/wiki/SteamCMD SteamCMD]'''.}}
  
Linux is one of the two platforms currently supported by Valve's dedicated server tool (HLDS), the other being [[Windows dedicated server|Microsoft Windows]]. Basic installation and configuration for a '''Linux dedicated server''' is the same for all distributions, but small details, such as package names, directories, etc. may differ from distribution to distribution. It is recommended that you check your distribution's repositories for the required packages before continuing.
+
This is a setup guide that allows you to install a basic ''[[Team Fortress 2]]'' '''Linux dedicated server'''. In the below example the [[server]] is installed into the user's home directory in a directory called 'hlserver'.
 +
 
 +
Basic installation and configuration for a '''Linux dedicated server''' is the same for all distributions, but small details, such as package names, directories, etc. may differ from distribution to distribution. It is recommended that you check your distribution's repositories for the required packages before continuing.
  
 
== Reading this article ==
 
== Reading this article ==
Line 16: Line 18:
 
* Write-access to the current working directory
 
* Write-access to the current working directory
 
* <code>glibc >= 2.3.6</code>
 
* <code>glibc >= 2.3.6</code>
* Approximately 9GB hard-drive space (for a barebones server with no custom maps, sounds, etc.)
+
* Approximately 4.49GB hard-drive space (for a barebones server with no custom maps, sounds, etc.)
 
* In the case of a '''64-bit''' distribution, the package '''lib32gcc1''' or '''ia32-libs''' is required to be installed:
 
* In the case of a '''64-bit''' distribution, the package '''lib32gcc1''' or '''ia32-libs''' is required to be installed:
 
On  64-bit CentOS run:   
 
On  64-bit CentOS run:   
Line 33: Line 35:
 
* If you are installing on FreeBSD (which is not Linux at all), you must enable Linux compatibility in the kernel and install a base system via the ports collection.  Instructions to get you started are located [http://www.ian-justman.com/wiki/index.php?title=HowTos:SRCDS_under_FreeBSD here].
 
* If you are installing on FreeBSD (which is not Linux at all), you must enable Linux compatibility in the kernel and install a base system via the ports collection.  Instructions to get you started are located [http://www.ian-justman.com/wiki/index.php?title=HowTos:SRCDS_under_FreeBSD here].
  
== Installation ==
+
==Download and install the SteamCMD Tool==
There are a number of different ways to run a dedicated server. In this article, we will assume that a specific user (''tf2server'') has been created for the sole purpose of running a Team Fortress 2 server. In order to create a user, issue the following command as root:
+
*Download [http://media.steampowered.com/client/steamcmd_linux.tar.gz steamcmd_linux.tar.gz]
 
+
*Use tar to uncompress it to a directory, for example './hlserver' :
# adduser tf2server
+
  tar zxf steamcmd_linux.tar.gz
 
 
You will be prompted for a name, a password, along with other information; fill this out as you please. Then switch user, for short su, to the newly created account:
 
 
 
  $ su -l tf2server
 
 
 
Next up, create a directory and change to it. You can call it anything you like; I've picked "hlds":
 
 
 
$ mkdir hlds && cd hlds
 
  
The next thing we need to do is to download the dedicated server update tool (hldsupdatetool.bin), and change its permissions to be executable, allowing us to download the Steam binary required to download our gameserver. Finally, we run the binary.
+
==Create a steamcmd script==
 +
*Create a file called tf2_ds.txt in the folder where you install the tool, i.e. './hlserver'
 +
*Edit the file with this text:
 +
@ShutdownOnFailedCommand 1
 +
@NoPromptForPassword 1
 +
login anonymous
 +
force_install_dir ./tf2
 +
app_update 232250
 +
quit
  
$ wget http://storefront.steampowered.com/download/hldsupdatetool.bin && chmod +x hldsupdatetool.bin
+
If you want to opt in to the prerelease version of the TF2 dedicated server, add this line before the app_update line:
  $ ./hldsupdatetool.bin
+
  beta prerelease
  
If you receive the error:
+
==Create an updating batch file==
 +
*Create a file called update.sh in the folder where you installed the tool, i.e. './hlserver'
 +
*Edit the file with this text:
 +
#!/bin/sh
 +
./steamcmd +runscript tf2_ds.txt
  
$ sh: uncompress: command not found
+
==Start the download/update==
$ tar: This does not look like a tar archive
+
*Run ./update.sh to start the download, may take several hours as dedicated server content is currently 4.4GB
$ tar: Error exit delayed from previous errors
+
*You may need to run the file *multiple* times until the message "Success! App '232250' fully installed." displays.
  
the reason is because uncompress is an alias for gunzip that many Linux distros do not use (CentOS 5 and 6 have this issue). To get around this, you need to symlink uncompress to gunzip. To do this run the following command
+
==Create/Update server files==
 +
*Create a file called server.cfg in '~/hlserver/tf2/tf/cfg'
 +
*Edit the file with these details
 +
hostname "Your_Servers_Name"
 +
rcon_password "Your_Rcon_Password"
 +
sv_contact "admin@yourdomain.com"
 +
mp_timelimit "30"
 +
* Edit the files motd.txt, maplist.txt and mapcycle.txt all found in the '~/hlserver/tf2/tf' folder
  
$  ln -s /usr/bin/gunzip /usr/bin/uncompress
+
==Create a shell script to run the server==
 +
*Create a file in './hlserver/' called tf.sh
 +
*Edit the file with this text:
 +
orangebox/srcds_run -game tf +sv_pure 1 +map ctf_2fort +maxplayers 24
 +
*Run the file tf.sh to start your server
  
When we run the binary, we're prompted to accept Valve's Terms and Conditions for using the update tool; after reading and agreeing to the terms included, type "yes", and hit Enter. The next thing to happen is that the ''steam'' binary should extract. Run it to download the latest version of the HLDS Update Tool.  ''steam'' may run an excess of 20 minutes to perform the updates, please be patient.
+
=== Other comamnd line options ===
  
$ ./steam
+
Some other common command-line options for TF2 are:
Checking bootstrapper version ...
 
Getting version 50 of Steam HLDS Update Tool
 
Downloading. . . . . . . . . . . .
 
Steam Linux Client updated, please retry the command
 
  
Do as prompted; repeat the same command. All we need to do now is to download the gameserver files, and launch it.
+
* <code>+ip 1.2.3.4</code> - Bind to a specific IP. By default, listens on all network interfaces
 
+
* <code>-port 27015</code> - Bind to a different port (27015 is the default)
Create another directory, which will house the actual files of the gameserver (inside /home/tf2server/hlds). We'll call this one ''gameserver''.
+
* <code>-strictportbind</code> - If a server is already running on the specified port, stop the server from running
 
+
* <code>+randommap</code> - Use instead of +map to select a map at random
  $ mkdir gameserver
+
* <code>+serverconfigfile</code> - Which tf/cfg/ file to execute on map change, defaults to server.cfg
 
+
* <code>+mapcyclefile</code> - Which tf/cfg/ file contains this server's mapcycle, defaults to mapcycle.txtWill also look in tf/
Next up, let's ask Steam to download the Team Fortress 2 game files into that folder, using the following command.
+
* <code>-replay</code> - Executes replay.cfg and adds an additonal port for the replay bot, but removes it from the player count.
 
+
* <code>-autoupdate</code> - Attempts to auto-update the server when an update comes out. You MUST use -steam_dir and -steamcmd_script
$ ./steam -command update -game tf -dir gameserver
+
* <code>-steam_dir ~/hl1server/</code> - Location of steamcmd. Required by <code>-autoupdate</code>
 
+
* <code>-steamcmd_script ~/hl1server/tf2_ds.txt</code> - SteamCMD script to update this server. Required by <code>-autoupdate</code>
This runs the ''update'' command of the game ''tf'' (Team Fortress 2) into the directory ''gameserver/''. Sit back and wait, this may take some time.
+
* <code>+sv_shutdown_timeout_minutes 360</code> - When autoupdating, automatically restart after this many minutesDefaults to 360 (6 hours).
 
 
== Running the server ==
 
We're almost done. The server is installed. The only thing left is to run it, using a number of arguments. Change to the <code>gameserver/orangebox/</code> directory. In this folder, create a file called <code>steam_appid.txt</code> and put in there only the following number:
 
 
 
  440
 
 
 
Next, in the same <code>orange box</code> folder, there should be a script called <code>srcds_run</code>, which is what launches the game. A basic use of this script '''could''' be:
 
 
 
  $ ./srcds_run -game tf -autoupdate -steambin /home/tf2server/hlds/steam -maxplayers 24 +map cp_badlands
 
 
 
This launches a ''Team Fortress 2'' server with a maximum of 24 players on [[Badlands (Control Point)|Badlands]] which will download updates automatically. There are many more ways of configuring the server and running it, but this covers the basics.
 
  
 
=== screen ===
 
=== screen ===
Line 100: Line 102:
  
 
=== Automated startup at server boot ===
 
=== Automated startup at server boot ===
In the event of unexpected power outages, it might be usefull to automatically restart your server. The following example Debian LSB init script can be used to automatically restart the server. Note that  <code>screen</code> is used. This script should be named TF2-server and can be put in the folder /etc/init.d. After doing that, run:
+
In the event of unexpected power outages, it might be useful to automatically restart your server. The following example Debian LSB init script can be used to automatically restart the server. Note that  <code>screen</code> is used. This script should be named TF2-server and can be put in the folder /etc/init.d. After doing that, run:
  
 
  $ update-rc.d TF2-server defaults
 
  $ update-rc.d TF2-server defaults
Line 122: Line 124:
 
USER="tf2server"
 
USER="tf2server"
 
SCREENREF="tf2"
 
SCREENREF="tf2"
BINARYPATH="/home/tf2server/hlds/gameserver/orangebox"
+
BINARYPATH="/home/tf2server/hlserver/tf2"
 
BINARYNAME="srcds_run"
 
BINARYNAME="srcds_run"
 
PIDFILE="tf2server.pid"
 
PIDFILE="tf2server.pid"
  
OPTS="-game tf -autoupdate -steambin /home/tf2server/hlds/steam +maxplayers 32 +ip 0.0.0.0 +map mvm_decoy"
+
OPTS="-game tf +maxplayers 32 +ip 0.0.0.0 +map mvm_decoy"
  
 
cd "$BINARYPATH"
 
cd "$BINARYPATH"
Line 214: Line 216:
  
 
== Troubleshooting ==
 
== Troubleshooting ==
; <tt>./steam</tt>  hangs the first time I run it.
 
: The first run of <tt>./steam</tt> may take an excess of 20 minutes to run. 
 
:# If no progress is made after 20 minutes please open ports 27000-27015 to incoming traffic in your firewall
 
:# If it continues to hang retry several times until it completes.
 
 
; Get an error like: "-bash: ./hldsupdatetool.bin: No such file or directory"?
 
: See the package requirement section to add the required libraries
 
 
 
; My server doesn’t show up in the LAN tab of my client’s server browser.
 
; My server doesn’t show up in the LAN tab of my client’s server browser.
 
; I cannot access my loadout when playing on this server.
 
; I cannot access my loadout when playing on this server.
Line 239: Line 233:
 
  WARNING: Could not locate steam binary:, ignoring.
 
  WARNING: Could not locate steam binary:, ignoring.
 
: If so, then you need point <code>srcds_run</code> to the location of your Steam binary, using the <code>-steambin</code> argument. See ''[[#Running the server|Running the server]]'', above.
 
: If so, then you need point <code>srcds_run</code> to the location of your Steam binary, using the <code>-steambin</code> argument. See ''[[#Running the server|Running the server]]'', above.
 
== Tips ==
 
# <tt>server.cfg</tt> goes in <tt>orangebox/tf/cfg</tt>. For more information on configuring your dedicated server, see [[Dedicated server configuration]].
 
# If you want people outside of your network to be able to connect – that is, you’re not just running a LAN server – remember to open ports 27000-27015 to incoming traffic in your firewall.
 
# If you don't have a firewall, get one. Exposing your server to the internet without a firewall is very risky.
 
  
 
== See also ==
 
== See also ==

Revision as of 23:28, 1 June 2013

This is a setup guide that allows you to install a basic Team Fortress 2 Linux dedicated server. In the below example the server is installed into the user's home directory in a directory called 'hlserver'.

Basic installation and configuration for a Linux dedicated server is the same for all distributions, but small details, such as package names, directories, etc. may differ from distribution to distribution. It is recommended that you check your distribution's repositories for the required packages before continuing.

Reading this article

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

  • A command prefixed by # (a hash) is meant to be run as root. Most distributions have a separate root account; for other distributions such as Ubuntu, Linux Mint, Crunchbang, etc., the sudo prefix to a command will ensure the command is run as root.
  • A command prefixed by $ (a dollarsign) is meant to be run as a user.
  • ./ means "current working directory".

Requirements

A number of requirements exist in order to run a Team Fortress 2 server on the Linux platform, namely:

  • Write-access to the current working directory
  • glibc >= 2.3.6
  • Approximately 4.49GB hard-drive space (for a barebones server with no custom maps, sounds, etc.)
  • In the case of a 64-bit distribution, the package lib32gcc1 or ia32-libs is required to be installed:

On 64-bit CentOS run:

# yum install libgcc.i686 glibc.i686

On 64-bit Debian/Ubuntu/Linux Mint run:

$ sudo apt-get install lib32gcc1 ia32-libs

On 64-bit ArchLinux run:

$ sudo pacman -Sy lib32gcc1 ia32-libs

  • If you are installing on CentOS, you will have to use this command before yum install ncompress
  • If you are installing on FreeBSD (which is not Linux at all), you must enable Linux compatibility in the kernel and install a base system via the ports collection. Instructions to get you started are located here.

Download and install the SteamCMD Tool

tar zxf steamcmd_linux.tar.gz

Create a steamcmd script

  • Create a file called tf2_ds.txt in the folder where you install the tool, i.e. './hlserver'
  • Edit the file with this text:
@ShutdownOnFailedCommand 1
@NoPromptForPassword 1
login anonymous
force_install_dir ./tf2
app_update 232250
quit

If you want to opt in to the prerelease version of the TF2 dedicated server, add this line before the app_update line:

beta prerelease

Create an updating batch file

  • Create a file called update.sh in the folder where you installed the tool, i.e. './hlserver'
  • Edit the file with this text:
#!/bin/sh
./steamcmd +runscript tf2_ds.txt

Start the download/update

  • Run ./update.sh to start the download, may take several hours as dedicated server content is currently 4.4GB
  • You may need to run the file *multiple* times until the message "Success! App '232250' fully installed." displays.

Create/Update server files

  • Create a file called server.cfg in '~/hlserver/tf2/tf/cfg'
  • Edit the file with these details
hostname "Your_Servers_Name"
rcon_password "Your_Rcon_Password"
sv_contact "admin@yourdomain.com"
mp_timelimit "30" 
  • Edit the files motd.txt, maplist.txt and mapcycle.txt all found in the '~/hlserver/tf2/tf' folder

Create a shell script to run the server

  • Create a file in './hlserver/' called tf.sh
  • Edit the file with this text:
orangebox/srcds_run -game tf +sv_pure 1 +map ctf_2fort +maxplayers 24
  • Run the file tf.sh to start your server

Other comamnd line options

Some other common command-line options for TF2 are:

  • +ip 1.2.3.4 - Bind to a specific IP. By default, listens on all network interfaces
  • -port 27015 - Bind to a different port (27015 is the default)
  • -strictportbind - If a server is already running on the specified port, stop the server from running
  • +randommap - Use instead of +map to select a map at random
  • +serverconfigfile - Which tf/cfg/ file to execute on map change, defaults to server.cfg
  • +mapcyclefile - Which tf/cfg/ file contains this server's mapcycle, defaults to mapcycle.txt. Will also look in tf/
  • -replay - Executes replay.cfg and adds an additonal port for the replay bot, but removes it from the player count.
  • -autoupdate - Attempts to auto-update the server when an update comes out. You MUST use -steam_dir and -steamcmd_script
  • -steam_dir ~/hl1server/ - Location of steamcmd. Required by -autoupdate
  • -steamcmd_script ~/hl1server/tf2_ds.txt - SteamCMD script to update this server. Required by -autoupdate
  • +sv_shutdown_timeout_minutes 360 - When autoupdating, automatically restart after this many minutes. Defaults to 360 (6 hours).

screen

Many server operators choose to run the server under screen, as it allows you to switch between the console and the shell at will, as well as end your SSH session without killing the server. It can be installed via your distribution's package manager. The server can then be run with:

$ screen -m -S tf2 ./srcds_run parameters

where parameters is your normal srcds_run parameters. You can use Ctrl+A+D to minimize the console, and screen -r tf2 to bring it back up. Ctrl+D will terminate the session (make sure you use the killserver console command first) and Ctrl+A+[ will allow you to scroll through it. See the manual for more commands and parameters.

Automated startup at server boot

In the event of unexpected power outages, it might be useful to automatically restart your server. The following example Debian LSB init script can be used to automatically restart the server. Note that screen is used. This script should be named TF2-server and can be put in the folder /etc/init.d. After doing that, run:

$ update-rc.d TF2-server defaults

This should ensure a proper startup of the server after each reboot.

#!/bin/sh

### BEGIN INIT INFO
# Provides:          tf2server
# Required-Start:    $remote_fs
# Required-Stop:     $remote_fs
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Team Fortress 2 server
# Description:       Starts a Team Fortress 2 server
### END INIT INFO

NAME="Team Fortress 2"
USER="tf2server"
SCREENREF="tf2"
BINARYPATH="/home/tf2server/hlserver/tf2"
BINARYNAME="srcds_run"
PIDFILE="tf2server.pid"

OPTS="-game tf +maxplayers 32 +ip 0.0.0.0 +map mvm_decoy"

cd "$BINARYPATH"

running() {
    if [ -n "`pgrep -f $BINARYNAME`" ]; then
        return 0
    else
        return 1
    fi
}

start() {
    if ! running; then
        echo -n "Starting the $NAME server... "
        start-stop-daemon --start --chuid $USER --user $USER --chdir $BINARYPATH --exec "/usr/bin/screen" -- -dmS $SCREENREF $BINARYPATH/$BINARYNAME $OPTS
        pgrep -f $BINARYNAME > $PIDFILE
        if [ -s $PIDFILE ]; then
            echo "Done"
        else
            echo "Failed"
            rm $PIDFILE
        fi
    else
        echo "The $NAME server is already started."
    fi
}

stop() {
    if running; then
        echo -n "Stopping the $NAME server... "
        kill `cat $PIDFILE`
        while running; do
            sleep 1
        done
        rm $PIDFILE
        echo "Done"
    else
        echo "The $NAME server is already stopped."
    fi
}

case "$1" in
    start)
        start
    ;;
    stop)
        stop
    ;;
    restart)
	stop
        start
    ;;
    status)
        if running; then
            echo "The $NAME server is started."
        else
            echo "The $NAME server is stopped."
        fi
    ;;
    *)
        echo "Usage: $0 (start|stop|restart|status)"
        exit 1
esac
exit 0

iptables rules

-A INPUT -i venet0 -p tcp -m tcp --dport 27015 -m state --state NEW,ESTABLISHED -j ACCEPT
-A INPUT -i venet0 -p tcp -m tcp --dport 27005 -m state --state NEW,ESTABLISHED -j ACCEPT
-A INPUT -i venet0 -p udp -m udp --dport 27015 -m state --state NEW,ESTABLISHED -j ACCEPT
-A INPUT -i venet0 -p udp -m udp --dport 27005 -m state --state NEW,ESTABLISHED -j ACCEPT
-A INPUT -i venet0 -p tcp -m tcp --dport 27016 -m state --state NEW,ESTABLISHED -j ACCEPT
-A INPUT -i venet0 -p tcp -m tcp --dport 27017 -m state --state NEW,ESTABLISHED -j ACCEPT
-A INPUT -i venet0 -p tcp -m tcp --dport 27018 -m state --state NEW,ESTABLISHED -j ACCEPT
-A INPUT -i venet0 -p tcp -m tcp --dport 27019 -m state --state NEW,ESTABLISHED -j ACCEPT
-A INPUT -i venet0 -p tcp -m tcp --dport 27020 -m state --state NEW,ESTABLISHED -j ACCEPT
-A INPUT -i venet0 -p udp -m udp --dport 27016 -m state --state NEW,ESTABLISHED -j ACCEPT
-A INPUT -i venet0 -p udp -m udp --dport 27017 -m state --state NEW,ESTABLISHED -j ACCEPT
-A INPUT -i venet0 -p udp -m udp --dport 27018 -m state --state NEW,ESTABLISHED -j ACCEPT
-A INPUT -i venet0 -p udp -m udp --dport 27019 -m state --state NEW,ESTABLISHED -j ACCEPT
-A INPUT -i venet0 -p udp -m udp --dport 27020 -m state --state NEW,ESTABLISHED -j ACCEPT
  • Note: may be shortened if you have multiports extension.

Troubleshooting

My server doesn’t show up in the LAN tab of my client’s server browser.
I cannot access my loadout when playing on this server.
Are you still able to connect using connect <ip-address> in the Developer Console?
During startup, does your server report the following?
*	Unable to load Steam support library.*
*	This server will operate in LAN mode only.*
When you connect with your client, does the server say the following?
NULL ISteamGameServer in ConnectClient. Steam authentication may fail.
…
Cannot verify load for invalid steam ID […]
If so, then both of these problems have the same solution: Make sure you have a steam_app.txt file containing the number 440 in your orange box folder. See Running the server, above.
My server doesn’t auto-update on startup.
When starting up, does your server say the following?
WARNING: Failed to locate steam binary.
WARNING: Could not locate steam binary:, ignoring.
If so, then you need point srcds_run to the location of your Steam binary, using the -steambin argument. See Running the server, above.

See also