Garry’s Mod on CentOS 7

Garry’s Mod enables complete control and modification of the video game engine, Source Engine. With Garry’s Mod, you can create almost any game you want. Setting up a Garry’s Mod server is a great way to play with friends over the internet while maintaining control over the server.

This guide shows how to create, maintain, and secure a Garry’s Mod server.

You will need a Steam account and a copy of Garry’s Mod to complete this guide.

Preparation

Before you begin, install necessary packages, create a user, and edit your firewall privileges.

This section assumes root access. Be sure to run the guide as root or with the sudo prefix.

Update Packages

  1. Log in to your VPS via SSH.
  2. Run the update command, and install the required dependencies to run SteamCMD:

    1
    2
    yum update
    yum install tmux gdb mailx postfix glibc.i686 libstdc++.i686
    

Update Firewall

If you have a firewall on your VPS, add the following ruleset to iptables.firewall.rules in order to run SteamCMD:

/etc/iptables.firewall.rules
1
2
3
# Allow SteamCMD
-A INPUT -p udp -m udp --sport 27000:27030 --dport 1025:65355 -j ACCEPT
-A INPUT -p udp -m udp --sport 4380 --dport 1025:65355 -j ACCEPT

Add A User

  1. Create the user. In this example, the user is called gmod:

    1
    adduser gmod
    
  2. Set the password for your user:

    1
    passwd gmod
    
  3. Login to your new user:

    1
    su - gmod
    

Installation

  1. Download the required script. This script installs both the server installer (SteamCMD) and the necessary server files:

    1
    wget http://danielgibbs.co.uk/dl/gmodserver
    
  2. Give the user execute permissions for the script:

    1
    chmod +x gmodserver
    
  3. Run the installer:

    1
    ./gmodserver install
    
  4. Press y when it asks about the server directory.

  5. Ensure that the install was successful, press y if the output reads affirmative:

    1
    2
    3
    4
    5
    6
    Update state (0x61) downloading, progress: 97.37 (3695044726 / 3795030198)
    Update state (0x61) downloading, progress: 99.92 (3792009490 / 3795030198)
    Success! App '4020' fully installed.
    
    =================================
    Was the install successful? [y/N]
    
  6. You can choose to install Game Server Query in the next step. The Game Server Query plugin improves monitoring of the server.

  7. Configure your server by replacing Example Server and password with your desired server name and password.

    1
    2
    Enter server name: Example Server
    Enter rcon password: password
    

Configuration

This section configures different aspects of the server, including gamemode and workshop addons.

  1. Create a collection of addons you want to install on your server at Garry’s Mod Collections. You will need to be logged into Steam.

  2. Note the collection ID. It is located at the end of the url, denoted by the ‘X’s here:

    1
    http://steamcommunity.com/sharedfiles/filedetails/?id=XXXXXXXXX
    
  3. Acquire a Steam API key from the Steam API Keys page. Note the key.

  4. Open gmodserver in the editor:

    1
    nano gmodserver
    
  5. Set the workshopauth to your Steam API Key, and your workshopcollectionid to your collection ID.

  6. Set the gamemode of the Garry’s Mod server by adding the following to the parms variable on line 34:

    1
    +gamemode terrortown
    

    This sets the game for the Trouble in Terrorist Town (TTT) gamemode, but can be changed to your desired gamemode, if you have it downloaded.

  7. Save and exit with CTRL-X followed by Y.

Running the Server

Start the server using:

1
./gmodserver start

To ensure it is running and access to the console, use:

1
./gmodserver console

To exit the console, use CTRL-B followed by D. Do not CTRL-C out of the console, which shuts down the server.

To stop the server, use:

1
./gmodserver stop

Server Maintenance

This section discusses how to do different maintenance functions for the server.

Run on Boot

  1. Open up /etc/rc.local:

    1
    nano /etc/rc.local
    
  2. Add a line at the end of the file for Garry’s Mod:

    /etc/rc.local
    1
    su - gmod -c '/home/gmod/gmodserver start'
    
  3. Save and exit using CTRL-X followed by Y.

Enable Email Notification

  1. Open the gmodserver file:

    1
    nano gmodserver
    
  2. Turn on email notifications by editing these lines:

    gmodserver
    1
    2
    emailnotification="on"
    email="test@example.com"
    
  3. Save and exit using CTRL-X followed by Y.

Daily Server Update

  1. Edit the crontab using:

    1
    crontab -e
    
  2. Press i to enter insertion mode.

  3. Add this line to the the end of the crontab:

    1
    0 5 * * *  su - gmod -c '/home/gmod/gmodserver update-restart' > /dev/null 2>&1
    

    This configuration updates and restarts the server everyday at 5:00 am.

  4. Exit cron using ESC, :x, ENTER.

Monitor the Server

This will make sure the server is online every 30 minutes.

  1. Edit the crontab using:

    1
    crontab -e
    
  2. Press i to enter insertion mode.

  3. Add this line to the end of the crontab:

    1
    */30 * * * *  su - gmod -c '/home/gmod/gmodserver monitor' > /dev/null 2>&1
    
  4. Exit cron using ESC, :x, ENTER.

Updating the Server

To update the server, run:

1
./gmodserver update

Validating the Server

If you think your Garry’s Mod version is corrupted for one reason or another, run:

1
./gmodserver validate

More Information

You may wish to consult the following resources for additional information on this topic. While these are provided in the hope that they will be useful, please note that we cannot vouch for the accuracy or timeliness of externally hosted materials.

Source: +
  • 0 Users Found This Useful
Was this answer helpful?

Related Articles

This guide will show you how to install a TeamSpeak Server on your VPS

This guide will show you how to install a TeamSpeak Server on your VPS. TeamSpeak is a voice...

PocketMine Server on Debian 7

PocketMine is a third party server for the MineCraft - Pocket Edition game for Android and iOS....

Installing McMyAdmin for Minecraft on Debian

McMyAdmin is one of the most popular Minecraft server control panels available. It boasts...

Installing Multicraft on Ubuntu

Multicraft is a control panel for single or multiple Minecraft servers, with free and paid...

Installing Multicraft on Debian

Multicraft is a control panel for single or multiple Minecraft servers Free and paid versions are...