![可以为每个 IP 提供一个连接吗?](https://linux22.com/image/598791/%E5%8F%AF%E4%BB%A5%E4%B8%BA%E6%AF%8F%E4%B8%AA%20IP%20%E6%8F%90%E4%BE%9B%E4%B8%80%E4%B8%AA%E8%BF%9E%E6%8E%A5%E5%90%97%EF%BC%9F.png)
我遇到了过载问题。连接太多,有些 IP 一次有超过 20 个连接。我执行此命令。
netstat -anp |grep 'tcp\|udp' | awk '{print $5}' | cut -d: -f1 | sort | uniq -c | sort -n
获取连接总数,这是输出:
1 106.3.98.81
1 106.3.98.82
1 108.171.251.2
1 110.85.103.207
1 111.161.30.217
1 113.53.103.55
1 119.235.237.20
1 124.106.19.34
1 157.55.32.166
1 157.55.33.49
1 157.55.34.28
1 175.141.103.239
1 180.76.5.59
1 180.76.5.61
1 188.235.165.216
1 205.213.195.70
1 216.157.222.25
1 218.93.205.100
1 222.77.209.105
1 27.153.148.109
1 27.159.194.242
1 27.159.253.71
1 54.242.122.201
1 61.172.50.99
1 65.55.24.239
1 71.179.78.5
1 74.125.136.27
1 74.125.182.30
1 74.125.182.36
1 79.112.225.39
1 93.190.139.208
2 124.227.191.67
2 157.55.33.84
2 157.55.35.34
2 190.66.3.107
2 203.87.153.38
2 220.161.119.3
2 221.6.15.156
2 27.153.148.116
2 27.159.197.0
2 96.47.224.42
3 202.14.70.1
3 218.6.15.42
3 222.77.218.226
3 222.77.224.187
3 37.59.66.100
3 46.4.181.244
3 87.98.254.192
3 91.207.8.62
4 188.143.233.222
4 218.108.168.166
4 221.12.154.18
4 93.182.157.8
4 94.142.128.183
5 180.246.170.187
5 8.21.6.226
6 178.137.94.87
6 218.93.205.112
7 199.15.234.222
9
9 125.253.97.6
10 178.137.17.196
11 46.118.192.179
12 212.79.14.14
21 72.201.187.135
27 0.0.0.0
谁能给我一些指导,由于这个原因,我的服务器这周崩溃了几次。
谢谢。
编辑:
好的,我的错误日志显示:
[Thu Oct 18 12:17:39 2012] [error] could not make child process 4842 exit, attempting to continue anyway
[Thu Oct 18 12:17:39 2012] [error] could not make child process 4843 exit, attempting to continue anyway
[Thu Oct 18 12:17:39 2012] [error] could not make child process 4855 exit, attempting to continue anyway
[Thu Oct 18 12:17:39 2012] [error] could not make child process 4856 exit, attempting to continue anyway
[Thu Oct 18 12:17:39 2012] [error] could not make child process 4861 exit, attempting to continue anyway
[Thu Oct 18 12:17:39 2012] [error] could not make child process 4869 exit, attempting to continue anyway
[Thu Oct 18 12:17:39 2012] [error] could not make child process 4872 exit, attempting to continue anyway
[Thu Oct 18 12:17:39 2012] [error] could not make child process 4873 exit, attempting to continue anyway
[Thu Oct 18 12:17:39 2012] [error] could not make child process 4874 exit, attempting to continue anyway
[Thu Oct 18 12:17:39 2012] [error] could not make child process 4875 exit, attempting to continue anyway
[Thu Oct 18 12:17:39 2012] [error] could not make child process 4876 exit, attempting to continue anyway
[Thu Oct 18 12:17:39 2012] [error] could not make child process 4880 exit, attempting to continue anyway
[Thu Oct 18 12:17:39 2012] [error] could not make child process 4882 exit, attempting to continue anyway
[Thu Oct 18 12:17:39 2012] [error] could not make child process 4885 exit, attempting to continue anyway
[Thu Oct 18 12:17:39 2012] [error] could not make child process 4897 exit, attempting to continue anyway
[Thu Oct 18 12:17:39 2012] [error] could not make child process 4900 exit, attempting to continue anyway
[Thu Oct 18 12:17:39 2012] [error] could not make child process 4901 exit, attempting to continue anyway
[Thu Oct 18 12:17:39 2012] [error] could not make child process 4906 exit, attempting to continue anyway
[Thu Oct 18 12:17:39 2012] [error] could not make child process 4907 exit, attempting to continue anyway
[Thu Oct 18 12:17:39 2012] [error] could not make child process 4925 exit, attempting to continue anyway
[Thu Oct 18 12:17:39 2012] [error] could not make child process 4926 exit, attempting to continue anyway
[Thu Oct 18 12:17:39 2012] [error] could not make child process 4927 exit, attempting to continue anyway
[Thu Oct 18 12:17:39 2012] [error] could not make child process 4931 exit, attempting to continue anyway
[Thu Oct 18 12:17:40 2012] [notice] caught SIGTERM, shutting down
PHP Warning: PHP Startup: Unable to load dynamic library '/usr/lib/php5/20060613+lfs/curl.iso' - /usr/lib/php5/20060613+lfs/curl.iso: cannot open shared object file: No such file or directory in Unknown on line 0
[Thu Oct 18 12:17:45 2012] [notice] Apache/2.2.9 (Debian) PHP/5.2.6-1+lenny10 with Suhosin-Patch configured -- resuming normal operations
我有数千行语句:(每个都有不同的进程 ID)
[Thu Oct 18 12:17:38 2012] [error] child process 4906 still did not exit, sending a SIGKILL
我还有一句话:
[Wed Oct 17 09:44:58 2012] [error] server reached MaxClients setting, consider raising the MaxClients setting
<IfModule prefork.c>
StartServers 8
MinSpareServers 5
MaxSpareServers 50
MaxClients 300
MaxRequestsPerChild 5000
</IfModule>
答案1
该命令忽略连接的状态。以下命令仅显示处于该ESTABLISHED
状态的连接。
netstat -anp |grep 'tcp\|udp' | awk '/ESTABLISHED/ {print $5}' | cut -d: -f1 | sort | uniq -c | sort -n
这个对它们进行分组和聚合:
netstat -tn | awk '/tcp/ {print $5, $6}' | sed 's/:[^ ]*//' | sort | uniq -c | sort -n
还有几个问题:
- “我的服务器崩溃了”是什么意思?操作系统重启?Apache 没有响应? 确切地发生了什么。
- 您如何知道连接数是导致“崩溃”的原因?如果您收到一条错误消息,指出“连接数过多;正在中止。”那就好了。如果没有,让我们先调查一下,然后再得出结论。