dotNet core 應(yīng)用部署centos

閱讀目錄

需要安裝的插件以及支撐架構(gòu)

安裝dotnetSDK

安裝jexus

安裝supervisord

遇到問(wèn)題匯總

注意事項(xiàng)、擴(kuò)展延伸

需要安裝的插件以及支撐架構(gòu)

1.dotnetSDK

dotnet 相關(guān)命令是屬于 .NET Core command-line (CLI) 的一部分,Microsoft 為我們提供了這個(gè)命令行工具以供我們?cè)陂_發(fā)程序中使用,它主要用來(lái)進(jìn)行對(duì)代碼的編譯、NuGet 包的管理、程序的運(yùn)行、測(cè)試等等。

2.jexus

Jexus 是Linux平臺(tái)上 的一款免費(fèi)的ASP.NET WEB服務(wù)器。它是 Linux、Unix、FreeBSD等非Windows系統(tǒng)架設(shè) ASP.NET WEB 服務(wù)器的核心程序,具備反向代理、入侵檢測(cè)等重要功能。擁有IIS和其它Web服務(wù)器所不具備的高度的安全性

3.supervisord

supervisord 是用Python實(shí)現(xiàn)的一款非常實(shí)用的進(jìn)程管理工具,在批量服務(wù)化管理時(shí)特別有效??梢詫⒎荄aemon的應(yīng)用轉(zhuǎn)為Daemon程序。

安裝dotNetSDK

執(zhí)行命令

sudo rpm -Uvh https://packages.microsoft.com/config/rhel/7/packages-microsoft-prod.rpmsudo yum update

sudo yum install libunwind libicu

sudo yum install dotnet-sdk-2.1.200

安裝對(duì)應(yīng)的 dotnet運(yùn)行時(shí),這次開發(fā)用到的是 2.0.6,

參考地址:

https://www.microsoft.com/net/download/linux-package-manager/centos/runtime-2.0.6

執(zhí)行命令

sudo yum install dotnet-runtime-2.0.6

安裝Jexus

curl https://jexus.org/release/x64/install.sh|shcd /usr/jexus/siteconf

cp default lottery? ? ? ? ? ? ? #lottery是配置名稱,不同網(wǎng)站名稱不同

vim lottery

修改的內(nèi)容參考:

port=80

root=/ /dotnet/webAPP/admin1.lottery.com/

hosts=*,admin2.lottery.com? ? #OR your.com,*.your.com

# addr=0.0.0.0

# CheckQuery=false

NoLog=true

AppHost={CmdLine=/dotnet/webAPP/admin1.lottery.com/Lottery.WEB.dll;AppRoot=/dotnet/webAPP/admin1.lottery.com;Port=5001}

#這一行數(shù)據(jù)可以不管他,配置https時(shí)候用到

# UseHttps=true

# ssl.certificate=/x/xxx.crt? #or pem

# ssl.certificatekey=/x/xxx.key

# ssl.protocol=TLSv1.0? ? # TLSv1.1 or? TLSv1.2...

# ssl.ciphers=


重啟讀取配置文件

sh /usr/jexus/jws restart

重啟讀取配置文件之后,本地機(jī)器做好host文件映射即可通過(guò)域名方式訪問(wèn)該站點(diǎn)

設(shè)置jexus開機(jī)自啟動(dòng)

參考地址:http://www.bubuko.com/infodetail-1295747.html

cd /etc/init.d

vim jws

按i編輯模式,粘貼下面內(nèi)容


#!/bin/bash

#chkconfig: 2345 80 05#description:jws

#

. /etc/rc.d/init.d/functionscase "$1" instart)

? echo "Jexus Start.."? /usr/jexus/jws start

? ;;

stop)

? echo "Jexus Stop.."? /usr/jexus/jws stop

? ;;

restart)

? echo "Jexus Restart"? /usr/jexus/jws restart

? ;;

status)

? /usr/jexus/jws status

? ;;*)

? exit 1? ;;

esac?

exit $RETVAL


添加權(quán)限

chmod 766 jws

添加服務(wù)

chkconfig --add jws

安裝Supervisord

參考地址:https://www.cnblogs.com/hobinly/p/7382038.html

yum install python-setuptools

easy_install supervisor

配置supervisor

在etc下創(chuàng)建目錄,并賦權(quán)限

mkdir -m 700 -p /etc/supervisor

在目錄“ /etc/supervisor”下創(chuàng)建配置文件

echo_supervisord_conf > /etc/supervisor/supervisord.conf

