Get Rewarded! We will reward you with up to €50 credit on your account for every tutorial that you write and we publish!

CSGO pelipalvelimen asennus

profile picture
Author
Markus
Published
2019-04-05
Time to read
5 minutes reading time

Introduction

Tässä artikkelissa käydään läpi kuinka asennetaan ja konfiguroidaan CSGO palvelin linux-järjetelmiin.

Vaatimukset

  • x86 / x64 yhteensopiva järjestelmä
  • Ubuntu 16.04 LTS
  • Asennettu steamcmd
  • CX23 palvelin tai parempi

Vaihe 1 - Valmistelut

Luodaan CSGO kansio, josta pelipalvelimen asetukset löytyy:

mkdir /opt/csgo/
chown steamcmd:steamcmd /opt/csgo/

Kaikki konsolikomennot kuuluu suorittaa steamcmd käyttäjänä.

su --shell /bin/bash steamcmd

Vaihe 2 - Asennus

Lataa pelipalvelimen tiedostot steamcmd:n kautta:

steamcmd +login anonymous +force_install_dir /opt/csgo/ +app_update 740 +quit

Kun palvelimen tiedostot on ladattu, voimme laittaa asetukset kuntoon.

CSGO palvelimen asetukset löytyy sijainnista /opt/csgo/csgo/cfg/server.cfg. Täällä voit muokata ja liittää sinne alla olevan asetustiedoston.

// ************************************************************************** //
//     Counter-Strike: Global Offensive - server.cfg                          //
//     Version 240917                                                         //
// ************************************************************************** //
// .................................. Basic ................................. //

// Hostname - Name of the server.
hostname "SERVERNAME"

// RCON - remote console password.
rcon_password "ADMINPASSWORD"

// Server password - for private servers.
sv_password ""

// Email - Server admin email.
// Example: sv_contact "email@example.com"
sv_contact ""

// LAN mode - If set the server will not show on the internet.
// Default: sv_lan 0
sv_lan 0

// ............................. Server Logging ............................. //

// Enable log - Enables logging to file, console, and udp < on | off >.
// Recommended: log on
log on

// Log bans - Log server bans in the server logs.
// Default: sv_logbans 1
// Recommended: sv_logbans 1
sv_logbans 1

// Log echo - Display log information to the server console.
// Default: sv_logecho 1
// Recommended: sv_logecho 1
sv_logecho 1

// Log file - Log server information in the log file.
// Default: sv_logfile 1
// Recommended: sv_logfile 1
sv_logfile 1

// One file log - Log server information to only one file.
// Default: sv_log_onefile 0
// Recommended: sv_log_onefile 0
sv_log_onefile 0

// Server Hibernation
sv_hibernate_when_empty 1
sv_hibernate_ms 5

// ............................. Server Query ............................. //
// More info at: https://www.gametracker.com/games/csgo/forum.php?thread=91691
host_name_store 1
host_info_show 1
host_players_show 2

// ................................ Ban List ................................ //

// User ban - Server banlist based on user steam ID.
// Recommended: exec banned_user.cfg
exec banned_user.cfg

// IP ban - Server banlist based on user IP.
// Recommended: exec banned_ip.cfg
exec banned_ip.cfg

// Write ID - Writes a list of permanently-banned user IDs to banned_user.cfg.
writeid

// Write IP - Save the ban list to banned_ip.cfg.
writeip

Vaihe 3 - Palvelimen hallinta

Palvelimen hallinta (käynnistä, pysäytä, päivitä) vaatii seuraavan skriptin.

Suurinta osaa asetuksista voidaan käyttää sellaisenaan, kunhan vaihdat GAMETOKEN kohdan omaan palvelintunnukseen. Palvelintunnuksen täytyy olla voimassa, sen saa hankittua täältä: Steam Game Server Account Management

(Matalan suorituskyvyn palvelimilla, TICK-asetus kannattaa vaihtaa arvoon 64.)

#!/bin/bash

################# SET VARs #################

DIR="/opt/csgo"
SCREENNAME="csgo"

