[坑爹的mono]
----------------------------------------
资源下载地址:
mono:https://wrench.mono-project.com/Wrench/
xsp:https://github.com/mono/xsp
pcre:ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/
nginx:http://nginx.org/en/download.html
全部下载最新版本即可,文件有四个,它们是:
mono-3.0.3.tar.bz2
xsp-master.zip
pcre-8.32.tar.bz2
nginx-1.2.6.tar.gz
-----------------------------------------
CentOS6.3安装后默认关闭网络,先打开:
vi /etc/sysconfig/network-scripts/ifcfg-eth0
修改两地方,如下所示:
NM_CONTROLLED="no"
ONBOOT="yes"
保存后执行:
/etc/init.d/network restart
然后要打开80端口:
/sbin/iptables -I INPUT -p tcp --dport 80 -j ACCEPT
/etc/init.d/iptables save
/etc/init.d/iptables restart
首先要说明一下为什么选择源代码编译安装,是为了体验最新的mono功能,特别是EntityFamework和Mvc4。
至于nginx有点特别,如果使用rpm包安装,会导至fastcgi-mono-server运行不起来,这个问题纠结了我一个星期.
现在安装编译环境,执行:
yum -y install gcc gcc-c++ bison pkgconfig glib2-devel gettext make libpng-devel libjpeg-devel libtiff-devel libexif-devel giflib-devel libX11-devel freetype-devel fontconfig-devel cairo-devel libtiff libtiff-devel libjpeg libjpeg-devel giflib giflib-devel libpng libpng-devel libX11 libX11-devel freetype freetype-devel fontconfig fontconfig-devel libexif libexif-devel libXft-devel ghostscript-devel gnome-doc-utils unzip
(一大堆的东西,谁知道哪几个可以省掉,就删了吧,我没一个一个的验证.)
使用SFTP工具(推荐xftp4)将下载的四个文件复制到centos /root目录
分别执行
tar -jvxf mono-3.0.3.tar.bz2
unzip xsp-master.zip
tar -jvxf pcre-8.32.tar.bz2
tar -vxf nginx-1.2.6.tar.gz
进行解压维.
现在开始最漫长的mono编译及安装
cd /root/mono-3.0.3
./configure
make
make install
大约15分钟,这点时间您可以去看两个vs2012的使用视频.赞一下codemap...
然后安装xsp:
cd /root/xsp-master
export PKG_CONFIG_PATH=/usr/lib64/pkgconfig
./autogen.sh
make
make install
解说一下PKG_CONFIG_PATH,这东西是使用yum安装的,路径在不同的系统中可能不一样.
可以使用
whereis pkgconfig
来找一下pkgconfig的路径,然后依情况修改export语句.
如果pkgconfig路径不对,会造成xsp找不到mono的情况.
本来是应该直接编译安装nginx的.
但nginx依赖pcre,所以:
cd /root/pcre-8.32
./configure
make
make install
然后安装nginx:
cd /root/nginx-1.2.6
./configure
make
make install
全部完成之后,开始配置:
首先,编译安装是没有启动本脚本的,这里需要两个,一个是nginx的启动脚本,一个是fastcgi-mono-server4的启动脚本.
参考:
http://www.21andy.com/blog/20100201/1606.html
http://yojimbo87.github.com/2010/03/14/mono-startup-script.html
我直接贴在下面,注意路径.及环境变量.
nginx:
1 #!/bin/sh 2 # 3 # nginx - this script starts and stops the nginx daemin 4 # 5 # chkconfig: - 85 15 6 # description: Nginx is an HTTP(S) server, HTTP(S) reverse \ 7 # proxy and IMAP/POP3 proxy server 8 # processname: nginx 9 # config: /usr/local/nginx/conf/nginx.conf 10 # pidfile: /usr/local/nginx/logs/nginx.pid 11 12 # Source function library. 13 . /etc/rc.d/init.d/functions 14 15 # Source networking configuration. 16 . /etc/sysconfig/network 17 18 # Check that networking is up. 19 [ "$NETWORKING" = "no" ] && exit 0 20 21 nginx="/usr/local/nginx/sbin/nginx" 22 prog=$(basename $nginx) 23 24 NGINX_CONF_FILE="/usr/local/nginx/conf/nginx.conf" 25 26 lockfile=/var/lock/subsys/nginx 27 28 start() { 29 [ -x $nginx ] || exit 5 30 [ -f $NGINX_CONF_FILE ] || exit 6 31 echo -n $"Starting $prog: " 32 daemon $nginx -c $NGINX_CONF_FILE 33 retval=$? 34 echo 35 [ $retval -eq 0 ] && touch $lockfile 36 return $retval 37 } 38 39 stop() { 40 echo -n $"Stopping $prog: " 41 killproc $prog -QUIT 42 retval=$? 43 echo 44 [ $retval -eq 0 ] && rm -f $lockfile 45 return $retval 46 } 47 48 restart() { 49 configtest || return $? 50 stop 51 start 52 } 53 54 reload() { 55 configtest || return $? 56 echo -n $"Reloading $prog: " 57 killproc $nginx -HUP 58 RETVAL=$? 59 echo 60 } 61 62 force_reload() { 63 restart 64 } 65 66 configtest() { 67 $nginx -t -c $NGINX_CONF_FILE 68 } 69 70 rh_status() { 71 status $prog 72 } 73 74 rh_status_q() { 75 rh_status >/dev/null 2>&1 76 } 77 78 case "$1" in 79 start) 80 rh_status_q && exit 0 81 $1 82 ;; 83 stop) 84 rh_status_q || exit 0 85 $1 86 ;; 87 restart|configtest) 88 $1 89 ;; 90 reload) 91 rh_status_q || exit 7 92 $1 93 ;; 94 force-reload) 95 force_reload 96 ;; 97 status) 98 rh_status 99 ;; 100 condrestart|try-restart) 101 rh_status_q || exit 0 102 ;; 103 *) 104 echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}" 105 exit 2 106 esac
fastcgi-mono-server4:
1 #!/bin/sh 2 3 ### BEGIN INIT INFO 4 # Provides: monoserve.sh 5 # Required-Start: $local_fs $syslog $remote_fs 6 # Required-Stop: $local_fs $syslog $remote_fs 7 # Default-Start: 2 3 4 5 8 # Default-Stop: 0 1 6 9 # Short-Description: Start fastcgi mono server with hosts 10 ### END INIT INFO 11 12 PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin 13 DAEMON=/usr/local/bin/mono 14 NAME=fastcgi-mono-server4 15 DESC=fastcgi-mono-server4 16 17 MONOSERVER=$(which fastcgi-mono-server4) 18 MONOSERVER_PID=$(ps auxf | grep fastcgi-mono-server4.exe | grep -v grep | awk '{print $2}') 19 20 WEBAPPS="/:/usr/local/nginx/html" 21 22 case "$1" in 23 start) 24 if [ -z "${MONOSERVER_PID}" ]; then 25 echo "starting mono server" 26 ${MONOSERVER} /applications=${WEBAPPS} /socket=tcp:127.0.0.1:9000 & 27 echo "mono server started" 28 else 29 echo ${WEBAPPS} 30 echo "mono server is running" 31 fi 32 ;; 33 stop) 34 if [ -n "${MONOSERVER_PID}" ]; then 35 kill ${MONOSERVER_PID} 36 echo "mono server stopped" 37 else 38 echo "mono server is not running" 39 fi 40 ;; 41 esac 42 43 exit 0
将脚本保存在 /etc/init.d/ 目录下.
执行:
chmod +x /etc/init.d/nginx
chmod +x /etc/init.d/fastcgi-mono-server4
/sbin/chkconfig nginx on
/sbin/chkconfig fastcgi-mono-server4 on
最后是nginx的conf配置,理论上是要先配好再去写启动脚本的,因为fastcgi-mono-server4启动脚本中的WEBAPPS路径必须与网站路径一致,所以配置的时候要注意一下.
参考:
http://www.mono-project.com/FastCGI_Nginx
首先修改fastcgi_params文件,按我的方法,他应该在/usr/local/nginx/conf 目录下.(不在?使用whereis fastcgi_params找到它.)
追加两行:
fastcgi_param PATH_INFO "";
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
保存后来配置nginx.conf文件
找到:
location / {
root html;
index index.html index.htm;
}
修改为
location / {
root html;
index default.aspx index.html index.htm;
fastcgi_index default.aspx;
fastcgi_pass 127.0.0.1:9000;
include fastcgi_params;
}
添加了三行.
注意 root html ,这里配置了网站的根目录.它是一个相对路径.
全部保存完毕之后,就可以开启服务了.执行:
/etc/init.d/fastcgi-mono-server4 start
/etc/init.d/nginx start
好了,现在使用浏览器打开服务器IP地址,将会看到:
感谢: