You will be able to get your Minecraft server up and running in less than 5 minutes for a fair price and only be charge for the hours you use it to play with your friends using Terraform and Digital Ocean’s droplet services.

Who is this guide for ?

I keep things as simple as possible so any Minecraft Server geek should be able to get his On Demand Minecraft server setup in few minutes.

Prerequisite

A Digital Ocean account with few credits to rent your droplet.

with few credits to rent your droplet. Digital Ocean CLI to get some informations from DO API.

to get some informations from DO API. OpenSSH client to generate your SSH key to be used to identify to your Droplets. I think it is available out of the box for all windows and mac. For linux refere to your favorit package manager.

client to generate your SSH key to be used to identify to your Droplets. I think it is available out of the box for all windows and mac. For linux refere to your favorit package manager. A tool to tar gz . Native on almost all linux distro and mac. For windows I prefer 7zip.

. Native on almost all linux distro and mac. For windows I prefer 7zip. Java 8 .

. MCrcon to inject commands on your running Minecraft Server.

to inject commands on your running Minecraft Server. Terraform.

1. Download the Terraform Project

You can simply download it from my github repository https://github.com/vyrtualsynthese/Digital-Ocean-OnDemand-Minecraft-Server

Or clone it using git

2. Prepare the project for production

A. Minecraft Server Files

Ignore step a. to d. if you already have your minecraft server ready

a. Download your Minecraft Server from minecraft official website https://www.minecraft.net/en-us/download/server/

cd Digital-Ocean-OnDemand-Minecraft-Server

wget [the server link taken from minecraft website]

b. Create an ‘minecraft-server’ folder and move your server files into the uploadFolder

mkdir uploadFolder/minecraft-server

mv server.jar uploadFolder/minecraft-server

c. If it is a new server Run it one time to generate server configuration files

java -Xmx1024M -Xms1024M -jar uploadFolder/minecraft-server/server.jar nogui

d. The server should start and stop by himself then you could edit eula.txt.

Set eula to true. It should be like this.

eula=true

e. Next step is to setup your server.properties file. Feel free to configure your server as you want but you need to make sure enable-rcon is set to true and you have an rcon.password set up.

rcon.password=foo

enable-rcon=true

f. Make sure your configuration is ok by running the server on last time and connecting to it. Then shut it down and you are all set. Last Step is to compress the server file in tar.gz format.

cd uploadFolder

tar czvf minecraft-server.tar.gz minecraft-server

B. SSH Keys

You need an ssh key to help terraform inject commands over SSH into your droplet instance after it is activated.

First it is better to generate a dedicated SSH key for your Terraform scripts.

ssh-keygen

We will name that new key mc_rsa

Output Generating public/private rsa key pair.

Enter file in which to save the key (/your_home/.ssh/id_rsa): mc_rsa

Now that we have generated our key we need to get its fingerprint.

ssh-keygen -lf ~/.ssh/mc_rsa -E md5

The output should look like this

2048 MD5:df:cd:9a:0c:72:0a:6e:af:dc:1f:98:96:88:12:37:fb meme@me (RSA)

Copy everything between MD5: and meme@me and keep it somewhere.

C. Connect doctl with your Digital Ocean account

Run doctl auth init command.

Go to your Digital Ocean accout under API and click Generate New Token.

Then copy your token into the terminal.

Now your doctl have access to your account information.

D. Configure your terraform script

Inside the project copy the environment variable file to edit

cp terraform.tfvars.dist terraform.tfvars

Then inside the terraform.tfvars file

do_token past your previous generated Digital Ocean API Token

pub_key input the path to your rsa public key in our exemple : "~/.ssh/mc_rsa.pub"

pvt_key input the path to your rsa private key in our exemple : "~/.ssh/mc_rsa"

ssh_fingerprint past the previous generated md5 ssh fingerprint

rcon_pwd your previously setup rcon password for your minecraft server

For the last two field you need to call Digital Ocean’s api to get droplets informations

doctl compute size list --output json will give your informations about available droplets. When you have chose your droplet size take note of your droplet slug and region and input it in your terraform.tfvars file.

My go to droplet is the “s-1vcpu-1gb” strong enough to play with few friends.

3. Run your Minecraft Server

Now the hard part is done time to run your Minecraft Server with two simple commands.

Make sur you are in your Terraform project folder then

terraform apply

Then after reviewing your configuration juste write

yes

Once finished terraform will print your server IP in your terminal. You may have to wait few more minutes untils the Minecraft Server finished starting.

To connect to the console of your server your can use mcrcon as following

mcrcon -H <Your-Server-ip> -p <your-rcon-password>

4. Destroy your Minecraft Server

From inside your Terraform project former type

terraform destroy

Then after reviewing your configuration

yes

Your minecraft server will be gracefully shut down then compressed the downloaded in your local Minecraft Server folder then shutdown.

Wraping up

You can now run your Minecraft Server in 5 minutes from 9 cents per hours.

This is my first ever technical guide and there is room for improvements ask questions and I will update this guide.