GAMETOKEN=""
TICK=128
GAMETYPE=0
GAMEMODE=1
MAPGROUP="mg_bomb"
MAP="de_dust2"
MAXPLAYER=10

################# DO NOT MODIFY #################

DEAMON="srcds_run"
PARAMS="-game csgo -ip 0.0.0.0 -port 27015 +maxplayers $MAXPLAYER +map $MAP -tickrate $TICK +game_type $GAMETYPE +game_mode $GAMEMODE +mapgroup $MAPGROUP +sv_setsteamaccount $GAMETOKEN"

function start_server {
    if [[ `screen -ls | grep $SCREENNAME` ]]; then
        echo "The server is already running $SCREENNAME"
    else
        echo "Starte $SCREENNAME"
        if [ -d $DIR ]; then
           cd $DIR
           screen -d -m -S $SCREENNAME ./$DEAMON $PARAMS
        else
           echo "The server directory was not specified"
        fi
    fi
}

function stop_server {
    if [[ `screen -ls | grep $SCREENNAME` ]]; then
        echo -n "Stoppe $SCREENNAME"
        kill `screen -ls | grep $SCREENNAME | awk -F . '{print $1}'| awk '{print $1}'`
        echo " ... done."
    else
        echo "Could not find the screen $SCREENNAME"
    fi
}

function update_server {
    stop_server
    steamcmd +login anonymous +force_install_dir $DIR +app_update 740 +quit
    start_server
}

case "$1" in
start)
    start_server
;;

stop)
    stop_server
;;

restart)
    stop_server
    start_server
;;

update)
    update_server
;;

  *)
    echo "Usage: $0  (start / stop / update)"
esac

exit 0

Skriptin voi tallentaa esimerkiksi sijaintiin /opt/steamcmd/csgo.sh.

Tallennuksen jälkeen skriptille täytyy antaa suoritusoikeudet:

chmod +x /opt/steamcmd/csgo.sh

Nyt tarvitaan vain systemd -palvelu, sen voi luoda sijaintiin: /etc/systemd/system/csgo.service:

[Unit]
Description=Counter-Strike: Global Offensive Server (SRCDS)
After=local-fs.target network.target

[Service]
User=steamcmd
Group=steamcmd

ExecStart=/opt/steamcmd/csgo.sh start
ExecStop=/opt/steamcmd/csgo.sh stop
Type=forking

[Install]
WantedBy=multi-user.target

Systemd -palvelu täytyy aktivoida komennolla systemctl daemon-reload. Nyt CSGO palvelimen saa käynnistettyä ja sammutettua komennoilla systemctl start csgo ja systemctl stop csgo.

Palvelimen automaattisten päivityksien käyttöönotto vaatii lisäyksen crontabiin. Suorita komento crontab -e ja lisää sinne komento:

0 4 * * * systemctl stop csgo && su --shell /bin/bash steamcmd -c "/opt/steamcmd/csgo.sh update" && systemctl start csgo >/dev/null 2>&1

Palvelimen uudelleenkäynnistys ja päivitys ajetaan nyt joka aamu kello 4:00.

Vianetsintä

Mikäli screen komentoa ajaessa tulee ongelmia, näet seuraavan virheen:

Cannot open your terminal '/dev/pts/0' - please check.

Voit ratkaista tämän ongelman suorittamalla seuraavan komennon nykyisessä istunnossa:

script /dev/null

Tämän jälkeen yhteys screen istuntoon on taas mahdollista.

Yhteenveto

Jos olet seurannut ohjeita tähän pisteeseen asti, sinulla on nyt oma CSGO palvelin joka automaattisesti päivittää itsensä joka päivä.

License: MIT
Want to contribute?

Get Rewarded: Get up to €50 in credit! Be a part of the community and contribute. Do it for the money. Do it for the bragging rights. And do it to teach others!

Report Issue

Discover our

Dedicated Servers

Get €20/$20 free credit!

Valid until: 31 December 2026 Valid for: 3 months and only for new customers
Configure now
Want to contribute?

Get Rewarded: Get up to €50 credit on your account for every tutorial you write and we publish!

Find out more