您的位置:首页 > 理论基础 > 计算机网络

MySQL 调优基础(五) Linux网络

2015-10-11 11:42 477 查看
1. TCP/IP模型

我们一般知道OSI的网络参考模型是分为7层:“应表会传网数物”——应用层,表示层,会话层,传输层,网络层,数据链路层,物理层。而实际的Linux网络层协议是参照了OSI标准,但是它实现为4层:应用层,传输层,网络层,网络接口层。OSI的多层对应到了实际实现中的一层。我们最为关注的是传输层和网络层。一般而言网络层也就是IP层,负责IP路由寻址等等细节,而传输层TCP/UDP负责数据的可靠/快速的传输功能。

[root@localhost ~]# ethtool --show-offload eth0
Features for eth0:
rx-checksumming: on
tx-checksumming: on
tx-checksum-ipv4: off
tx-checksum-unneeded: off
tx-checksum-ip-generic: on
tx-checksum-ipv6: off
tx-checksum-fcoe-crc: off [fixed]
tx-checksum-sctp: off [fixed]
scatter-gather: on
tx-scatter-gather: on
tx-scatter-gather-fraglist: off [fixed]
tcp-segmentation-offload: on
tx-tcp-segmentation: on
tx-tcp-ecn-segmentation: off
tx-tcp6-segmentation: off
udp-fragmentation-offload: off [fixed]
generic-segmentation-offload: on
generic-receive-offload: on
large-receive-offload: off [fixed]
rx-vlan-offload: on [fixed]
tx-vlan-offload: on [fixed]
ntuple-filters: off [fixed]
receive-hashing: off [fixed]
highdma: off [fixed]
rx-vlan-filter: on [fixed]
vlan-challenged: off [fixed]
tx-lockless: off [fixed]
netns-local: off [fixed]
tx-gso-robust: off [fixed]
tx-fcoe-segmentation: off [fixed]
tx-gre-segmentation: off [fixed]
tx-udp_tnl-segmentation: off [fixed]
fcoe-mtu: off [fixed]
loopback: off [fixed]


View Code
ethtool -K eth0 rx on|off, ethtool -K eth0 tx on|off, ethtool -K eth0 tso on|off 进行修改

10.6 调大 接收队列和发送队列的大小:

1)接收队列:/proc/sys/net/core/netdev_max_backlog 对应内核参数:net.core.netdev_max_backlog

2)发送队列:

[root@localhost ~]# ifconfig eth0 | grep txqueue
collisions:0 txqueuelen:1000


进行修改:ifconfig eth0 txqueuelen 20000

10.7 调大 SYN 半连接 [b]tcp_max_syn_backlog 数量[/b]

TCP三次握手建立连接时,被动打开方,有一个状态是SYN,

When the server is heavily loaded or has many clients with bad connections with high latency, it can result in an increase in half-open connections. This is common for Web servers, especially when there are a lot of dial-up users. These half-open connections are stored in the backlog connections queue. You should set this value to at least 4096. (The default is 1024.)
Setting this value is useful even if your server does not receive this kind of connection, because it can still be protected from a DoS (syn-flood) attack.

cat /proc/sys/net/ipv4/tcp_max_syn_backlog 对应内核参数: net.ipv4.tcp_max_syn_backlog,可以在/etc/sysctl.conf文件中配置。

sysctl -w net.ipv4.tcp_max_syn_backlog=4096

当服务器负载很重时,会导致很多的客户端的连接,服务器没有进行确认,所以就处在 SYN 状态,这就是所谓的半连接(half-open connection).半连接的数目由 tcp_max_syn_backlog 参数控制,增大它可以避免客户端的连接被拒绝,同时也能防御SYN洪水攻击。也就是可以容纳更多的等待连接的数量。

10.8 /proc/sys/net/core/somaxconn 和 net.core.somaxconn

该参数为完成3次握手,已经建立了连接,等待被accept然后进行处理的数量。默认为128,我们可以调整到 65535,甚至更大。也就是尅有容纳更多的等待处理的连接。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: