微软的Windows Azure上也支持Linux虚拟机服务,下面我使用Azure的虚拟机服务跑一个OpenSuse的虚拟机测试Mono 3.0.2, 测试ASP.NET WebAPI 失败了。
安装系统补丁和更新:
azureuser@mono3:/usr/src/local> sudo zypper update
安装Wget工具包
azureuser@mono3:/usr/src/local> sudo zypper install wget
看下系统的版本是x86_64,下载相应版本的Mono 3.0.2安装包:
azureuser@mono3:/usr/src/local> sudo uname -a
Linux mono3 3.1.10-1.10-default #1 SMP Mon May 28 14:19:15 UTC 2012 (94036a4) x86_64 x86_64 x86_64 GNU/Linux
wget默认会根据网站的robots.txt进行操作,如果robots.txt里是User-agent: * Disallow: /的话,wget是做不了镜像或者下载目录的,使用-e robots=off参数即可绕过该限制。
指定下载制定后缀的文件,如只下载http://download.mono-project.com/archive/3.0.2/linux/x64/下.rpm文件:
azureuser@mono3:/usr/src/local> sudo wget -nd -r -l1 --no-parent -e robots=off -A.rpm http://download.mono-project.com/archive/3.0.2/linux/x64/
确认已经完全下载成功了Mono软件包
azureuser@mono3:/usr/src/local> ls
ibm-data-db2-3.0.2-0.x86_64.rpm mono-data-sqlite-3.0.2-0.x86_64.rpm
libmono-2_0-1-3.0.2-0.x86_64.rpm mono-devel-3.0.2-0.x86_64.rpm
libmono-2_0-devel-3.0.2-0.x86_64.rpm monodoc-core-3.0.2-0.x86_64.rpm
libmonosgen-2_0-0-3.0.2-0.x86_64.rpm mono-extras-3.0.2-0.x86_64.rpm
libmonosgen-2_0-devel-3.0.2-0.x86_64.rpm mono-locale-extras-3.0.2-0.x86_64.rpm
mono-complete-3.0.2-0.x86_64.rpm mono-mvc-3.0.2-0.x86_64.rpm
mono-core-3.0.2-0.src.rpm mono-nunit-3.0.2-0.x86_64.rpm
mono-core-3.0.2-0.x86_64.rpm mono-wcf-3.0.2-0.x86_64.rpm
mono-data-3.0.2-0.x86_64.rpm mono-web-3.0.2-0.x86_64.rpm
mono-data-oracle-3.0.2-0.x86_64.rpm mono-winforms-3.0.2-0.x86_64.rpm
mono-data-postgresql-3.0.2-0.x86_64.rpm mono-winfxcore-3.0.2-0.x86_64.rpm
安装下载的所有Mono软件包
azureuser@mono3:/usr/src/local>sudo zypper install *.rpm
查看成功安装了mono 3.0.2
azureuser@mono3:/usr/src/local> mono --version
Mono JIT compiler version 3.0.2 (tarball Wed Dec 5 14:50:07 GMT 2012)
Copyright (C) 2002-2012 Novell, Inc, Xamarin Inc and Contributors. www.mono-project.com
TLS: __thread
SIGSEGV: altstack
Notifications: epoll
Architecture: amd64
Disabled: none
Misc: softdebug
LLVM: supported, not enabled.
GC: Included Boehm (with typed GC and Parallel Mark)
安装Jexus 5.2
azureuser@mono3:/usr/src/local> sudo wget http://linuxdot.net/down/jexus-5.2.tar
azureuser@mono3:/usr/src/local> sudo tar -zxvf jexus-5.2.tar.gz
具体可以参照 32和64位的CentOS 6.0下 安装 Mono 2.10.8 和Jexus 5.0
然后放了一个ASP.NET Web API项目(http://code.msdn.microsoft.com/wpapps/Contact-Manager-Web-API-0e8e373d)上去测试了下,WebAPI项目还是跑不起来,继续测试下个版本,可以访问这个地址看到具体错误 http://ndon.cloudapp.net/default.htm。也有同学在报这个问题 http://mono.1490590.n4.nabble.com/ASP-NET-Web-API-on-Mono-3-0-Could-not-load-type-System-Web-Http-WebHost-HttpControllerHandler-td4657079.html , 后来在Mono 3.0.4上成功了。
参考文档:
Create a Virtual Machine Running Linux
Use root privileges on Linux virtual machines in Windows Azure