zabbix添加agent主动模式

zabbix添加agent主动模式

#!/bin/bash
#Author:royoy
#Desc:add zabbix_agentd active conf
#Eg: bash add_zabbix_agentd.sh "zabbix-server-ip"

zabbix_server_ip="${1:?need a zabbix server ip}"
zabbix_agentd_conf="/etc/zabbix/zabbix_agentd.conf"
za_hostname="$(hostname)_$(curl ifconfig.me 2>/dev/null)"

useradd -M -s /usr/sbin/nologin zabbix
apt install locales-all -y
wget https://repo.zabbix.com/zabbix/2.4/ubuntu/pool/main/z/zabbix-release/zabbix-release_2.4-1+trusty_all.deb
dpkg -i zabbix-release_2.4-1+trusty_all.deb
apt update
apt install zabbix-agent -y

sh -c "openssl rand -hex 32 > /etc/zabbix/zabbix_agentd.psk"
sed -i '/^Server=/s/127.0.0.1/'"$zabbix_server_ip"'/'  $zabbix_agentd_conf
sed -i '/^ServerActive=/s/127.0.0.1/'"$zabbix_server_ip"'/'  $zabbix_agentd_conf
sed -i '/^Hostname=/cHostname='"$za_hostname"''  $zabbix_agentd_conf
echo "
StartAgents=0
TLSConnect=psk
TLSAccept=psk
TLSPSKIdentity=PSK-${za_hostname}
TLSPSKFile=/etc/zabbix/zabbix_agentd.psk" >> $zabbix_agentd_conf

systemctl restart zabbix-agent
systemctl enable zabbix-agent

echo "pskID: PSK-${za_hostname}"
echo "pskKEY: $(cat /etc/zabbix/zabbix_agentd.psk)"