修改配置文件

vim /etc/supervisor/supervisord.conf

在文件末尾添加,注意首尾需無(wú)空格,需頂格

[include]

files=/etc/supervisor/conf.d/*.conf

在目錄“/etc/supervisor”下創(chuàng)建dotnet core 進(jìn)程配置文件存放目錄“conf.d”

mkdir -m 700 /etc/supervisor/conf.d

創(chuàng)建進(jìn)程配置文件

vim /etc/supervisor/conf.d/lottery.conf


[program:Lottery.WEB]

command=/bin/bash -c "dotnet Lottery.WEB.dll"directory=/dotnet/webAPP/admin1.lottery.com/

stderr_logfile=/var/log/Lottery.error.log

stdout_logfile=/var/log/Lottery.stdout.log

environment=ASPNETCORE_ENVIRONMENT=Production

user=root

stopsignal=INT

autostart=true

autorestart=true

startsecs=1


備注:command=/bin/bash -c "dotnet Lottery.WEB.dll"

可以改成 command=dotnet /dotnet/webAPP/admin1.lottery.com/dotnet Lottery.WEB.dll

[program:Lottery.WEB] ;顯示名稱

command=/bin/bash -c "dotnet MyDotNetName.dll"? ;運(yùn)行命令,啟動(dòng)dotnet進(jìn)程

directory=/usr/PublishOutput/? ;MyDotNetName目錄

stderr_logfile=/var/log/Lottery.error.log? ;錯(cuò)誤日志文件

stdout_logfile=/var/log/Lottery.stdout.log? ;日志文件

environment=ASPNETCORE_ENVIRONMENT=Production? ;進(jìn)程環(huán)境變量

user=root? ;進(jìn)程執(zhí)行用戶

autostart=true? ;自動(dòng)啟動(dòng) autorestart=true? ;是否自動(dòng)重啟

startsecs=1? ? ;自動(dòng)重啟間隔時(shí)間

創(chuàng)建supervisor 自啟動(dòng)服務(wù)

vim /etc/systemd/system/supervisor.service

編輯內(nèi)容:

[Unit]

Description=supervisor

[Service]

Type=forking

ExecStart=/usr/bin/supervisord -c /etc/supervisor/supervisord.conf

ExecStop=/usr/bin/supervisorctl shutdown

ExecReload=/usr/bin/supervisorctl reload

KillMode=process

Restart=on-failure

RestartSec=42s

[Install]

WantedBy=multi-user.target


使配置生效

systemctl daemon-reload

設(shè)置服務(wù)開機(jī)啟動(dòng),即設(shè)置enable

systemctl enable supervisor.service

啟動(dòng)服務(wù)

systemctl start supervisor.service

驗(yàn)證dotnet進(jìn)程是否啟動(dòng)

使用命令“ps -ef | grep dotnet”查看dotnet 是否運(yùn)行

ps -ef | grep dotnetroot? ? ? 1549? 2529? 0 17:17 pts/0? ? 00:00:00 grep --color=auto dotnet

root? ? 27795 27764? 0 17:07 ?? ? ? ? 00:00:02 dotnet Lottery.WEB.dll

supervisor遠(yuǎn)程管理

使用命令“vim /etc/supervisor/supervisord.conf”修改配置文件,如下設(shè)置

;[inet_http_server]? ? ? ? ; inet (TCP) server disabled by default

;port=127.0.0.1:9001? ? ? ? ; (ip_address:port specifier, *:port for all iface)

;username=user? ? ? ? ? ? ? ; (default is no username (open server))

;password=123? ? ? ? ? ? ? ; (default is no password (open server))

;以下內(nèi)容開啟http服務(wù)[inet_http_server]

[inet_http_server]

port=192.168.1.71:9001? ? ? ;ip 加端口

username=admin? ? ? ? ? ? ? ;登陸賬號(hào),可以不設(shè)

password=123456? ? ? ? ? ? ? ;登陸賬戶,可以不設(shè)

重啟服務(wù),就可以訪問(wèn)了

注意防火墻是否對(duì)端口9001開放

也可以設(shè)置成

[inet_http_server]

port=*:9001

username=root? ? ? ? ? ? ? ;登陸賬號(hào),可以不設(shè)

password=123456? ? ? ? ? ? ? ;登陸賬戶,可以不設(shè)


問(wèn)題匯總

圖片驗(yàn)證碼報(bào)錯(cuò)的話安裝

解決:

yum install libgdiplus-devel

注意:

yum install libgdiplus 后,在centos7 下,程序并不能運(yùn)行成功還是報(bào)錯(cuò),查看libgdiplus安裝情況

rpm -qa |grep libgdiplus

rpm? -ql libgdiplus-2.10-9.el7.x86_64

在/usr/lib64下缺少libgdiplus.so文件

Centos7 需要通過(guò)安裝libgdiplus-devel來(lái)解決

yum install autoconf automake libtoolyum install freetype-devel fontconfig libXft-develyum install libjpeg-turbo-devel libpng-devel giflib-devel libtiff-devel libexif-develyum install glib2-devel cairo-develgit clone https://github.com/mono/libgdipluscd libgdiplus./autogen.shmakemake installcd /usr/lib64/ln -s /usr/local/lib/libgdiplus.so gdiplus.dll

錯(cuò)誤一

type init 錯(cuò)誤。提示找不到libgdiplus組件

Make solution 1:

ln -s /usr/local/lib/libgdiplus.so /usr/lib64/libgdiplus.so

ln -s /usr/local/lib/libgdiplus.so /usr/libgdiplus.so

驗(yàn)證碼亂碼問(wèn)題:

如果驗(yàn)證碼亂碼,請(qǐng)確認(rèn)生成驗(yàn)證碼的字體庫(kù)是否存在服務(wù)器中



注意事項(xiàng)、擴(kuò)展延伸

關(guān)于更新應(yīng)用

Dotnet程序在運(yùn)行當(dāng)中,如果需要更新 dotnetCore應(yīng)用,將新打包的應(yīng)用直接覆蓋到部署的路徑下,在從supervisord 9001端口中重啟指定的應(yīng)用,或者在服務(wù)器上執(zhí)行命令

supervisorctl -c /etc/supervisor/supervisord.conf restart Lottery.WEB

關(guān)于dotnetCore WEB應(yīng)用設(shè)置不同的端口

修改Program.cs文件

? ? ? ? public static IWebHost BuildWebHost(string[] args) =>

? ? ? ? ? ? WebHost.CreateDefaultBuilder(args)

? ? ? ? ? ? ? .UseContentRoot(Directory.GetCurrentDirectory())

? ? ? ? ? ? ? .UseKestrel()

? ? ? ? ? ? .UseStartup()

? ? ? ? ? .UseUrls("http://*:5001")

? ? ? ? ? ? .Build();

? ? }

關(guān)于部署 https的WEB應(yīng)用

在部署https WEB應(yīng)用的時(shí)候,我已經(jīng)拿到了 一個(gè)后綴為pem文件還有一個(gè)后綴為key的文件

第一步:需要這兩個(gè)文件生成后綴為pfx的文件,并設(shè)置生成 pfx文件的密碼

centos系統(tǒng)下執(zhí)行命令

openssl pkcs12 -export -out iiscert.pfx -inkey private.key -in public.pem

然后會(huì)讓你輸入密碼(密碼不要忘記了)

第二步:修改jexus站點(diǎn)配置信息

vim /etc/supervisor/conf.d/lottery.conf

UseHttps=true

ssl.certificate=/dotnet/httpsKey/public.pem? #crt or pem

ssl.certificatekey=/dotnet/httpsKey/private.key

ssl.protocol=TLSv1.2? ? # TLSv1.1 or? TLSv1.2...

#ssl.ciphers=

wp! 保存

修改程序 Program.cs文件

? public static IWebHost BuildWebHost(string[] args) =>

? ? ? ? ? ? WebHost.CreateDefaultBuilder(args)

? ? ? ? ? ? .UseContentRoot(Directory.GetCurrentDirectory())

? ? ? ? .UseKestrel(options => options.Listen(IPAddress.Any, 5003, listenOptions =>

? ? ? ? {

? ? ? ? ? ? listenOptions.UseHttps(new X509Certificate2("/dotnet/httpsKey/iiscert.pfx", "123456"));? ? ? ? ? ?

? ? ? ? }))

? ? ? ? ? ? ? .UseStartup()

? ? ? ? ? ? .Build();

重新部署到服務(wù)器,并重啟supervisor對(duì)應(yīng)的進(jìn)程

關(guān)于部署非WEB應(yīng)用

如果需要部署到非WEB應(yīng)用程序,則不需要執(zhí)行 jexus的步驟,直接在 supervisor上新增一個(gè)進(jìn)程配置文件(/etc/supervisor/conf.d/? 這個(gè)目錄下一個(gè)*,conf文件代表一個(gè)進(jìn)程配置)

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容