×ðÁú¿­Ê±¹ÙÍøµÇ¼

ÔõÑùÓÅ»¯LinuxϵͳµÄTCP/IPÐÔÄܺÍÍøÂçÐÔÄÜ

ÔÚÏÖ´úÅÌËã»úÁìÓò£¬TCP/IPЭÒéÊÇʵÏÖÍøÂçͨѶµÄ»ù´¡¡£Linux×÷Ϊ¿ª·ÅÔ´´úÂë²Ù×÷ϵͳ£¬ÒѳÉΪÐí¶àÆóÒµºÍ×é֯ʹÓõÄÊ×Ñ¡²Ù×÷ϵͳ¡£È»¶ø£¬Ëæ×ÅÍøÂçÓ¦ÓóÌÐòºÍЧÀÍÔ½À´Ô½³ÉΪӪҵµÄÒªº¦×é³É²¿·Ö£¬ÖÎÀíÔ±ÍùÍùÐèÒªÓÅ»¯ÍøÂçÐÔÄÜ£¬ÒÔÈ·± £¿ìËٺͿɿ¿µÄÊý¾Ý´«Êä¡£

±¾ÎĽ«ÏÈÈÝÔõÑùͨ¹ý¶ÔLinuxϵͳ¾ÙÐÐTCP/IPÐÔÄܺÍÍøÂçÐÔÄÜÓÅ»¯À´Ìá¸ßLinuxϵͳµÄÍøÂç´«ÊäËÙÂÊ¡£±¾ÎĽ«Ì½ÌÖһЩÐëÒªµÄTCP²ÎÊý£¬ÒÔ¼°ÔõÑù¸ü¸ÄÕâЩ²ÎÊýÒÔÓÅ»¯ÍøÂçÐÔÄÜ¡£±¾ÎÄ»¹½«ÏÈÈÝÔõÑùʹÓÃһЩ³£ÓõÄCLIºÍÄں˹¤¾ßÀ´¼ì²éϵͳÖеÄÍøÂçÐÔÄÜ£¬²¢Îª¶ÁÕßÌṩһЩ´úÂëʾÀý¡£

Ò»¡¢Ïàʶtcp tw_reuse

TCPÅþÁ¬ÊÇÒ»ÖÖÃæÏòÅþÁ¬µÄ´«ÊäЭÒ飬Òò´ËIPµØµãºÍ¶Ë¿Ú×éºÏ±ØÐè²î±ð²Å»ª½¨ÉèÐÂÅþÁ¬¡£ÔÚ¿Í»§¶ËÓëЧÀÍÆ÷ÒѾ­¹Ø±Õ£¬µ«LinuxÈÔÔÚÆÚ´ý¿ÉÄÜ×î½ü½¨ÉèÅþÁ¬µÄÒ»¶Îʱ¼äÖ®ºó£¬»áʵÑ齨ÉètcpÅþÁ¬¡£Õâһʱ¼ä¶Î±»³ÆΪ¡°TIME_WAIT¡±×´Ì¬£¬´Ë״̬ϵÄÅþÁ¬²»¿É±»¸´Óá£ÕâÖÖÐÐΪ»á¼õ»ºÐ§ÀÍÆ÷µÄTCP/IPÐÔÄÜ¡£

ΪÁË×èÖ¹ÕâÖÖÇéÐΣ¬ÎÒÃÇ¿ÉÒÔʹÓÃtw_reuse²ÎÊý¡£ÆôÓÃtw_reuse¿ÉÒÔÔÊÐíÒѾ­Í˳öµÄÅþÁ¬±»ÖØÓ㬶øÎÞÐèÆÚ´ýһ׼ʱ¼ä¡ £¿ÉÒÔͨ¹ýÒÔÏÂÏÂÁîÆôÓøòÎÊý£º

echo 1 >/proc/sys/net/ipv4/tcp_tw_reuse

µÇ¼ºó¸´ÖÆ

¶þ¡¢Êʵ±µ÷½âTCP keepalive²ÎÊý

