LNMP(Linux + Nginx + MySQL + PHP)环境是常见的Web服务架构,以下是针对LNMP环境的系统性故障排查方法。
ping 目标IP/域名
traceroute 目标IP/域名
netstat -tulnp | grep 'nginx\|mysql\|php'
iptables -L -n
ufw status # Ubuntu系统
firewall-cmd --list-all # CentOS 7+
systemctl status nginx
nginx -t # 测试配置文件语法
tail -f /var/log/nginx/error.log
tail -f /var/log/nginx/access.log
netstat -tulnp | grep :80
/var/www/html
目录权限nginx -t
检查语法systemctl status mysql # 或 mariadb
mysqladmin -u root -p ping
tail -f /var/log/mysql/error.log
show processlist;
my.cnf
配置SELECT user,host FROM mysql.user;
systemctl status php-fpm
ps aux | grep php-fpm
创建测试文件/var/www/html/info.php
:
<?php phpinfo(); ?>
访问http://your-server/info.php
tail -f /var/log/php-fpm.log
top
htop
df -h
du -sh /var/log/*
free -m
vmstat 1 5
/var/run/php-fpm
目录权限chown -R nginx:nginx /var/www/html
strace -p [PID] # 跟踪进程系统调用
perf top # 性能分析
mysqldumpslow # 分析慢查询
pt-query-digest # Percona工具包
ab -n 1000 -c 100 http://your-site.com/ # Apache Benchmark
siege -c 100 -t 1M http://your-site.com/
通过以上系统性的排查方法,可以解决LNMP环境下的大多数常见问题。对于复杂问题,建议结合多种工具和方法综合分析。