Zabbix Agent ver5.0 批量部署
背景
使用包安装或是二进制源码编译安装zabbix-agent
批量安装使用pssh或ansilbe playbook的方式批量下发主
1 准备主控文件包
zabbix-5.0.12.tar.gz # 主程序包
zabbix-agent.service # service文件
zabbix_agentd.conf # 主程序配置文件
zabbix_agentd.conf.d/* # 脚本文件
2 安装脚本
#!/bin/bash
DIR=`pwd`
grep "Ubuntu" /etc/issue &> /dev/null
if [ $? -eq 0 ];then
apt update
apt-get -y install iproute2 ntpdate tcpdump telnet traceroute nfs-kernel-server nfs-common lrzsz tree openssl libssl-dev libpcre3 libpcre3-dev zlib1g-dev ntpdate tcpdump telnet traceroute gcc openssh-server lrzsz tree openssl libssl-dev libpcre3 libpcre3-dev zlib1g-dev ntpdate tcpdump telnet traceroute iotop unzip zip make
fi
grep "Kernel" /etc/issue &> /dev/null
if [ $? -eq 0 ];then
yum install vim iotop bc gcc gcc-c++ glibc glibc-devel pcre pcre-devel openssl openssl-devel zip unzip zlib-devel net-tools lrzsz tree ntpdate telnet lsof tcpdump wget libevent libevent-devel bc systemd-devel bash-completion traceroute -y
fi
tar xvf zabbix-5.0.12.tar.gz && cd zabbix-5.0.12 && ./configure --prefix=/apps/zabbix_agent --enable-agent && make && make install
useradd zabbix -s /sbin/nologin
mkdir /apps/zabbix_agent/{pid,logs}
\cp ${DIR}/zabbix-agent.service /lib/systemd/system/zabbix-agent.service
\cp ${DIR}/zabbix_agentd.conf /apps/zabbix_agent/etc/zabbix_agentd.conf
\cp ${DIR}/zabbix_agentd.conf.d/* /apps/zabbix_agent/etc/zabbix_agentd.conf.d/
HOST_IP=`ifconfig eth0 | grep -w inet | awk '{print $2}'`
sed -i "s/Hostname=/Hostname=${HOST_IP}/g" /apps/zabbix_agent/etc/zabbix_agentd.conf
chown zabbix.zabbix -R /apps/zabbix_agent/
systemctl daemon-reload && systemctl enable zabbix-agent && systemctl restart zabbix-agent