V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX 提问指南
nowheretoseek
V2EX  ›  问与答

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

  •  
  •   nowheretoseek · 2021-08-15 12:35:24 +08:00 · 1368 次点击
    这是一个创建于 999 天前的主题,其中的信息可能已经有所发展或是发生改变。

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

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

    • cpu 和内存占用都不高;
    • 同 IP 上的某静态小站页面可访问;
    • apache2 服务 reload 、restart 都没用;
    • 站点的 error 日志文件仍在记录,但只是 AH01630: client denied by server configuration 类的错误;

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

    18 条回复    2021-08-18 16:36:50 +08:00
    redford42
        1
    redford42  
       2021-08-15 17:07:16 +08:00
    你的站点被别人访问的时候挂掉
    还是别人的网站你的服务去访问的时候会挂掉呢
    hefish
        2
    hefish  
       2021-08-15 18:00:17 +08:00
    换 nginx 吧。
    nowheretoseek
        3
    nowheretoseek  
    OP
       2021-08-15 19:09:01 +08:00
    @redford42 我的站挂掉,并且基本是每天按时挂掉,跟有无人访问关系并不大,毕竟流量很小。
    nowheretoseek
        4
    nowheretoseek  
    OP
       2021-08-15 19:09:40 +08:00
    @hefish 一直没来得及学会 nginx 的配置,apache 学的早比较习惯了,希望先解决这个问题。
    hefish
        5
    hefish  
       2021-08-15 20:17:06 +08:00
    因为没有更具体的信息,建议还是自行谷歌来解决。
    我谷歌下来,都说是 apache 2.2 与 2.4 配置的差别。因为不清楚具体配置,所以无法进一步判断。
    ysc3839
        6
    ysc3839  
       2021-08-16 10:22:26 +08:00
    “同 IP 上的某静态小站”是同一个端口吗?
    出现 connection timeout 个人怀疑是服务商封端口了,因为用户模式的程序似乎制造不出无回应的效果。要不然是没监听端口,或者监听了但不 accept,内核在 SYN 阶段直接发个 RST,错误会是 connection refused 。要不然是连接建立后发送 RST,错误会是 connection reset 。
    nowheretoseek
        7
    nowheretoseek  
    OP
       2021-08-16 14:52:17 +08:00
    @ysc3839 是同 80 端口,apache 下不同的 virtual host 。监控邮件显示”The monitor is currently DOWN (Connection Timeout)“
    nowheretoseek
        8
    nowheretoseek  
    OP
       2021-08-16 14:53:33 +08:00
    @hefish 谷歌过,没找到类似描述的问题,用 2.4 很久了,配置模板也一直用,用了好几个地方,就这个出问题。
    ysc3839
        9
    ysc3839  
       2021-08-16 17:08:21 +08:00
    @nowheretoseek 那说明监控程序的报告有问题,建议自己访问看看是什么错误。
    hefish
        10
    hefish  
       2021-08-17 10:18:35 +08:00
    贴一下 <VirtualHost /> 部分的配置吧
    nowheretoseek
        11
    nowheretoseek  
    OP
       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
        12
    nowheretoseek  
    OP
       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
        13
    nowheretoseek  
    OP
       2021-08-17 15:08:53 +08:00
    行首的空格没了,pastebin 发了一下: https://pastebin.com/Mr94f31q
    nowheretoseek
        14
    nowheretoseek  
    OP
       2021-08-17 15:09:57 +08:00
    @nowheretoseek @redford42 @hefish @ysc3839 补充个信息,就是中午问题重现时,测试发现重启后问题消失,所以应该不是腾讯云服务器网络方面的问题。
    ysc3839
        15
    ysc3839  
       2021-08-17 16:30:36 +08:00
    @nowheretoseek curl 加上 -vv 参数看输出什么,以及有试过在服务器本地访问吗?
    nowheretoseek
        16
    nowheretoseek  
    OP
       2021-08-17 16:33:18 +08:00
    @ysc3839 就是在运行站点的服务器测试的,明天中午加-vv 试试。
    nowheretoseek
        17
    nowheretoseek  
    OP
       2021-08-18 16:28:03 +08:00   ❤️ 1
    刚才大致明白怎么回事了,明天中午验证下。
    我本地有个定时任务,每天中午用 ssh+mysqldump 备份服务器上的数据库,这个站未压缩的数据库有 170M+,而这台服务器带宽很小,所以很可能是我备份数据库时占满了带宽,导致新连接不能被接受;考虑到连接静态站时没问题,也可能时备份数据表时锁表什么的导致数据库不响应,总之很大可能是这个定时任务导致的。刚才手动运行备份任务验证下没有重现,明天中午再验证吧。
    @redford42 @hefish @ysc3839
    nowheretoseek
        18
    nowheretoseek  
    OP
       2021-08-18 16:36:50 +08:00
    在手动运行备份任务十几分钟后,收到无法连接的监控邮件了,不清楚为什么有这么长时间的延迟,服务器端备份进程还在继续,本地监控的下载速度一直稳定在 120-160k 之间,可能是锁表什么的吧。无论如何问题明确了,hoory !感谢提供排查思路。
    @nowheretoseek @redford42 @hefish @ysc3839
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   3659 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 04:51 · PVG 12:51 · LAX 21:51 · JFK 00:51
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.