So, yeah, I’m moving a bunch of stuff off local servers to the cloud, starting with my blog, and also including my Notebook – well, that one, I’m moving both into local storage and out to the cloud. But instead of stashing stuff on another wiki, I’m going to simplify things considerably and just post ‘em up here, and let search find them for me when I want ‘em. So there’ll be a fair few technical notes and such cropping up here in the future.
Anyway. Here’s how to run OpenSim on Amazon EC2, for testing. This is fairly old, but it’s what I used when I was playing around with it, and is probably readily transferrable to newer versions. It’s a simple standalone image of a Linux installation of OpenSim (based on 02/12/2009 SVN release). It is configured in the simplest possible configuration, using SQLite, and with no provision made for persistence between instances. Thus, it is intended for evaluation/test/play/try-out purposes only.
Or, of course, for building further OpenSim instances on top of.
First Stage: Running the Instance via EC2
Ok. So, how does all this work?
Well, if you haven’t used Amazon EC2 before, the first thing you need to do is become familiar with Amazon Web Services in general, and it in particular. Go along to http://aws.amazon.com/ and sign up, then take a look around. In particular, if you intend to use your shiny new OpenSim server a lot, you may want to pay attention to the information on pricing you’ll find there. It doesn’t add up to much for casual use – indeed, all the time I spent initially getting things set up, complete with false start using the Windows version, only cost me $0.64. But be aware of it. I am not responsible for any costs you may incur due to losing track of time, forgetting you left the instance running, etc.
I’m going to assume that you can read the getting started guide on your own, and don’t really need me to help you out with that. After all, you are about to run a piece of server software here, so I’m going to assume that I’m dealing with a relatively technical audience.
Anyway, before you proceed to the next step, you need to have:
- generated a key-pair
- created a security group for your OpenSim instances (I call mine “opensim”).
The rules you want on this security group are:
- tcp/22 (ssh) from your external IP address – and note, if you are using NAT, this means the address on the outside of your router
- icmp 8:0 (ping) likewise
- tcp/9000 from anywhere – 0.0.0.0/0
- udp/9000 from anywhere – 0.0.0.0/0
If you’re using the command-line, the results of an:
ec2-describe-group.cmd opensim
Should look something like this, only with different user/group numbers and IP addresses:
GROUP 465102135893 opensim OpenSim instance group
PERMISSION 465102135893 opensim ALLOWS tcp 0 65535 FROM USER 465102135893 GRPNAME default
PERMISSION 465102135893 opensim ALLOWS udp 0 65535 FROM USER 465102135893 GRPNAME default
PERMISSION 465102135893 opensim ALLOWS tcp 9000 9000 FROM CIDR 0.0.0.0/0
PERMISSION 465102135893 opensim ALLOWS udp 9000 9000 FROM CIDR 0.0.0.0/0
PERMISSION 465102135893 opensim ALLOWS tcp 22 22 FROM CIDR 24.249.106.76/32
PERMISSION 465102135893 opensim ALLOWS icmp 8 0 FROM CIDR 24.249.106.76/32
And/or you’ll see the analogous thing in the web-based EC2 console.
Okay, now you’re ready to start that instance up. Here’s the command line for those of you who installed the tools; those of you who are using the console get a nifty wizard when you right-click the AMI and launch it, so just plug in the right data in the right place. Basically, you want to launch one instance, on a small server, in security group opensim, and with the key-pair you made – mine’s called ec2-keypair, for this example – which on the command line looks like this:
ec2-run-instances ami-73f3141a –g opensim –k ec2-keypair
Now, when you see it “running” in the console, or you see that ec2-describe-instances has started showing it as running instead of pending, then the server is up and running. And you can move on to the next step.
Second Stage: Fixing Up The Instance
So, can we connect yet?
No. See, OpenSim needs to know the external hostname or IP address of the server it’s running on to serve the region, and it gets that from one of its configuration files. Trouble is, every time you start an instance on Amazon EC2, it’s automatically assigned a new one, so the first thing we need to do is log in to it and alter that config file.
When you started the instance, the command-line tool or the console will have given you its external name, which happens to have its IP address embedded in it. It looks something like this:
ec2-75-101-189-104.compute-1.amazonaws.com
So, the next thing we have to do is connect to the server using ssh, and for identification, use the private key file which you got when you generated your key-pair, and username root. Since there are about a gazillion ssh clients out there, you’re going to have to check how it wants the information on your own; for mine, PuTTY, the command line looks like this:
putty ec2-75-101-189-104.compute-1.amazonaws.com -l root -i z:\ec2-putty-keypair.ppk
(Oh, yeah. With PuTTY, due to annoying stuff, you have to mangle the .pk file EC2 gives you into PuTTY's own format before this will work. Details at http://docs.amazonwebservices.com/AWSEC2/2007-03-01/GettingStartedGuide/putty.html . You probably won't have to do this with other ssh clients.)
Okay. Now you're logged onto the instance. The file we need to edit is /var/opensim/bin/Regions/default.xml, so open it up for editing:
vi /var/opensim/bin/Regions
(Assuming you know how to use vi; tutorial here: http://www.unix-manuals.com/tutorials/vi/vi-in-10-1.html . I suggest practising on your own local copy for cheapness's sake.)
Find the external_host_name="174.129.229.27" part of the Config line, delete the part between the double-quotes, and replace it with the IP address of the host name we got above. That is, if the host name was ec2-75-101-189-104.compute-1.amazonaws.com, fill in 75.101.189.104. (This should work with the host name, yes, but it doesn't seem to for some reason.) Then save the file.
Now it should be able to find itself when it starts, so start it up. You need to be in the same directory as the server to start it, so these commands should do the trick:
cd /var/opensim/bin mono OpenSim.exe
You'll find a whole bunch of text flashing by in your SSH session as the server starts up. When it ends with the lines:
Currently selected region is root 16:07:18 - [STARTUP]: Startup took 0m 15s
You're ready to go.
Third Stage: Running OpenSim and Connecting
You can connect to the OpenSim with any compatible viewer, including the standard Second Life viewer. The easiest way to do this is to simply copy the shortcut for that viewer on your desktop, and edit the "Target" line in the shortcut properties to include the --loginuri part below, obviously replacing the host name part of the URI with the same one that you used in the last step.
"C:\Program Files\SecondLifeReleaseCandidate\SecondLifeReleaseCandidate.exe" --loginuri http://ec2-75-101-189-104.compute-1.amazonaws.com:9000/
Then just run it. The AMI is set up to accept logins from one user with first name "Test", last name "User", and password "test", initially.
And you're in your very own test sim!
When You’re Done
You can type "shutdown" to the OpenSim server if you really want to, but since in this instance EC2 will just throw away all the changes as soon as you terminate it anyway, there's not much need.
Anyway, don't bother trying to shut down the Linux server from inside it. Instead, either use the ec2-terminate-instances command:
ec2-terminate-instances.cmd i-b4bd37dd
with the instance number you got when you started the thing up, or right-click on the instance in the EC2 Console and hit Terminate.
DO NOT FORGET THIS STEP. OMIT IT AND YOU WILL BE BILLED FOR ALL THE TIME IT WILL BE RUNNING BEFORE YOU REMEMBER.
Stuff To Note
If you hate changing the IP address manually in step two, yes, you can get around this by using an Elastic IP and associating it with your instance each time you start it. Then you only have to change it the first time. I've done this myself when I was fiddling with it a lot, but please note that while Elastic IPs you use are free, Elastic IPs start costing you money when you aren't using them, and it adds up.
Yes, this is impractical for actual hosting, because any time the instance shuts down or is shut down, you lose all your changes. It should be possible to use Amazon's Elastic Block Store volumes to house the data files, with or without a MySQL database, to get around this, but I haven't got around to it yet. And, well, unless I'm gettin' paid, probably don't hold your breath for that coming out any time soon.