TCP keepaliveÊÇÒ»ÖÖ»úÖÆ£¬Äܹ»¼ì²âÅþÁ¬ÊÇ·ñÈÔÈ»´¦ÓÚÔ˶¯×´Ì¬£¬ÒÔ¼°±ÜÃâÓÉÓÚÍøÂçÓµÈûÎÊÌâÔì³ÉÅþÁ¬É¥Ê§¡£TCP keepalive°´ÆÚ¼ì²éÅþÁ¬×´Ì¬£¬ÒÔÈ·¶¨ÅþÁ¬ÊÇ·ñÈÔ´¦ÓÚÔ˶¯×´Ì¬£¬ÈôÊDz»ÊÇ£¬Ôò¹Ø±ÕÅþÁ¬¡£

µ÷½âTCP keepalive²ÎÊý¿ÉÒÔÌá¸ß´«ÊäÐÔÄÜ¡£ÒÔÏÂÊÇÈý¸öÖ÷ÒªµÄTCP²ÎÊý£º

1.tcp_keepalive_time

tcp_keepalive_time²ÎÊý½ç˵ÔÚ·¢Ëͼá³ÖÔ˶¯??±¨ÎÄÖ®¼äµÄʱ¼ä¾àÀë¡£ÈôÊÇÍøÂçÖеÄÒ»¸ö½ÚµãÎÞ·¨ÏìÓ¦£¬Ôòkeepalive»úÖÆ»áʵÑéÖØн¨ÉèÅþÁ¬¡£

ĬÈÏֵΪ7200Ã루¼´2Сʱ£©

2.tcp_keepalive_intvl

tcp_keepalive_intvl²ÎÊý½ç˵ÁË·¢Ëͼá³ÖÔ˶¯±¨ÎÄÖ®ºóµÄÖØÊÔʱ¼ä¾àÀë¡£

ĬÈÏֵΪ75Ãë

3.tcp_keepalive_probes

tcp_keepalive_probes½ç˵ÁËÔÚ·¢ËÍkeepalive±¨ÎÄ֮ǰ¾ÙÐÐÒ»ÔÙTCP̽²â¡£

ĬÈÏֵΪ9´Î

¿ÉÒÔ¸ü¸ÄÕâЩ²ÎÊýÒÔÌá¸ßTCPÐÔÄÜ¡£ÒÔÏÂÊǸü¸ÄÒÔÉÏÈý¸ö²ÎÊýµÄÏÂÁ

echo 600 >/proc/sys/net/ipv4/tcp_keepalive_time
echo 30 >/proc/sys/net/ipv4/tcp_keepalive_intvl
echo 5 >/proc/sys/net/ipv4/tcp_keepalive_probes

µÇ¼ºó¸´ÖÆ

Èý¡¢ÆôÓÃTCP´°¿ÚÀ©Õ¹Ñ¡Ïî

TCP´°¿ÚÀ©Õ¹£¨TCP Window Scaling£©ÊÇÒ»ÖÖÀ©Õ¹TCPÍ·²¿µÄÑ¡ÏÒÔÖ§³Ö¸ßËÙÍøÂ硣ĬÈÏÇéÐÎÏ£¬LinuxÄں˻á×Ô¶¯ÆôÓÃTCP´°¿ÚÀ©Õ¹Ñ¡Ïµ«ÈôÊÇÄúʹÓõÄÊǽϾɰ汾µÄÄںˣ¬Ôò¿ÉÄÜÐèÒªÆôÓøÃÑ¡Ïî¡£

ÒÔÏÂÊÇÆôÓÃTCP´°¿ÚÀ©Õ¹Ñ¡ÏîµÄÏÂÁ

echo 1 >/proc/sys/net/ipv4/tcp_window_scaling

µÇ¼ºó¸´ÖÆ

ËÄ¡¢Ê¹ÓÃifconfigµ÷½âMTUºÍMRUÖµ

MTU£¨×î´ó´«Ê䵥룩ÊÇÊý¾Ý°ü¿ÉÒÔ´«ÊäµÄ×î´ó¾Þϸ£¬¶øMRU£¨×î´óÎüÊÕµ¥Î»£©ÊÇÎüÊÕ¶ËËùÄÜÎüÊÕµÄ×î´óÊý¾Ý°ü¾Þϸ¡£

