准备以下文件
1、root@test:/usr/local/src# ll
-rwxr-xr-x 1 root root 1259 Mar 4 20:57 install_zabbix.sh*
-rw-r--r-- 1 root root 17200784 Feb 27 13:45 zabbix-4.0.18.tar.gz
-rw-r--r-- 1 root root 10968 Mar 4 20:56 zabbix_agentd.conf
drwxr-xr-x 2 root root 4096 Mar 4 17:19 zabbix_agentd.d/
-rw-r--r-- 1 root root 472 Mar 4 13:46 zabbix-agent.service
2、tar zcvf zabbix-install.tar.gz ./*
一键安装脚本
root@test:/usr/local/src# vim install_zabbix.sh
#!/bin/bash
grep "Ubuntu" /etc/issue &>/dev/null
if [ $? -eq 0 ];then
apt update
apt install iproute2 ntpdate tcpdump telnet traceroute nfs-kernel-server nfs-common lrzsz tree openssl libssl-dev libpcre3 libpcre3-dev zlib1g-dev g
cc iotop unzip zip make -y
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
mkdir /apps/
ZABBIX_VERSION="4.0.18"
tar xvf zabbix-${ZABBIX_VERSION}.tar.gz && cd zabbix-${ZABBIX_VERSION} && ./configure --prefix=/apps/zabbix_agent --enable-agent && make && make ins
tall
mkdir /apps/zabbix_agent/run
mkdir /apps/zabbix_agent/logs
useradd zabbix
cd ../
ZABBIX_HOST=`ifconfig eth0 | grep -w "inet" | awk '{print $2}'`
sed -i "s/Hostname=/Hostname=${ZABBIX_HOST}/" zabbix_agentd.conf
cp zabbix_agentd.d/* /apps/zabbix_agent/etc/zabbix_agentd.conf.d/
cp zabbix_agentd.conf /apps/zabbix_agent/etc/
cp zabbix-agent.service /lib/systemd/system/
chown zabbix.zabbix /apps/zabbix_agent/ -R
systemctl daemon-reload
systemctl enable zabbix-agent
systemctl start zabbix-agent
测试
1、ssh-keygen #生成公钥私钥对儿
2、ssh-copy-id 192.168.3.205 #把公钥拷贝到指定地址的服务器上,用来实现基于key验证的非交互式传输
3、ssh root@192.168.3.205 "cd /usr/local/src && tar xvf zabbix-install.tar.gz"
4、ssh root@192.168.3.205 "cd /usr/local/src && ./install_zabbix.sh"
#ssh以root用户的身份连接到指定服务器,执行完指定的命令后退出