LNMP在Debian上的自动化运维实践
一、部署与配置自动化
sudo apt update && sudo apt upgrade -ysudo apt install nginx -y && sudo systemctl enable --now nginxsudo apt install mariadb-server -y && sudo systemctl enable --now mariadb,随后执行 sudo mysql_secure_installation 完成安全加固sudo apt install php8.2 php8.2-fpm php8.2-mysql -y && sudo systemctl enable --now php8.2-fpmindex index.php index.html;location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php8.2-fpm.sock;
}
location ~ /\.ht { deny all; }
sudo nginx -t && sudo systemctl reload nginx二、安全与证书自动化
sudo apt install ufw -y && sudo ufw enablesudo ufw allow 'Nginx Full'sudo apt install certbot python3-certbot-nginx -ysudo certbot --nginx -d yourdomain.com0 3 * * * certbot renew --quiet && systemctl reload nginx)三、监控与告警
四、自动扩展与高可用
五、备份与回滚策略
mysqldump -u root -p --single-transaction --routines --triggers --databases your_db > backup_$(date +%F).sql0 2 * * * mysqldump -u root -p'YOUR_PASS' --single-transaction --routines --triggers --databases your_db | gzip > /opt/backup/db_$(date +\%F).sql.gztar czf /opt/backup/www_$(date +%F).tgz -C /var/www/html . && tar czf /opt/backup/nginx_$(date +%F).tgz /etc/nginxgunzip < backup_YYYY-MM-DD.sql.gz | mysql -u root -p,静态文件与配置使用备份包解压覆盖并 sudo systemctl reload nginx