CentOS5.1下跑Mono和Asp.net

來源:互聯網
上載者:User

  由於想研究在linux下跑.net程式的可行性,於是嘗試在CentOS5.1下搭建Mono環境和Asp.Net的伺服器。Asp.Net的伺服器是採用mod_mono和Apache的方式搭建(Nginx的搭建尚未研究)。

 

下載編譯環境:

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://blog.rubypdf.com/2009/10/23/how-to-install-mono-2-4-2-3-on-centos-5/
http://blog.rubypdf.com/2009/10/23/how-to-install-xsp-and-integrate-xsp-with-apache-2-under-centos-5/
http://blog.bennyland.com/2010/02/06/serving-asp-net-pages-in-apache-on-centos-5/
http://mingster.com/site/?q=content/mono-2x-centos-5
http://mono-project.com/DllNotFoundException
http://mono-project.com/Config_DllMap

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.