You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Mac Sonoma 14.3.1修改ulimit文件限制失败求排查

解决Mac Sonoma 14.3.1设置maxfiles ulimit时的Load failed错误

遗漏操作及修复步骤

1. 修正plist文件格式问题

你粘贴的plist内容包含HTML转义的",这会导致系统解析失败。替换为原生双引号的正确内容:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN"
        "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
  <dict>
    <key>Label</key>
    <string>limit.maxfiles</string>
    <key>ProgramArguments</key>
    <array>
      <string>launchctl</string>
      <string>limit</string>
      <string>maxfiles</string>
      <string>64000</string>
      <string>524288</string>
    </array>
    <key>RunAtLoad</key>
    <true/>
    <key>ServiceIPC</key>
    <false/>
  </dict>
</plist>

覆盖原文件内容,确保无转义字符。

2. 设置标准文件权限

除了chown root:wheel,还需将plist权限设为LaunchDaemon要求的644:

sudo chmod 644 /Library/LaunchDaemons/limit.maxfiles.plist

3. 先卸载旧服务再重新加载

若之前尝试加载过该服务,需先卸载避免冲突:

sudo launchctl unload -w /Library/LaunchDaemons/limit.maxfiles.plist

再执行加载命令:

sudo launchctl load -w /Library/LaunchDaemons/limit.maxfiles.plist

4. 添加内核级sysctl配置

Mac Sonoma需同时设置内核参数才能让maxfiles限制完全生效,创建并编辑/etc/sysctl.conf:

sudo touch /etc/sysctl.conf
sudo echo "kern.maxfiles=524288" >> /etc/sysctl.conf
sudo echo "kern.maxfilesperproc=64000" >> /etc/sysctl.conf

执行命令让配置即时生效:

sudo sysctl -w kern.maxfiles=524288
sudo sysctl -w kern.maxfilesperproc=64000

5. 配置用户会话级ulimit

系统级设置生效后,需在用户shell配置中添加会话级限制:

  • 若使用zsh:
echo "ulimit -n 64000 524288" >> ~/.zshrc
source ~/.zshrc
  • 若使用bash:
echo "ulimit -n 64000 524288" >> ~/.bashrc
source ~/.bashrc

验证设置

重启系统后,执行以下命令确认配置生效:

launchctl limit maxfiles
ulimit -n
sysctl kern.maxfiles kern.maxfilesperproc

内容的提问来源于stack exchange,提问作者olaf

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.29 08:40:31