<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Server &#8211; Bubblog</title>
	<atom:link href="https://blog.yangyuanping.com/tag/server/feed/" rel="self" type="application/rss+xml" />
	<link>https://blog.yangyuanping.com</link>
	<description>nullable reference types</description>
	<lastBuildDate>Fri, 19 Dec 2025 17:22:40 +0000</lastBuildDate>
	<language>zh-Hans</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.1</generator>

<image>
	<url>https://blog.yangyuanping.com/wp-content/uploads/2025/11/cropped-patrick_log_logo_251121-2-32x32.png</url>
	<title>Server &#8211; Bubblog</title>
	<link>https://blog.yangyuanping.com</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>TencentOS Server 4 安装 dotnet 运行时</title>
		<link>https://blog.yangyuanping.com/tencentos-server-4-%e5%ae%89%e8%a3%85-dotnet-%e8%bf%90%e8%a1%8c%e6%97%b6/</link>
		
		<dc:creator><![CDATA[peny911]]></dc:creator>
		<pubDate>Wed, 17 Dec 2025 18:39:49 +0000</pubDate>
				<category><![CDATA[Linux Nibbles]]></category>
		<category><![CDATA[.Net]]></category>
		<category><![CDATA[Server]]></category>
		<category><![CDATA[TencentOS]]></category>
		<guid isPermaLink="false">https://blog.yangyuanping.com/?p=1051</guid>

					<description><![CDATA[TencentOS Server 4 基于 RHEL 8，使用 dnf： 添加 Microsoft 仓库 su [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>TencentOS Server 4 基于 RHEL 8，使用 dnf：</p>
<h1>添加 Microsoft 仓库</h1>
<p>sudo rpm -Uvh <a href="https://packages.microsoft.com/config/centos/8/packages-microsoft-prod.rpm">https://packages.microsoft.com/config/centos/8/packages-microsoft-prod.rpm</a></p>
<h1>安装运行时</h1>
<p>sudo dnf install -y aspnetcore-runtime-8.0</p>
<h1>验证</h1>
<p>dotnet &#8211;list-runtimes</p>
<p>如果上面的源不可用，可以用脚本安装：</p>
<h1>下载安装脚本</h1>
<p>curl -sSL <a href="https://dot.net/v1/dotnet-install.sh">https://dot.net/v1/dotnet-install.sh</a> -o dotnet-install.sh<br />
chmod +x dotnet-install.sh</p>
<h1>安装到 /usr/share/dotnet（全局）</h1>
<p>sudo ./dotnet-install.sh &#8211;channel 8.0 &#8211;runtime aspnetcore &#8211;install-dir /usr/share/dotnet</p>
<h1>创建软链接</h1>
<p>sudo ln -sf /usr/share/dotnet/dotnet /usr/bin/dotnet</p>
<h1>验证</h1>
<p>dotnet &#8211;list-runtimes</p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>Nginx + .NET 压测与连接问题排查总结</title>
		<link>https://blog.yangyuanping.com/nginx-net-%e5%8e%8b%e6%b5%8b%e4%b8%8e%e8%bf%9e%e6%8e%a5%e9%97%ae%e9%a2%98%e6%8e%92%e6%9f%a5%e6%80%bb%e7%bb%93/</link>
		
		<dc:creator><![CDATA[peny911]]></dc:creator>
		<pubDate>Wed, 17 Dec 2025 16:41:10 +0000</pubDate>
				<category><![CDATA[Linux Nibbles]]></category>
		<category><![CDATA[.Net]]></category>
		<category><![CDATA[Server]]></category>
		<guid isPermaLink="false">https://blog.yangyuanping.com/?p=1049</guid>

					<description><![CDATA[Nginx + .NET 压测与连接问题排查总结 本文是一次完整的 线上问题排查 + 架构修复 + 压力测试验 [&#8230;]]]></description>
										<content:encoded><![CDATA[<h1>Nginx + .NET 压测与连接问题排查总结</h1>
<blockquote>
<p>本文是一次完整的 <strong>线上问题排查 + 架构修复 + 压力测试验证</strong> 的工程级总结，可作为 <strong>事故复盘、容量评估报告、运维 Runbook</strong> 使用。</p>
</blockquote>
<hr />
<h2>一、问题背景与现象</h2>
<h3>初始问题</h3>
<ul>
<li>
<p>Nginx 错误日志频繁出现：</p>
<pre><code class="language-text">upstream timed out (110: Connection timed out) while connecting to upstream</code></pre>
</li>
<li>
<p>请求多为：</p>
<pre><code class="language-text">OPTIONS /api/Ads/resolve HTTP/2.0</code></pre>
</li>
<li>上游地址：&lt;code&gt;127.0.0.1:5085&lt;/code&gt;（.NET Kestrel）</li>
</ul>
<h3>同时观测到的内核异常</h3>
<ul>
<li>&lt;code&gt;listen queue overflow&lt;/code&gt;</li>
<li>&lt;code&gt;SYNs to LISTEN sockets dropped&lt;/code&gt;</li>
<li>&lt;code&gt;SYN cookies sent&lt;/code&gt;</li>
<li>&lt;code&gt;TCPTimeWaitOverflow&lt;/code&gt;</li>
</ul>
<h3>直接影响</h3>
<ul>
<li>Nginx 无法连接本机上游</li>
<li>API 出现大量失败</li>
<li>高并发下服务不可用</li>
</ul>
<hr />
<h2>二、根因分析（结论级）</h2>
<h3>1&#x20e3; Nginx → Kestrel 连接模型错误（<strong>核心根因</strong>）</h3>
<p>在 &lt;code&gt;location /&lt;/code&gt; 中错误地配置了：</p>
<pre><code class="language-nginx">proxy_set_header Connection "upgrade";</code></pre>
<p>导致：</p>
<ul>
<li>所有普通 HTTP 请求被迫使用 &lt;code&gt;Connection: upgrade&lt;/code&gt;</li>
<li>Keepalive 失效</li>
<li>每个请求都建立/断开 TCP 连接</li>
</ul>
<p><img src="https://s.w.org/images/core/emoji/17.0.2/72x72/1f449.png" alt="👉" class="wp-smiley" style="height: 1em; max-height: 1em;" /> <strong>直接引发短连接风暴</strong></p>
<hr />
<h3>2&#x20e3; OPTIONS 预检请求被放大</h3>
<ul>
<li>外站（如豆瓣）触发大量跨域请求</li>
<li>每个请求都会先发 &lt;code&gt;OPTIONS&lt;/code&gt;</li>
<li>&lt;code&gt;OPTIONS&lt;/code&gt; 被转发到上游应用</li>
</ul>
<p>在短连接模型下形成 <strong>连接洪峰</strong>。</p>
<hr />
<h3>3&#x20e3; 内核层连锁反应</h3>
<ul>
<li>SYN backlog 被打满</li>
<li>accept queue 溢出</li>
<li>内核开始丢 SYN / 启用 SYN cookies</li>
<li>Nginx 连接上游直接超时（110）</li>
</ul>
<hr />
<h2>三、关键修复措施（工程级）</h2>
<h3>1&#x20e3; 引入 upstream keepalive（<strong>最关键修复</strong>）</h3>
<p>在 &lt;code&gt;http {}&lt;/code&gt; 作用域中新增：</p>
<pre><code class="language-nginx">upstream eaglex_upstream {
    server 127.0.0.1:5085;
    keepalive 256;
}</code></pre>
<p>统一使用：</p>
<pre><code class="language-nginx">proxy_pass http://eaglex_upstream;
proxy_http_version 1.1;
proxy_set_header Connection "";</code></pre>
<hr />
<h3>2&#x20e3; 修正 Connection 头使用方式（<strong>非常关键</strong>）</h3>
<ul>
<li>
<p><img src="https://s.w.org/images/core/emoji/17.0.2/72x72/274c.png" alt="❌" class="wp-smiley" style="height: 1em; max-height: 1em;" /> 禁止在普通 HTTP 路径中使用：</p>
<pre><code class="language-nginx">Connection: upgrade</code></pre>
</li>
<li><img src="https://s.w.org/images/core/emoji/17.0.2/72x72/2705.png" alt="✅" class="wp-smiley" style="height: 1em; max-height: 1em;" /> 只在 <strong>WebSocket 专用 location</strong> 中使用 upgrade</li>
</ul>
<hr />
<h3>3&#x20e3; 在 Nginx 层直接短路 OPTIONS 预检</h3>
<pre><code class="language-nginx">location = /api/Ads/resolve {
    if ($request_method = OPTIONS) {
        add_header Access-Control-Allow-Origin $http_origin always;
        add_header Access-Control-Allow-Methods "GET,POST,OPTIONS" always;
        add_header Access-Control-Allow-Headers "Content-Type,Authorization" always;
        add_header Access-Control-Max-Age 86400 always;
        return 204;
    }
    proxy_pass http://eaglex_upstream;
}</code></pre>
<p><img src="https://s.w.org/images/core/emoji/17.0.2/72x72/1f449.png" alt="👉" class="wp-smiley" style="height: 1em; max-height: 1em;" /> <strong>彻底消除预检请求对上游的压力放大</strong></p>
<hr />
<h3>4&#x20e3; 缩短 proxy_connect_timeout（防止雪崩）</h3>
<pre><code class="language-nginx">proxy_connect_timeout 2s;</code></pre>
<p>避免 Nginx worker 在连接失败时长时间阻塞。</p>
<hr />
<h2>四、压测阶段的验证结论</h2>
<h3>压测过程中观测到的健康状态</h3>
<ul>
<li>&lt;code&gt;.NET&lt;/code&gt; CPU：≈ 260%–300%（4C 机器，尚有余量）</li>
<li>Nginx CPU：≈ 10%–20%</li>
<li>&lt;code&gt;ksoftirqd&lt;/code&gt;：极低</li>
<li>
<p>TCP 状态：</p>
<pre><code class="language-text">estab ≈ 3000
timewait ≈ 30
orphan = 0</code></pre>
</li>
<li>
<p>内核累计计数在压测前后 <strong>完全无增长</strong>：</p>
<ul>
<li>listen queue overflow</li>
<li>SYN dropped</li>
<li>TCPTimeWaitOverflow</li>
</ul>
</li>
</ul>
<h3>明确结论</h3>
<blockquote>
<p><strong>连接层 / Nginx / 内核 TCP 已完全稳定，系统瓶颈成功转移至 .NET 应用 CPU 层。</strong></p>
</blockquote>
<hr />
<h2>五、错误日志的两类问题区分（重要）</h2>
<h3>A. &lt;code&gt;110 Connection timed out&lt;/code&gt;</h3>
<pre><code class="language-text">while connecting to upstream</code></pre>
<ul>
<li>含义：连接队列 / accept / backlog 问题</li>
<li>根因：连接模型错误</li>
<li><strong>已在本次修复中解决</strong></li>
</ul>
<hr />
<h3>B. &lt;code&gt;111 Connection refused&lt;/code&gt;</h3>
<pre><code class="language-text">connect() failed (111: Connection refused)</code></pre>
<ul>
<li>含义：上游端口当时 <strong>没有进程在监听</strong></li>
<li>
<p>可能原因：</p>
<ul>
<li>dotnet 进程崩溃</li>
<li>被 OOM killer 杀死</li>
<li>重启 / 发布</li>
</ul>
</li>
</ul>
<p><img src="https://s.w.org/images/core/emoji/17.0.2/72x72/1f449.png" alt="👉" class="wp-smiley" style="height: 1em; max-height: 1em;" /> 属于 <strong>上游进程稳定性问题</strong>，与 backlog 无关。</p>
<hr />
<h2>六、压测与日常排障常用监控命令清单</h2>
<h3>1&#x20e3; TCP 全局状态（必看）</h3>
<pre><code class="language-bash">ss -s</code></pre>
<p>关注：&lt;code&gt;estab / timewait / orphan&lt;/code&gt;</p>
<hr />
<h3>2&#x20e3; 上游端口连接数（Nginx → Kestrel）</h3>
<pre><code class="language-bash">ss -ant | awk '$4=="127.0.0.1:5085"{c++} END{print c}'</code></pre>
<hr />
<h3>3&#x20e3; 上游连接状态分布</h3>
<pre><code class="language-bash">ss -ant | awk '$4=="127.0.0.1:5085"{print $1}' | sort | uniq -c | sort -nr</code></pre>
<hr />
<h3>4&#x20e3; 内核是否再次被打爆（差分判断）</h3>
<pre><code class="language-bash">netstat -s | egrep -i 'listen queue|SYNs to LISTEN|SYN cookies|TCPTimeWaitOverflow'</code></pre>
<blockquote>
<p>必须用 <strong>前后对比</strong> 判断是否仍在发生。</p>
</blockquote>
<hr />
<h3>5&#x20e3; Nginx 错误日志关键字</h3>
<pre><code class="language-bash">tail -n 200 /www/wwwlogs/eaglex_ads_api.error.log | egrep -i 'timed out|refused|502|504'</code></pre>
<hr />
<h3>6&#x20e3; 上游进程是否存活 / 是否重启</h3>
<pre><code class="language-bash">ps -p &lt;dotnet_pid&gt; -o pid,etimes,%cpu,%mem,cmd
ss -lntp | grep 5085</code></pre>
<hr />
<h3>7&#x20e3; OOM / 内核杀进程检查</h3>
<pre><code class="language-bash">dmesg -T | egrep -i 'oom|killed process'
journalctl -k | egrep -i 'oom|killed'</code></pre>
<hr />
<h3>8&#x20e3; .NET 运行时指标（强烈推荐）</h3>
<pre><code class="language-bash">dotnet-counters monitor System.Runtime --process-id &lt;pid&gt;</code></pre>
<p>关注：</p>
<ul>
<li>CPU Usage</li>
<li>ThreadPool Queue Length</li>
<li>% Time in GC</li>
</ul>
<hr />
<h2>七、最终工程级结论（可直接写入文档）</h2>
<blockquote>
<p>本次问题的根因是 Nginx → Kestrel 连接模型错误（短连接 + OPTIONS 预检放大），导致 TCP listen queue 溢出与 upstream connect timeout。</p>
<p>通过引入 upstream keepalive、修正 Connection 头、在 Nginx 层短路 CORS 预检，并配合合理的超时配置，连接层问题已完全消除。</p>
<p>压测结果表明：系统当前瓶颈已转移至 .NET 应用 CPU 层，TCP 与代理层稳定可靠，具备可预测的容量上限。</p>
</blockquote>
]]></content:encoded>
					
		
		
			</item>
	</channel>
</rss>
