閱讀目錄
需要安裝的插件以及支撐架構(gòu)
安裝dotnetSDK
安裝jexus
安裝supervisord
遇到問題匯總
注意事項传泊、擴(kuò)展延伸
需要安裝的插件以及支撐架構(gòu)
1.dotnetSDK
dotnet 相關(guān)命令是屬于 .NET Core command-line (CLI) 的一部分型诚,Microsoft 為我們提供了這個命令行工具以供我們在開發(fā)程序中使用孟岛,它主要用來進(jìn)行對代碼的編譯锄贼、NuGet 包的管理曲稼、程序的運(yùn)行榴都、測試等等待锈。
2.jexus
Jexus 是Linux平臺上 的一款免費的ASP.NET WEB服務(wù)器。它是 Linux嘴高、Unix竿音、FreeBSD等非Windows系統(tǒng)架設(shè) ASP.NET WEB 服務(wù)器的核心程序和屎,具備反向代理、入侵檢測等重要功能春瞬。擁有IIS和其它Web服務(wù)器所不具備的高度的安全性
3.supervisord
supervisord 是用Python實現(xiàn)的一款非常實用的進(jìn)程管理工具柴信,在批量服務(wù)化管理時特別有效】砥可以將非Daemon的應(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
安裝對應(yīng)的 dotnet運(yùn)行時,這次開發(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時候用到
# 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文件映射即可通過域名方式訪問該站點
設(shè)置jexus開機(jī)自啟動
參考地址: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
在文件末尾添加袄琳,注意首尾需無空格询件,需頂格
[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)行命令,啟動dotnet進(jìn)程
directory=/usr/PublishOutput/? ;MyDotNetName目錄
stderr_logfile=/var/log/Lottery.error.log? ;錯誤日志文件
stdout_logfile=/var/log/Lottery.stdout.log? ;日志文件
environment=ASPNETCORE_ENVIRONMENT=Production? ;進(jìn)程環(huán)境變量
user=root? ;進(jìn)程執(zhí)行用戶
autostart=true? ;自動啟動 autorestart=true? ;是否自動重啟
startsecs=1? ? ;自動重啟間隔時間
創(chuàng)建supervisor 自啟動服務(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ī)啟動,即設(shè)置enable
systemctl enable supervisor.service
啟動服務(wù)
systemctl start supervisor.service
驗證dotnet進(jìn)程是否啟動
使用命令“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? ? ? ? ? ? ? ;登陸賬號宛琅,可以不設(shè)
password=123456? ? ? ? ? ? ? ;登陸賬戶,可以不設(shè)
重啟服務(wù)逗旁,就可以訪問了
注意防火墻是否對端口9001開放
也可以設(shè)置成
[inet_http_server]
port=*:9001
username=root? ? ? ? ? ? ? ;登陸賬號嘿辟,可以不設(shè)
password=123456? ? ? ? ? ? ? ;登陸賬戶,可以不設(shè)
問題匯總
圖片驗證碼報錯的話安裝
解決:
yum install libgdiplus-devel
注意:
yum install libgdiplus 后片效,在centos7 下红伦,程序并不能運(yùn)行成功還是報錯,查看libgdiplus安裝情況
rpm -qa |grep libgdiplus
rpm? -ql libgdiplus-2.10-9.el7.x86_64
在/usr/lib64下缺少libgdiplus.so文件
Centos7 需要通過安裝libgdiplus-devel來解決
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
錯誤一
type init 錯誤淀衣。提示找不到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
驗證碼亂碼問題:
如果驗證碼亂碼昙读,請確認(rèn)生成驗證碼的字體庫是否存在服務(wù)器中
注意事項、擴(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)用的時候沮稚,我已經(jīng)拿到了 一個后綴為pem文件還有一個后綴為key的文件
第一步:需要這兩個文件生成后綴為pfx的文件,并設(shè)置生成 pfx文件的密碼
centos系統(tǒng)下執(zhí)行命令
openssl pkcs12 -export -out iiscert.pfx -inkey private.key -in public.pem
然后會讓你輸入密碼(密碼不要忘記了)
第二步:修改jexus站點配置信息
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對應(yīng)的進(jìn)程
關(guān)于部署非WEB應(yīng)用
如果需要部署到非WEB應(yīng)用程序蕴掏,則不需要執(zhí)行 jexus的步驟,直接在 supervisor上新增一個進(jìn)程配置文件(/etc/supervisor/conf.d/? 這個目錄下一個*,conf文件代表一個進(jìn)程配置)