New user here - I've known about Minecraft forever, but first time actually getting into the game, believe it or not. My son wants it big time, and it looks like a blast. So, we'll both be grabbing it really soon.
Question on the EC2 hosting side of things. I was thinking it would be really useful for the Minecraft server host community to have a schedule script, firing up their servers at specific time of day, and winding them down as well. That way you're not burning server hours constantly.
Anyone know how to make a Windows scheduler based script to automatically start/stop EC2 instances using the AWS API? I would certainly use it.
I have a Linux instance, because I want to learn Linux at least a little. But, I would like to have the command & control of the MC server from my Windows desktop at home. Anyone interested in showing me how that can be done? My son and I thank you in advance!
Anyone know how to make a Windows scheduler based script to automatically start/stop EC2 instances using the AWS API?
Hi. Get the Amazon command line tools working in Windows (see my earlier post in this thread), then use the tool ec2-stop-instances to stop your server on demand.
For startup you'll need Minecraft server to be kicked off at server start; there will be many posts on this on the web.
An "EC2 instance" is just a linux computer. An "EBS Volume" is just a disk drive. Fancy cloud terms for a regular computer.
So find server.properties on the disk (wherever you installed Minecraft and edit it.
You can use built in linux editors like "nano" or "vim". They are very basic but do the job.
I've been running a small instance for several weeks for the family and friends. We have 4-5 people on in very large worlds and have had no problems with a small.
I stop the instance when we are not playing so it's pretty cheap (just click "Stop" in the EC2 Web Console (https://console.aws.amazon.com/ec2)
Other useful things I've used:
Elastic IP Addresses
Elastic IPs are static IP addresses you can attach to any running instance. That address is yours forever. As long as it is attached it is free.
in https://console.aws.amazon.com/ec2 go to "Elastic IPs" and click "Allocate".
You can now click "Attach" and select your instance. You now have an IP address like 107.22.12.14 you can hand out to your friends. No DNS needed (though that's nice, too).
The downside to EIP's is that if you stop an instance you detach, it wont automatically re-attach when you start. In my next post I'll paste a short script that will auto-reattach on startup.
[This got a lot longer than I intended, but I hope someone finds it useful]
How to attach an Elastic IP automatically after restarting an EC2 instance (and automatically start Minecraft, too)
You can always manually attach an Elastic IP to your restarted instance, but here's how you attach it automatically.
This uses the EC2 command-line tools (which are pre-installed on your EC2 instance if you used the standard Amazon Linux AMI)
To start with I already attached my Elastic IP (107.22.212.xx) to my instance using the AWS Console https://console.aws.amazon.com/ec2
I prefer the unix command line, so I connect from linux this way:
where the pem file is my identity, i.e. the private key (ec2 keypair) I saved when I started the instance.
107.22.212.xx is my personal instance IP address (replace it with yours)
You can stuff this command in an alias or just into a file:
You'll have a couple files with ridiculous long names like cert-JHGLJHG446LJHGJHG.pem
The name is not important unless you have lots of certs, you can safely shorten it to anything.
Copy these files to a directory on your ec2 instance, convention says to call it ".ec2"
On your EC2 instance:
mkdir .ec2
From your own machine (linux) copy the files over to your .ec2 directory
#!/bin/sh
# This script will attach the below Elastic IP address to this ec2 instance
HOMEDIR=/home/ec2-user
# ==CHANGE THESE==
# Your Elasic IP Address
ip=107.22.212.xx
# keys downloadable from https://aws-portal.amazon.com/gp/aws/developer/account/index.html?action=access-key#access_credentials
# Click X.509 certificates and download both Private Key and Certificate
export EC2_PRIVATE_KEY=$HOMEDIR/.ec2/pk-[REPLACE THIS WITH YOURS].pem
export EC2_CERT=$HOMEDIR/.ec2/cert-[REPLACE THIS WITH YOURS].pem
# TOUCH NOTHING ELSE AFTER HERE
export EC2_HOME=/opt/aws/apitools/ec2
export JAVA_HOME=/usr/lib/jvm/jre
instanceId=$(curl -s http://169.254.169.254/latest/meta-data/instance-id)
echo "Instance: $instanceId"
echo "Attaching IP address $ip..."
echo $($EC2_HOME/bin/ec2-associate-address -i $instanceId $ip)
Fun little fact, try this on your EC2 instance, it'll tell you all sorts of things about your instance. For our purposes we just need the instance-id
To make this run on startup, make it executable and call it in /etc/rc.local
chmod +x attachIP.sh
sudo nano /etc/rc.local
Paste this in the middle (assumes you have a script called minecraft/run-server that starts minecraft, replace this with whatever you do to start minecraft):
# Attach our elastic IP to this instance
/home/ec2-user/attachIP.sh
# start up Minecraft on reboot, woot!
cd /home/ec2-user/minecraft && screen -dmS minecraft /home/ec2-user/minecraft/run-server
Now you can log in and attach to your server using screen:
How AWESOME is this thread? Thank you guys SO much for filling me in on almost everything I needed not only to set my Minecraft server up on AWS, but also to learn the basics of EC2 in a much easier way than the tutorials out there! That was really useful. Let me share my findings and add something new here.
So, I ended up creating a micro instance, launching a vanilla minecraft server from the script on MinecraftWiki and using CpuLimit at 30% to keep the throttling at bay. Also used @dwhitnee's great post on how to automatically attach elastic ips.
I had some trouble finding out how to use Screen and CpuLimit correctly, but ended up doing it right (I think). To find the developer tools for installing CpuLimit, I had to find the name of the package. Got it with the yum grouplist command on the Ec2 console, as @gjdunga pointed out. Then, to finally put the program to limit java's cpu:
First, run the minecraft script.
Then, screen -r , to enter minecraft server screen.
Ctrl+A then c , to make a new screen
sudo ./cpulimit -e java -l 30 -z , on the new screen
Ctrl+A then d , to leave the screens on background and return to ec2 shell
Allright, that got my server running fine on my free tier micro instance. But, as everyone else pointed out, it doesn't hold many people online. The best solution I found out was to upgrade the instance to small, pay while people are actually playing and then downgrade the instance back to micro.
Two reasons for that: I allocated an elastic IP, and I'll be charged if it's not attached to a running instance. As my micro instance is free, I'm better off keeping it online all the time. I also thought of keeping two instances and firing up one or another, but I can only remap the IP a hundred times each month, and it takes a couple minutes for my players to finally be able to connect to the new instance with it.
Script for upgrading / downgrading an instance
So I made a (linux) script for this upgrade/downgrade thing, scavenging parts here and there. I believe this is halfway what to do a startable server like @Aahzmundus suggested on the first page (I'll get there!). Had some help from this site here while making the script: http://paulstamatiou.com/how-to-getting-started-with-amazon-ec2
Also, to find the right JAVA_HOME, had to use whereis java on my machine and remove the "/bin" end of it. For some reason, the --region argument on all API commands is mandatory for me. If I don't use it, the command never finds my instance.
Create a new file, name it "updateServer.sh" or something and paste the code below inside it. Use sudo chmod +x updateServer.sh to make it executable, then run it.
Example:
./updateServer upgrade
MICRO='t1.micro'
SMALL='m1.small'
INSTANCE='your-instance-id-here'
REGION='your-region-here. example: sa-east-1'
# Define the string we’re looking for from ec2-describe-instances to determine stopped status
export STOPPED='stopped'
export EC2_PRIVATE_KEY=your-folder/pk-your-primary-key.pem
export EC2_CERT=your-folder/cert-your-certificate.pem
export EC2_HOME=your-folder/ec2-api-tools-1.xx.xx.xx
export JAVA_HOME=/usr
# Upgrading
upgrade() {
# Stop the instance
echo Script - Stopping instance $INSTANCE
${EC2_HOME}/bin/ec2-stop-instances $INSTANCE --region $REGION
echo Script - Instance $INSTANCE stopped.
# Upgrade it
# Set the flag to false. As soon as it’s stopped, we’ll change the type.
export done='false'
while [ $done == 'false' ]
do
export status=`${EC2_HOME}/bin/ec2-describe-instances ${INSTANCE} --region $REGION | grep INSTANCE | cut -f6`
if [ $status == ${STOPPED} ]; then
export done='true'
else
echo "Waiting…"
sleep 10
fi
done
echo Script - Upgrading from $MICRO to $SMALL
${EC2_HOME}/bin/ec2-modify-instance-attribute $INSTANCE --region $REGION --instance-type $SMALL
echo Script - Upgraded
# Start it again.
echo Script - Starting instance $INSTANCE
${EC2_HOME}/bin/ec2-start-instances $INSTANCE --region $REGION
echo Script - Started ok
}
# Downgrading
downgrade() {
# Stop the instance
echo Script - Stopping instance $INSTANCE
${EC2_HOME}/bin/ec2-stop-instances $INSTANCE --region $REGION
echo Script - Instance $INSTANCE stopped.
# Upgrade it
# Set the flag to false. As soon as it’s stopped, we’ll change the type.
export done='false'
while [ $done == 'false' ]
do
export status=`${EC2_HOME}/bin/ec2-describe-instances ${INSTANCE} --region $REGION | grep INSTANCE | cut -f6`
if [ $status == ${STOPPED} ]; then
export done='true'
else
echo "Waiting…"
sleep 10
fi
done
echo Script - Downgrading from $SMALL to $MICRO
${EC2_HOME}/bin/ec2-modify-instance-attribute $INSTANCE --region $REGION --instance-type $MICRO
sleep 10 # Make sure the changes have been made
echo Script - Upgraded
# Start it again.
echo Script - Starting instance $INSTANCE
${EC2_HOME}/bin/ec2-start-instances $INSTANCE --region $REGION
echo Script - Instance started. In a few moments, will be running
}
# Just showing instance status
status() {
export status=`${EC2_HOME}/bin/ec2-describe-instances ${INSTANCE} --region $REGION | grep INSTANCE | cut -f6`
echo Instance $INSTANCE now on status: $status
}
#Start-Stop here
case "$1" in
upgrade)
upgrade
;;
downgrade)
downgrade
;;
status)
status
;;
*)
echo "Usage: ./updateServer {upgrade|downgrade|status}"
exit 1
;;
esac
exit 0
I've heard about a Java option: -Xincgc
Has anybody tried this with Amazon's micro instance?
-Xincgc
Enable the incremental garbage collector. The incremental garbage collector, which is off by default, will eliminate occasional garbage-collection pauses during program execution. However, it can lead to a roughly 10% decrease in overall GC performance.
This could help "avoid" long bursts of GC, which could cause throttling by Amazon, thus being a good thing.
OR
It could cause more overall CPU usage in total, which could cause more throttling by Amazon, and thus be bad.
So always remember to launch your Minecraft with the -server switch:
This tutorial is great, thanks
I get an error when making the command to run the server.
"Could not reserve enough space for object heap"
After doing some research i found it has to do with the Hadoop but i have no idea how to configure.
Any help would be greatly appreciated.
Thanks
New user here - I've known about Minecraft forever, but first time actually getting into the game, believe it or not. My son wants it big time, and it looks like a blast. So, we'll both be grabbing it really soon.
Question on the EC2 hosting side of things. I was thinking it would be really useful for the Minecraft server host community to have a schedule script, firing up their servers at specific time of day, and winding them down as well. That way you're not burning server hours constantly.
Anyone know how to make a Windows scheduler based script to automatically start/stop EC2 instances using the AWS API? I would certainly use it.
I have a Linux instance, because I want to learn Linux at least a little. But, I would like to have the command & control of the MC server from my Windows desktop at home. Anyone interested in showing me how that can be done? My son and I thank you in advance!
ZAG
Zombie Apocalypse Games
Hi. Get the Amazon command line tools working in Windows (see my earlier post in this thread), then use the tool ec2-stop-instances to stop your server on demand.
For startup you'll need Minecraft server to be kicked off at server start; there will be many posts on this on the web.
Good luck!
So find server.properties on the disk (wherever you installed Minecraft and edit it.
You can use built in linux editors like "nano" or "vim". They are very basic but do the job.
I've been running a small instance for several weeks for the family and friends. We have 4-5 people on in very large worlds and have had no problems with a small.
I stop the instance when we are not playing so it's pretty cheap (just click "Stop" in the EC2 Web Console (https://console.aws.amazon.com/ec2)
Other useful things I've used:
Elastic IP Addresses
Elastic IPs are static IP addresses you can attach to any running instance. That address is yours forever. As long as it is attached it is free.
in https://console.aws.amazon.com/ec2 go to "Elastic IPs" and click "Allocate".
You can now click "Attach" and select your instance. You now have an IP address like 107.22.12.14 you can hand out to your friends. No DNS needed (though that's nice, too).
The downside to EIP's is that if you stop an instance you detach, it wont automatically re-attach when you start. In my next post I'll paste a short script that will auto-reattach on startup.
How to attach an Elastic IP automatically after restarting an EC2 instance (and automatically start Minecraft, too)
You can always manually attach an Elastic IP to your restarted instance, but here's how you attach it automatically.
This uses the EC2 command-line tools (which are pre-installed on your EC2 instance if you used the standard Amazon Linux AMI)
To start with I already attached my Elastic IP (107.22.212.xx) to my instance using the AWS Console https://console.aws.amazon.com/ec2
I prefer the unix command line, so I connect from linux this way:
where the pem file is my identity, i.e. the private key (ec2 keypair) I saved when I started the instance.
107.22.212.xx is my personal instance IP address (replace it with yours)
You can stuff this command in an alias or just into a file:
Now you can just type ./ec2ssh and connect to your host.
Configuring the EC2 command line tools
To make the ec2 command line tools work you need some local key files (different from the ec2 keypair you ssh with).
1. Go to Your Account: https://aws-portal.amazon.com/gp/aws/developer/account/index.html?action=access-key#access_credentials
2. Click "X.509 certificates" and "Create a new Certificate."
3. Download both Private Key and Certificate and save to disk.
You'll have a couple files with ridiculous long names like cert-JHGLJHG446LJHGJHG.pem
The name is not important unless you have lots of certs, you can safely shorten it to anything.
Copy these files to a directory on your ec2 instance, convention says to call it ".ec2"
On your EC2 instance:
From your own machine (linux) copy the files over to your .ec2 directory
Now copy the below script into a local file called attachIP.sh, edit the "CHANGE THESE" section, and copy it to your ec2 instance:
Fun little fact, try this on your EC2 instance, it'll tell you all sorts of things about your instance. For our purposes we just need the instance-id
To make this run on startup, make it executable and call it in /etc/rc.local
Paste this in the middle (assumes you have a script called minecraft/run-server that starts minecraft, replace this with whatever you do to start minecraft):
Now you can log in and attach to your server using screen:
Have fun!
So, I ended up creating a micro instance, launching a vanilla minecraft server from the script on MinecraftWiki and using CpuLimit at 30% to keep the throttling at bay. Also used @dwhitnee's great post on how to automatically attach elastic ips.
I had some trouble finding out how to use Screen and CpuLimit correctly, but ended up doing it right (I think). To find the developer tools for installing CpuLimit, I had to find the name of the package. Got it with the yum grouplist command on the Ec2 console, as @gjdunga pointed out. Then, to finally put the program to limit java's cpu:
Allright, that got my server running fine on my free tier micro instance. But, as everyone else pointed out, it doesn't hold many people online. The best solution I found out was to upgrade the instance to small, pay while people are actually playing and then downgrade the instance back to micro.
Two reasons for that: I allocated an elastic IP, and I'll be charged if it's not attached to a running instance. As my micro instance is free, I'm better off keeping it online all the time. I also thought of keeping two instances and firing up one or another, but I can only remap the IP a hundred times each month, and it takes a couple minutes for my players to finally be able to connect to the new instance with it.
Script for upgrading / downgrading an instance
So I made a (linux) script for this upgrade/downgrade thing, scavenging parts here and there. I believe this is halfway what to do a startable server like @Aahzmundus suggested on the first page (I'll get there!). Had some help from this site here while making the script:
http://paulstamatiou.com/how-to-getting-started-with-amazon-ec2
Also, to find the right JAVA_HOME, had to use whereis java on my machine and remove the "/bin" end of it. For some reason, the --region argument on all API commands is mandatory for me. If I don't use it, the command never finds my instance.
Create a new file, name it "updateServer.sh" or something and paste the code below inside it. Use sudo chmod +x updateServer.sh to make it executable, then run it.
Example:
./updateServer upgrade
I'm pretty sure there's a lot of room for improvement here, but I think this gives a good idea on how to use the AWS API for this kind of task. More on each command available on:
http://docs.amazonwebservices.com/AWSEC2/latest/CommandLineReference/command-reference.html
Has anybody tried this with Amazon's micro instance?
-Xincgc
Enable the incremental garbage collector. The incremental garbage collector, which is off by default, will eliminate occasional garbage-collection pauses during program execution. However, it can lead to a roughly 10% decrease in overall GC performance.
This could help "avoid" long bursts of GC, which could cause throttling by Amazon, thus being a good thing.
OR
It could cause more overall CPU usage in total, which could cause more throttling by Amazon, and thus be bad.
I also wrote an article for getting the MSM tool up and running: http://www.aaronbell.com/how-to-run-minecraft-server-manager-on-amazon-linux/