- 创建服务文件
# /usr/lib/systemd/system/zabbix-agent.service
[Unit]
Description=Zabbix Agent
After=syslog.target
After=network.target
[Service]
Environment="CONFFILE=/etc/zabbix/etc/zabbix_agentd.conf"
EnvironmentFile=-/etc/default/zabbix-agent
Type=forking
Restart=on-failure
PIDFile=/run/zabbix/zabbix_agentd.pid
KillMode=control-group
ExecStartPost=/usr/bin/sleep 1
ExecStart=/etc/zabbix/sbin/zabbix_agentd -c $CONFFILE
ExecStop=/bin/kill -SIGTERM $MAINPID
RestartSec=10s
User=ec2-user
Group=ec2-user
[Install]
WantedBy=multi-user.target
- 修改 agentd 配置文件
# 增加一行
PidFile=/var/run/zabbix/zabbix_agentd.pid
- 并创建目录
cd /var/run/
sudo mkdir zabbix
sudo chown -R ec2-user: zabbix/
- 启动、配置开机启动