这篇文章所写的脚本并不具有通用性,只是简单的安装步骤而已,以此做一个记录
另外,本文只是一个够用即可的脚本,可以优化的地方还很多,如果能想起来的话会继续进行优化
#!/bin/bash source ~/.bashrc COLOR="echo -e \\033[01;31m" END='\033[0m' SRC_DIR=/tmp Centos='zabbix-agent2-7.0.0-alpha6.release2.el7.x86_64.rpm' Ubuntu1804='zabbix-agent2_7.0.0~alpha6-2+ubuntu18.04_amd64.deb' Ubuntu2004='zabbix-agent2_7.0.0~alpha6-2+ubuntu20.04_amd64.deb' Ubuntu2204='zabbix-agent2_7.0.0~alpha6-2+ubuntu22.04_amd64.deb' #systemctl status zabbix-agent* $COLOR "请确认是否安装"$END read -p "Please enter the Y/N:" para case $para in [yY]) echo "entered Y" # systemctl disable zabbix-agent ;; [nN]) echo "entered N" exit 1 ;; *) echo "Invalid input ......" read -p "Please enter any key to exit" exit exit 1 esac #read -p "Please enter any key to exit" exit_shell $COLOR"请将相关软件放在${SRC_DIR}目录下"$END OS=`awk -F'[ ="]+' '/^PRETTY_NAME/{print $2}' /etc/os-release` VERSION_ID=`awk -F'[ ="]+' '/^VERSION_ID/{print $2}' /etc/os-release` cd $SRC_DIR Ubuntu_install (){ dpkg -i zabbix-agent2_7.0.0~alpha6*.deb if [ $? -eq 0 ];then sed -i "/^Server/s#=\(.*\)#=172.29.18.67#;/^Hostname/s#=\(.*\)#=$(hostname)#" /etc/zabbix/zabbix_agent2.conf else apt install libpcre2-8-0 && apt --fix-broken -y install zabbix-agent2_7.0.0~alpha6*.deb sed -i "/^Server/s#=\(.*\)#=172.29.18.67#;/^Hostname/s#=\(.*\)#=$(hostname)#" /etc/zabbix/zabbix_agent2.conf fi } if [ "CentOS" = $OS ];then if [ ! -e $Centos ];then $COLOR"缺少${Centos}文件,将开始下载"$END wget http://mirrors.aliyun.com/zabbix/zabbix/6.5/rhel/7/x86_64/$Centos fi `rpm -Uvh zabbix-agent2-7.0.0-alpha6*.rpm` if [ $? -eq 0 ];then sed -i "/^Server/s#=\(.*\)#=172.29.18.75,172.29.18.79#;/^Hostname/s#=\(.*\)#=$(hostname)#" /etc/zabbix/zabbix_agent2.conf else systemctl status zabbix-agent2 if [ $? -eq 0 ];then yum install -y zabbix-agent2-7.0.0-alpha6*.rpm mv /etc/zabbix/zabbix_agent2.conf /etc/zabbix/zabbix_agent2.conf.old;mv /etc/zabbix/zabbix_agent2.conf.rpmnew /etc/zabbix/zabbix_agent2.conf else yum install -y zabbix-agent2-7.0.0-alpha6*.rpm fi sed -i "/^Server/s#=\(.*\)#=172.29.18.75,172.29.18.79#;/^Hostname/s#=\(.*\)#=$(hostname)#" /etc/zabbix/zabbix_agent2.conf fi else [ "Ubuntu" = $OS ] if [ "18.04" = $VERSION_ID ];then if [ ! -e $Ubuntu1804 ];then $COLOR"缺少${Ubuntu1804}文件,将开始下载"$END wget http://mirrors.aliyun.com/zabbix/zabbix/6.5/ubuntu/pool/main/z/zabbix/$Ubuntu1804 fi Ubuntu_install elif [ "20.04" = $VERSION_ID ];then if [ ! -e $Ubuntu2004 ];then $COLOR"缺少${Ubuntu2004}文件,将开始下载"$END wget http://mirrors.aliyun.com/zabbix/zabbix/6.5/ubuntu/pool/main/z/zabbix/$Ubuntu2004 fi Ubuntu_install elif [ "22.04" = $VERSION_ID ];then if [ ! -e $Ubuntu2204 ];then $COLOR"缺少${Ubuntu2204}文件,将开始下载"$END wget http://mirrors.aliyun.com/zabbix/zabbix/6.5/ubuntu/pool/main/z/zabbix/$Ubuntu2204 fi Ubuntu_install fi fi grep -Ev "^#|^$" /etc/zabbix/zabbix_agent2.conf $COLOR "请确认文件是否正确"$END read -p "Please enter the Y/N:" para case $para in [yY]) echo "entered Y" systemctl status zabbix-agent.service if [ $? -eq 0 ];then systemctl disable --now zabbix-agent.service else echo "Invalid input ......" read -p "Please enter any key to exit" exit exit 1 fi systemctl status zabbix-agent.service echo "已终止zabbix-agent进程,即将唤起新进程" systemctl enable zabbix-agent2 sleep 3 systemctl restart zabbix-agent2 systemctl status zabbix-agent2 sleep 1 /usr/sbin/zabbix_agent2 -V ;; [nN]) echo "entered N" exit 1 ;; *) echo "Invalid input ......" read -p "Please enter any key to exit" exit exit 1 esac read -p "Please enter any key to exit" exit_shell
文章评论