Results 1 to 8 of 8

Thread: MC Server Tutorial

  1. #1
    GrnEyedDvl's Avatar Barackolypse Now
    Artifex Technical Staff

    Join Date
    Jan 2007
    Location
    Denver CO
    Posts
    21,874

    Default MC Server Tutorial

    For those that are interested I will make one of my machines available for practice. I will install Ubuntu and give you root level access, the rest will be up to you. This is a first come first server offer, so everyone will have to take turns.


    You will need the following to use this tutorial:

    A home network already configured and working properly.
    A machine you can install Ubuntu on, this doesnt have to be extremely powerful.
    A different machine you can use to play Minecraft on.
    Some basic Linux command line knowledge such as navigating the file system.
    An FTP client, I suggest FileZilla.
    An ssh terminal you can run from your Windows machine. I suggest Poderosa.
    Install Ubuntu 10.04 LTS with the following software packages
    LAMP server
    OpenSSH server


    When installing LAMP it will ask you for a password for the root MySQL user. Choose something complex and random, and write it down.
    Login to your server and run the following command to get the IP address of your box. My machine is named ubuntu and my username is grneyeddvl.
    The IP address of the machine in my example is 10.100.128.23, which is assigned by my server. Yours is probably 192.168.0.xxx. Whatever it is, write it down.
    Spoiler Alert, click show to read: 
    grneyeddvl@ubuntu:~$ ifconfig
    eth0 Link encap:Ethernet HWaddr 48:5b:39:d1:ff:07
    inet addr:10.100.128.23 Bcast:10.100.128.255 Mask:255.255.255.0
    inet6 addr: fe80::4a5b:39ff:fed1:ff07/64 Scope:Link
    UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
    RX packets:303 errors:0 dropped:0 overruns:0 frame:0
    TX packets:59 errors:0 dropped:0 overruns:0 carrier:0
    collisions:0 txqueuelen:1000
    RX bytes:275866 (275.8 KB) TX bytes:7985 (7.9 KB)
    Interrupt:27 Base address:0xe000
    lo Link encap:Local Loopback
    inet addr:127.0.0.1 Mask:255.0.0.0
    inet6 addr: ::1/128 Scope:Host
    UP LOOPBACK RUNNING MTU:16436 Metric:1
    RX packets:0 errors:0 dropped:0 overruns:0 frame:0
    TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
    collisions:0 txqueuelen:0
    RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)



    Now we are going to add a usergroup, and a user to run Minecraft with. This user will not have root level access in case your machine gets compromised.
    Code:
    sudo addgroup mcusers
    sudo adduser minecraft

    Now add the minecraft user to the mcusers group.
    Code:
    sudo adduser minecraft mcusers

    You now have a user named "minecraft" that belongs to the usergroup "mcusers". The reason we are creating the mcusers group is in case you want to add administrators to your machine later. We can give permissions to the mcusers group and your new user will inherit them, and will not have root access to the box.


    Now we are going to create folders for minecraft, and folders for backups. Most tutorials have you create these in your home directory, but we are not going to do that as we want other users to be able to access them in the future. We are going to create a minecraft folder and a mc_backups folder in the root of your drive. These are the steps, you might want to clear your screen first by typing the command "clear" without quotes.

    The process is as follows:

    Change directory to the root: cd /
    Create minecraft folder: sudo mkdir minecraft
    Create mc_backups folder: sudo mkdir mc_backups
    List the folders to make sure they appear properly: ls
    Code:
    grneyeddvl@ubuntu:~$ cd /
    grneyeddvl@ubuntu:/$ sudo mkdir minecraft
    grneyeddvl@ubuntu:/$ sudo mkdir mc_backups
    grneyeddvl@ubuntu:/$ ls
    bin  boot  cdrom  dev  etc  home  initrd.img  lib  lib64  lost+found  mc_backups  media  minecraft  mnt  opt  proc  root  sbin  selinux  srv  sys  tmp  usr  var  vmlinuz
    You should see the minecraft and mc_backup folders listed.
    Now we are going to change the ownership of the minecraft and mc_backup folders to your minecraft user and your mcusers group. We also need to make sure this is recursive so that all new files created have the same owners, we will use the -R tag for this. The command for this is chown (change ownership) and the syntax is as follows:

    sudo chown -R user:group folder/file

    Run the commands and then run ls -l to see that they are properly executed:
    Spoiler Alert, click show to read: 
    ]grneyeddvl@ubuntu:/$ sudo chown minecraft:mcusers minecraft
    grneyeddvl@ubuntu:/$ sudo chown minecraft:mcusers mc_backups
    grneyeddvl@ubuntu:/$ ls -l
    total 96
    drwxr-xr-x 2 root root 4096 2011-09-07 20:12 bin
    drwxr-xr-x 3 root root 4096 2011-09-07 20:13 boot
    drwxr-xr-x 2 root root 4096 2011-09-07 20:05 cdrom
    drwxr-xr-x 18 root root 3620 2011-09-07 20:14 dev
    drwxr-xr-x 82 root root 4096 2011-09-07 20:24 etc
    drwxr-xr-x 4 root root 4096 2011-09-07 20:23 home
    lrwxrwxrwx 1 root root 32 2011-09-07 20:05 initrd.img -> boot/initrd.img-2.6.32-33-server
    drwxr-xr-x 13 root root 12288 2011-09-07 20:12 lib
    lrwxrwxrwx 1 root root 4 2011-09-07 20:04 lib64 -> /lib
    drwx------ 2 root root 16384 2011-09-07 20:03 lost+found
    drwxr-xr-x 2 minecraft mcusers 4096 2011-09-07 20:37 mc_backups
    drwxr-xr-x 2 root root 4096 2011-09-07 20:03 media
    drwxr-xr-x 2 minecraft mcusers 4096 2011-09-07 20:37 minecraft
    drwxr-xr-x 2 root root 4096 2011-07-15 07:48 mnt
    drwxr-xr-x 2 root root 4096 2011-09-07 20:04 opt
    dr-xr-xr-x 106 root root 0 2011-09-07 20:14 proc
    drwx------ 4 root root 4096 2011-09-07 20:10 root
    drwxr-xr-x 2 root root 4096 2011-09-07 20:14 sbin
    drwxr-xr-x 2 root root 4096 2009-12-05 15:25 selinux
    drwxr-xr-x 2 root root 4096 2011-09-07 20:04 srv
    drwxr-xr-x 13 root root 0 2011-09-07 20:14 sys
    drwxrwxrwt 3 root root 4096 2011-09-07 20:15 tmp
    drwxr-xr-x 10 root root 4096 2011-09-07 20:04 usr
    drwxr-xr-x 15 root root 4096 2011-09-07 20:12 var
    lrwxrwxrwx 1 root root 29 2011-09-07 20:05 vmlinuz -> boot/vmlinuz-2.6.32-33-server

    You will see that the folders list minecraft as the user and mcusers as the group.



    Now we are going to create a few more folders, so we can run multiple Minecraft servers off of this machine without them conflicting. One will be a Creative server, one will be a PvP server for our example. So navigate to your minecraft folder and create two new folders: creative and pvp, then run the ls command and make sure they appear.
    Code:
    grneyeddvl@ubuntu:/minecraft$ cd /minecraft
    grneyeddvl@ubuntu:/minecraft$ sudo mkdir creative
    grneyeddvl@ubuntu:/minecraft$ sudo mkdir pvp
    grneyeddvl@ubuntu:/minecraft$ ls 
    creative  pvp


    Then do the same thing for the mc_backups folder.
    Code:
    grneyeddvl@ubuntu:/minecraft$ cd /mc_backups
    grneyeddvl@ubuntu:/mc_backups$ sudo mkdir creative
    grneyeddvl@ubuntu:/mc_backups$ sudo mkdir pvp
    grneyeddvl@ubuntu:/mc_backups$ ls
    creative  pvp


    Now lets create the sub folders for backups. We need folders named worlds, logs, and fullbackup
    Code:
    grneyeddvl@ubuntu:/$ cd /mc_backups/pvp
    grneyeddvl@ubuntu:/mc_backups/pvp$ mkdir worlds
    grneyeddvl@ubuntu:/mc_backups/pvp$ mkdir logs
    grneyeddvl@ubuntu:/mc_backups/pvp$ mkdir fullbackup
    grneyeddvl@ubuntu:/mc_backups/pvp$ cd /mc_backups/creative
    grneyeddvl@ubuntu:/mc_backups/creative$ mkdir worlds
    grneyeddvl@ubuntu:/mc_backups/creative$ mkdir logs
    grneyeddvl@ubuntu:/mc_backups/creative$ mkdir fullbackup


    Now we need to give write permissions to anyone you allow shell access, and therefore SFTP access on your server. The easy way to do this is to use the command:

    Code:
    sudo chmod 777 -R minecraft
    sudo chmod 777 -R mc_backups

    Now loadup FileZilla and connect to your box. Place the latest build of CraftBukkit in the creative folder and in the pvp folder and MAKE SURE YOU RENAME THEM. You cannot run them both at the same time if they have the same name. I named mine mc_creative.jar and mc_pvp.jar.


    Now that your Bukkit server files are on the machine and ready to run, we need to install Java. Ubuntu 10.04 does not come with Java installed, and its not part of the package distribution by default. This means we need to install python and update the repository list before we can install Java. Run these commands in this exact order, and press Y when it asks you a question.

    Code:
    sudo apt-get install python-software-properties
    sudo add-apt-repository "deb http://archive.canonical.com/ lucid partner"
    sudo apt-get update
    sudo apt-get install sun-java6-jre sun-java6-plugin
    PRESS TAB KEY TO SELECT OK and YES when this one pops you some questions.


    Now we are ready to run Bukkit for the first time. logout of your ssh client, and log back in as your minecraft user. We need to run the server to create the default files, and to make sure your user works. Navigate to your minecraft/pvp folder and run this command. The numbers are how much RAM to allocate, I used 2048 or two gigs. Put your own numbers in if you wish. You will know it is working when you see the console start spitting out Minecraft stuff. MAKE SURE YOU RUN THE COMMAND WITH THE SAME FILENAME YOU USED WHEN YOU UPLOADED YOUR FILES!
    Spoiler Alert, click show to read: 
    minecraft@ubuntu:/minecraft/pvp$ cd /minecraft/pvp
    minecraft@ubuntu:/minecraft/pvp$ java -Xmx2048M -Xms2048M -jar mc_pvp.jar
    151 recipes
    16 achievements
    21:44:41 [INFO] Starting minecraft server version Beta 1.7.3
    21:44:41 [INFO] Loading properties
    21:44:41 [WARNING] server.properties does not exist
    21:44:41 [INFO] Generating new properties file
    21:44:41 [INFO] Starting Minecraft server on *:25565
    21:44:41 [INFO] This server is running Craftbukkit version git-Bukkit-0.0.0-980-g4ed23b1-b1060jnks (MC: 1.7.3)
    21:44:41 [WARNING] Failed to load ban list: java.io.FileNotFoundException: banned-players.txt (No such file or directory)
    21:44:41 [WARNING] Failed to load ip ban list: java.io.FileNotFoundException: banned-ips.txt (No such file or directory)
    21:44:41 [WARNING] Failed to load ops: java.io.FileNotFoundException: ops.txt (No such file or directory)
    21:44:41 [WARNING] Failed to load white-list: java.io.FileNotFoundException: white-list.txt (No such file or directory)
    21:44:41 [INFO] Preparing level "world"



    Open up Minecraft on your desktop and try to connect. The default port is 25565 so in my case the address is 10.100.128.23:25565


    As long as you can connect and move around that is all we care about at this point. We havent changed any settings at all, and we need to get the default folders and files created in the creative folder now as well.


    Type the command "stop" into your ssh console and Minecraft will exit. Navigate to your creative folder and run the same command with the proper file name. You should get the same Minecraft console as you did when you ran the pvp file. Connect to it if you want, and then stop the server using the stop command.
    Spoiler Alert, click show to read: 
    minecraft@ubuntu:/minecraft/pvp$ cd /minecraft/creative
    minecraft@ubuntu:/minecraft/creative$ java -Xmx2048M -Xms2048M -jar mc_creative.jar




    Now if you run the ls command from inside either the pvp or creative folder, you will see a normal looking file structure for a Minecraft server.
    Code:
    minecraft@ubuntu:/minecraft/creative$ cd /minecraft/pvp
    minecraft@ubuntu:/minecraft/pvp$ ls
    banned-ips.txt  banned-players.txt  bukkit.yml  mc_pvp.jar  ops.txt  permissions.yml  plugins  server.log  server.properties  white-list.txt  world  world_nether


    The next thing we need to do is use a text editor to change the server.properties file and to add yourself to the ops.txt file. You can connect with your FTP client again and download those two files, edit them, and then upload them again, or you can use one of Ubuntu's built in text editors. I prefer to use nano over vi as its much easier to use.

    MAKE SURE YOUR TWO FILES HAVE DIFFERENT PORT NUMBERS! Highlighted in red.


    Code:
    cd /minecraft/pvp
    nano ops.txt 
    nano server.properties
    cd /minecraft/creative 
    nano ops.txt 
    nano server.properties

    The PvP file:
    Code:
    #GED's PvP Server Properties
    #Minecraft server properties
    #Wed Sep 07 21:44:42 MDT 2011
    level-name=world 
    allow-nether=true
    view-distance=10
    spawn-monsters=true
    online-mode=true
    spawn-animals=true
    max-players=20
    server-ip= 
    pvp=true
    level-seed=
    server-port=25565
    allow-flight=false
    white-list=false

    The Creative file:
    Code:
    #GED's Creative Server Properties
    #Minecraft server properties
    #Wed Sep 07 21:50:05 MDT 2011
    level-name=world
    allow-nether=true
    view-distance=10
    spawn-monsters=false
    online-mode=true
    spawn-animals=false
    max-players=20
    server-ip=
    pvp=false
    level-seed=
    server-port=25566
    allow-flight=false
    white-list=false


    You can run both files again and connect to make sure your changes applied if you wish. Make sure you use the correct port numbers.
    Code:
    minecraft@ubuntu:/minecraft/creative$ cd/minecraft/creative                                                                                                                                                                      
    minecraft@ubuntu:/minecraft/creative$ java -Xmx2048M -Xms2048M -jar mc_creative.jar
    Code:
    minecraft@ubuntu:/minecraft/creative$ cd /minecraft/pvp
    minecraft@ubuntu:/minecraft/pvp$ java -Xmx2048M -Xms2048M -jar mc_pvp.jar
    Now that we know both versions of your server work, we need to set it up so they will both run at once, and so that they will automatically run when the server boots. To do this you need to use a script. I have attached a couple of versions of the script to this post. Download that and change as needed.


    Now these files need to go in the /etc/init.d folder, but you cannot write to that folder with SFTP. You need to upload them someplace you have permissions for, and then move them into the etc/init.d folder with the sudo mv command. I suggest putting them into their Minecraft folders for now, so the mc_creative goes in /minecraft/creative and the mc_pvp goes in /minecraft/pvp. Then login to your Ubuntu server as your original user, your minecraft account does not have sudo rights.

    Login
    Go to minecraft/pvp
    Check to make sure the file is there
    Move the file
    Code:
    grneyeddvl@ubuntu:/minecraft/pvp$ ls
    banned-ips.txt  banned-players.txt  bukkit.yml  mc_pvp  mc_pvp.jar  ops.txt  permissions.yml  plugins  server.log  server.properties  white-list.txt  world  world_nether
    grneyeddvl@ubuntu:/minecraft/pvp$ sudo mv mc_pvp /etc/init.d

    Do the same for the mc_creative:
    Code:
    grneyeddvl@ubuntu:/minecraft/creative$ ls
    banned-ips.txt  banned-players.txt  bukkit.yml  mc_creative  mc_creative.jar  ops.txt  permissions.yml  plugins  server.log  server.properties  white-list.txt  world  world_nether
    grneyeddvl@ubuntu:/minecraft/creative$ sudo mv mc_creative /etc/init.d

    Move to the etc/init.d folder and make sure the files are there:
    Code:
    grneyeddvl@ubuntu:/minecraft/creative$ cd /etc/init.d
    grneyeddvl@ubuntu:/etc/init.d$ ls
    Now we need to set permissions on the script, and update the server startup file so they will run when the server boots.
    Code:
    grneyeddvl@ubuntu:/minecraft/creative$ sudo chmod 755 /etc/init.d/mc_pvp
    grneyeddvl@ubuntu:/minecraft/creative$ sudo chmod 755 /etc/init.d/mc_creative
    grneyeddvl@ubuntu:/minecraft/creative$ sudo update-rc.d mc_creative defaults
    grneyeddvl@ubuntu:/minecraft/creative$ sudo update-rc.d mc_pvp defaults
     Adding system startup for /etc/init.d/mc_pvp ...
       /etc/rc0.d/K20mc_pvp -> ../init.d/mc_pvp
       /etc/rc1.d/K20mc_pvp -> ../init.d/mc_pvp
       /etc/rc6.d/K20mc_pvp -> ../init.d/mc_pvp
       /etc/rc2.d/S20mc_pvp -> ../init.d/mc_pvp
       /etc/rc3.d/S20mc_pvp -> ../init.d/mc_pvp
       /etc/rc4.d/S20mc_pvp -> ../init.d/mc_pvp
       /etc/rc5.d/S20mc_pvp -> ../init.d/mc_pvp


    Before you can run the server, we have to move the worlds. This has to be done for the RAMdisk to work properly. Create a folder called worldstorage in both your creative and your pvp folders.
    Code:
    grneyeddvl@ubuntu:/minecraft/creative$ cd /minecraft/pvp
    grneyeddvl@ubuntu:/minecraft/pvp$ mkdir worldstorage
    grneyeddvl@ubuntu:/minecraft/pvp$ cd /minecraft/creative
    grneyeddvl@ubuntu:/minecraft/creative$ mkdir worldstorage

    Make all of your Minecraft folders writeable from SFTP so you can move world folders easily
    Code:
    sudo chmod 777 -R /minecraft

    Login to FileZilla again, and drag the world and world_nether folders into the worldstorage folder. They will get recreated again as the symlinks are generated.

    IMPORTANT! AFTER YOU MOVE THEM YOU MUST RENAME THEM TO MATCH YOUR SCRIPT FILES OR SAVES WILL GET CORRUPTED!

    I renamed my worlds pvp and pvp_nether, and creative and creative_nether. YOU MUST ALSO CHANGE YOUR server.properties FILE TO MATCH!



    Now you can start each service independently and they will both run at the same time. They will also run when the server boots.
    Run these two commands:
    Code:
    grneyeddvl@ubuntu:/minecraft/creative$ sudo /etc/init.d/mc_pvp start
    grneyeddvl@ubuntu:/minecraft/creative$ sudo /etc/init.d/mc_creative start


    Your output should look like this:
    Code:
    grneyeddvl@ubuntu:/minecraft/creative$ sudo /etc/init.d/mc_pvp start
    ls: cannot access /minecraft/pvp/world: No such file or directory
    created link for world
    ls: cannot access /minecraft/pvp/world_nether: No such file or directory
    created link for world_nether
    links checked
    world copied to ram
    mc_pvp.jar was not running... starting.
    mc_pvp.jar is now running.
    grneyeddvl@ubuntu:/minecraft/creative$ sudo /etc/init.d/mc_creative start
    ls: cannot access /minecraft/creative/world: No such file or directory
    created link for world
    ls: cannot access /minecraft/creative/world_nether: No such file or directory
    created link for world_nether
    links checked
    world copied to ram
    mc_creative.jar was not running... starting.
    mc_creative.jar is now running.


    You should now be able to start Minecraft and connect to both of them, even though you cannot see the console running. Try it and make sure. Remember to use the correct port numbers, my two connections are:
    10.100.128.23:25565
    10.100.128.23:25566

    Login to your ssh client as your minecraft user. Run the following commands to access the Minecraft console:
    Code:
    screen -r pvp
    screen -r creative

    When you run either of those, you will be able to watch the game realtime from your ssh client. You can even enter commands such as stop, reload, say, etc. When you want to exit the console press:

    Ctrl + A + D

    This will give you back your shell prompt.



    These are the commands you can run from your shell prompt that are built into the Minecraft script attached to this post. Swap mc_creative with mc_pvp as needed. If you run any of the backup or restart scripts while someone is logged in, they will get notices about the server shutting down 60 seconds before they get kicked.
    Code:
    /etc/init.d/mc_creative start
    /etc/init.d/mc_creative stop
    /etc/init.d/mc_creative restart
    /etc/init.d/mc_creative backup
    /etc/init.d/mc_creative whole-backup
    /etc/init.d/mc_creative update - THIS WILL BREAK PLUGINS - DO IT MANUALLY
    /etc/init.d/mc_creative whole-backup
    /etc/init.d/mc_creative log-roll
    /etc/init.d/mc_creative to-disk
    /etc/init.d/mc_creative connected
    /etc/init.d/mc_creative status
    /etc/init.d/mc_creative version
    /etc/init.d/mc_creative links
    /etc/init.d/mc_creative help

    If you want people outside your network to be able to connect to your two Minecraft servers, you will have to forward ports 25565 and 25566 to your Ubuntu machine.

    Reboot your Ubuntu server, and then try to play Minecraft. It should start up just fine.

    This is the end of the first and hardest part of setting up your server. Next we will setup MySQL and create databases and users that Minecraft can access, and setup automated cron jobs for backups and log rotation.
    Attached Files Attached Files
    Last edited by GrnEyedDvl; August 05, 2013 at 02:48 PM.

  2. #2
    GrnEyedDvl's Avatar Barackolypse Now
    Artifex Technical Staff

    Join Date
    Jan 2007
    Location
    Denver CO
    Posts
    21,874

    Default Re: MC Server Tutorial

    Reserved for MySQL tutorial.

  3. #3
    GrnEyedDvl's Avatar Barackolypse Now
    Artifex Technical Staff

    Join Date
    Jan 2007
    Location
    Denver CO
    Posts
    21,874

    Default Re: MC Server Tutorial

    Reserved for cronjob tutorial.

  4. #4
    Mangerman's Avatar Only the ladder is real
    Join Date
    Aug 2006
    Location
    The Netherlands
    Posts
    4,245

    Default Re: MC Server Tutorial

    You should sticky this!

  5. #5
    General Brewster's Avatar The Flying Dutchman
    Join Date
    Jul 2011
    Location
    Kingdom of The Netherlands
    Posts
    8,095

    Default Re: MC Server Tutorial

    Great job GED.

  6. #6
    GrnEyedDvl's Avatar Barackolypse Now
    Artifex Technical Staff

    Join Date
    Jan 2007
    Location
    Denver CO
    Posts
    21,874

    Default Re: MC Server Tutorial

    It actually needs to be updated for Java 7.

  7. #7
    General Brewster's Avatar The Flying Dutchman
    Join Date
    Jul 2011
    Location
    Kingdom of The Netherlands
    Posts
    8,095

    Default Re: MC Server Tutorial

    I was more aiming at the effort you take to lean other people about it I really appeticiate it!

  8. #8
    Ikko-Ikki
    Join Date
    Feb 2013
    Posts
    1

    Default Re: MC Server Tutorial

    First of all I want to thank you for a great tutorial!
    I am rather new to this and I need all the help I can get.
    You wrote that there were some files attached to the post, but I canīt find any attached files.
    Can you please attach them again?

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •