Ubuntu阿里云搭建Mono.net环境

简介:

查看磁盘信息

我们买的系统默认情况下只是安装了系统,而数据盘需要自己挂载,例如我这里的系统占用20多G,还有40多G的数据盘默认是没有挂载的,首先我们运行df -h查看:

root@AY1212241134392134698:~# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/xvda1 20G 1.4G 18G 7% /
udev 237M 4.0K 237M 1% /dev
tmpfs 99M 260K 98M 1% /run
none 5.0M 0 5.0M 0% /run/lock
none 246M 0 246M 0% /run/shm

可以看到文件系统里面只有一个/dev/xvda1大小是20G,我们是用fdisk -l 可以看到所有的硬盘:

root@AY1212241134392134698:~# fdisk -l

Disk /dev/xvda: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders, total 41943040 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x0002bfb2

Device Boot      Start         End      Blocks   Id  System

/dev/xvda1 * 2048 41940991 20969472 83 Linux

Disk /dev/xvdb: 42.9 GB, 42949672960 bytes
255 heads, 63 sectors/track, 5221 cylinders, total 83886080 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000

Disk /dev/xvdb doesn't contain a valid partition table

上面显示了2块盘,其中第一块盘是Disk /dev/xvda 有21.5G的容量,已经装上了系统,而第二块Disk /dev/xvdb: 42.9 GB是没有挂载的,Disk /dev/xvdb doesn't contain a valid partition table表明没有分区表。
分区与挂载

下面对/dev/xvdb进行分区与挂载,使用fdisk /dev/xvdb 命令

root@AY1212241134392134698:~# fdisk /dev/xvdb
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier 0xabc9a42f.
Changes will remain in memory only, until you decide to write them.
After that, of course, the previous content won't be recoverable.

Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)

Command (m for help): n ===========> 这里输入n
Partition type:
p primary (0 primary, 0 extended, 4 free)
e extended
Select (default p): p ===========> 这里输入p
Partition number (1-4, default 1): 1 ===========> 这里输入1
First sector (2048-83886079, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-83886079, default 83886079):
Using default value 83886079

Command (m for help): wq ===========> 这里输入wq保存设置
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.

再次输入fdisk -l可以查看是否分区成功

root@AY1212241134392134698:~# fdisk -l

Disk /dev/xvda: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders, total 41943040 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x0002bfb2

Device Boot      Start         End      Blocks   Id  System

/dev/xvda1 * 2048 41940991 20969472 83 Linux

Disk /dev/xvdb: 42.9 GB, 42949672960 bytes
171 heads, 5 sectors/track, 98112 cylinders, total 83886080 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0xabc9a42f

Device Boot      Start         End      Blocks   Id  System

/dev/xvdb1 2048 83886079 41942016 83 Linux

可以看到/dev/xvdb1已经有内容了,System为Linux。

为分区指定文件系统

下面对分区进行格式化,我们将分区格式化为ext4文件系统。可以使用df -hT 查看分区使用的文件系统,我们可以看到Disk /dev/xvda使用的文件系统就是ext4,所以我们将/dev/xvdb1也格式化为同样的ext4文件系统

sudo mkfs -t ext4 /dev/xvdb1 #格式化分区/dev/xvdb1并指定文件系统为ext4
将分区挂载到目录

/dev/xvdb1 /root/test ext4 defaults, 0 2 # 挂载分区到目录/root/test中,此目录可以自己指定,此命令会将挂载信息写到/etc/fstab中
安装mono

sudo apt-get install mono-complete 这个是安装mono的完整版所以可能要安装很多东西,包括桌面开发的东西。mono-utils mono-xsp monodoc-http mono-gmcs
安装Nginx

sudo apt-get update
sudo apt-get install nginx

Nginx的启动与停止:
sudo /etc/init.d/nginx start
sudo /etc/init.d/nginx stop

配置nginx:

vi /etc/nginx/nginx.conf #这个文件是关于nginx服务器的配置,这里面配置的网站应该是服务器的默认网站
在http节点中加上:
server {

    listen       80;
    server_name  localhost;

    location ~ {
        root  /root/test/www;    # 这个目录也是你自己指定的,表示你的网站的根目录
        index  index.html index.htm;

        fastcgi_pass  127.0.0.1:8000; #此处端口要与fastcgi映射的端口一致
        fastcgi_param  SCRIPT_FILENAME  $document_root/$fastcgi_script_name;
         include /etc/nginx/fastcgi_params;
        }
}

