一个站点每天中午 down 掉大约 20 分钟,找不到原因

2021-08-15 12:35:24 +08:00
 nowheretoseek

因为用 uptimerobot 监控着,每天都收到邮件,所以能估计每天掉线的时间。每天都在大约 12:05-12:25,浮动三两分钟的样子。访问失败的原因是 connection timeout 。

网站程序是 apache,运行自己写的 PHP+Mysql 程序,放在腾讯云上,刚才访问失败期间去排查了下,有以下几个现象:

现在没有头绪,不知是啥问题,请各位指教。

1392 次点击
所在节点    问与答
18 条回复
redford42
2021-08-15 17:07:16 +08:00
你的站点被别人访问的时候挂掉
还是别人的网站你的服务去访问的时候会挂掉呢
hefish
2021-08-15 18:00:17 +08:00
换 nginx 吧。
nowheretoseek
2021-08-15 19:09:01 +08:00
@redford42 我的站挂掉,并且基本是每天按时挂掉,跟有无人访问关系并不大,毕竟流量很小。
nowheretoseek
2021-08-15 19:09:40 +08:00
@hefish 一直没来得及学会 nginx 的配置,apache 学的早比较习惯了,希望先解决这个问题。
hefish
2021-08-15 20:17:06 +08:00
因为没有更具体的信息,建议还是自行谷歌来解决。
我谷歌下来,都说是 apache 2.2 与 2.4 配置的差别。因为不清楚具体配置,所以无法进一步判断。
ysc3839
2021-08-16 10:22:26 +08:00
“同 IP 上的某静态小站”是同一个端口吗?
出现 connection timeout 个人怀疑是服务商封端口了,因为用户模式的程序似乎制造不出无回应的效果。要不然是没监听端口,或者监听了但不 accept,内核在 SYN 阶段直接发个 RST,错误会是 connection refused 。要不然是连接建立后发送 RST,错误会是 connection reset 。
nowheretoseek
2021-08-16 14:52:17 +08:00
@ysc3839 是同 80 端口,apache 下不同的 virtual host 。监控邮件显示”The monitor is currently DOWN (Connection Timeout)“
nowheretoseek
2021-08-16 14:53:33 +08:00
@hefish 谷歌过,没找到类似描述的问题,用 2.4 很久了,配置模板也一直用,用了好几个地方,就这个出问题。
ysc3839
2021-08-16 17:08:21 +08:00
@nowheretoseek 那说明监控程序的报告有问题,建议自己访问看看是什么错误。
hefish
2021-08-17 10:18:35 +08:00
贴一下 <VirtualHost /> 部分的配置吧
nowheretoseek
2021-08-17 15:01:30 +08:00
@ysc3839 中午问题重现时 curl 连接了以下,等了很久报错:`curl: (35) OpenSSL SSL_connect: SSL_ERROR_SYSCALL in connection to xxx.com:443`
nowheretoseek
2021-08-17 15:06:36 +08:00
@hefish 分了两部分,80 端口和 443 端口的,80 的自动跳到 443,并且 www 的自动跳到主域名;再就是为了减少恶意爬虫骚扰,用了个 https://github.com/mitchellkrogza/apache-ultimate-bad-bot-blocker,以下是完整配置,去除了注释:
```
# xxx.conf
<VirtualHost *:80>
Protocols h2 h2c http/1.1
ServerName xxx.com
ServerAlias www.xxx.com

ServerAdmin webmaster@localhost
DocumentRoot /var/www/html/xxx/public

<Directory /var/www/html/xxx/public>
Header set Access-Control-Allow-Origin *
Options -Indexes +FollowSymLinks
Include /etc/apache2/custom.d/globalblacklist.conf
DirectoryIndex index.php
AllowOverride All
Require all denied
</Directory>


ErrorLog ${APACHE_LOG_DIR}/xxx_error.log
CustomLog ${APACHE_LOG_DIR}/xxx_access.log combined

RewriteEngine on
RewriteCond %{SERVER_NAME} =xxx.com
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
RewriteCond %{SERVER_NAME} =www.xxx.com
RewriteRule ^ https://xxx.com%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>

# xxx-le-ssl.conf
<IfModule mod_ssl.c>
<VirtualHost *:443>
ServerName www.xxx.com
RewriteEngine on
RewriteCond %{SERVER_NAME} =www.xxx.com
RewriteRule ^ https://xxx.com%{REQUEST_URI} [END,NE,R=permanent]
SSLCertificateFile /etc/letsencrypt/live/xxx.com/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/xxx.com/privkey.pem
Include /etc/letsencrypt/options-ssl-apache.conf
</VirtualHost>

<VirtualHost *:443>
Protocols h2 h2c http/1.1
ServerName xxx.com

ServerAdmin webmaster@localhost
DocumentRoot /var/www/html/xxx/public

<Directory /var/www/html/xxx/public>
Header set Access-Control-Allow-Origin *
Options -Indexes +FollowSymLinks
Include /etc/apache2/custom.d/globalblacklist.conf
DirectoryIndex index.php
AllowOverride All
Require all denied
</Directory>

RewriteEngine on
RewriteRule .* - [E=REQ:%{THE_REQUEST}]

ErrorLogFormat "[%{u}t] [%-m:%l] [pid %P:tid %T] %7F: %E: [client %a] %M% ~ Referer: %-{Referer}i ~ Request: %{REQ}e ~ UserAgent: %{User-Agent}i"
ErrorLog ${APACHE_LOG_DIR}/xxx_error.log
CustomLog ${APACHE_LOG_DIR}/xxx_access.log combined

SSLCertificateFile /etc/letsencrypt/live/xxx.com-0001/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/xxx.com-0001/privkey.pem
Include /etc/letsencrypt/options-ssl-apache.conf
</VirtualHost>
</IfModule>

```
nowheretoseek
2021-08-17 15:08:53 +08:00
行首的空格没了,pastebin 发了一下: https://pastebin.com/Mr94f31q
nowheretoseek
2021-08-17 15:09:57 +08:00
@nowheretoseek @redford42 @hefish @ysc3839 补充个信息,就是中午问题重现时,测试发现重启后问题消失,所以应该不是腾讯云服务器网络方面的问题。
ysc3839
2021-08-17 16:30:36 +08:00
@nowheretoseek curl 加上 -vv 参数看输出什么,以及有试过在服务器本地访问吗?
nowheretoseek
2021-08-17 16:33:18 +08:00
@ysc3839 就是在运行站点的服务器测试的,明天中午加-vv 试试。
nowheretoseek
2021-08-18 16:28:03 +08:00
刚才大致明白怎么回事了,明天中午验证下。
我本地有个定时任务,每天中午用 ssh+mysqldump 备份服务器上的数据库,这个站未压缩的数据库有 170M+,而这台服务器带宽很小,所以很可能是我备份数据库时占满了带宽,导致新连接不能被接受;考虑到连接静态站时没问题,也可能时备份数据表时锁表什么的导致数据库不响应,总之很大可能是这个定时任务导致的。刚才手动运行备份任务验证下没有重现,明天中午再验证吧。
@redford42 @hefish @ysc3839
nowheretoseek
2021-08-18 16:36:50 +08:00
在手动运行备份任务十几分钟后,收到无法连接的监控邮件了,不清楚为什么有这么长时间的延迟,服务器端备份进程还在继续,本地监控的下载速度一直稳定在 120-160k 之间,可能是锁表什么的吧。无论如何问题明确了,hoory !感谢提供排查思路。
@nowheretoseek @redford42 @hefish @ysc3839

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/795880

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX