在树莓派上借助Mono + Jexus 布署 .Net 4.0 WebForm应用
介紹
樹莓派
樹莓派是一種微型電腦,不到300元的成本就可以擁有一個4核1G的低功耗Linux環境,并且自帶了40針IO,HDMI,WIFI,USB,100M網卡,SPI顯示屏接口。
樹莓派Mono
Mono是一個由Xamarin公司所主持的自由開放源代碼項目。 該項目的目標是創建一系列匹配ECMA標準(Ecma-334和Ecma-335)的.NET工具,包括C#編譯器和通用語言架構。
與微軟的.NET Framework(共通語言運行平臺)不同,Mono項目不僅可以運行于Windows系統上,還可以運行于Linux,FreeBSD,Unix,OS X和Solaris等系統上。
所以,我們要想在樹莓派上運行WebForm應用,主要就得靠它了。
Jexus
Jexus是一款Linux平臺上的高性能WEB服務器和負載均衡網關,以支持ASP.NET、ASP.NET CORE、PHP為特色,同時具備反向代理、入侵檢測等重要功能。可以這樣說,Jexus是.NET、.NET CORE跨平臺的最優秀的宿主服務器,如果我們認為它是Linux平臺的IIS,這并不為過,因為,Jexus不但非常快,而且擁有IIS和其它Web服務器所不具備的高度的安全性,這是政府機構和重要企業對web服務器最必要也是最重要的品質需求。
Jexus既是免費軟件,也是自由軟件,你可以自由發布、自由集成、自由分發,你擁用完整的使用權。
實驗材料
- 樹莓派 3 Model B
- Raspbian
- Jexus 5.8.3 Linux ARM 標準版
- WinScp
- XShell
實驗過程
安裝Mono
確認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進入MONO官網,按相關指引操作進行安裝。
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執行安裝
sudo apt install mono-devel驗證安裝
1、創建/home/test目錄,并進入目錄
2、創建/home/test/Program.cs文件,寫入以下代碼
3、編譯csc Program.cs或mcs Program.cs
4、執行mono Program.exe
安裝Jexus
下載ARM版,解壓并安裝(注意:云服務器或PC裝請下載對應的其它版本,不要安裝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'.默認的配置在/usr/jexus/siteconf下,是一個指向/var/www/default/目錄的網站。我們在此目錄下編寫一個測試頁面default.aspx,輸出當時的日期與時間。
<%@ Page Language="C#" %> <%=DateTime.Now%>在樹莓派上運行/usr/jexus/jws start
root@mc-server:/home# /usr/jexus/jws start Starting ... OK查看一下本機的 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以服務運行、開機自啟
附錄
mono安裝的其它選擇
mono-devel should be installed to compile code.
編譯開發環境安裝,可以在linux下編寫、編譯.net 應用程序
mono-complete should be installed to install everything - this should cover most cases of "assembly not found" errors.
完整安裝,可以解決某些情況下出現“未找到程序集”的錯誤 。
mono-dbg should be installed to get debugging symbols for framework libraries - allowing you to get line numbers in stack traces.
調試符號,安裝后,在錯誤信息的StackTrace中可以顯示行號。
referenceassemblies-pcl should be installed for PCL compilation support - this will resolve most cases of "Framework not installed: .NETPortable" errors during software compilation.
可以解決某些情況下出現“Framework not installed: .NETPortable”的錯誤 。
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的安裝
總結
以上是生活随笔為你收集整理的在树莓派上借助Mono + Jexus 布署 .Net 4.0 WebForm应用的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Redis的搭建和Redis的集群搭建
- 下一篇: EntityFramework 6.x和