节点异常连接数

Posted by Zeusro on May 21, 2020
👈🏻 Select language

常用命令

1
iftop -i eth0 -nNB -m 10M

image

查看不同状态的连接数数量

1
netstat -an | awk '/^tcp/ {++y[$NF]} END {for(w in y) print w, y[w]}'
1
2
3
4
5
6
7
8
9
10
11
12
[root@dddd ~]# ss  -s

Total: 9599 (kernel 9688)
TCP:   12227 (estab 26, closed 12043, orphaned 6, synrecv 0, timewait 4920/0), ports 0

Transport Total     IP        IPv6
*         9688      -         -
RAW       0         0         0
UDP       14        8         6
TCP       184       35        149
INET      198       43        155
FRAG      0         0         0

这个是 closed 状态较多。

closed 状态只是表示连接恢复到初始的状态,这个socket 还在使用中, 而这样的话,后面程序有通信的话会继续使用这个socket ,不用重新分配,效率会有提高的。 不然重复创建销毁socket会带来很多消耗的。

补充知识

net.ipv4.tcp_retries2

默认是 15 ,即 linux 系统会监测一个 tcp 连接,如果没有数据量传输,最长要等到 15m 后才会释放

意思是 php 的服务,产生了大量没有关闭的连接

好像是 TIME_WAIT 状态的比较多

参考链接

  1. 浅谈iptables防SYN Flood攻击和CC攻击
  2. ss命令和Recv-Q和Send-Q状态
  3. 每天一个linux命令(57):ss命令

Common Commands

1
iftop -i eth0 -nNB -m 10M

image

View the number of connections in different states

1
netstat -an | awk '/^tcp/ {++y[$NF]} END {for(w in y) print w, y[w]}'
1
2
3
4
5
6
7
8
9
10
11
12
[root@dddd ~]# ss  -s

Total: 9599 (kernel 9688)
TCP:   12227 (estab 26, closed 12043, orphaned 6, synrecv 0, timewait 4920/0), ports 0

Transport Total     IP        IPv6
*         9688      -         -
RAW       0         0         0
UDP       14        8         6
TCP       184       35        149
INET      198       43        155
FRAG      0         0         0

This shows many connections in closed state.

The closed state only means the connection has returned to its initial state. This socket is still in use, so if the program needs to communicate later, it will continue using this socket without reallocation, which improves efficiency. Otherwise, repeatedly creating and destroying sockets would bring a lot of overhead.

Supplementary Knowledge

net.ipv4.tcp_retries2

Default is 15, meaning the Linux system will monitor a TCP connection. If there’s no data transmission, it will wait up to 15 minutes before releasing it.

This means PHP services have generated a large number of unclosed connections.

It seems there are many connections in TIME_WAIT state.

  1. Brief Discussion on iptables Preventing SYN Flood Attacks and CC Attacks
  2. ss Command and Recv-Q and Send-Q States
  3. One Linux Command Per Day (57): ss Command

Общие команды

1
iftop -i eth0 -nNB -m 10M

image

Просмотр количества соединений в разных состояниях

1
netstat -an | awk '/^tcp/ {++y[$NF]} END {for(w in y) print w, y[w]}'
1
2
3
4
5
6
7
8
9
10
11
12
[root@dddd ~]# ss  -s

Total: 9599 (kernel 9688)
TCP:   12227 (estab 26, closed 12043, orphaned 6, synrecv 0, timewait 4920/0), ports 0

Transport Total     IP        IPv6
*         9688      -         -
RAW       0         0         0
UDP       14        8         6
TCP       184       35        149
INET      198       43        155
FRAG      0         0         0

Это показывает много соединений в состоянии closed.

Состояние closed только означает, что соединение вернулось в свое начальное состояние. Этот сокет все еще используется, поэтому, если программе нужно общаться позже, она продолжит использовать этот сокет без перераспределения, что повышает эффективность. В противном случае повторное создание и уничтожение сокетов принесет много накладных расходов.

Дополнительные знания

net.ipv4.tcp_retries2

По умолчанию 15, что означает, что система Linux будет отслеживать TCP-соединение. Если передачи данных нет, она будет ждать до 15 минут перед освобождением.

Это означает, что службы PHP генерируют большое количество незакрытых соединений.

Похоже, много соединений в состоянии TIME_WAIT.

Ссылки

  1. Краткое обсуждение предотвращения атак SYN Flood и CC с помощью iptables
  2. Команда ss и состояния Recv-Q и Send-Q
  3. Одна команда Linux в день (57): команда ss