在树莓派上借助Mono + Jexus 布署 .Net 4.0 WebForm应用
介紹
樹莓派
樹莓派是一種微型電腦,不到300元的成本就可以擁有一個(gè)4核1G的低功耗Linux環(huán)境,并且自帶了40針I(yè)O,HDMI,WIFI,USB,100M網(wǎng)卡,SPI顯示屏接口。
樹莓派Mono
Mono是一個(gè)由Xamarin公司所主持的自由開放源代碼項(xiàng)目。 該項(xiàng)目的目標(biāo)是創(chuàng)建一系列匹配ECMA標(biāo)準(zhǔn)(Ecma-334和Ecma-335)的.NET工具,包括C#編譯器和通用語言架構(gòu)。
與微軟的.NET Framework(共通語言運(yùn)行平臺(tái))不同,Mono項(xiàng)目不僅可以運(yùn)行于Windows系統(tǒng)上,還可以運(yùn)行于Linux,FreeBSD,Unix,OS X和Solaris等系統(tǒng)上。
所以,我們要想在樹莓派上運(yùn)行WebForm應(yīng)用,主要就得靠它了。
Jexus
Jexus是一款Linux平臺(tái)上的高性能WEB服務(wù)器和負(fù)載均衡網(wǎng)關(guān),以支持ASP.NET、ASP.NET CORE、PHP為特色,同時(shí)具備反向代理、入侵檢測(cè)等重要功能。可以這樣說,Jexus是.NET、.NET CORE跨平臺(tái)的最優(yōu)秀的宿主服務(wù)器,如果我們認(rèn)為它是Linux平臺(tái)的IIS,這并不為過,因?yàn)?#xff0c;Jexus不但非常快,而且擁有IIS和其它Web服務(wù)器所不具備的高度的安全性,這是政府機(jī)構(gòu)和重要企業(yè)對(duì)web服務(wù)器最必要也是最重要的品質(zhì)需求。
Jexus既是免費(fèi)軟件,也是自由軟件,你可以自由發(fā)布、自由集成、自由分發(fā),你擁用完整的使用權(quán)。
實(shí)驗(yàn)材料
- 樹莓派 3 Model B
- Raspbian
- Jexus 5.8.3 Linux ARM 標(biāo)準(zhǔn)版
- WinScp
- XShell
實(shí)驗(yàn)過程
安裝Mono
確認(rèn)Raspbian版本,我的是8.0
lsb_release -a ################################## No LSB modules are available. Distributor ID: Raspbian Description: Raspbian GNU/Linux 8.0 (jessie) Release: 8.0 Codename: jessie進(jìn)入MONO官網(wǎng),按相關(guān)指引操作進(jìn)行安裝。
9.x
sudo apt install apt-transport-https dirmngr sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 3FA7E0328081BFF6A14DA29AA6A19B38D3D831EF echo "deb https://download.mono-project.com/repo/debian stable-raspbianstretch main" | sudo tee /etc/apt/sources.list.d/mono-official-stable.list sudo apt update8.x
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 3FA7E0328081BFF6A14DA29AA6A19B38D3D831EF sudo apt install apt-transport-https echo "deb https://download.mono-project.com/repo/debian stable-raspbianjessie main" | sudo tee /etc/apt/sources.list.d/mono-official-stable.list sudo apt update執(zhí)行安裝
sudo apt install mono-devel驗(yàn)證安裝
1、創(chuàng)建/home/test目錄,并進(jìn)入目錄
2、創(chuàng)建/home/test/Program.cs文件,寫入以下代碼
3、編譯csc Program.cs或mcs Program.cs
4、執(zhí)行mono Program.exe
安裝Jexus
下載ARM版,解壓并安裝(注意:云服務(wù)器或PC裝請(qǐng)下載對(duì)應(yīng)的其它版本,不要安裝ARM版)
cd /home wget https://www.linuxdot.net/down/jexus-5.8.3-arm.tar.gz tar xzvf jexus-5.8.3-arm.tar.gz cd jexus-5.8.3-arm ./install安裝完成
root@mc-server:/home/jexus-5.8.3-arm# ./install Installed /usr/jexus/jxAspx.dll into the gac (/usr/lib/mono/gac) Installed /usr/jexus/jxHost.dll into the gac (/usr/lib/mono/gac) OK, Jexus web server has been installed to '/usr/jexus'.默認(rèn)的配置在/usr/jexus/siteconf下,是一個(gè)指向/var/www/default/目錄的網(wǎng)站。我們?cè)诖四夸浵戮帉懸粋€(gè)測(cè)試頁面default.aspx,輸出當(dāng)時(shí)的日期與時(shí)間。
<%@ Page Language="C#" %> <%=DateTime.Now%>在樹莓派上運(yùn)行/usr/jexus/jws start
root@mc-server:/home# /usr/jexus/jws start Starting ... OK查看一下本機(jī)的 IP地址
root@mc-server:/usr/jexus# ifconfig eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500inet 192.168.10.89 netmask 255.255.255.0 broadcast 192.168.10.255inet6 fe80::dba:92f0:f625:2fc9 prefixlen 64 scopeid 0x20<link>ether b8:27:eb:a3:15:86 txqueuelen 1000 (Ethernet)RX packets 2082 bytes 513167 (501.1 KiB)RX errors 0 dropped 0 overruns 0 frame 0TX packets 773 bytes 94248 (92.0 KiB)TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0在瀏覽器輸入http://192.168.10.89,觀察效果
image.png延伸閱讀:在樹莓派上使Jexus以服務(wù)運(yùn)行、開機(jī)自啟
附錄
mono安裝的其它選擇
mono-devel should be installed to compile code.
編譯開發(fā)環(huán)境安裝,可以在linux下編寫、編譯.net 應(yīng)用程序
mono-complete should be installed to install everything - this should cover most cases of "assembly not found" errors.
完整安裝,可以解決某些情況下出現(xiàn)“未找到程序集”的錯(cuò)誤 。
mono-dbg should be installed to get debugging symbols for framework libraries - allowing you to get line numbers in stack traces.
調(diào)試符號(hào),安裝后,在錯(cuò)誤信息的StackTrace中可以顯示行號(hào)。
referenceassemblies-pcl should be installed for PCL compilation support - this will resolve most cases of "Framework not installed: .NETPortable" errors during software compilation.
可以解決某些情況下出現(xiàn)“Framework not installed: .NETPortable”的錯(cuò)誤 。
ca-certificates-mono should be installed to get SSL certificates for HTTPS connections. Install this package if you run into trouble making HTTPS connections.
mono-xsp4 should be installed for running ASP.NET applications.
支持Asp.net的安裝
總結(jié)
以上是生活随笔為你收集整理的在树莓派上借助Mono + Jexus 布署 .Net 4.0 WebForm应用的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Redis的搭建和Redis的集群搭建
- 下一篇: EntityFramework 6.x和