首先说下 先看 按照ab 每秒请求的结果 看看 都有每秒能请求几个 如果并发量超出你请求的个数 会这样 所以一般图片和代码服务器最好分开 还有看看io瓶ding 和有没有延迟的PHP代码执行

0 先修改内核参数

<pre>
1、调整同时打开文件数量

ulimit -n 20480
2、TCP最大连接数(somaxconn)

echo 10000 > /proc/sys/net/core/somaxconn
3、TCP连接立即回收、回用(recycle、reuse)

echo 1 > /proc/sys/net/ipv4/tcp_tw_reuse
echo 1 > /proc/sys/net/ipv4/tcp_tw_recycle
4、不做TCP洪水抵御

echo 0 > /proc/sys/net/ipv4/tcp_syncookies
</pre>
也可以直接使用优化后的配置,在/etc/sysctl.conf中加入:
<pre>
net.core.somaxconn = 20480
net.core.rmem_default = 262144
net.core.wmem_default = 262144
net.core.rmem_max = 16777216
net.core.wmem_max = 16777216
net.ipv4.tcp_rmem = 4096 4096 16777216
net.ipv4.tcp_wmem = 4096 4096 16777216
net.ipv4.tcp_mem = 786432 2097152 3145728
net.ipv4.tcp_max_syn_backlog = 16384
net.core.netdev_max_backlog = 20000
net.ipv4.tcp_fin_timeout = 15
net.ipv4.tcp_max_syn_backlog = 16384
net.ipv4.tcp_tw_reuse = 1
net.ipv4.tcp_tw_recycle = 1
net.ipv4.tcp_max_orphans = 131072
net.ipv4.tcp_syncookies = 0
</pre>

然后修改nginx.conf 比如worker_processes等等

1 查看nginx错误日记 error.log日志得到connect() to unix:/tmp/php-cgi.sock failed xxxxx........
如果是因为突然的网站访问量大(这里说明这个是说tcp过高,并不能说明cpu过高和内存使用率过高,带宽过高)导致那么一般是因为子进程数不足:
到php-fpm.conf找到max_children也就是子进程最大数改为:<value name="max_children">128</value>

2

<pre>
tail -n 10 /var/log/messages

Dec 1 15:33:31 iZ238qupob7Z kernel: TCP: time wait bucket table overflow
Dec 1 15:33:31 iZ238qupob7Z kernel: TCP: time wait bucket table overflow
Dec 1 15:33:31 iZ238qupob7Z kernel: TCP: time wait bucket table overflow
Dec 1 15:33:31 iZ238qupob7Z kernel: TCP: time wait bucket table overflow
Dec 1 15:33:31 iZ238qupob7Z kernel: TCP: time wait bucket table overflow
Dec 1 15:33:31 iZ238qupob7Z kernel: TCP: time wait bucket table overflow
Dec 1 15:33:31 iZ238qupob7Z kernel: TCP: time wait bucket table overflow
Dec 1 15:33:32 iZ238qupob7Z kernel: TCP: time wait bucket table overflow
Dec 1 15:33:32 iZ238qupob7Z kernel: TCP: time wait bucket table overflow
Dec 1 15:33:32 iZ238qupob7Z kernel: TCP: time wait bucket table overflow
</pre>
time wait bucket table overflow 这种代表 服务器的TCP连接数,超出了内核定义最大数

查看当前的内核定义最大数
<pre>
cat /proc/sys/net/ipv4/tcp_max_tw_buckets
</pre>

<pre>
解决方法:
修改内核参数 /proc/sys/net/ipv4/tcp_max_tw_buckets
# echo 30000 > /proc/sys/net/ipv4/tcp_max_tw_buckets
写入/etc/sysctl.conf使之永久生效
echo 'net.ipv4.tcp_max_tw_buckets = 30000' >> /etc/sysctl.conf && sysctl -p
</pre>

3 当然也有可能PHP代码 消耗太多CPU 执行时间过长 将采取如下方法 看看里面的错误连接的链接是不是请求时间过长

nginx recv() failed (104: Connection reset by peer) while reading response header from upstream解决方法 除了升级服务器配置还有以下方法可以参考下

request_terminate_timeout = 0//这样 就不怕了 之前是PHP执行时间因为超过了设置的值所以报错 这个时候需要重启php-fpm 或者等他自己重启时间相当漫长
还有另外设置下PHP限制执行时间 设置2秒即可 超过2秒就直接报错让用户不要继续访问了 就不影响服务器性能了
<pre>
max_execution_time = 10;
</pre>

比如像导出excel耗时的 在代码中加
<pre>
set_time_limit(0);
</pre>

ps:可以开启慢查询日记 PHP执行超过1秒的记录下
<pre>
slowlog = /data/logs/php-fpm.log.slow
request_slowlog_timeout = 6
</pre>

4 如果以上都不行 图片都用CDN 或者就直接再买个服务器负载均衡就好了 买1个星期的 估计能抗几下

复制ecs实例的方法
1、系统盘
通过创建自定义镜像的方式,创建一个自定义镜像,然后使用这个自定义镜像创建ECS即可。
http://help.aliyun.com/knowledge_detail.htm?spm=5176.7114037.1996646101.1.uamHK9&categoryId=8314847&knowledgeId=5974456&pos=1

