欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  网络运营

CentOS 5.1下跑Mono和Asp.net的实现方法

程序员文章站 2022-06-27 21:19:53
下载编译环境: yum install gcc bison pkgconfig glib2-devel gettext make httpd-devel gcc-c++ l...
下载编译环境:
yum install gcc bison pkgconfig glib2-devel gettext make httpd-devel gcc-c++ libstdc++-devel

下载并解压源代码:
wget http://ftp.novell.com/pub/mono/sources/mono/mono-2.6.3.tar.bz2
wget http://ftp.novell.com/pub/mono/sources/mod_mono/mod_mono-2.6.3.tar.bz2
wget http://ftp.novell.com/pub/mono/sources/xsp/xsp-2.6.3.tar.bz2
tar -jxvf mono-2.6.3.tar.bz2
tar -jxvf xsp-2.6.3.tar.bz2
tar -jxvf mod_mono-2.6.3.tar.bz2

安装mono环境:
cd /root/mydir/mono-2.6.3
./configure --prefix=/opt/mono; make ; make install
echo export pkg_config_path=/opt/mono/lib/pkgconfig:$pkg_config_path>>~/.bash_profile
echo export path=/opt/mono/bin:$path>>~/.bash_profile
source ~/.bash_profile

安装xsp:
cd /root/mydir/xsp-2.6.3
./configure --prefix=/opt/mono; make ; make install

安装mod_mono:
先用find / -iname apr*config命令查找出“--with-apr-config=/usr/bin/apr-1-config”(不知道--with-apr-config=/usr/bin/apr-1-config有什么用,好像不要也可以,麻烦知道的告诉一下小弟)
再执行下面的命令:
cd /root/mydir/mod_mono-2.6.3
./configure --prefix=/opt/mono --with-mono-prefix=/opt/mono --with-apr-config=/usr/bin/apr-1-config; make ; make install
cp /etc/httpd/conf.d/ /etc/httpd/conf/mod_mono.conf

selinux阻止了httpd对mod-mono-server的访问,所以执行下面的语句:
setsebool -p httpd_disable_trans=1

重启httpd服务器:
service httpd restart

在防火墙中开启80端口,允许同一个lan的其他机器访问:
方法1.在不使用图形界面工具的时候,通过关闭防火墙来实现允许开放80端口
service iptables stop
(ps:我尝试过下面的方法,
vi /etc/sysconfig/iptables
添加:-a rh-firewall-1-input -m state --state new -m tcp -p tcp --dport 80 -j accept
service iptables restart
虽然在iptables -l中看到http
但无法从其他机器访问该服务器。
如果有谁成功,请告知小弟):

方法2.在安装有图形界面工具的情况下,用startx进入图形界面,用“security level and firewall”开启80端口。

安装libgdiplus(xsp的测试页面中,有很多都需要libgdiplus):
yum install httpd build-essential gcc bzip bison pkgconfig glib-devel \
glib2-devel httpd-devel libpng-devel libx11-devel freetype fontconfig \
pango-devel ruby ruby-rdoc gtkhtml38-devel wget
wget http://ftp.novell.com/pub/mono/sources/libgdiplus/libgdiplus-2.6.2.tar.bz2
tar -jxvf libgdiplus-2.6.2.tar.bz2
cd /root/mydir/libgdiplus-2.6.2
./configure
make ; make install
echo export ld_library_path=/usr/local/lib/:$ld_library_path >>~/.bash_profile
source ~/.bash_profile

vi /opt/mono/etc/mono/config
添加节点:<dllmap dll="gdiplus.dll" target="/usr/lib/libgdiplus.so.0" />
否则会出现dllnotfoundexception的异常。

测试:
一、测试mono
a.运行mono -v输出:
mono jit compiler version 2.6.3 (tarball fri apr 2 06:13:46 cst 2010)
copyright (c) 2002-2010 novell, inc and contributors. http://www.mono-project.com/
tls: __thread
gc: included boehm (with typed gc and parallel mark)
sigsegv: altstack
notifications: epoll
architecture: x86
disabled: none
b.运行mono-test-install输出:
active mono: /opt/mono/bin/mono
your have a working system.drawing setup
your file system watcher is: system.io.inotifywatcher

二、测试asp.net服务器
a.测试是否能够执行aspx:
在/var/www/html/目录下建一个test.aspx页面,内容为
<%="hello world!"%>
通过wget http://localhost/test.aspx来下载该页面的内容。

b.测试同一个lan下其他机器能否访问:
用其他机器的浏览器打开http://ip/test.aspx

c.跑xsp自带的测试程序(多点几个页面,查看是否会出现gdiplus.dll dllnotfoundexception的一场):
1.修改apache的配置,开放防火墙8080端口
listen 8080
namevirtualhost *:8080
<virtualhost *:8080>
serveradmin hlfstephen@gmail.com
documentroot /var/www/test/
servername local.mydomain.com
errorlog logs/local.mydomain.com-error_log
customlog logs/local.mydomain.com common
</virtualhost>
2.复制/opt/mono/lib/xsp/test目录到var/www/下
3.service httpd restart
4.用浏览器打开http://ip:8080/

参考:




http://mono-project.com/dllnotfoundexception
http://mono-project.com/config_dllmap