##!/bin/bash
# file:ssh.sh
# author: pansn
# date:2020-07-17 15:02
# version 1.0
# description: Shell script
# @Copyright (c) all right reserved
#IP=`ifconfig | grep -E -o "(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?).(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?).(25[0-5]|2[0-4][0-9]|[04][0-9]|[01]?[0-9][0-9]?)"|grep -E '^10.|^172.|^192.'|head -n1`
wget https://repo.zabbix.com/zabbix/5.0/ubuntu/pool/main/z/zabbix-release/zabbix-release_5.0-1+xenial_all.deb
dpkg -i zabbix-release_5.0-1+xenial_all.deb
apt update
echo "安装zabbix-agent"
apt install zabbix-agent -y
#rm -rf zabbix-agent-4.2.6-1.el7.x86_64.rpm
echo‘备份agent.conf配置文件‘
cp /etc/zabbix/zabbix_agentd.conf /etc/zabbix/zabbix_agentd.conf.bak
echo '修改配置文件'
sed -i 's/Server=127.0.0.1/Server=zbx.xxx.cn/' /etc/zabbix/zabbix_agentd.conf
sed -i "s/Hostname=Zabbix server/Hostname=`hostname`/" /etc/zabbix/zabbix_agentd.conf
sed -i 's/^ServerActive=127.0.0.1/ServerActive=zbx.xxx.cn/' /etc/zabbix/zabbix_agentd.conf
sed -i 's/# HostMetadata=/HostMetadata=linux zabbix.oneplus/' /etc/zabbix/zabbix_agentd.conf
systemctl start zabbix-agent && systemctl enable zabbix-agent
#检测是否存在agent端口
port=$(netstat -nlp|grep 10050|wc -l)
if [ ${port} -ne 0 ];then
echo "zabbix-agent安装成功"
else
echo "zabbix安装失败请检查"
fi
rm -rf zabbix-release_5.0-1+xenial_all.deb