4zhvml8 发表于 2024-9-1 00:15:21

聊聊服务器优化~(意见保藏)


    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">咱们</span><span style="color: black;">研发</span>的软件服务需要在服务器上运行,<span style="color: black;">因此</span>服务器性能<span style="color: black;">表率</span>了软件的性能上限,<span style="color: black;">因此呢</span>服务器性能调优是个<span style="color: black;">非常</span>重要的环节,然而大部分<span style="color: black;">朋友</span>对服务器性能调优关注的较少,今天从3个部分对服务器性能调优进行介绍,分别是:服务器配置<span style="color: black;">选取</span>,服务器负载分析,服务器内核参数调优。</p>
    <h1 style="color: black; text-align: left; margin-bottom: 10px;">服务器配置<span style="color: black;">选取</span></h1>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">服务器<span style="color: black;">通常</span><span style="color: black;">是由于</span>CPU、内存、磁盘和网卡<span style="color: black;">构成</span>,<span style="color: black;">因此呢</span><span style="color: black;">选取</span>服务器配置<span style="color: black;">便是</span><span style="color: black;">选取</span>CPU核数、内存<span style="color: black;">体积</span>、磁盘<span style="color: black;">体积</span>及类型、网络带宽。<span style="color: black;">然则</span>,服务器配置的<span style="color: black;">选取</span>是很难标准化的,<span style="color: black;">亦</span><span style="color: black;">便是</span>说很难推断出“一台需要达到1000TPS的后端服务器”的配置应该是什么样的。<span style="color: black;">由于</span>软件的<span style="color: black;">最后</span>运行性能与软件的实现方式是紧密<span style="color: black;">关联</span>的,即使是同一个后端应用程序中的两个接口,<span style="color: black;">因为</span><span style="color: black;">详细</span>功能的差别,性能<span style="color: black;">亦</span>会有所差别。</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">因此呢</span>,服务器配置的<span style="color: black;">选取</span>应该基于<span style="color: black;">详细</span>的测试结果。一<span style="color: black;">起始</span><span style="color: black;">能够</span><span style="color: black;">选择</span>配置较低的服务器做调优和测试,并以该服务器的测试结果<span style="color: black;">做为</span><span style="color: black;">选取</span>服务器的依据。</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">以一个订单业务为例,经过测试后,一台配置为4核 CPU 、16GB内存、10Mbps带宽、50GB机械磁盘的服务器的测试结果为:支持50并发量和300TPS吞吐量(增大并发量后会<span style="color: black;">显现</span>超时报错)。而在压力测试过程中, CPU 的<span style="color: black;">运用</span>率接近75%,内存<span style="color: black;">运用</span>率在 50%以下,带宽<span style="color: black;">运用</span>率在50%以下,除去日志以外无磁盘操作。</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">因此呢</span><span style="color: black;">能够</span>认为,一台配置为4核 CPU ( CPU <span style="color: black;">运用</span>率需要在75%以下)、8GB内存(内存<span style="color: black;">运用</span>率<span style="color: black;">能够</span>接近100%)、 5Mbps 带宽(带宽<span style="color: black;">运用</span>率<span style="color: black;">能够</span>接近100%)的服务器,<span style="color: black;">能够</span>满足订单接口支持50并发量、300TPS吞吐量的压力。</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">倘若</span>需要达到200并发数、2400TPS吞吐量的<span style="color: black;">目的</span>的话,则需要8台配置为4核 CPU 、8GB内存、5Mbps带宽的服务器,<span style="color: black;">或</span>1台配置为32核 CPU 、64GB内存、40Mbps带宽的服务器。当然,<span style="color: black;">最后</span>的服务器配置还是需要<span style="color: black;">经过</span>测试来验证。</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">重视</span>:在以上订单接口的例子中,后端服务器和数据库等服务器需要<span style="color: black;">一块</span>调试,避免后端服务器性能过剩,而数据库等服务器性能不足的<span style="color: black;">状况</span><span style="color: black;">出现</span>。<span style="color: black;">另一</span>,以上<span style="color: black;">选取</span>服务器配置的<span style="color: black;">办法</span>不<span style="color: black;">必定</span>适用于所有场景,请斟酌参考。</p>
    <h1 style="color: black; text-align: left; margin-bottom: 10px;">服务器负载分析</h1>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">在性能调优时,需要先对服务器负载进行分析,<span style="color: black;">一般</span>而言,<span style="color: black;">咱们</span><span style="color: black;">重点</span>分析CPU<span style="color: black;">运用</span>率、内存<span style="color: black;">运用</span>率、磁盘I/O,服务器负载和带宽<span style="color: black;">运用</span><span style="color: black;">状况</span>。</p>
    <h1 style="color: black; text-align: left; margin-bottom: 10px;">CPU<span style="color: black;">运用</span>率</h1>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">CPU<span style="color: black;">运用</span>率反应的是CPU的忙碌<span style="color: black;">状况</span>。当CPU达到100%时,部分进程会进入等待状态,CPU暂时不会对其进行处理。<strong style="color: blue;">在<span style="color: black;">实质</span><span style="color: black;">状况</span>下,为了应对一下突发性的请求压力,服务器CPU<span style="color: black;">运用</span>率<span style="color: black;">通常</span>需要在75%以下。<span style="color: black;">倘若</span>一台服务器的CPU<span style="color: black;">运用</span>率多次高于75%,<span style="color: black;">此时</span>候就<span style="color: black;">思虑</span><span style="color: black;">增多</span>新的服务器。</strong></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">监控CPU<span style="color: black;">运用</span>率我<span style="color: black;">举荐</span><span style="color: black;">大众</span><span style="color: black;">运用</span><strong style="color: blue;">htop</strong>工具,<span style="color: black;">能够</span>非常直观看到CPU<span style="color: black;">运用</span>率、内存<span style="color: black;">运用</span>率、及负载等信息。</p>
    <h1 style="color: black; text-align: left; margin-bottom: 10px;"><span style="color: black;">运用</span>htop查看CPU负载</h1>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">首要</span><span style="color: black;">咱们</span>需要安装htop,以centos为例,安装命令如下:</p><span style="color: black;">yum</span>install htop -y<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">安装完成后<span style="color: black;">咱们</span>就<span style="color: black;">能够</span><span style="color: black;">经过</span>htop命令观察CPU负载了</p>htop<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">输入htop命令后<span style="color: black;">咱们</span><span style="color: black;">能够</span>很直观的看到CPU负载<span style="color: black;">状况</span>,该命令的CPU<span style="color: black;">运用</span>率会以多个核<span style="color: black;">做为</span>单位进行<span style="color: black;">表示</span>。操作系统机会自动分配多个核的负载,当所有核的CPU<span style="color: black;">运用</span>率都超过75%时<span style="color: black;">才可</span>认为服务器的CPU<span style="color: black;">运用</span>率<span style="color: black;">已然</span>超过75%。</p>
    <div style="color: black; text-align: left; margin-bottom: 10px;"><img src="https://p3-sign.toutiaoimg.com/tos-cn-i-qvj2lq49k0/99e7e58efd4e4822a89a3b390e11d6ca~noop.image?_iz=58558&amp;from=article.pc_detail&amp;lk3s=953192f4&amp;x-expires=1725618492&amp;x-signature=87GJWBUaig6V1dxOi81k%2B6mkgs4%3D" style="width: 50%; margin-bottom: 20px;"></div>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">如上图所示,这是一个4核CPU服务器,在截图的时候其中3核CPU<span style="color: black;">运用</span>率都超过了75%,再观察一会<span style="color: black;">发掘</span>所有CPU的<span style="color: black;">运用</span>率都在85%<span style="color: black;">上下</span>徘徊,说明CPU负载很高了,需要<span style="color: black;">思虑</span><span style="color: black;">增多</span>新的服务器。</p>
    <h1 style="color: black; text-align: left; margin-bottom: 10px;">内存<span style="color: black;">运用</span>率</h1>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">内存<span style="color: black;">运用</span>率反应的是内存的<span style="color: black;">运用</span><span style="color: black;">状况</span>。内存用于存放程序的代码及数据,<span style="color: black;">通常</span>分为<span style="color: black;">理学</span>内存和虚拟内存,其中<span style="color: black;">理学</span>内存指的是服务器的内存,而虚拟内存指的是硬盘的<span style="color: black;">一起</span>空间。当<span style="color: black;">理学</span>内存<span style="color: black;">运用</span>率达到100%时将会<span style="color: black;">运用</span>虚拟内存。需要<span style="color: black;">重视</span>的是,虚拟内存的读写速度远远<span style="color: black;">小于</span><span style="color: black;">理学</span>内存,<span style="color: black;">倘若</span>程序被放在了虚拟内存执行,<span style="color: black;">那样</span>程序的执行效率会变得很低。</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><strong style="color: blue;"><span style="color: black;">通常</span>而言,服务器的<span style="color: black;">理学</span>内存应该保持在80%以下,虚拟内存<span style="color: black;">运用</span>率保持在0%。</strong></p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">服务器内存<span style="color: black;">运用</span><span style="color: black;">状况</span>还是<span style="color: black;">能够</span><span style="color: black;">经过</span>hop工具进行查看</p>
    <div style="color: black; text-align: left; margin-bottom: 10px;"><img src="https://p3-sign.toutiaoimg.com/tos-cn-i-qvj2lq49k0/99bbf1bb4e204b8082543d3b823d4055~noop.image?_iz=58558&amp;from=article.pc_detail&amp;lk3s=953192f4&amp;x-expires=1725618492&amp;x-signature=VAzOkVqNeOXUNB%2BQAwQVc14PApk%3D" style="width: 50%; margin-bottom: 20px;"></div>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">上面<span style="color: black;">表示</span>了服务器的内存<span style="color: black;">运用</span><span style="color: black;">状况</span>:总内存16G,<span style="color: black;">运用</span>了10G<span style="color: black;">上下</span>,内存<span style="color: black;">运用</span>率62%,<span style="color: black;">能够</span>继续<span style="color: black;">运用</span>,<span style="color: black;">同期</span>关闭了Swap虚拟内存。</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">在下MEM%栏中<span style="color: black;">表示</span>了单个进程的内存<span style="color: black;">运用</span>率。</p>
    <h1 style="color: black; text-align: left; margin-bottom: 10px;">磁盘I/O</h1>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">磁盘I/O指的是磁盘的读写,在软件系统中,日志、文件操作、数据库操作都会<span style="color: black;">导致</span>磁盘读写压力,其中又以数据库操<span style="color: black;">做为</span>甚,在高并发<span style="color: black;">状况</span>下<span style="color: black;">常常</span>数据库会<span style="color: black;">首要</span><span style="color: black;">作为</span>系统的瓶颈。</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">磁盘监控我<span style="color: black;">举荐</span><span style="color: black;">大众</span><span style="color: black;">运用</span>iostat工具,<span style="color: black;">能够</span>很方便查看磁盘的<span style="color: black;">运用</span><span style="color: black;">状况</span>。</p>
    <h1 style="color: black; text-align: left; margin-bottom: 10px;"><span style="color: black;">运用</span>iostat查看磁盘I/O</h1>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">首要</span><span style="color: black;">咱们</span>需要安装iostat,以centos为例,安装命令如下:</p><span style="color: black;">yum</span> install sysstat -y<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">安装完成后<span style="color: black;">咱们</span>就<span style="color: black;">能够</span><span style="color: black;">经过</span>iostat命令磁盘使用<span style="color: black;">状况</span>了。</p><span style="color: black;"># 查看磁盘总体读写<span style="color: black;">状况</span>, 1<span style="color: black;">表率</span>每1秒读取一次数据</span>
    <span style="color: black;">iostat</span> -x <span style="color: black;">1</span>
    <div style="color: black; text-align: left; margin-bottom: 10px;"><img src="https://p3-sign.toutiaoimg.com/tos-cn-i-qvj2lq49k0/56d6651c89bc40889b9f6f26a026653a~noop.image?_iz=58558&amp;from=article.pc_detail&amp;lk3s=953192f4&amp;x-expires=1725618492&amp;x-signature=LGqmCQTo2asRzfUz5EbE0rGQqZM%3D" style="width: 50%; margin-bottom: 20px;"></div>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">输入iostat命令后,磁盘总体读写<span style="color: black;">状况</span>如上所示。磁盘负载<span style="color: black;">重点</span>关注2个指标:%idle,%util</p>%idle:<span style="color: black;">暗示</span>CPU<strong style="color: blue;">除去等待磁盘I/O以外</strong>的空闲时间百分比,这个指标应该要<span style="color: black;">保准</span>在70%以上%util:该设备用于I/O操作的时间百分比,这个指标需要<span style="color: black;">保准</span>在70%以下,当到达100%时<span style="color: black;">暗示</span><span style="color: black;">已然</span>满负载。为了降低磁盘负载,<span style="color: black;">能够</span>采用性能更高的磁盘(OSD,PCIE)<span style="color: black;">或</span>降低磁盘的操作频率(异步写、合并写)<h1 style="color: black; text-align: left; margin-bottom: 10px;">平均负载</h1>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">平均负载指的是单位时间内平均的活跃进程数,是一个<span style="color: black;">暗示</span>服务器负载的指标。<span style="color: black;">通常</span><span style="color: black;">状况</span>下需要<span style="color: black;">保准</span>平均负载的值<span style="color: black;">少于</span>当前服务器的CPU核数。</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">一样</span>的,查看服务器平均负载<span style="color: black;">咱们</span><span style="color: black;">亦</span><span style="color: black;">能够</span><span style="color: black;">运用</span>htop命令</p>
    <div style="color: black; text-align: left; margin-bottom: 10px;"><img src="https://p3-sign.toutiaoimg.com/tos-cn-i-qvj2lq49k0/2f53d0b308b3437e9ded9dac44fc2b8d~noop.image?_iz=58558&amp;from=article.pc_detail&amp;lk3s=953192f4&amp;x-expires=1725618492&amp;x-signature=62OQZV%2BF5VwKE4%2BVEc6%2BVF5dGho%3D" style="width: 50%; margin-bottom: 20px;"></div>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">在<span style="color: black;">这儿</span><span style="color: black;">咱们</span><span style="color: black;">重点</span>关注Load average指标,上图有3个数字,分别<span style="color: black;">表率</span>1分钟,5分钟,15分钟的平均负载。</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">通常</span><span style="color: black;">状况</span>下服务器的平均负载需要<span style="color: black;">少于</span>当前服务器的CPU核数,为了应对突发<span style="color: black;">情况</span>,服务器的平均负载应该在75%即3 以下,很显然,上图这台服务器平均负载超过了75%,需要<span style="color: black;">思虑</span><span style="color: black;">提高</span>性能了。</p>
    <h1 style="color: black; text-align: left; margin-bottom: 10px;">网络<span style="color: black;">运用</span><span style="color: black;">状况</span></h1>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">网络<span style="color: black;">运用</span><span style="color: black;">状况</span><span style="color: black;">亦</span>是监控的重要指标。当带宽不足时会大大<span style="color: black;">增多</span>请求的响应时间。为了防止突发性并发压力,应该<span style="color: black;">保准</span>服务器的带宽<span style="color: black;">运用</span>率在80%以上。<span style="color: black;">这儿</span>需要<span style="color: black;">重视</span>的是,<span style="color: black;">理学</span>网卡限制了服务器所能<span style="color: black;">运用</span>的最大宽带。</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">查看网络<span style="color: black;">运用</span><span style="color: black;">状况</span>我<span style="color: black;">举荐</span><span style="color: black;">运用</span>nload工具。</p>
    <h1 style="color: black; text-align: left; margin-bottom: 10px;"><span style="color: black;">运用</span>nload查看网络</h1>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">首要</span>需要安装nload,以centos为例</p><span style="color: black;">yum</span> install nload -y<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">安装完成后<span style="color: black;">咱们</span>直接运行nload</p>nload<div style="color: black; text-align: left; margin-bottom: 10px;"><img src="https://p3-sign.toutiaoimg.com/tos-cn-i-qvj2lq49k0/6eede335e7c840e2a35bc798020bbdfb~noop.image?_iz=58558&amp;from=article.pc_detail&amp;lk3s=953192f4&amp;x-expires=1725618492&amp;x-signature=y%2FnsFNEtRUO7OvOU1D6z4EX%2BAOQ%3D" style="width: 50%; margin-bottom: 20px;"></div>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">输入nload命令后,网络<span style="color: black;">运用</span><span style="color: black;">状况</span>如上图所示。其中,网络<span style="color: black;">运用</span><span style="color: black;">状况</span>分为流入网卡的数据与流出网卡的数据。流入网卡的对应下行带宽的网速,流出网卡的数据对应上行带宽的网速。 <span style="color: black;">倘若</span> “当前网速” <span style="color: black;">连续</span>接近 “最大网速” 时,<span style="color: black;">表率</span>带宽<span style="color: black;">运用</span>率<span style="color: black;">已然</span>接近100%。</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">指标说明:</p>Curr:当前网速Avg:平均网速Min:最小网速Max:最大网速Ttl:总流量<h1 style="color: black; text-align: left; margin-bottom: 10px;">服务器内核参数调优</h1>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">光有强大的<span style="color: black;">理学</span>性能是<span style="color: black;">不足</span>的,还需要对内核参数进行调优,<span style="color: black;">这般</span><span style="color: black;">才可</span>在高并发压力下充分<span style="color: black;">表现</span>服务器应有的性能。当然,并不是所有的服务器都需要做高并发性能调优,<span style="color: black;">通常</span><span style="color: black;">来讲</span>,只需要对要处理高并发请求的服务器进行内核参数调优<span style="color: black;">就可</span>,<span style="color: black;">平常</span>的<span style="color: black;">包含</span>:前端服务器,后端服务器,数据库服务器。</p>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">服务器<span style="color: black;">平常</span>的调优参数<span style="color: black;">重点</span>有两个:单个进程最大打开文件数 和 TCP<span style="color: black;">关联</span>设置。</p>
    <h1 style="color: black; text-align: left; margin-bottom: 10px;">单个进程最大打开文件数</h1>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">修改单个文件最大打开文件数,只需要编辑/etc/security/limits.conf文件,在文件末尾加上以下四句</p><span style="color: black;">* </span>soft nofile 65535
    <span style="color: black;">* </span>hard nofile 65535
    <span style="color: black;">* </span>soft nproc 65535
    <span style="color: black;">* </span>hard nproc 65535<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">其中* <span style="color: black;">表率</span>所有用户,65536<span style="color: black;">表率</span>修改的值,重启后生效。</p>
    <h1 style="color: black; text-align: left; margin-bottom: 10px;">TCP<span style="color: black;">关联</span>设置</h1>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">修改TCP相关参数,<span style="color: black;">能够</span>优化TCP高并发通信,编辑/etc/sysctl.conf文件,添加以下内容</p><span style="color: black;"># 为防止洪水攻击,高并发系统需要将此项关闭</span>
    <span style="color: black;">net.ipv4.tcp_syncookies</span> <span style="color: black;">=</span> <span style="color: black;">0</span>

    <span style="color: black;"># 开启TCP连接重用,<span style="color: black;">准许</span>处理TIME-WAIT状态的连接重新用于新的TCP连接</span>
    <span style="color: black;">net.ipv4.tcp_tw_reuse</span> <span style="color: black;">=</span> <span style="color: black;">1</span>

    <span style="color: black;"># 开启快速回收TCP连接中<span style="color: black;">处在</span>TIME-WAIT状态的连接</span>
    <span style="color: black;">net.ipv4.tcp_tw_recycle</span> <span style="color: black;">=</span> <span style="color: black;">1</span>

    <span style="color: black;">#修改超时时间(</span> <span style="color: black;">s</span> <span style="color: black;">),该值<span style="color: black;">暗示</span><span style="color: black;">倘若</span>连接由本端关闭,则连接<span style="color: black;">处在</span></span> <span style="color: black;">FIN-WAIT-2状态的时间为</span>
    <span style="color: black;">net.ipv4.tcp_fin_timeout</span> <span style="color: black;">=</span> <span style="color: black;">30</span>

    <span style="color: black;">#当</span> <span style="color: black;">keepalive(长连接)启用的时候,TCP发送</span> <span style="color: black;">keepalive</span> <span style="color: black;"><span style="color: black;">信息</span>(探测包)的时间间隔(</span> <span style="color: black;">s</span> <span style="color: black;">),默认为2个小时</span>
    <span style="color: black;">net.ipv4.tcp_keepalive_time</span> <span style="color: black;">=1200</span>

    <span style="color: black;">#服务器对外连接的端口范围,影响该服务器与其他服务器的连接数</span>
    <span style="color: black;">net.ipv4.ip_local_port_range</span> <span style="color: black;">=102465535</span>

    <span style="color: black;">#SYN队列的长度,<span style="color: black;">能够</span>容纳<span style="color: black;">更加多</span>等待连接的网络连接数,默认为1024</span>
    <span style="color: black;">net.ipv4.tcp_max_syn_backlog</span> <span style="color: black;">=</span> <span style="color: black;">65535</span>

    <span style="color: black;">#保持</span> <span style="color: black;">TIME_WAIT</span> <span style="color: black;">状态连接的最大数量,<span style="color: black;">倘若</span>超过此值,TIME_WAIT</span> <span style="color: black;">将立刻被清除并打印警告信息,默认为180000</span>
    <span style="color: black;">net.ipv4.tcp_max_tw_buckets</span> <span style="color: black;">=5000</span>

    <span style="color: black;">#<span style="color: black;">每一个</span>网络接口接收数据包的速率比内核处理这些包的速率快时,<span style="color: black;">准许</span>送到队列的数据包的最大数目</span>
    <span style="color: black;">net.core.netdev_max_backlog</span> <span style="color: black;">=65535</span>

    <span style="color: black;"># TCP最大连接数</span>
    <span style="color: black;">net.core.somaxconn</span> <span style="color: black;">=</span> <span style="color: black;">65535</span>

    <span style="color: black;">#预留用于接收缓冲的内存默认值(字节)</span>
    <span style="color: black;">net.core.rmem_default</span> <span style="color: black;">=</span> <span style="color: black;">8388608</span>

    <span style="color: black;">#预留用于接收缓冲的内存最大值(字节)</span>
    <span style="color: black;">net.core.rmem_max</span> <span style="color: black;">=</span> <span style="color: black;">16777216</span>

    <span style="color: black;">#预留用于发送缓冲的内存默认值(字节)</span>
    <span style="color: black;">net.core.wmem_default</span> <span style="color: black;">=</span> <span style="color: black;">8388608</span>

    <span style="color: black;">#预留用于发送缓冲的内存最大值(字节)</span>
    <span style="color: black;">net.core.wmem_maX</span> <span style="color: black;">=</span> <span style="color: black;">16777216</span>

    <span style="color: black;">#避免时间戳<span style="color: black;">反常</span></span>
    <span style="color: black;">net.ipv4.tcp_timestamps</span> <span style="color: black;">=</span> <span style="color: black;">0</span>

    <span style="color: black;">#系统中最多有多少个</span> <span style="color: black;">TCP</span> <span style="color: black;">套接字不被<span style="color: black;">相关</span>到任何一个用户文件句柄上,<span style="color: black;">倘若</span>超过这个数字,连接将即刻被复位并打印警告信息,这个限制仅仅是为了防止简单的DoS</span> <span style="color: black;">攻击</span>
    <span style="color: black;">net.ipv4.tcp_max_orphans</span> <span style="color: black;">=3276800</span>
    <div style="color: black; text-align: left; margin-bottom: 10px;"><img src="https://p26-sign.toutiaoimg.com/tos-cn-i-qvj2lq49k0/82f4ea94925441e593927a8378060316~noop.image?_iz=58558&amp;from=article.pc_detail&amp;lk3s=953192f4&amp;x-expires=1725618492&amp;x-signature=kNjfeto%2BtX7qd3jZpg1eH6uASjw%3D" style="width: 50%; margin-bottom: 20px;"></div>
    <p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">原文链接:</p>https://juejin.cn/post/7106103652435263496




很甜的橙橙橙子 发表于 2024-9-8 14:53:52

我深感你的理解与共鸣,愿对话长流。

nqkk58 发表于 2024-11-3 09:31:34

外链发布论坛学习网络优化SEO。

4zhvml8 发表于 2024-11-10 20:50:02

楼主的文章深得我心,表示由衷的感谢!
页: [1]
查看完整版本: 聊聊服务器优化~(意见保藏)