2、数据盘
对已经配置完成的数据盘进行打快照。
然后在购买或者升级页面,添加磁盘的地方点:“用快照创建磁盘”,选择你要的快照即可。

nginx recv() failed (104: Connection reset by peer) while reading response header from upstream解决方法的更多相关文章

  1. recv() failed (104: Connection reset by peer) while reading response header from upstream

    2017年12月1日10:18:34 情景描述: 浏览器执行了一会儿, 报500错误 运行环境:  nginx + php-fpm nginx日志:  recv() failed (104: Conn ...

  2. 转:get value from agent failed: ZBX_TCP_READ() failed;[104] connection reset by peer

    get value from agent failed: ZBX_TCP_READ() failed;[104] connection reset by peer zabbix都搭建好了,进行一下测试 ...

  3. nginx错误分析 `104: Connection reset by peer`

    故障描述 应用从虚拟机环境迁移到kubernetes环境中,有些应用不定时出现请求失败的情况,且应用没有记录任何日志,而在NGINX中记录502错误.我们查看了之前虚拟机中的访问情况,没有发现该问题. ...

  4. fwrite(): send of 8192 bytes failed with errno=104 Connection reset by peer

    问题:fwrite(): send of 8192 bytes failed with errno=104 Connection reset by peer 问题描述 通过mysql + sphinx ...

  5. 【Azure Redis 缓存】 Python连接Azure Redis, 使用redis.ConnectionPool 出现 "ConnectionResetError: [Errno 104] Connection reset by peer"

    问题描述 Python连接Azure Redis, 使用redis.ConnectionPool 出现 "ConnectionResetError: [Errno 104] Connecti ...

  6. Error -27780: [GENERAL_MSG_CAT_SSL_ERROR]connect to host "124.202.213.70" failed: [10054] Connection reset by peer [MsgId: MERR-27780]

    解决方案一: 备注: 此方案如果请求响应时间太长,勾选"WinInet replay instead of Sockets(Windows only)"将会导致如下错误:

  7. OGG-01232 Receive TCP params error: TCP/IP error 104 (Connection reset by peer), endpoint:

    源端: 2015-02-05 17:45:49 INFO OGG-01815 Virtual Memory Facilities for: COM anon alloc: mmap(MAP_ANON) ...

  8. java.net.SocketException: recvfrom failed: ECONNRESET (Connection reset by peer)

    java.net.SocketException: recvfrom failed: ECONNRESET (Connection reset by peer)

  9. urllib2.URLError: <urlopen error [Errno 104] Connection reset by peer>

    http://www.dianping.com/shop/8010173 File "综合商场1.py", line 152, in <module>    httpC ...

随机推荐

  1. asp.net mvc select用法

    var statusSelectItems = new List<SelectListItem> { "}, "}, "}, "}, "} ...

  2. maven在线自动更新太慢怎么办?

    使用IDEA和Eclipse开发maven项目时,maven在添加一项新的依赖时,如果发现本地仓库没有,就会向位于国外服务器的中央仓库下载.如果所处网络没有翻墙,下载速度会慢到你想原地爆炸. 这个时候 ...

  3. Java序列化总结(最全)

    概念 实现 Serializable 接口, 它只是一个标记接口,不实现也能够进行序列化 RMI: 远程方法调用 RPC: 远程过程调用 序列化ID 解决了序列化与反序列出现代码不一致的问题, 不一致 ...

  4. 如何成为一个伟大的 JavaScript 程序员

    这篇文章主要概述在我5年工作经验的基础上,我成为优秀JavaScript开发人员所使用的技术和资源. 当前大多数Web开发人员面临着这样一个共同的问题:他们必须在多个不同的领域领先于他人——从数据库到 ...

  5. Oracle数据库提权(dba权限执行系统命令)

    0x01 提权准备 这里我们先创建一个低权限的用户test SQL> conn sys/admin123@orcl as sysdba; 已连接. SQL> create user tes ...

  6. macbook使用美化工具在屏幕展示出常查信息

    磕叨 凭本人自己的经验,写代码过程中要经常查看内存使用网络流量下等,所以经常用到命令去查,而且mac上的命令跟linux上又有些不一样,经常打错. 多年前还没用mac前我用的是ubnutu,那时还是1 ...

  7. Intel Sandy Bridge Microarchitecture Events

    This is a list of all Intel Sandy Bridge Microarchitecture performance counter event types. Please s ...

  8. .NET Core3.0创建Worker Services

    .NET CORE 3.0新增了Worker Services的新项目模板,可以编写长时间运行的后台服务,并且能轻松的部署成windows服务或linux守护程序.如果安装的vs2019是中文版本,W ...

  9. VSCode 配置 Python 开发环境

    一.环境准备 首先需要先安装好 Python 和 VSCode, 下载地址如下 VSCode Python 二.安装 Python 扩展 首先在VSCode上安装 Python 扩展,如图: 三.新建 ...

  10. TCC推导过程

    svn 账号 yuanzn 密码:TCH5mb 项目分层 MapperDao 数据校验 throw new CloudBaseRuntimeException Helper 数据转换 manager ...