2022 Zabbix中国峰会
2022 Zabbix中国峰会

9 以 root 用户身份运行agent

Zabbix从 5.0.0 版本开始,Zabbix agent 服务的启动文件 官方包 已更新为显示包含 UserGroup的参数。 两者都设置为 zabbix

由于agent会通过以systemd服务文件指定的用户运行,而忽略zabbix_agentd.conf配置文件,这也将导致不再支持通过配置zabbix_agentd.conf 来指定运行用户 。 可以通过如下描述的修改来实现agent以root用户运行。

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

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

[Service]
       User=root
       Group=root

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

systemctl daemon-reload
       systemctl restart zabbix-agent2

对于Zabbix agent2,运行用户完全取决于上述修改,不再需要其他修改。