Thursday, March 03, 2011

Setting up Mono on Amazon EC2

A while ago I managed to set up Mono on an Amazon EC2 instance running the standard Amazon Linux AMI, by compiling from sources. Boy, that was a pain, took a while (I was stupid enough to do it on a Micro instance) and turned out to be totally unnecessary.

Today I found a better way to do it, thanks to this post on StackOverflow. You'll have to modify the steps that the poster follows, though, mostly because you can't log in as root on an Amazon Linux instance, but everything is available using sudo.

First you have to set up an instance (use a Large instance, you won't regret it), and the easiest way to do that is through the Amazon Management Console. Once you have your instance running and you can log in, do the following:

First, add the official Mono repository to yum. I'm quite new to yum, but the SO post made it quite clear. In your home directory, issue the command 'vi mono.repo', and press 'i' to enter 'insert mode', then paste the following snippet:


[Mono]
name=Mono Stack (RHEL_5)
type=rpm-md
baseurl=http://ftp.novell.com/pub/mono/download-stable/RHEL_5/
gpgcheck=1
gpgkey=http://ftp.novell.com/pub/mono/download-stable/RHEL_5/repodata/repomd.xml.key
enabled=1

Then, press the 'escape' key, and type ':w' and ':q'. I'm not used to vi, but I know it's on there and this happens to work. Now you have the repo file in your home directory and you need to move it to the /etc/yum.repos.d directory, but only root can do that, so issue the command 'sudo mv mono.repo /etc/yum.repos.d'.

Next, you'll need to clear the cache using 'sudo yum clean' and install the Mono stack using 'sudo yum install monotools-addon-server'. That will install the latest stable version of Mono, currently 2.10.1.

You can do this on a Large instance and make it quicker, then shutdown your instance, make a snapshot, terminate the instance and make a new 'Micro' instance using the instance and you'll be set up. For some funny reason Micro instances are 64-bit and Large instances are too, but Normal instances are 32-bit only.

Now I have to figure out how to set up a decent web server so I can try to get ASP.NET MVC going.

UPDATE: I definitely needed the following to make ASP.NET MVC work: I had to install WCF, by issuing this command: ‘sudo yum install mono-addon-wcf’. The mod_mono module is autohosting, which means that when installed, it automatically loads so ASP.NET should work out of the box, and the example site is located at /opt/novell/mono/lib/xsp/test.

9 comments:

  1. Pretty nice - this is exactly what I need. Have you deployed anything "serious" on it? Something public, 24x7, etc etc... I'm afraid of installing it on my box and have the same delusion I had after installing Java on a micro instance... :)

    ReplyDelete
  2. Well, no, as right now I'm still experimenting with Mono. Being a .NET dev I usually deploy on Windows, and I'm in the process of moving my hosting needs from a dedicated box to a micro instance. But isn't that the nice thing about Amazon EC2? When you outgrow the Micro instance, you can just add another or migrate to a larger instance type.

    ReplyDelete
  3. Thanks Dave - this was exactly what I was looking for!

    Rob.

    ReplyDelete
  4. Awesome tutorial! So I've got a micro instance setup, installed apache, installed mono, can see the default home page for apache in my browser... now its time to figure out how to deploy an mvc website to it. :-)

    ReplyDelete
  5. Thanks for the post! BTW, it's easy enough to switch to root. Just use "sudo bash"

    ReplyDelete
  6. Anonymous5:49 AM

    Thanks - For me it worked fine on a 32 bit micro instance (less than 2 minutes) for the big mono distribution. Somehow in the path I took I wound up without gdiplus installed so none of the controls would work.

    I fixed that by "yum list '*gdi*'" to find the package I needed and then "sudo yum install mono-addon-libgdiplus0".

    ReplyDelete
  7. This comment has been removed by the author.

    ReplyDelete
  8. Crap. The repositories are no longer.

    I tried:

    [Mono]
    name=Mono Stack (openSUSE_11)
    type=rpm-md
    baseurl=http://download.mono-project.com/download-stable/openSUSE_11.4/
    gpgcheck=1
    gpgkey=http://origin-download.mono-project.com/download-stable/openSUSE_11.4/repodata/repomd.xml.key
    enabled=1

    But after that, "sudo yum install monotools-addon-server" throws and error.

    I tried also "sudo yum install mono-complete" but that throws dependency errors:

    Error: Package: mono-devel-2.10.6-0.xamarin.i586 (Mono)
    Requires: libgmodule-2_0-0
    Error: Package: libgdiplus0-2.10-30.2.i586 (Mono)
    Requires: libpng14.so.14
    Error: Package: libgdiplus0-2.10-30.2.i586 (Mono)
    Requires: libpng14.so.14(PNG14_0)
    Error: Package: mono-devel-2.10.6-0.xamarin.i586 (Mono)
    Requires: libglib-2_0-0
    Error: Package: mono-devel-2.10.6-0.xamarin.i586 (Mono)
    Requires: libz.so.1(ZLIB_1.2.3.3)
    You could try using --skip-broken to work around the problem
    ** Found 1 pre-existing rpmdb problem(s), 'yum check' output follows:
    aws-cfn-bootstrap-1.3-6.noarch has missing requires of python-requests

    ...crap


    ReplyDelete
  9. Yeah... I know. Now that Mono is gone from Novell, there hasn't been any reason to support SUSE anymore, it seems.

    ReplyDelete