How to start the Minecraft and HLDS servers?
Posted by on 09.01.2014 11:00
Real players are well aware that there is no multiplayer without a good CPU power backend. Action games, shooters and above all, massive multiplayer online RPG games require a central server that receives game progress data from all the players, synchronizes the state of the world and sends it to each individual.
Naturally many games contain embedded server software - you run the application on your computer, and you give other players a chance to connect through the Internet. It's enough when only few people are playing less demanding titles, preferably on the LAN, but when more players appear - problems begin. A typical home Internet connection is unable to cope, the upload transfer bandwidth is usually the bottleneck. Delays causes an unfair advantage for the player that uses the host computer and when you raise this topic, he can take offense and leave, and then multiplayer fun is over for everyone.
That's why serious players choose stand-alone servers - special software running in the data center, running no matter who connects to them, providing low latency and high performance in processing of the game world. The drawback is, of course, cost. Hosting such software is not free, what's more, the game server usually has much higher requirements than a simple website and it is also often available only in the Windows version.
So what should players do? Usually a group of friends who want to play with each other online, just raise the money for the VPS - usually with parameters they don't need. The administrator installs the server, sends login details to a group and then... everyone is unhappy because their VPS (that costs them hundreds USD per month) becomes unstable for some players at unexpected moments and there are delays in gameplay, and although hosting provider ensures about highest performance of its services and the administrator is experimenting with tuning the configuration, it's not helping.
The problem is in fact at the infrastructure level. Typical VPS hosting, that benefits from the OpenVZ or Virtuozzo containers, suffers from delays at the kernel level, not to mention the problems with elastic scaling of resource consumption or low storage capacity. In this situation, wealthier players clench their teeth and buy a dedicated server that solves their problems and the less wealthy gamers just stay with VPS.
In our experience, however, servers run in an efficient cloud computing technology is a much better option than the VPS and much cheaper than dedicated servers. Why is that?
That's the theory. We'll show you how to run a Minecraft server in Oktawave and HLDS (Server for Valve games based on the Source engine).
Blocks in the cloud. A world for you and your friends
Minecraft needs no introduction. You collect materials, create variety of things, such as the Turing machine or the Malbork castle. In this endless world of cubes, in which the only official goal is to survive, you live by yourself, but it's much more interesting to live with friends. Admittedly, the list of publicly available Minecraft server is very long, but they all have one drawback - no one can guarantee that what you build won't be spoiled by some faceless villain. So if you want to feel safe in your world, it is best not to allow strangers to him.
Step 1: prepare an instance of OCI
If you have already used virtual servers in Oktawave, this step should be easy. If not, then we recommend our guide How to add instances (OCI) and how to manage them later?, and then read the following guide: How to resize your OVS.
Our goal is to obtain an "Small" class instance, disk with Tier-2 class, running Debian 7. Why we don't suggest starting something bigger? The answer is simple - Minecraft has its own specific requirements.
First, contrary to popular myths game server does not need a large amount of RAM, 2 GB of memory for the "Small" class instance should suffice for 30-40 players. Taking "Colossus" instance with 64 GB of RAM would make very little change.
Second, Minecraft is a single-threaded applications - 16 virtual processors do not help him. At best, you can use the Minecraft mod called Optifine, allowing the use of two cores - and just as much as "Small" instance.
Thirdly, the storage at Tier-2 means that you don't have to create buffer in the RAM disk to cope with a large number of read/write operations on game files. At 20 000 IOPS available for Tier- 2 volume in Oktawave, Minecraft can handle even the largest worlds.
Step 2: install the Java environment
After creating an instance of the OCI, prepare runtime environment for Minecraft. Log in over SSH (according to the tutorial: I started the service. How do I get the access?) and update Debian with commands: apt-getupdate&&apt-getupgrade, then install Java 7 from Oracle (you can also use the OpenJDK, but Oracle's version seems a bit faster). The official Oracle installer is inconvenient and not very friendly to Debian, but fortunately there is unofficial repository available, allowing for convenient installation.
Add the repository with commands:
echo "deb http://ppa.launchpad.net/webupd8team/java/ubuntu precisemain" | tee
echo "deb-src http://ppa.launchpad.net/webupd8team/java/ubuntu precisemain" | tee
apt-keyadv --keyserver keyserver.ubuntu.com --recv-keys EEA14886
and then install with command
This will start the Java installer (you must agree to the license terms). Then, set the Java 7 as the default in the system
and check and see if it is working properly:
The result should be similar to the following:
Java(TM) SE Runtime Environment (build 1.7.0_40-b43)
Java HotSpot(TM) 64-Bit Server VM (build 24.0-b56, mixedmode)
Step 3: install Minecraft
Minecraft server can be downloaded from the https://minecraft.net/download. For this purpose we will use the following command:
(note - check the current version number and if necessary, change the link above).
Then prepare a regular user account, from which you will run the server (running it as a root is not a good idea, mainly because of the frequently occurring vulnerabilities in Java). We can do it with commands:
useradd -c "minecraft" -m minecraft
cp -R /root/* /home/minecraft/
chown -R minecraft:minecraft /home/minecraft/
Step 4: configure and run Minecraft
There is a lot of ways to optimally run Minecraft server and one is better than another. From our experience, however, for greater smoothness of the game world, you just need to enable incremental garbage collection (Xincgc - flag).
So switch to a Minecraft user account with command
and run the server by typing
java -jar -Xincgc -Xmx2G minecraft_server.1.6.4.jar
In this way, we have created a new world of Minecraft, to which you can get with the OCI instance IP address, the default port 25565. As you can see, when you first start, at the beginning the server looks up of the configuration files and existing worlds - if server cannot find them, he create new ones.
Now you can kill the server process (CTRL + C) and then look at the server.properties file that was created upon first start. This is where you can determine almost all of the options of the game world, such as the possibility of fighting between players, the appearance of monsters and animals, or the mode of play - survival or creative. Detailed explanations can be found in Minecraft Wiki.
Before starting the game you should also look into the ops.txt file. Enter there Minecraft account name, so that it will be listed as a server operator, with the right to issue administrative orders. After logging into the Minecraft client and issuing the chat with /help command, you can watch the whole list of them (there are commands for actions like digging or banning).
If you depend on the privacy of the world, you should open the white-list.txt file and add it to the list of friends accounts. In this way, no unauthorized player will get to them.
It is also wise to install screen tool in the system, so you can redirect the output from running command on a virtual terminal, thus not binding terminal on the server.
If we want to simplify our life with starting and stopping the server later, we should prepare initial daemon startup script. For Debian, this script can be found for example here. After saving the file as minecraft-init and copying it to the /etc/init.d/, we need to update the list of scripts with command update-rc.dminecraft-initdefaults.
Then, to start the server we will only need to issue the command /etc/init.dminecraft-init start, and to stop him the command /etc/init.dminecraft-init stop.
That's all. Let us remember that at the end of play, when the server is no longer needed, we must turn off Minecraft and then stop the virtual machine. In this way, we will not pay for Oktawave service at a time when no one was playing.
One more thing at the end - official Minecraft is a little boring. It is much better to immediately install CraftBukkita, independent version of the server, which can complement the various, sometimes really amazing plugins. This is done exactly the same, except that CrafBukkita can be downloaded from the dl.bukkit.org. Obviously, the more plugins you install, the more RAM on the server is needed, but in Oktawave this is not a problem - to reconfigure an existing instance of OCI takes a few moments.
HLDS. A source in the cloud
We don't need to introduce Valve to online gamers. Titles such as Counterstrike: Source, Team Fortress 2, Left 4 Dead and Half-Life 2: Deathmatch are a classics and still millions of people around the world play them. There are many Public servers that can be used, but if someone wants to fully customize the game world to his requirements, all that remains is to run own HLDS server (Half-Life Dedicated Server). It will be able to handle each of mentioned games.
Step 1: prepare an OCI instance
As the operating system we propose to use Ubuntu 12.04 LTS. Why is that? Valve is testing their Linux software primarily on Ubuntu. As an instance, select "Starter" type - offered 0.9 GB of RAM and one virtual processor is completely enough. As the HLDS is a single-threaded application, running two processors will not bring any benefit. The default size of the disk - 5 GB - will be enough (unless you want to make a server for multiple games), it is worth to switch their class to Tier-2, as described in the guide "How to change size of the OVS disk?".
Step 2: prepare Ubuntu
HLDS Server is a 32-bit application, while available in Oktawave system images are 64-bit. So after upgrading Ubuntu (log in via SSH and issue the commands sudoapt-getupdate&&apt-getupgrade) we have to download the 32 -bit runtime, use the command:
sudoapt-getinstall lib32gcc1 ia32-libs
Then create a user account on which you run HLDS:
and with command suhlds switch to the server user, setting the home directory as default with command cd /home/hlds/.
Step 3 : download the HLDS server
Server installation is made possible by the tool hldsupdatetool by Valve - it is also responsible for keeping the game server. Grab it from the Valve server with command:
Now we must set file permissions
chmod +x hldsupdatetool.bin
and run the tool with command ./hldsupdatetool.bin to agree to the license terms by typing yes under the message.
hlsupdatetool will be installed in the current Steam client directory. Run it with the command ./steam. This will verify software and download tens of megabytes of data. When the steam client is already present, you can use it to install a server for one of the games running on HLDS. You can do this by using the command
./steam –command update –game gamename -dir ~/gamename_hlds -verify_all -retry
The values that the parameter 'gamename' can accept, can be found for example here - for example, to install Team Fortress 2, use tf and for Counter-Strike 1.6 use cstrike.
Now you need to prepare for a long wait - for example, if you install Team Fortress 2, the Steam client will download more than 3 GB of data.
Step 4 : Start the game server
Before starting the server, set the basic options. Settings file can be found in the orangebox/gamename/cfg directory. There are hundreds of possible settings, a description of most of them, you will find in the HLDS wiki. It should also read the articles on the Steam page. Remember that all variables that are not set in the configuration file, adopt the default values, which in the case of most of the games should be enough. Experiment with them at your own risk. It certainly is wise to set the value of the variable sv_region to for example "3" (server located in Europe), thanks to this, players from further parts of the world won't see Oktawave server while using the region filter.
As with Minecraft, it is worth the time to set starting script that will allow the game server to run even after you log out of the SSH session. First, install the screen tool (sudo apt-get install screen) and then prepare hlds script in /etc/init.d/ directory with command sudo nano /etc/init.d/hlds.
One of these scripts (srcds-service) can be found on GitHub - here. After copying the contents to hlds file, change the value of variables SRCDS_USER (hlds), DIR (/home/hlds/orangebox) and PARAMS (it depends on the type of game to be started by default - for example, -gamecstrike starts the counter-Strike server and -gametf - Team Fortress 2).
What remains now is to save the script. You can control it using the command
sudo /etc/init.d/hlds start (server start)
If you want the server to start with the Oktawave virtual machine, enter the command sudo /etc/init.d/hlds enable. To disable startup issue command sudo /etc/init.d/hlds disable.
A few thoughts
In our experience as players, cloud computing is the most cost-effective solution for those who play occasionally, trying to put the server for the weekend. Whatever you choose, remember to avoid service providers, who offer VPS only as a addition to shared hosting. In spite of the attractive prices, as a result of virtualization solutions that are used, they are not able to provide a stable and efficient operation of virtual machines, not to mention the storage efficiency.
Before you choose the parameters of that server, take a look at the exact specification requirements of the server software. Multi-processor configurations bring nothing here. Check also that the delay associated with the location of the data center - for example for Polish players, server physically located in France or the USA is a bad idea.
Of course, if you want to use Oktawave cloud, the matter will be easier. In Oktawave type of used virtual machine can be freely changed in order to determine which option will be most suited to the needs of the players. Of course you do not have to worry about lag because the servers are in Poland. Enjoy gaming!
And remember that each new Oktawave user gets 7 USD for the start to be able to test your machine. More on this topic can be found here: https://www.oktawave.com/promotions/25-pln-for-start.html.