2GB 内存设备配置优化
2GB 内存设备配置优化
简介
本文介绍如何减少 2GB 内存入门级 FortiGate 设备在进入内存保护模式前的内存使用率。当前≤2GB 设备的型号如下:
30D/30E/30G/40C/40F/50E/50G/60D/60E/61E/60F/61F/70D/80C/80D/80E/81E/90D/91/92D
这类设备的一个突出问题是:基础内存占用就很高(约 50% ~ 70%),预留的内存空间有限。一旦遭遇突发事件,如网络流量突然增加、大量并发会话、攻击或短时高峰流量,内存极易飙升至阈值,从而触发“内存保护”模式。进入该模式后,设备会作为保护措施阻止新的连接请求,虽然能避免系统崩溃,但也可能影响业务连续性。这种情况在低端型号中尤为常见,因此必须特别关注内存的合理使用和优化。
查看内存大小
要检查 FortiGate 的内存大小与使用情况,可在设备 CLI 下运行diagnose hardware sysinfo memory(或get hardware memory、fnsysctl cat/proc/meminfo)命令,如下所示,FortiGate-60F 的总内存大小为 2GB:
FortiGate-60F # diagnose hardware sysinfo memory
MemTotal: 1963616 kB
MemFree: 493552 kB
Buffers: 39388 kB
Cached: 537824 kB
SwapCached: 0 kB
Active: 675400 kB
Inactive: 126488 kB
Active(anon): 485728 kB
Inactive(anon): 42588 kB
Active(file): 189672 kB
Inactive(file): 83900 kB
Unevictable: 190276 kB
Mlocked: 20400 kB
SwapTotal: 0 kB
SwapFree: 0 kB
Dirty: 76 kB
Writeback: 0 kB
AnonPages: 414976 kB
Mapped: 135568 kB
Shmem: 121484 kB
Slab: 209332 kB
SReclaimable: 16468 kB
SUnreclaim: 192864 kB
KernelStack: 3968 kB
PageTables: 31116 kB
NFS_Unstable: 0 kB
Bounce: 0 kB
WritebackTmp: 0 kB
CommitLimit: 981808 kB
Committed_AS: 13450496 kB
VmallocTotal: 260046784 kB
VmallocUsed: 126860 kB
VmallocChunk: 259812288 kB优化建议
使用推荐版本或型号
- 建议在网络规划阶段评估业务需求,并根据性能要求选择合适规格的 FortiGate 型号,以避免后续扩容风险。设备选型请联系 [se_china@fortinet.com](mailto: se_china_fortinet.com)。
- 强烈建议在 FortiGate 上使用推荐的 FortiOS 版本。推荐版本通常包含对内存相关问题的修复和优化,可提升系统稳定性与可靠性。FortiGate 各型号版本推荐请参考:系统管理 → 固件与配置管理 → 固件版本管理 → 固件下载章节。
FortiGuard 更新
优化 FortiGuard 更新相关配置。
config system fortiguard set webfilter-cache-ttl 600 <----减小WebFilter缓存时间,默认值3600 set antispam-cache-ttl 600 <----减小反垃圾邮件缓存时间,默认值1800 set outbreak-prevention-cache-ttl 300 <----减小病毒爆发防御缓存时间,默认值300 set update-ffdb disable <----只在设备未进入“内存保护模式”时更新ISDB end修改 FortiGuard 更新间隔。
config system autoupdate schedule set frequency daily <----将FortiGuard自动更新间隔增加到每天 set time 03:00 <----FortiGuard自动更新时间为凌晨3:00 end
会话时间
减少 TCP 会话相关状态的超时时间,更快释放内存。请根据 FortiGate 的实际流量情况调整以下值:
config system global set reset-sessionless-tcp disable set tcp-halfclose-timer 30 <----减小TCP halfclose超时时间,默认值120 set tcp-halfopen-timer 5 <----减小TCP halfopen超时时间,默认值10 set tcp-timewait-timer 0 <----减小TCP timewait超时时间,默认值1 set udp-idle-timer 60 <----减小UDP超时时间,默认值180 end减少 TCP 会话和 DNS 会话的老化时间。
config system session-ttl set default 300 config port edit 0 set protocol 17 set timeout 10 set end-port 53 set start-port 53 next end end
系统配置
关闭安全评级相关功能。
config system global set internet-service-database on-demand <----仅下载已使用的ISDB条目 set security-rating-result-submission disable <----关闭安全评级结果提交 set security-rating-run-on-schedule disable <----关闭安全评级执行计划 end减少部分系统进程的数量。如果 FortiGate 上某些进程同时运行多个实例,应适当减少其数量(谨慎操作)。
config system global set miglogd-children 1 set sslvpn-max-worker-count 1 set wad-worker-count 1 set scanunit-count 2 end减少 DNS 缓存条目的老化时间。
config system dns set dns-cache-limit 600 <----DNS缓存条目最大数,默认值5000 set dns-cache-ttl 600 <----DNS缓存条目老化时间,默认值1800 end
日志相关
关闭报告功能。对于 2GB 或 4GB 内存型号,不建议启用报告功能,会消耗较多比例的内存。
config report setting set pdf-report disable set fortiview disable end diagnose report-runner clean <----删除之前已生成的报告文件关闭内存日志,关闭硬盘日志记录流量日志,推荐将日志发送到 FortiAnalyzer 或 syslog 服务器。
config log memory setting set status disable end config log disk filter set forward-traffic disable end
UTM 相关
启用 IPS 的
fail-open, 设备进入“内存保护模式”后 bypass 需要检测的流量。config ips global set fail-open enable set cp-accel-mode none end关闭 AV 启发式扫描。
config antivirus settings set machine-learning-detection disable end缺省的 AV 扫描文件大小为 10 MB,可能会导致内存消耗太多进入“内存保护模式”。根据病毒要求传播快的特点,一般病毒文件都不会太大,所以可以调整扫描文件的大小:
配置自定义的 profile-protocol-options,设置各个应用的扫描阈值为 1 MB,大于 1 MB 的文件会被 AV bypass:
config firewall profile-protocol-options edit "av-profile-options" set oversize-log enable config http set ports 80 set options clientcomfort servercomfort chunkedbypass unset post-lang set oversize-limit 1 set uncompressed-oversize-limit 2 set uncompressed-nest-limit 2 set stream-based-uncompressed-limit 2 end config ftp set ports 21 set options clientcomfort splice set oversize-limit 1 set uncompressed-oversize-limit 2 set uncompressed-nest-limit 2 set stream-based-uncompressed-limit 2 end config imap set ports 143 set options fragmail set oversize-limit 1 set uncompressed-oversize-limit 2 set uncompressed-nest-limit 2 end config mapi set ports 135 set options fragmail set oversize-limit 1 set uncompressed-oversize-limit 2 set uncompressed-nest-limit 2 end config pop3 set ports 110 set options fragmail set oversize-limit 1 set uncompressed-oversize-limit 2 set uncompressed-nest-limit 2 end config smtp set ports 25 set options fragmail splice set oversize-limit 1 set uncompressed-oversize-limit 2 set uncompressed-nest-limit 2 end config nntp set ports 119 set options splice set oversize-limit 1 set uncompressed-oversize-limit 2 set uncompressed-nest-limit 2 end config ssh unset options set oversize-limit 1 set uncompressed-oversize-limit 2 set uncompressed-nest-limit 2 set stream-based-uncompressed-limit 2 end config dns set ports 53 end config cifs set ports 445 unset options set oversize-limit 1 set uncompressed-oversize-limit 2 set uncompressed-nest-limit 2 end next end需要在防火墙策略内调用相应的 profile-protocol-options 才能生效。
config firewall policy edit <policy_id> set profile-protocol-options av-profile-options next end
自动化重启 IPS
结合正常期间的内存占⽤,调整内存利⽤率⾼的阈值,当内存⾼时,⾃动触发 IPS engine 重启并释放内存。重启 IPS engine 不会影响业务流量。
降低进入“内存保护模式”的 green 和 red 阈值,内存值到达
memory-use-threshold-red设置的 75% 时,会进⼊ “内存保护模式”,当 FortiGate 进⼊ “内存保护模式”后,如果内存在 red 和 extreme 之间时,新会话不会被丢弃,继续转发,当内存到达 extreme 时开始丢弃新会话。config system global set memory-use-threshold-extreme 95 set memory-use-threshold-green 70 <----默认值82 set memory-use-threshold-red 75 <----默认值88 end配置自动化触发器,触发条件为设备进入了“内存保护模式”。
config system automation-trigger edit "Enters_Conserve_Mode" set event-type low-memory next end配置自动化动作,动作内容为重启 IPS Engine。
config system automation-action edit "RestartIPS" set action-type cli-script set script "config global <----如果未开启多VDOM,则不需要此行 diagnose test application ipsmonitor 99" set accprofile "super_admin" next end配置自动化工作流,绑定触发条件和动作。
config system automation-stitch edit "Restart_IPS_during_Conserve_Mode" set trigger "Enters_Conserve_Mode" config actions edit 1 set action "RestartIPS" next end next end补充:也可以设置一个周期性重启 IPS 的自动化(可以与上述脚本同时使用),如下所示,每天凌晨 4 点重启 IPS engine。
config system automation-trigger edit "4AM" set trigger-type scheduled set trigger-hour 4 next end config system automation-action edit "RestartIPS" set action-type cli-script set script "config global <----如果未开启多VDOM,则不需要此行 diagnose test application ipsmonitor 99" set accprofile "super_admin" next end config system automation-stitch edit "RestartIPS" set trigger "4AM" config actions edit 1 set action "RestartIPS" next end next end
内存保护模式收集信息
当设备进入内存保护模式时,请协助收集下列命令的输出结果,并提交给 TAC 团队(需要 super_admin 权限)。
fnsysctl date
get system status
get hardware status
diagnose autoupdate versions
get sys perf status
diag sys session stat
get sys perf firewall statistics
diag hardware sysinfo memory
diag hardware sysinfo slab
diagnose hardware sysinfo shm
diag sys vd list | grep fib
diagnose sys mpstat 1 5
diag sys top-all 2 50
diag sys top-mem 20
diagnose sys top-fd 20
diag snmp ip frags
diagnose ips session status
diagnose ips memory status
diagnose ips raw status
diagnose ips session performance
diagnose ips session list by-mem
fnsysctl df -k
fnsysctl ls -l /tmp
fnsysctl du -i /tmp
fnsysctl du -a /tmp
fnsysctl du -a / -d 1
fnsysctl du -i /dev/shm
fnsysctl du -a /dev/shm
fnsysctl du -i /node-scripts
fnsysctl du -a /node-scripts注意事项
- 上述优化配置的具体参数应根据您的实际网络状态进行调整。
- 从 FortiOS 7.4.4 版本开始,从 ≤ 2GB 内存的设备上移除了代理相关的功能。
- 从 FortiOS 7.6.3 版本开始,从 ≤ 2GB 内存的设备上移除了部分 Security Fabric 相关功能。