vi /etc/nginx/sites-enabled/default #这个文件是关于nginx虚拟主机的配置
修改里面的server节点中的location ~节点与 nginx.conf中的server节点中一致,并修改root的值与 location ~ 中root的值一致
安装svn

这里要安装svn主要是我们需要安装fastcgi-mono-server,而fastcgi-mono-server不能通过apt-get install进行安装,只能通过源码安装,所以这里我们先安装svn通过svn命令得到fastcgi-mono-server的源码,再自己编译,安装。因为nginx要解析aspx的网页必须通过fastcgi-mono-server去调用mono的运行时。

sudo apt-get install subversion
获取fastcgi-mono-server 源码

svn co http://mono-soc-2007.googlecode.com/svn/trunk/brian/FastCgi/ fastcgi-mono-server
安装编译环境

阿里云默认是没有编译环境的,需要自己安装
sudo apt-get install automake
sudo apt-get install gcc g++ make # 会自动安装libc的库以及一些需要的工具,例如binutils等
编译fastcgi-mono-server

你或许要cd到fastcgi-mono-server目录下去运行./autogen.sh脚本:
./autogen.sh # 如果运行有问题,请使用bash执行此脚本,一种方法是修改/autogen.sh的第一行#!/bin/sh修改为#!/bin/bash

上面的shell会生成Makefile,下面进行编译:
make
安装fastcgi-mono-server

sudo make install

安装好之后,输入 fastcgi-mono-server2 --help 和 fastcgi-mono-server --help 都会有相关选项出来
或者直接输入fastcgi-mono-server 连续按2个tab键也会列出两个fastcgi-mono-server和fastcgi-mono-server2命令,表示安装成功。
启动fast-cgi

要注意下面的目录/root/test/www与上面配置的目录是一致的:
sudo fastcgi-mono-server2 /socket=tcp:8000 /address=127.0.0.1 /applications=/:/root/test/www >/dev/null 2>&1 &

其实到此为止你的环境应该搭建好了,你可以在/root/test/www下面添加网页,例如Default.aspx,内容如下进行测试,这也是我的测试网页的内容。

<%@ Page Language="C#" %>
<%

int number = 0;
if(Application["number"]!=null)
{
    number = int.Parse(Application["number"].ToString());
    number ++;
}
Application["number"] = number;

%>

<%="Hello Mono.net "+number.ToString() %>
安装ftp服务器

我们使用的是vsftpd:

sudo apt-get update
sudo apt-get install vsftpd

启动与停止:
/etc/init.d/vsftpd start
/etc/init.d/vsftpd stop
/etc/init.d/vsftpd restart

ftp的配置:
vi /etc/vsftpd.conf

打开这么几个属性:
local_enable=YES #允许linux系统上的本机用户作为ftp账户访问ftp
write_enable=YES #允许写,这个是针对非匿名用户的
local_umask=022 # 本机用户的umask
connect_from_port_20=YES #使用20端口传递数据
idle_session_timeout=600 # 会话超时时间
data_connection_timeout=120 # 数据连接超时时间
chroot_local_user=YES #如果设为YES,本地用户登录后将被(默认地)锁定在虚根下,并被放在他的home目录下。

vsftpd的用户有几种,一种是使用linux操作系统的系统账户当作ftp用户使用,另一种是使用叫做ftp虚拟用户的用户,此用户是vsftpd识别的用户,但是不能登录系统,也不是系统本身的账户。当然所有这种虚拟用户登录到ftp之后对文件的读写权限是寄宿在一个真实的linux系统用户上面额。这里我们仅仅说明直接使用系统本身就有的账户去登录ftp,所以需要打开local_enbale选项。

添加一个系统账户专门用来操作ftp,ftp不能使用root登录。

useradd -d /home/ftpdir -s /sbin/nologin ftptest #添加一个叫做ftptest的系统账户,该用户不能通过ssh或者telnet登录系统,只能通过ftp访问其home目录,该home目录就是此用户

在ftp共享文件的目录,其home目录是/home/ftpdir ,这个可以自己指定,但是一定要对该目录有访问权限,否则ftp登陆的时候进不去.

passwd ftptest #为该用户指定密码

