CentOS 6.6上部署asp.net MVC项目详细过程

一、首先更新系统

1
[[email protected] ~]# yum –y update

二、安装Mono

1.安装Mono源码安装需要的组件:
1
[[email protected]localhost ~]# yum -y install wget glib2-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 gcc-c++ gettext unzip zip
2.安装Mono之前,需要先安装其依赖的GDI+组件。联网下载libgdiplus源码安装包
1
2
[[email protected] ~]# cd /usr
[[email protected] usr]# wget http://download.mono-project.com/sources/libgdiplus/libgdiplus-2.10.tar.bz2

解压libgdiplus源码安装包:

1
[[email protected] usr]# tar jxvf libgdiplus-2.10.tar.bz2

配置libgdiplus组件安装路径:

1
2
[[email protected] usr]# cd libgdiplus-2.10
[[email protected] libgdiplus-2.10]# ./configure --prefix=/usr/apollo/hostd/mono/

编译libgdiplus源码:

1
[[email protected] libgdiplus-2.10]# make

安装libgdiplus组件:

1
[[email protected] libgdiplus-2.10]# make install

3.安装Mono:

Mono是Linux平台的.NET Framework实现,是.NET程序移植到Linux平台的不二选择。首先,联网下载Mono源码安装包:

1
2
[[email protected] libgdiplus-2.10]# cd /usr
[[email protected] usr]# wget http://download.mono-project.com/sources/mono/mono-4.0.4.1.tar.bz2

解压Mono源码安装包:

1
[[email protected] usr]# tar jxvf mono-4.0.4.1.tar.bz2

配置Mono安装路径:

1
2
[[email protected] usr]# cd mono-4.0.4
[[email protected] mono-4.0.4]# ./configure --prefix=/usr/apollo/hostd/mono

编译Mono源码(此过程耗时一般为半小时到一小时,视系统软硬件配置而定):

1
[[email protected] mono-4.0.4]# make

安装Mono:

1
[[email protected] mono-4.0.4]# make install

通过查看Mono版本,确认Mono是否安装成功

1
2
[[email protected] mono-4.0.4]# cd /usr/apollo/hostd/mono/bin/
[[email protected] bin]# ./mono -V

三、安装Jexus

Jexus是国人开发的Linux平台上的ASP.NET Web应用中间件,类似于Windows平台的IIS。实践证明Jexus安装简单,运行稳定,是Linux平台架设ASP.NET应用的不错选择。

1.首先,联网下载Jexus安装包:
1
2
[[email protected] ~]# cd /usr
[[email protected] usr]# wget http://www.linuxdot.net/down/jexus-5.6.5.tar.gz

解压Jexus安装包:

1
[[email protected] usr]# tar zxvf jexus-5.6.5.tar.gz

修改Jexus安装路径:

1
2
3
4
5
6
7
8
9
[[email protected] usr]# cd jexus-5.6.5
[[email protected] jexus-5.6.5]# vi install

用vim编辑文件
#!/bin/sh
SRC_DIR=$(cd $(dirname $0);pwd)
DAT_DIR=${SRC_DIR}/data
JWS_DIR='/usr/apollo/hostd/jexus'

2.安装Jexus:
1
[[email protected] jexus-5.6.5]# sudo ./install

修改Jexus关于mono路径的配置:

1
2
3
4
5
6
7
8
9
[[email protected] jexus-5.6.5]# cd /usr/apollo/hostd/jexus
[[email protected] jexus]# vi jws

#!/bin/sh
JWS_HOME=$(cd $(dirname $0);pwd)
export LANG="zh_CN.UTF-8"
export PATH=/usr/bin:${JWS_HOME}/../mono/bin:$PATH
export LD_LIBRARY_PATH=/usr/lib:${JWS_HOME}/../mono/lib:$LD_LIBRARY_PATH

3.启动Jexus服务,测试Jexus安装是否正确:
1
[[email protected] jexus]# ./jws start

设置Jexus服务开机自启动,增加如下高亮行:

1
2
3
[[email protected] jexus]# vi /etc/rc.d/rc.local
touch /var/lock/subsys/local
/usr/apollo/hostd/jexus/jws start

修改该文件权限并重启:

1
[[email protected] jexus]# chmod +x /etc/rc.d/rc.local

四、部署网站

创建网站目录:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
[[email protected] jexus]# cd /usr/apollo/
[[email protected] apollo]# mkdir webapps
[[email protected] apollo]# cd webapps/
[[email protected] webapps]# mkdir default
[[email protected] webapps]# cd default/
[[email protected] default]# touch index.html
[[email protected] default]# vi index.html

<html>
<head>
<title>测试ASP.NET</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
</head>
<body>
测试ASP.NET
</body>
</html>

修改Jexus网站配置:

1
2
3
4
5
6
7
8
9
10
11
[[email protected] default]# cd /usr/apollo/hostd/jexus/siteconf 
[[email protected] siteconf]# vi default

######################
# Web Site: Default
########################################

port=80
root=/ /usr/apollo/webapps/default
hosts=* #OR your.com,*.your.com

开放防火墙80端口:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
[[email protected] siteconf]# vi /etc/sysconfig/iptables 

# Firewall configuration written by system-config-firewall
# Manual customization of this file is not recommended.
*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
-A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
-A INPUT -p icmp -j ACCEPT
-A INPUT -i lo -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT
-A INPUT -j REJECT --reject-with icmp-host-prohibited
-A FORWARD -j REJECT --reject-with icmp-host-prohibited
COMMIT

重启iptables,使防火墙设置生效:

1
[[email protected] siteconf]# /etc/init.d/iptables restart

重启Jexus服务:

1
[[email protected] siteconf]# /usr/apollo/hostd/jexus/jws restart

终端浏览器输入网址http://ip:port/index.html访问网站:
此处输入图片的描述

五、数据库

1.卸载centos6.5本身所安装的mysql:
1
2
3
[[email protected]]# yum remove  mysql mysql-server mysql-libs mysql-server
[[email protected]]# find / -name mysql #将找到的都删掉 rm -fr
[[email protected]]# rpm -qa|grep -i mysql #查看还有么没有mysql,如果有的话,使用rpm -e –nodeps 包名 删除
2.安装mysql
1
[[email protected] usr]# yum list mysql-server

如果显示列表,则说明成功了
此处输入图片的描述

1
[[email protected] usr]# yum install mysql-server

过程中选择Y继续安装,最后安装成功

3.设置Mysql的服务

先启动Mysql服务

1
[[email protected] usr]# service mysqld start

设置Mysql开机启动

1
[[email protected] usr]# chkconfig mysqld on

开启3306端口并保存

1
2
[[email protected] usr]# /sbin/iptables -I INPUT -p tcp --dport 3306 -j ACCEPT
[[email protected] usr]# /etc/rc.d/init.d/iptables save

4.修改密码并设置远程访问

连接mysql数据库设置密码

1
2
[[email protected] usr]# use mysql
mysql> update user set password=password('密码') where user='root';flush privileges;

5.重启mysql服务
1
[[email protected] usr]# service mysqld restart

参考文章: ASP.NET 跨平台最佳实践