Welcome!

Join our community of MMO enthusiasts and game developers! By registering, you'll gain access to discussions on the latest developments in MMO server files and collaborate with like-minded individuals. Join us today and unlock the potential of MMO server development!

Join Today!

In-Depth Guide to Linux Server Setup

Initiate Mage
Joined
Feb 26, 2018
Messages
1
Reaction score
1
# Intro

Hello RageZone,
Today I will teach you how to set up a Linux box to host your server on. This will assume you have absolutely no previous knowledge and that your box isn't preconfigured.

This guide is long, which is why I've tried to split it up into as many sections as possible. Find the ones relevant to you, and skip over the ones you don't need. This is also why there's no webserver setup: It's not critical to running a server.

# Table of Contents
  1. Intro
  2. Table of Contents
  3. Requirements
  4. Picking a Distro
  5. Terminology
  6. Setup
    1. sudo
      1. Checking that sudo is Installed
      2. Installing sudo
      3. Adding Yourself to sudoers
    2. Installing a Compiler
    3. Downloading Source Files
    4. Setting up the Database
      1. Creating a Schema
      2. Executing Scripts
    5. Compiling
  7. Launching
  8. Additional Considerations


# Requirements



  1. Linux machine (doesn't need to have a GUI installed)
  2. Shell (can be SSH)
  3. A way to get your server files onto the Linux box (SCP, FTP, Git, SVN), no need to precompile
  4. Basic knowledge about your source and the programming language it's written in
  5. Patience


# Picking a Distro
Disclaimer: This section assumes you haven't installed Linux yet, or are in the process of choosing. If you've already installed Linux, do not change your distribution! There isn't much of a point in doing so, regardless of what others might tell you.

I recommend you pick Debian as your Linux Distribution. It's easy to use, widely adopted (so you can Google and find answers 99% of the time), well documented, stable and easy to update. It's more lightweight than Ubuntu Server and compared to CentOS, it's a bit easier to learn and much easier to update. However, Ubuntu Server and CentOS are also great choices so don't worry too much if you've already installed one of either.

This tutorial will assume you're using a Debian-based distro (which includes Ubuntu Server). The commands for CentOS should be identical, except you should replace apt-get with yum, when you see it.


# Terminology
I'm assuming you have no previous Linux knowledge, so here's a small list of terms.

The Windows analogue (or closest thing to) will be put [in square brackets]:


  • Shell [CMD, PowerShell]: A program that interprets text-based commands
  • root [Administrator]: The user on your machine which has access to everything; unlike in Windows, you should be very careful about running programs as root or staying logged in as it for more than is needed
  • Distribution: A flavor of Linux, different distributions come preinstalled with different programs
  • Package Manager: A tool used to download, update and remove programs installed on your computer
  • manpage: Linux has a tool called man (short for manual), which shows information about a program; to display a manpage, type man programname (e.g. man bash to show info about the shell)
In this tutorial you'll see snippets of code that start with a dollar sign ($), for example:
Code:
$ javac -version
This means you should input code in a non-root shell, conversely, code starting with a pound sign (#):
Code:
# apt-get install sudo
Is meant to be run from a root shell.

Additionally, any bold arguments to commands should be changed depending on your configuration/preference.


# Setup
Remember that at any point you can type man programname to read in-depth information about a program.

Before we can actually install and configure anything, we have to make sure our environment is configured properly.

## sudo
sudo allows you to execute a command as root (refer to Terminology to see why this is important); without it, we won't be able to install anything. Not all distributions have it preinstalled!

### Checking that sudo is Installed
To check if you have sudo installed, type:
Code:
$ which sudo
If you have sudo installed, you should see:
Code:
$ which sudo
/usr/bin/sudo
If you don't have sudo, you might see something similar to:
Code:
$ which sudo
which: no sudo in (/usr/local/bin:/usr/bin)
Or you might get no output at all.
If you have sudo, you can skip this part.

### Installing sudo
Before anything, display your username (which we will use later):
Code:
$ whoami
Since we need root access to install programs, first you must log in as root:
Code:
$ su
You'll be prompted to enter the root password, which you should've set during the install process. Even though characters won't appear on screen, your password is being recorded, so once you're done hit enter.
You'll be greeted by a prompt similar to this:
Code:
root@hostname:/home/user/#
Now type:
Code:
# apt-get install sudo
Press Y and hit enter when prompted

### Adding Yourself to sudoers
Execute:
Code:
# usermod -aG sudo [B]user[/B]
where user is the result of whoami executed earlier.
Type exit to return to your user.

## Installing a Compiler
To install a program, type sudo apt-get install followed by the program name. You can install mutliple programs at once by specifying their names one after the other. When asked yes/no questions, press y and hit enter.
You'll also notice that the first time you use sudo or every so often (five minutes, to be exact), sudo will prompt you for your password. You won't see any text (not even little stars) coming up, but your password is still being recorded. Press enter when done. If you get a message about not being in sudoers, see the "Adding yourself to sudoers" section
Java
Installing the JDK
Type:
Code:
$ sudo apt-get install default-jdk-headless
If you need Maven or Gradle as well:
Code:
$ sudo apt-get install default-jdk-headless maven
or
Code:
$ sudo apt-get install default-jdk-headless gradle

Check that the compiler works:
Code:
$ javac -version
On my system I see javac 1.8.0_151, which corresponds to my Java Compiler version

Note: You do not need to install JCE!
C++
Installing GCC
Type:
Code:
$ sudo apt-get install g++
If you need make or CMake, install them by adding their name to the end. Note that CMake will automatically install make, too.
Code:
$ sudo apt-get install g++ make
or
Code:
$ sudo apt-get install g++ cmake

Check that the compiler works:
Code:
$ g++ --version
On my system I see g++ (Debian 6.3.0-18+deb9u1) 6.3.0 20170516 followed by a copyright notice, which corresponds to the installed version of g++

You should also go ahead and install any libraries your source depends on. For example, to install OpenSSL and Boost, you'd type:
Code:
$ sudo apt-get install libssl-dev libboost-all-dev

## Downloading Source Files
Transfer the source files onto your box.
I recommend you use SCP, since you should have SSH already set up and SCP uses SSH.
If you have a GitHub repository set up, you can do the following:
Code:
$ git clone https://github.com/[B]YourUser[/B]/[B]RepoName[/B].git
(you might have to install git, which by now you should know how to do)
You can also use SVN or FTP, but I won't cover those for brevity's sake.
Once you've downloaded the files, you should:
Code:
$ cd [B]Source[/B]
to change your directory to where the source is located.

## Setting up the Database
I'm assuming your source uses MySQL/MariaDB.
### Installation and Basic Setup
Code:
$ sudo apt-get install mysql-server
Once that is done, you must run the following command to set up the database:
Code:
$ sudo mysql_secure_installation
Use it to set the root password (which should be blank by default). If you're unsure about an option, you should select yes and proceed.

### Creating a Schema
Code:
 $ mysql -u root -p
You'll be asked to enter the root password you just set. Characters won't appear, but your password is being recorded. Press enter when done.
You should see something like this:
Code:
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 6
Server version: 10.1.26-MariaDB-0+deb9u1 Debian 9.1

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]>

Note that commands end in a semicolon (;)
Create a schema for your server to use:
Code:
CREATE SCHEMA [B]SchemaName[/B];

If you need to execute scripts, keep reading. Otherwise, you can type exit to quit the MySQL interface.

### Executing Scripts
First tell MySQL to use the schema you just created:
Code:
USE [B]SchemaName[/B];
To execute a script, type:
Code:
SOURCE [B]sql/script.sql[/B]
The argument should be the path to the script you want to execute, This example assumes your scripts are in a folder called sql and you want to execute the script called script.sql.
Repeat as needed for all scripts you want to execute.

Once done, type exit to quit the MySQL interface.


## Compiling
I'm assuming your source doesn't have a build system (Maven, Gradle, CMake). If it does, use the build system and skip this section.
Java
First, make an output directory. Traditionally it's called bin, however many Odin-based sources like to call it dist. If you'd like to use dist (or any other name, for that matter), replace bin with dist in the following commands:
Code:
$ mkdir -p [B]bin[/B]

Now, if your source has any external dependencies, put them in a folder called lib
I'm also assuming your source files are in a folder called src
Code:
$ javac -d [B]bin [/B]-cp [B]lib [/B]$(find [B]src[/B] "*.java")
If you did everything correctly, you should see no output (or just a few warnings).
If you check the bin folder, you'll see a bunch of directories with .class files. Your server will work like this, there's no need to make a jar.
C++
Disclaimer: Your source must be written with cross platform compatibility in mind. If it isn't, this won't work!

You must first know which language standard your source is using (c++03, c++11, c++14, c++17) and which libraries it depends on. Make sure all dependencies are installed before attempting this, or you will get linker errors.
I'm assuming your C++ source files have the .cpp extension.
To compile a directory (called srcdir in this example) into an executable (called server-executable in this example), with Boost and OpenSSL as the required libraries:
Code:
$ g++ -DNDEBUG -std=[B]STANDARD [/B]-O3 -s -pthread -o [B]server-executable [/B]$(find [B]srcdir[/B] -name "*[B].cpp[/B]") -l[B]boost_system[/B] -l[B]ssl[/B]
Note that library order matters, if a library B depends on A, you should have -lA -lB (dependencies go last)

If you did everything correctly, you should get no output (warnings are fine).


# Launching
Java
You'll have to create a launch script. Type the following:
Code:
$ touch [B]launch.sh[/B]
$ chmod +x [B]launch.sh[/B]
This will create a file called launch.sh which you'll be able to execute.
To edit it:
Code:
$ nano launch.sh
And type the following in it:
Code:
#!/bin/bash
cp=$(echo [B]lib[/B]/*)
cp=.:[B]bin[/B]:${cp// /:}
java -cp $cp [B]net.server.Main[/B]
Where lib is the directory containing any JARs your server needs to run, bin is where you compiled your source files to, and net.server.Main is the name of your main class prefixed by the package it's in.
To launch, type:
Code:
$ ./[B]launch.sh[/B]
C++
Type:
Code:
$ ./[B]server-executable[/B]



# Additional Considerations
Your server will work as it is. However, you might want to create a dedicated MySQL user as well as a dedicated Linux user for your server to execute in, each with proper permissions. I won't go over them since this guide is already immense as it is, and because I want you to experiment for yourself.
 
Back
Top