要注意的是:指定chroot_local_user=YES之后,必须设定ftp的虚根目录不能有写权限,这是新版的vsftpd为了安全设定的,否则会出现登录不进去的情况,报如下错误:
500 OOPS: vsftpd: refusing to run with writable root inside chroot()
意思是,如果开启了chroot来控制用户路径,则用户不能再具有该用户根目录的写的权限。
解决办法:
去掉该用户根目录的写的权限,再新建一目录,以后用新目录

sudo chmod a-w /home/用户名

sudo mkdir /home/用户名/新目录名

其实很不方便,用户登陆进去会发现必须要再进一层目录才能找到自己的文件

/etc/init.d/vsftpd restart #重启vsftpd就可以了

提示:如果已经存在用户,但是需要禁止该用户登录liux系统,可以直接使用root用户编辑/etc/passwd文件,修改该用户对应的行的最后面的shell路径就可以了。

相关文章
|
1月前
|
Ubuntu JavaScript 关系型数据库
在阿里云Ubuntu 20.04服务器中搭建一个 Ghost 博客
在阿里云Ubuntu 20.04服务器上部署Ghost博客的步骤包括创建新用户、安装Nginx、MySQL和Node.js 18.x。首先,通过`adduser`命令创建非root用户,然后安装Nginx和MySQL。接着,设置Node.js环境,下载Nodesource GPG密钥并安装Node.js 18.x。之后,使用`npm`安装Ghost-CLI,创建Ghost安装目录并进行安装。配置过程中需提供博客URL、数据库连接信息等。最后,测试访问前台首页和后台管理页面。确保DNS设置正确,并根据提示完成Ghost博客的配置。
在阿里云Ubuntu 20.04服务器中搭建一个 Ghost 博客
|
3月前
|
IDE Ubuntu Java
百度搜索:蓝易云【Ubuntu快速搭建单步调试openjdk环境】
现在,你已经成功在Ubuntu上搭建了OpenJDK的单步调试环境,可以使用Eclipse IDE方便地进行Java程序的调试。请注意,Eclipse IDE提供了丰富的调试功能,使得调试过程更加高效和准确。
26 0
|
3月前
|
Ubuntu 网络协议 Linux
如何在无公网IP环境使用Windows远程桌面Ubuntu
如何在无公网IP环境使用Windows远程桌面Ubuntu
61 0
|
3月前
|
Ubuntu 开发工具 Python
解决阿里云远程连接yum无法安装问题(Ubuntu 22.04)
解决阿里云远程连接yum无法安装问题(Ubuntu 22.04)
512 1
|
3月前
|
弹性计算 Ubuntu Linux
【阿里云】阿里云ECS云服务器幻兽帕鲁游戏优化及存档导出导入(Ubuntu)
【阿里云】阿里云ECS云服务器幻兽帕鲁游戏优化及存档导出导入(Ubuntu)
1477 4
|
8天前
|
应用服务中间件 Linux 开发工具
如何在阿里云服务器快速搭建部署Nginx环境
以下是内容的摘要: 本文档主要介绍了在阿里云上购买和配置服务器的步骤,包括注册阿里云账号、实名认证、选择和购买云服务器、配置安全组、使用Xshell和Xftp进行远程连接和文件传输,以及安装和配置Nginx服务器的过程。在完成这些步骤后,你将能够在服务器上部署和运行自己的网站或应用。
|
9天前
|
存储 弹性计算 监控
阿里云函数的环境
【4月更文挑战第17天】阿里云函数的环境
23 1
|
18天前
|
Ubuntu 开发工具 git
ubuntu18.04下配置muduoC++11环境
以上步骤将在Ubuntu 18.04下配置C++11环境,并编译安装muduo库。请根据实际情况对配置步骤进行调整。 买CN2云服务器,免备案服务器,高防服务器,就选蓝易云。百度搜索:蓝易云
17 0
|
2月前
|
关系型数据库 MySQL Apache
Ubuntu22.04搭建LAMP环境
LAMP是一个用于构建Web应用程序的技术堆栈,你可以用它开发很多Web程序,比如WordPress。如果你想手工在VPS上搭建WordPress的话,那么你就需要先搭建LAMP环境。这篇文章讲解如何在Ubuntu22.04上搭建LAMP环境。首先,你需要先注册一台VPS服务器,然后登录VPS安装Apache服务、安装MySQL数据库,以及安装PHP。
50 0
Ubuntu22.04搭建LAMP环境
|
2月前
|
安全 应用服务中间件 开发工具
Ubuntu20安装docker并部署相关漏洞环境
Ubuntu20安装docker并部署相关漏洞环境
52 0