¸ü¸ÄMTUºÍMRUÖµ¿ÉÒÔÌá¸ßϵͳµÄÍøÂçÐÔÄÜ¡£ÎÒÃÇ¿ÉÒÔʹÓÃifconfigÏÂÁîÀ´¸ü¸ÄÕâЩֵ¡£ÒÔÏÂÊǸü¸ÄMTUºÍMRUµÄÏÂÁ

ifconfig eth0 mtu 9000
ifconfig eth0 mru 9000

µÇ¼ºó¸´ÖÆ

Î塢ʹÓÃiperf3²âÊÔÍøÂçÐÔÄÜ

iperf3ÊÇÒ»ÖÖÁ÷Á¿¼ì²âºÍÍøÂçЧÀÍÖÊÁ¿²âÊÔ¹¤¾ß¡£Ëü¿ÉÒÔ×ÊÖúÖÎÀíÔ±ÕÉÁ¿ÏµÍ³µÄÍøÂçÐÔÄÜ£¬²¢¼ì²éÍøÂçÓµÈûÇéÐΡ£Ê¹ÓÃiperf3¿ÉÒÔ¿ìËÙ·¢Ã÷ÍøÂçµÄÆ¿¾±£¬ÒÔ±ã¾ÙÐе÷ÓÅ¡£

Ê×ÏÈ£¬ÔÚЧÀÍÆ÷¶ËÆô¶¯iperf3¡£ÒÔÏÂÏÂÁî¿ÉÒÔÆô¶¯Ò»¸öTCPЧÀÍÆ÷£¬ÒÔÕìÌýĬÈ϶˿ڣº

iperf3 -s

µÇ¼ºó¸´ÖÆ

È»ºó£¬ÔÚ¿Í»§¶ËÉÏÔËÐÐiperf3£¬ÒÔ²âÊÔÍøÂçÐÅÏ¢µÄ¹ã²¥ËÙÂÊ¡£¹ØÓÚTCP²âÊÔ£¬Äú¿ÉÒÔÔËÐÐÒÔÏÂÏÂÁ

iperf3 -c <server-ip>

µÇ¼ºó¸´ÖÆ

Áù¡¢Ê¹ÓÃnetstatÏÂÁî¼à¿ØÍøÂçÐÔÄÜ

netstatÏÂÁîÊÇÒ»¸ö³£ÓõÄÏÂÁîÐй¤¾ß£¬¿ÉÓÃÓÚ¼ì²éLinuxϵͳÖеÄÍøÂçÅþÁ¬ºÍ´«ÊäÐÔÄÜ¡£

¿ÉÒÔʹÓÃÒÔÏÂÏÂÁîÀ´¼ì²éLinuxϵͳÖеÄTCPÅþÁ¬ÊýºÍ״̬£º

netstat -nat | grep -i "tcp.*established"

µÇ¼ºó¸´ÖÆ

¸ÃÏÂÁ·µ»ØÄ¿½ñ½¨ÉèµÄTCPÅþÁ¬µÄÊýÄ¿¡£½¨ÉèµÄÅþÁ¬ÊýÄ¿Ô½¶à£¬ÏµÍ³µÄTCP/IPÐÔÄܾͻáÔ½µÍ¡£

Æß¡¢Ê¹ÓÃsysctlÉó²éTCP/IP²ÎÊý

sysctlÊÇÒ»¸öÖÎÀíÄں˲ÎÊýµÄCLIÊÊÓóÌÐò¡ £¿ÉÒÔʹÓÃËüÀ´Éó²éºÍ¸ü¸ÄTCP/IP²ÎÊý¡£

ÒÔÏÂÊÇÉó²éTCP/IP²ÎÊýµÄÏÂÁ

sysctl -a | grep tcp

µÇ¼ºó¸´ÖÆ

ÎÒÃÇ¿ÉÒÔƾ֤ÐèÒª¸ü¸ÄÕâЩ²ÎÊý£¬ÒªÁìÊÇʹÓÃÒÔÏÂÏÂÁ

sysctl -w <parameter=value>

µÇ¼ºó¸´ÖÆ

ÀýÈ磬ÒÔÏÂÏÂÁ¸ü¸ÄTCP¿ÍÕ»µÄ×î´óÄÚ´æѹËõ´óС£º

