去 GitHub 发布页下载 Agent 程序
根据自己 CPU 架构选择下载 darwin amd64 还是 arm64。Intel CPU 下载 amd64,Apple Silicon 下载 arm64
将下面的内容保存为 xxx.plist 文件并修改,规则如下:
<?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>KeepAlive</key>
<true/>
<key>Label</key>
<string>moe.flinty.nezha</string>
<key>ProgramArguments</key>
<array>
<string>/Users/flintylemming/nezha-agent</string>
<string>--password=链接密码</string>
<string>--server=服务器地址:端口号</string>
</array>
<key>RunAtLoad</key>
<true/>
</dict>
</plist>
例如我的 agent 直接保存在用户根目录下,我的 plist 文件大概就是这样
<?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>KeepAlive</key>
<true/>
<key>Label</key>
<string>moe.flinty.nezha</string>
<key>ProgramArguments</key>
<array>
<string>/Users/flintylemming/nezha-agent</string>
<string>--password=xxxxx</string>
<string>--server=xxxxx:5555</string>
</array>
<key>RunAtLoad</key>
<true/>
</dict>
</plist>
将编辑好的 plist 文件放到 ~/Library/LaunchAgents 路径下,如果提示没有这个文件夹,就手动创建一个
在 Terminal 中使用下面的命令 load plist 文件到 launchd 里,注意替换文件名称
launchctl load ~/Library/LaunchAgents/xxxx.plist
启动进程,start 后面跟 Label
launchctl start xxxxx
可以通过命令查看进程是否在运行
launchctl list | grep xxxxx