Debian 上 LNMP 的可扩展路径
一 扩展总览与路线选择
二 快速扩展清单
sudo apt install php-{fpm,mysql,opcache,gd,curl,memcached}(按你的 PHP 版本 调整包名)。opcache.enable=1、opcache.memory_consumption=256、opcache.interned_strings_buffer=64、opcache.max_accelerated_files=10000、opcache.validate_timestamps=1(生产可改为按文件时间戳验证)。sudo systemctl restart php<版本>-fpm。gzip on; gzip_vary on; gzip_comp_level 6; gzip_buffers 16 8k; gzip_http_version 1.1;proxy_cache_path /var/cache/nginx levels=1:2 keys_zone=my_cache:10m max_size=1g inactive=60m use_temp_path=off;worker_processes auto; worker_rlimit_nofile 65535; events { worker_connections 32768; use epoll; }。sudo systemctl restart nginx。innodb_buffer_pool_size 设为内存的 50%–80%;按负载调整 max_connections;开启并分析 慢查询日志。sudo certbot --nginx -d example.com。三 水平扩展与高可用
upstream backend { server 10.0.0.11:80; server 10.0.0.12:80; }proxy_pass http://backend; 并设置 Host/X-Real-IP/X-Forwarded-For/X-Forwarded-Proto 头。CHANGE MASTER TO ...; START SLAVE;。vrrp_instance VI_1 { state MASTER; interface eth0; virtual_router_id 51; priority 100; advert_int 1; authentication { auth_type PASS; auth_pass 42; } virtual_ipaddress { 192.168.1.100/24; } track_script { chk_nginx { script "killall -0 nginx"; interval 2; weight 2; } } }。四 自动扩展与容量规划
五 运维与安全要点
sudo ufw allow 'Nginx Full' && sudo ufw enable。ulimit -n 65535;sysctl -w net.core.somaxconn=65535; net.ipv4.ip_local_port_range="1024 65535"; net.ipv4.tcp_fin_timeout=30; net.core.netdev_max_backlog=65535。mysqldump 或物理备份;文件:rsync/对象存储;变更前 备份与灰度,变更后 回归与压测。