在 Debian 上维护 LNMP(Linux + Nginx + MySQL/MariaDB + PHP) 主要包括:系统更新、服务管理、日志管理、安全维护、性能优化、备份与故障排查。下面按模块给你一份实用维护指南。
apt update
apt upgrade -y
apt dist-upgrade -y
查看可更新内容:
apt list --upgradable
⚠️ 更新前建议先备份重要配置。
systemctl status nginx
systemctl restart nginx
systemctl reload nginx # 平滑重启(不中断连接)
nginx -t
/var/log/nginx/access.log
/var/log/nginx/error.log
日志轮转(默认已配置):
cat /etc/logrotate.d/nginx
logrotate -f /etc/logrotate.d/nginx
systemctl status mariadb
systemctl restart mariadb
mysql_secure_installation
mysqldump -u root -p --all-databases > /backup/mysql_all.sql
自动备份(crontab 示例):
0 2 * * * mysqldump -u root -p'密码' --all-databases > /backup/db_$(date +\%F).sql
SHOW PROCESSLIST;
SHOW STATUS;
检查慢查询:
/etc/mysql/mariadb.conf.d/50-server.cnf
slow_query_log = 1
php -v
systemctl status php8.2-fpm
systemctl restart php8.2-fpm
/etc/php/8.2/fpm/php.ini
/etc/php/8.2/fpm/pool.d/www.conf
upload_max_filesize = 50M
post_max_size = 50M
memory_limit = 256M
max_execution_time = 300
chown -R www-data:www-data /var/www/html
chmod -R 755 /var/www/html
apt install certbot python3-certbot-nginx
certbot --nginx
自动续期测试:
certbot renew --dry-run
ufw allow 22
ufw allow 80
ufw allow 443
ufw enable
/etc/ssh/sshd_config
建议:
apt install fail2ban
systemctl enable fail2ban
top
htop
free -h
df -h
pm = dynamic
pm.max_children = 50
pm.start_servers = 10
nginx -t
systemctl status nginx
systemctl status php8.2-fpm
/var/log/nginx/error.log
mysql -u user -p
| 项目 | 频率 |
|---|---|
| 系统更新 | 每周 |
| 备份 | 每天 |
| 日志检查 | 每周 |
| 安全审计 | 每月 |
| 性能检查 | 不定期 |
如果你愿意,我可以:
你可以直接贴出你的 Debian 版本 + Nginx/PHP/MySQL 版本。