10 以 root 身份运行 agent

自 Zabbix 5.0.0 起,官方软件包中的 Zabbix agent 的 systemd 服务文件已明确包含 UserGroup 指令。 两者均设置为 zabbix

现在已无法通过 zabbix_agentd.conf 文件配置 Zabbix agent 以哪个用户身份运行, 因为 agent 会绕过此配置,并以 systemd 服务文件中指定的用户身份运行。 若要以 root 身份运行 Zabbix agent,您需要进行如下修改。

Zabbix agent

要覆盖缺省用户和用户组,执行: systemctl edit zabbix-agent 然后,增加如下内容:

[Service]
User=root
Group=root

重新加载守护进程并重启 zabbix-agent 服务

systemctl daemon-reload
systemctl restart zabbix-agent

对于Zabbix agent,依然要在 zabbix_agentd.conf 文件中重新启用配置用户的功能。因此,为了以 root 身份运行 zabbix agent,您仍然需要编辑 agent [配置文件](/manual/annex/config/zabbix_agentd)并指定 User=root 以及 AllowRoot=1 两个参数。

Zabbix agent 2

要覆盖 Zabbix agent 2 的默认用户和组,请运行:

systemctl edit zabbix-agent2

然后,添加以下内容:

[Service]
User=root
Group=root

重新加载守护进程并重启 zabbix-agent2 服务:

systemctl daemon-reload
systemctl restart zabbix-agent2

对于 Zabbix agent2,这将完全决定其运行时所使用的用户。 不需要进行其他修改。