#!/bin/bash
# by yanqianling 2023.9.25
# v1.0

apt install zabbix-agent


cat > /etc/zabbix/zabbix_agentd.conf <<EOF
PidFile=/run/zabbix/zabbix_agentd.pid
LogFile=/var/log/zabbix-agent/zabbix_agentd.log
LogFileSize=0
Server=10.1.8.18
ServerActive=10.1.8.18
Include=/etc/zabbix/zabbix_agentd.conf.d/*.conf
EOF


echo "Hostname=$(hostname)" >> /etc/zabbix/zabbix_agentd.conf


cat >/etc/systemd/system/zabbix-agent.service<<'EOF'
[Unit]
Description=Zabbix Agent
After=syslog.target network.target

[Service]
[Service]
Environment="CONFFILE=/etc/zabbix/zabbix_agentd.conf"
Type=simple
ExecStart=/usr/sbin/zabbix_agentd -c $CONFFILE -f
Restart=on-failure
RestartSec=10s

[Install]
WantedBy=multi-user.target
EOF


systemctl daemon-reload
systemctl enable zabbix-agent.service
systemctl start zabbix-agent.service

ps -ef |grep zabbix

systemctl restart zabbix-agent.service
