Windows XP Windows 7 Windows 2003 Windows Vista Windows教程綜合 Linux 系統教程
Windows 10 Windows 8 Windows 2008 Windows NT Windows Server 電腦軟件教程
 Windows教程網 >> Linux系統教程 >> Linux教程 >> CentOS Linux搭建.NET環境

CentOS Linux搭建.NET環境

日期:2017/2/7 14:36:41      編輯:Linux教程
 

Mono是一個跨平台的、開源的.NET開發框架。支持Linux系統,它是Novell公司基於SUSE Linux操作系統開發的。
官網:http://mono-project.com/Main_Page

網上查了下,在Linux上要使用ASP.NET環境的Web服務器可以使用Apache+mod_mono方式或Mono+Jexus方式(Jexus是國人開發的一個免費軟件),當然Nginx也可以支持。http://www.mono-project.com/ASP.NET

官方軟件包下載地址:http://ftp.novell.com/pub/mono/sources-stable/

Apache+mod_mono方式
安裝必備軟件:

yum install bison make gcc gcc-c++ libstdc++-devel gettext pkgconfig glib2-devel

1、安裝libgdiplus
libgdiplus是mono中的System.Drawing依賴的一個組件,用於顯示web頁面基本顏色等。目前最新是libgdiplus-2.10。

cd /tmp
wget http://ftp.novell.com/pub/mono/sources/libgdiplus/libgdiplus-2.10.tar.bz2
tar -xjvf libgdiplus-2.10.tar.bz2
cd libgdiplus-2.10
./configure --prefix=/usr/local


生成makefile時提示失敗:
configure: WARNING: *** TIFF plug-in will not be built (TIFF library not found) ***
checking for jpeg_destroy_decompress in -ljpeg... no
configure: WARNING: *** JPEG loader will not be built (JPEG library not found) ***
checking for DGifOpenFileName in -lgif... no
configure: WARNING: *** GIF loader will not be built (giflibrary not found) ***
checking for DGifOpenFileName in -lungif... no
configure: WARNING: *** GIF loader will not be built (ungiflibrary not found) ***
checking for libpng12... no
checking for png_read_info in -lpng... no
configure: error: *** libpng12 not found. See http://www.libpng.org/pub/png/libpng.html.

缺少libtiff、libjpeg、libgif、libpng庫。補了這些庫之後還會提示有庫缺少,一起裝了:

yum install libtiff libtiff-devel libjpeg libjpeg-devel giflib giflib-devel libpng libpng-devel libX11 libX11-devel freetype freetype-devel fontconfig fontconfig-devel libexif libexif-devel

繼續安裝libgdiplus:

./configure --prefix=/usr/local
make
make install

2、安裝Mono

cd /tmp
wget http://ftp.novell.com/pub/mono/sources/mono/mono-2.10.2.tar.bz2
tar -xjvf mono-2.10.2.tar.bz2
cd mono-2.10.2
./configure --prefix=/usr/local
make
make install

Mono安裝之後,可以用命令mono -V查看一下mono的安裝情況,如果能夠看到mono版本號等信息,說明Mono安裝成功。

3、安裝Apache

cd /tmp
wget http://labs.renren.com/apache-mirror//httpd/httpd-2.2.21.tar.gz
tar -xzvf httpd-2.2.21.tar.gz
cd httpd-2.2.21
./configure --prefix=/usr/local/apache --enable-mods-shared=most
make
make install

4、安裝mod_mono

cd /tmp
wget http://ftp.novell.com/pub/mono/sources/mod_mono/mod_mono-2.10.tar.bz2
tar -xjvf mod_mono-2.10.tar.bz2
cd mod_mono-2.10
./configure
make
make install

5、安裝xsp
xsp就是mod-mono-server。

cd /tmp
wget http://ftp.novell.com/pub/mono/sources/xsp/xsp-2.10.2.tar.bz2
tar -xjvf xsp-2.10.2.tar.bz2
cd xsp-2.10.2
./configure --prefix=/usr/local
make
make install

如果生成makefile時提示:
checking for MONO_MODULE... configure: error: Package requirements (mono >= 2.10.0) were not met:

No package 'mono' found

Consider adjusting the PKG_CONFIG_PATH environment variable if you
installed software in a non-standard prefix.

Alternatively, you may set the environment variables MONO_MODULE_CFLAGS
and MONO_MODULE_LIBS to avoid the need to call pkg-config.
See the pkg-config man page for more details.

需要設置環境變量,就能編譯通過了:

export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig

6、配置Apache
查看/usr/local/apache/conf裡已經有mod_mono.conf文件了。

編輯httpd.conf:

vim /usr/local/apache/conf/httpd.conf

1)添加mod_mono.conf配置文件
找到

# Server-pool management (MPM specific)
#Include conf/extra/httpd-mpm.conf

在前面加入:

Include /usr/local/apache/conf/mod_mono.conf

2)將以下一句前的注釋去掉:

#ServerName www.example.com:80

不設置ServerName,Apache在啟動時會因為domain name報錯。

3)建立測試頁面:

vim /usr/local/apache/htdocs/test.aspx

網上找了一個,輸入:

<%@ Page Language="C#" %>
<html>
<head>
<title>hello world</title>
</head>
<body>
<%
for (int i=1; i<=7; i++)
{
Response.Write("<font size=" + i.ToString() + ">");
Response.Write("hello world");
Response.Write("</font><br />");
}
%>
</body>
</html>

4)重啟Apache:

/usr/local/apache/bin/apachectl restart

5)訪問測試頁面:

http://IP/test.aspx

顯示出以下內容表示成功。

6)設置Apache開機自啟動:

vim /etc/rc.local

加入:

/usr/local/apache/bin/apachectl start

7)原理說明:
上面所搭建asp.net運行環境,是以apache作為通訊框架,mod_mono作為接口橋(apache的插件),連接apache與xsp的通訊,xsp最終負責asp.net的服務處理,xsp會監聽本地端口用來與mod_mono通訊,後者將處理結果返回給apache,apache再返回給客戶端。

Copyright © Windows教程網 All Rights Reserved