下载文件

哪吒监控 Agent

去 GitHub 发布页下载 Agent 程序

Releases · naiba/nezha

根据自己 CPU 架构选择下载 darwin amd64 还是 arm64。Intel CPU 下载 amd64,Apple Silicon 下载 arm64

launchd plist 文件

将下面的内容保存为 xxx.plist 文件并修改,规则如下:

  1. 文件名为 Label 字段里面的内容,这里我默认写了个 moe.flinty.nezha,可以自己改
  2. pasword 填写链接密码
  3. server 填写服务器地址
<?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>

配置 launchd

  1. 将编辑好的 plist 文件放到 ~/Library/LaunchAgents 路径下,如果提示没有这个文件夹,就手动创建一个

  2. 在 Terminal 中使用下面的命令 load plist 文件到 launchd 里,注意替换文件名称

    launchctl load ~/Library/LaunchAgents/xxxx.plist
    
  3. 启动进程,start 后面跟 Label

    launchctl start xxxxx
    
  4. 可以通过命令查看进程是否在运行

    launchctl list | grep xxxxx
    

    Untitled