Learn how to simply manage a TF2 server on Linux VPS or a local server with this very fine guide by BurningSmile. Please view the text instructions below as they are kept up to update with the newest changes.
Alternatively you can use this script to automate everything except the cfg.tf configuration. To run it do the following.
git clone https://github.com/BurningSmile/LinuxScripts.git
cd LinuxScripts
chmod +x auto-tf2serverinstall.sh
sudo ./auto-tf2serverinsall.sh
su - tf2server -c '/home/tf2server/tf2server stop'
reboot
Text directions:
Updating:
apt update
apt -y upgrade
apt -y dist-upgrade
apt -y autoremove
apt autoclean
Turn off auto updates
vim /etc/apt/apt.conf.d/10periodic
Change 1 to 0
Save and exit file
Dependencies for LGSM
Ubuntu
dpkg --add-architecture i386; apt-get update; apt-get install mailutils postfix curl wget file bzip2 gzip unzip bsdmainutils python util-linux tmux lib32gcc1 libstdc++6 libstdc++6:i386 libcurl4-gnutls-dev:i386
Debian
dpkg --add-architecture i386; sudo apt-get update; sudo apt-get install mailutils postfix curl wget file bzip2 gzip unzip bsdmainutils python util-linux tmux lib32gcc1 libstdc++6 libstdc++6:i386 libcurl4-gnutls-dev:i386
Fedora
dnf install mailx postfix curl wget file bzip2 gzip unzippython tmux glibc.i686 libstdc++ libstdc++.i686 libcurl.i686
Centos
yum install mailx postfix curl wget bzip2 gzip unzip python tmux glibc.i686 libstdc++ libstdc++.i686 libcurl.i686
Create a tf2server account
useradd -m --password default tf2server
Create a password for the account
passwd tf2server
Change to the account
su - tf2server
Download the tf2 server management stack
wget -N --no-check-certificate https://gameservermanagers.com/dl/linuxgsm.sh && chmod +x linuxgsm.sh && bash linuxgsm.sh tf2server
Install the server
./tf2server auto-install
Lgsm has recently changed the way they handel server settings. You now copy them to a file in the directory $HOME/lgsm/configs-lgsm/tf2server/tf2server.cfg. Use the following commands to setup this file with the items you will most likely be changing.
vim /home/tf2server/lgsm/config-lgsm/tf2server/tf2server.cfg
Add the following
defaultmap="cp_badlands"
maxplayers="16"
updateonstart="on"
Save the file
Allow tf2server through the firewall.
This will setup our firewall. I setup up firewalls to block all incoming traffic that is not whitelisted.
sudo iptables -I INPUT 1 -i lo -j ACCEPT
sudo iptables -A INPUT -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT
sudo iptables -A INPUT -p tcp -m state --state NEW,ESTABLISHED --dport 22 -j ACCEPT
sudo iptables -A INPUT -p icmp --icmp-type echo-request -m state --state ESTABLISHED,RELATED -j ACCEPT
sudo iptables -A INPUT -p tcp --dport 80 -m state --state NEW,ESTABLISHED -j ACCEPT
sudo iptables -A INPUT -p tcp --dport 443 -m state --state NEW,ESTABLISHED -j ACCEPT
sudo iptables -A INPUT -p udp --dport 27015 -m state --state NEW,ESTABLISHED -j ACCEPT
sudo iptables -A INPUT -p tcp --dport 27015 -m state --state NEW,ESTABLISHED -j ACCEPT
sudo iptables -A INPUT -p udp --dport 27020 -m state --state NEW,ESTABLISHED -j ACCEPT
sudo iptables -P INPUT DROP
iptables-save > /etc/iptables/rules.v4
ip6tables-save > /etc/iptables/rules.v6
Start the server
./tf2server start
Test connecting to it
Connect ip-here in game console
Stop the server
./tf2server stop
Installing apache2 webserver
exit
apt install apache2
mkdir -p /var/www/html/fastdl/tf2/
cd /var/www/html/fastdl/tf2/
ln -s /home/tf2server/serverfiles/tf/maps maps
ls -la
systemctl status apache2.service
systemctl start apache2.service
systemctl enable apache2.service
cd ../..
mv index.html index.html.bak
Refresh the page and test downloading a map
Address sftp:// ip here
User tf2server
Password The password you set up on the tf2 server account
Port 22
Change FileZilla directory to serverfiles/tf
Back in the ssh session
su - tf2server
cd serverfiles/tf/
Now for metamod:
Go to the site and copy its link address for the Linux version.
https://www.metamodsource.net/downloads.php?branch=stable
wget (link here)
tar -xvf mmsource
(Use tab completion)
rm mmsource
(tab complete)
Now for sourcemod:
Go to the souremod site and copy its link address for the Linux version.
https://www.sourcemod.net/downloads.php?branch=stable
wget (link here)
tar -xvf sourcemod
(tab complete)
rm sourcemod
( tab complete)
Setting up admin account
vim ./addons/souremod/config/admins_simple.ini
Go to a steamidfinder.com
Paste your steam url and paste the steam id. Follow the below example
“STEAMID” “99:z” //useraccountname
Go to cfg.tf and follow my example for configuring the server.
Custom settings used in video. Remember to replace IP-GOES-HERE with the ip of your vps.
// Server downloads and files
net_maxfilesize "64"
sv_downloadurl "http://IP-GOES-HERE/fastdl/tf2/"
sv_allowdownload "1"
sv_allowupload "1"
sv_consistency "1"
Unzip the file and upload it to your server in sftp to your serverfiles/tf directory, overwrite any files if asked.
Start the server via ssh
./tf2server start
Automate a restart at midnight. And automate the SRCDS instance starting on server start and restart.
Refer to crontab documentation if needed.
https://linux.die.net/man/5/crontab
https://help.ubuntu.com/community/CronHowto
crontab -e
Choose 3 to use vim
Add the following in insert mode
0 0 * * * /home/tf2server/tf2server restart
@reboot /home/tf2server/tf2server start
Save the file and exit vim
Ensure the crontab file works
./tf2server stop
exit
reboot
After the reboot make sure your Srcds instance starts on boot.