叫我三万大人 發表於 2024-4-25 16:46:00

开发日志:Kylin麒麟操作系统部署ASP.NET CORE

<p><strong>需求场景:</strong></p>
<p>&nbsp; &nbsp; &nbsp;我需要部署的项目是在Windows上开发的,目标框架为.net core 6.0 因此我们需要先在kylin上部署项目运行所需要的环境。</p>
<p>借助百度词条,先看看Kylin是什么:</p>
<p><img src="https://img2024.cnblogs.com/blog/54346/202404/54346-20240425155113180-778032686.png" alt="" width="826" height="202" loading="lazy"></p>
<p>&nbsp;服务器资源:</p>
<p><img src="https://img2024.cnblogs.com/blog/54346/202404/54346-20240425155308400-795027406.png" alt="" width="836" height="328" loading="lazy"></p>
<p>&nbsp;查看系统版本&nbsp; cat /etc/kylin-release&nbsp; &nbsp; cat /proc/version&nbsp; &nbsp;</p>
<p><img src="https://img2024.cnblogs.com/blog/54346/202404/54346-20240425162240118-103129928.png" alt="" width="803" height="467" loading="lazy"></p>
<p>&nbsp;<strong>需要用到的工具:</strong></p>
<ol>
<li>SSH远程链接工具&nbsp; &nbsp; &nbsp;https://mobaxterm.mobatek.net/download.html</li>
<li>7-zipWindows下打包tar.gz文件&nbsp;https://7-zip.org/download.html&nbsp;&nbsp;</li>
</ol>
<p><strong>&nbsp;部署步骤和方法:</strong></p>
<p>在Kylin操作系统中安装ASP.NET Core,您可以遵循以下步骤:</p>
<ol><ol>
<li>打开终端(SSH远程链接工具)</li>
<li>添加Microsoft包存储库:rpm -Uvh https://packages.microsoft.com/config/centos/7/packages-microsoft-prod.rpm</li>
<li>安装.NET Core SDK:yum install dotnet-sdk-6.0</li>
<li>安装ASP.NET Core 运行时:yum install aspnetcore-runtime-6.0</li>
上传编译好的DotNet项目文件(*.tar.gz)上传目录 /root/website/&nbsp; 也就是当前目录</ol></ol><img src="https://img2024.cnblogs.com/blog/54346/202404/54346-20240425163318927-1661734077.png" alt="" width="721" height="417" loading="lazy"><ol>
<li>解压tar -zxvf&nbsp; *.tar.gz 项目文件到指定目录</li>
<li>运行项目 dotnet *.dll</li>
<li>访问项目,这时需要一直开着终端才能访问所以需要</li>
<li>安装Supervisor守护进程</li>
<li>创建 Systemd 服务文件</li>
<li>完成</li>
</ol>
<p>以上步骤会在Kylin操作系统上安装.NET Core SDK和ASP.NET Core 运行时以及项目部署到Kylin服务器上。请确保替换步骤4中的URL,使之指向最新的.NET Core版本。</p>
<div>
<p><strong>Supervisor安装步骤:</strong></p>
<ol>
<li>输入命令:yum install python-setuptools</li>
<li>输入命令:easy_install supervisor</li>
<li>配置Supervisor:mkdir /etc/supervisor&nbsp; 执行&nbsp; echo_supervisord_conf &gt; /etc/supervisor/supervisord.conf 生成配置文件<ol>
<li>
<p>修改配置文件 /etc/supervisor/supervisord.conf文件内容在文件结尾节点处把;</p>
</li>
<li>
<p>files = relative/directory/*.ini&nbsp; 改为&nbsp; files = conf.d/*.conf</p>
</li>
<li>在/etc/supervisor/下创建conf.d文件夹</li>
<li>
<p>在&nbsp;/etc/supervisor/ conf.d/ 路径下新增.conf文件 内容如下:</p>
</li>
<li>
<div class="cnblogs_code">
<pre><span style="color: rgba(128, 0, 0, 1); font-weight: bold">[</span><span style="color: rgba(128, 0, 0, 1)">program: fxxyrsapp</span><span style="color: rgba(128, 0, 0, 1); font-weight: bold">]</span><span style="color: rgba(0, 0, 0, 1)">
command</span>=<span style="color: rgba(0, 0, 0, 1)">dotnet Web.dll
directory</span>=<span style="color: rgba(0, 0, 0, 1)">/home/ftproot/website/fxxyrs
autorestart</span>=<span style="color: rgba(0, 0, 0, 1)">true
autostart</span>=<span style="color: rgba(0, 0, 0, 1)">true
stderr_logfile</span>=<span style="color: rgba(0, 0, 0, 1)">/home/ftproot/website/hdj_fxxyrs/fxxyrsapp.err.log
stdout_logfile</span>=<span style="color: rgba(0, 0, 0, 1)">/home/ftproot/website/hdj_fxxyrs/fxxyrsapp.out.log
environment</span>=ASPNETCORE_ENVIRONMENT=<span style="color: rgba(0, 0, 0, 1)">Production
user</span>=<span style="color: rgba(0, 0, 0, 1)">root
stopsignal</span>=<span style="color: rgba(0, 0, 0, 1)">INT
startsecs</span>=1</pre>
</div>
</li>
<li>
<p>重启命令:supervisorctl -c /etc/supervisor/supervisord.conf reload 或者&nbsp;supervisorctl reload</p>
</li>
<li>运行supervisord,查看是否生效,执行以下命令:&nbsp;</li>
<li>supervisord -c /etc/supervisor/supervisord.conf</li>
<li><em><em>查看进程:ps -ef | grep&nbsp;</em></em><span style="color: rgba(255, 0, 0, 1)">fxxyrsapp</span></li>
<li><span style="color: rgba(51, 51, 51, 1)">配置supervisor UI 管理台</span></li>
<li>
<div id="cnblogs_post_body" class="blogpost-body cnblogs-markdown">
<p>编辑 supervisord.conf 文件,加入/修改 </p>
<pre class="highlighter-hljs"><code class="highlighter-hljs hljs language-ini"><span class="hljs-section">      <span class="hljs-comment">
<span class="hljs-attr">port=*:<span class="hljs-number">9001                  <span class="hljs-comment">
<span class="hljs-attr">username=user            <span class="hljs-comment">
<span class="hljs-attr">password=<span class="hljs-number">123            </span></span></span></span></span></span></span></span></span></code></pre>
<p>接下来访问ip:9001,就可以看到正在运行的进程了</p>
<p><img src="https://img2020.cnblogs.com/blog/1674580/202005/1674580-20200529171601291-1593219272.png" alt="" class="medium-zoom-image" loading="lazy"></p>
</div>
<div id="MySignature">&nbsp;</div>
</li>
</ol></li>
</ol>
<p><strong><strong>创建 Systemd 服务文件:</strong></strong></p>
<div class="cnblogs_code">
<pre><span style="color: rgba(0, 0, 0, 1)"># 创建 Systemd 服务文件
sudo bash -c 'cat &lt;&lt; EOF &gt; /etc/systemd/system/fxxyrspc.service
</span><span style="color: rgba(128, 0, 0, 1); font-weight: bold">[</span><span style="color: rgba(128, 0, 0, 1)">Unit</span><span style="color: rgba(128, 0, 0, 1); font-weight: bold">]</span><span style="color: rgba(0, 0, 0, 1)">
Description</span>=<span style="color: rgba(0, 0, 0, 1)">jx fxxy rs pc

</span><span style="color: rgba(128, 0, 0, 1); font-weight: bold">[</span><span style="color: rgba(128, 0, 0, 1)">Service</span><span style="color: rgba(128, 0, 0, 1); font-weight: bold">]</span><span style="color: rgba(0, 0, 0, 1)">
WorkingDirectory</span>=<span style="color: rgba(0, 0, 0, 1)">/home/ftproot/hdjftp/website/fxxyrspc
ExecStart</span>=<span style="color: rgba(0, 0, 0, 1)">/home/ftproot/hdjftp/website/fxxyrs/pc/fxxyrspc.dll

# 程序崩溃后自动启动
Restart</span>=<span style="color: rgba(0, 0, 0, 1)">always
RestartSec</span>=10<span style="color: rgba(0, 0, 0, 1)">
KillSignal</span>=<span style="color: rgba(0, 0, 0, 1)">SIGINT
SyslogIdentifier</span>=<span style="color: rgba(0, 0, 0, 1)">fxxyrspc.service
# 用户角色
User</span>=<span style="color: rgba(0, 0, 0, 1)">root
Environment</span>=ASPNETCORE_ENVIRONMENT=<span style="color: rgba(0, 0, 0, 1)">Production
Environment</span>=DOTNET_PRINT_TELEMETRY_MESSAGE=<span style="color: rgba(0, 0, 0, 1)">false
# The default value is </span>90<span style="color: rgba(0, 0, 0, 1)"> seconds for most distributions.
TimeoutStopSec</span>=90

<span style="color: rgba(128, 0, 0, 1); font-weight: bold">[</span><span style="color: rgba(128, 0, 0, 1)">Install</span><span style="color: rgba(128, 0, 0, 1); font-weight: bold">]</span><span style="color: rgba(0, 0, 0, 1)">
WantedBy</span>=<span style="color: rgba(0, 0, 0, 1)">multi-user.target
EOF'

# 启动并设置服务开机自启
sudo systemctl daemon-reload
sudo systemctl start fxxyrspc.service
sudo systemctl enable fxxyrspc.service
sudo systemctl status fxxyrspc.service
journalctl -u fxxyrspc.service
journalctl -fu fxxyrspc.service</span></pre>
</div>
<p><strong>常用命令:</strong></p>
<div class="cnblogs_code">
<pre><span style="color: rgba(0, 0, 0, 1)">复制文件
mv /home/ftproot/</span>5<span style="color: rgba(0, 0, 0, 1)">.tar.gz /var/opt/mssql/data
解压
sudo tar -zxvf /home/ftproot/</span>5<span style="color: rgba(0, 0, 0, 1)">.tar.gz -C/var/opt/mssql/data
删除文件夹
rm -rf/home/ftproot/hdjftp/website/fxxyrs/pc
创建文件夹:
mkdir/home/ftproot/hdjftp/website/fxxyrs/pc
授权
chmod -R </span>777<span style="color: rgba(0, 0, 0, 1)"> /home/ftproot/hdjftp/website/pc<br>进入目录
cd /home/ftproot/hdjftp/website/pc/<br>查询进程<br>ps -ef | grep HDJ<br>删除进程<br>kill ID</span></pre>
</div>
<p><strong>安装vsftpd:&nbsp; https://blog.csdn.net/weixin_38642722/article/details/146607235</strong></p>
<p>&nbsp;</p>
<p><strong>使用7-zip打包tar.gz文件:</strong></p>
<ol>
<li>&nbsp;右键-7.ZIP-添加压缩包压缩格式选择"tar"确定</li>
<li>选择打包好的“tar”右键-7.ZIP-添加压缩包压缩格式选择"gzip"确定就打包*.tar.gz格式的文件了</li>
</ol></div>
<hr>
<p>&nbsp;</p>
<p>A connection was successfully established with the server, but then an error occurred during the pre-login handshake. (provider: SSL Provider, error: 31 - Encryption(ssl/tls) handshake failed)<br>https://github.com/dotnet/SqlClient/issues/2252</p>
<p><strong>解决方法:</strong></p>
<div class="cnblogs_code">
<pre><span style="color: rgba(0, 0, 0, 1)">vim /etc/pki/tls/openssl.cnf
#在oid_section</span>=<span style="color: rgba(0, 0, 0, 1)">new_oids下增加
openssl_conf </span>=<span style="color: rgba(0, 0, 0, 1)"> default_conf
#在文件末尾增加
</span><span style="color: rgba(128, 0, 0, 1); font-weight: bold">[</span><span style="color: rgba(128, 0, 0, 1)">default_conf</span><span style="color: rgba(128, 0, 0, 1); font-weight: bold">]</span><span style="color: rgba(0, 0, 0, 1)">
ssl_conf </span>=<span style="color: rgba(0, 0, 0, 1)"> ssl_sect
</span><span style="color: rgba(128, 0, 0, 1); font-weight: bold">[</span><span style="color: rgba(128, 0, 0, 1)">ssl_sect</span><span style="color: rgba(128, 0, 0, 1); font-weight: bold">]</span><span style="color: rgba(0, 0, 0, 1)">
system_default </span>=<span style="color: rgba(0, 0, 0, 1)"> system_default_sect
</span><span style="color: rgba(128, 0, 0, 1); font-weight: bold">[</span><span style="color: rgba(128, 0, 0, 1)">system_default_sect</span><span style="color: rgba(128, 0, 0, 1); font-weight: bold">]</span><span style="color: rgba(0, 0, 0, 1)">
MinProtocol </span>=<span style="color: rgba(0, 0, 0, 1)"> TLSv1
CipherString </span>= DEFAULT@SECLEVEL=1</pre>
</div>
<hr>
<p>错误信息:</p>
<p><img src="https://img2024.cnblogs.com/blog/54346/202504/54346-20250418142236581-1605710378.png" alt="" loading="lazy"></p>
<p>&nbsp;<strong>解决方法:</strong></p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>https://learn.microsoft.com/zh-cn/troubleshoot/developer/webapps/aspnetcore/practice-troubleshoot-linux/1-3-install-dotnet-core-linux</p>
<p>&nbsp;</p>
<h3>Nginx代理:https://blog.csdn.net/u011575168/article/details/120284495</h3>
<p>1:安装:安装Nginx‌: 如果你还没有安装Nginx,可以通过以下命令安装</p>
<p>&nbsp; &nbsp;sudo apt-get install -y nginx</p>
<p>2:配置:配置Nginx‌: 编辑Nginx配置文件,通常位于<code>/etc/nginx/sites-available/default</code>。添加以下配置以代理到你的ASP.NET Core应用</p>
<div class="cnblogs_code">
<pre><span style="color: rgba(0, 0, 0, 1)">server {
listen </span>80<span style="color: rgba(0, 128, 0, 1)">;</span><span style="color: rgba(0, 128, 0, 1)"> # 或其他端口号,取决于你的需求。确保与防火墙设置相匹配。</span>
server_name yourdomain.com<span style="color: rgba(0, 128, 0, 1)">;</span><span style="color: rgba(0, 128, 0, 1)"> # 替换为你的域名或IP地址。</span>
<span style="color: rgba(0, 0, 0, 1)">location / {
proxy_pass http://localhost:</span>5000<span style="color: rgba(0, 128, 0, 1)">;</span><span style="color: rgba(0, 128, 0, 1)"> # 根据你的ASP.NET Core应用监听的端口修改。确保防火墙开放相应的端口。如果使用了反向代理,这里的端口通常是5000。如果直接运行在5000端口,则无需此配置。否则,你需要确保防火墙允许访问此端口。例如,使用UFW可以运行:sudo ufw allow 5000/tcp。如果使用了反向代理(如Nginx),则ASP.NET Core通常监听80端口(HTTP)或443端口(HTTPS)。在这种情况下,你应该将proxy_pass指向反向代理服务器的地址和端口。例如,如果你的Nginx配置为将请求代理到localhost的5001端口,则应为proxy_pass http://localhost:5001;。确保ASP.NET Core应用监听正确的端口,并通过反向代理转发请求到此端口。如果使用了反向代理(如Nginx),则ASP.NET Core通常监听80端口(HTTP)或443端口(HTTPS)。</span></pre>
</div>
<p>&nbsp;</p><br><br>
来源:https://www.cnblogs.com/luomingui/p/18157938
頁: [1]
查看完整版本: 开发日志:Kylin麒麟操作系统部署ASP.NET CORE