温馨提示×

如何排查centos lnmp故障

小樊
36
2025-12-09 19:21:27
栏目: 智能运维

排查 CentOS 上的 LNMP(Linux, Nginx, MySQL, PHP)故障可以通过以下步骤进行:

1. 检查 Nginx 状态

  • 查看 Nginx 服务状态
    systemctl status nginx
    
  • 检查 Nginx 错误日志
    tail -f /var/log/nginx/error.log
    

2. 检查 MySQL 状态

  • 查看 MySQL 服务状态
    systemctl status mysqld
    
  • 检查 MySQL 错误日志
    tail -f /var/log/mysqld.log
    

3. 检查 PHP 状态

  • 查看 PHP-FPM 状态(如果使用 PHP-FPM):
    systemctl status php-fpm
    
  • 检查 PHP 错误日志
    tail -f /var/log/php-fpm/error.log
    

4. 检查文件权限

  • 确保 Nginx 用户有权限访问网站目录
    chown -R nginx:nginx /path/to/your/website
    chmod -R 755 /path/to/your/website
    

5. 检查 SELinux 设置

  • 查看 SELinux 状态
    sestatus
    
  • 如果 SELinux 启用,检查相关日志
    tail -f /var/log/audit/audit.log | grep avc
    

6. 检查网络连接

  • 使用 ping 命令检查服务器是否可达
    ping your_server_ip
    
  • 使用 telnetnc 检查端口是否开放
    telnet your_server_ip 80
    # 或者
    nc -zv your_server_ip 80
    

7. 检查防火墙设置

  • 查看防火墙状态
    firewall-cmd --state
    
  • 检查防火墙规则
    firewall-cmd --list-all
    

8. 检查 DNS 设置

  • 使用 nslookupdig 检查域名解析
    nslookup yourdomain.com
    # 或者
    dig yourdomain.com
    

9. 检查 PHP 配置

  • 查看 php.ini 文件
    cat /etc/php.ini
    
  • 检查 PHP 扩展是否加载
    php -m
    

10. 检查 Nginx 配置

  • 查看 Nginx 配置文件
    cat /etc/nginx/nginx.conf
    
  • 检查是否有语法错误
    nginx -t
    

11. 重启服务

  • 重启 Nginx
    systemctl restart nginx
    
  • 重启 MySQL
    systemctl restart mysqld
    
  • 重启 PHP-FPM(如果使用 PHP-FPM):
    systemctl restart php-fpm
    

通过以上步骤,你可以逐步排查并解决 CentOS 上的 LNMP 故障。如果问题依然存在,可以考虑查看系统日志或寻求社区帮助。

0