Limesurvay系统“48核心92GB服务器”优化方案
1、Redis
maxmemory 16GB # 限制Redis内存(预留足够空间给其他服务)
maxmemory-policy volatile-lru # 自动淘汰旧会话(仅对带TTL的键)
save 300 100 # 仅保留一个条件减少阻塞
stop-writes-on-bgsave-error no # 快照失败仍允许写入
2、php.ini
(1)Redis连接优化
persistent=1: #启用持久连接,减少TCP握手开销;
timeout=1.5: #连接超时1.5秒(避免阻塞)
session.save_path =
"tcp://127.0.0.1:6379?auth={pwd}&persistent=1&weight=1&timeout=1.5&read_timeout=10"
(2)session参数优化
session.gc_probability = 0 # 禁用PHP垃圾回收(依赖Redis自动过期)
session.gc_maxlifetime = 7200 # 会话有效期2小时(按业务需求调整)
session.cookie_lifetime = 0 # 浏览器会话级Cookie(关闭浏览器即失效)
session.use_strict_mode = 1 # 防止会话固定攻击
session.lazy_write = 1 # 仅当Session变化时写入(减少Redis操作)
(3)OPCache加速
opcache.enable=1
opcache.memory_consumption=1024
opcache.interned_strings_buffer=64
opcache.max_accelerated_files=100000
opcache.revalidate_freq=60
opcache.fast_shutdown=1
opcache.enable_cli=0
opcache.jit_buffer_size=256m
opcache.jit=1255
JIT兼容性条件说明:
1、确认PHP版本≥8.0(JIT在PHP7.4中实验性支持)
2、如遇段错误(segfault),降级为opcache.jit=off
开发环境差异:
1、开发时建议设置 opcache.revalidate_freq=0(实时检查文件更新)
2、生产环境设置为60秒以上减少I/O压力
3、PHP-FPM与Redis的协同优化
; /etc/php-fpm.d/www.conf
pm = dynamic
pm.max_children = 1000 # 提升至800进程(需测试内存)
pm.start_servers = 80
pm.min_spare_servers = 50
pm.max_spare_servers = 150
request_terminate_timeout = 30 # 保持严格超时(依赖Redis会话持久化)
pm.max_requests = 10000 #单进程最大请求数
自动优化PHPFPM脚本,服务器高峰出现问题时使用:
#!/bin/bash
#动态调整pm.max_children(根据内存剩余)
FREE_MEM=$(free -m | awk '/Mem:/ {print $7}')
CHILDREN=$(( FREE_MEM / 100 )) # 假设每个进程100MB
sed -i "s/pm.max_children = .*/pm.max_children = $CHILDREN/" /etc/php-fpm.d/www.conf
systemctl reload php-fpm
4、Limesurvey
详见配置文件