sysctl -w net.ipv4.tcp_mem='10000000 10000000 10000000'

µÇ¼ºó¸´ÖÆ

°Ë¡¢Ê¹ÓÃtcpdump¼à¿ØÍøÂçÁ÷Á¿

tcpdumpÊÇÒ»ÖÖץȡÍøÂçÊý¾Ý°üµÄÏÂÁîÐÐÊÊÓù¤¾ß¡ £¿ÉÒÔʹÓÃËüÀ´¼à¿ØÍøÂçÁ÷Á¿£¬ÒÔ²éÕÒÍøÂç¹ÊÕÏ»òÆ¿¾±¡£

ÒÔÏÂÊÇʹÓÃtcpdumpÏÂÁ»ñÈëÕ¾ºÍ³öÕ¾TCPÁ÷Á¿µÄÏÂÁ

tcpdump -i eth0 -vv tcp

µÇ¼ºó¸´ÖÆ

¿ÉÒÔ½«ÆäÊä³öÖض¨Ïòµ½ÎļþÖУ¬È»ºóʹÓÃwiresharkÉó²é£º

tcpdump -i eth0 -vv tcp -w <filename>
wireshark <filename>

µÇ¼ºó¸´ÖÆ

½áÂÛ

ͨ¹ýÊÊÍâµØÉèÖÃTCP/IPºÍÍøÂç²ÎÊý£¬¿ÉÒÔÌá¸ßLinuxϵͳµÄÍøÂçÐÔÄÜ¡£Í¨¹ý±¾ÎÄÌṩµÄCLIºÍÄں˹¤¾ß£¬ÖÎÀíÔ±¿ÉÒÔ¸üºÃµØÃ÷ȷϵͳµÄÍøÂçÐÔÄܲ¢¾ÙÐÐÓÅ»¯¡£±¾ÎÄÌṩ´úÂëʾÀý£¬ÒÔ×ÊÖúÖÎÀíÔ±¸üºÃµØÃ÷È·ÔõÑùÓÅ»¯TCP/IPÐÔÄܺÍÍøÂçÐÔÄÜ¡£

ÒÔÉϾÍÊÇÔõÑùÓÅ»¯LinuxϵͳµÄTCP/IPÐÔÄܺÍÍøÂçÐÔÄܵÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡

ÃâÔð˵Ã÷£ºÒÔÉÏչʾÄÚÈÝȪԴÓÚÏàÖúýÌå¡¢ÆóÒµ»ú¹¹¡¢ÍøÓÑÌṩ»òÍøÂçÍøÂçÕûÀí£¬°æȨÕùÒéÓë±¾Õ¾Î޹أ¬ÎÄÕÂÉæ¼°¿´·¨Óë¿´·¨²»´ú±í×ðÁú¿­Ê±¹ÙÍøµÇ¼ÂËÓÍ»úÍø¹Ù·½Ì¬¶È£¬Çë¶ÁÕß½ö×ö²Î¿¼¡£±¾ÎĽӴýתÔØ£¬×ªÔØÇë˵Ã÷À´ÓÉ¡£ÈôÄúÒÔΪ±¾ÎÄÇÖÕ¼ÁËÄúµÄ°æȨÐÅÏ¢£¬»òÄú·¢Ã÷¸ÃÄÚÈÝÓÐÈκÎÉæ¼°ÓÐÎ¥¹«µÂ¡¢Ã°·¸Ö´·¨µÈÎ¥·¨ÐÅÏ¢£¬ÇëÄúÁ¬Ã¦ÁªÏµ×ðÁú¿­Ê±¹ÙÍøµÇ¼ʵʱÐÞÕý»òɾ³ý¡£

Ïà¹ØÐÂÎÅ

ÁªÏµ×ðÁú¿­Ê±¹ÙÍøµÇ¼

18523999891

¿É΢ÐÅÔÚÏß×Éѯ

ÊÂÇéʱ¼ä£ºÖÜÒ»ÖÁÖÜÎ壬9:30-18:30£¬½ÚãåÈÕÐÝÏ¢

QR code
ÍøÕ¾µØͼ