其实,说句心里话,蛮不喜欢写这个脚本的,为啥?

因为太简单了,无非就是一条命令能解决的问题,那为啥还要写这个脚本呢?

无奈,这社会总是存在一些逼着你进步的人!

刚入软件行业的时候,总有一些人给你提一些你没做过的需求,总觉得有人在刁难你。然而,当你实现这个需求被人夸你很屌的时候,你心里总会默默的感谢“这些”人,是他们给了你进步的机会。

服务器操作系统多样化,那安装zabbix就很麻烦需要找对应的版本,于是,懒人的脚本就此诞生了。

以下就是见证奇迹的时刻

#!/bin/bash
# auth by huwj
# date:2019-12
# auto install zabbix-agent# .bash_profile
# Get the aliases and functions
if [ -f ~/.bashrc ]; then. ~/.bashrc
fi
# User specific environment and startup programs
export PATH# 获取操作系统位数
sys_num=`getconf LONG_BIT`
# zabbix服务端IP
ServerIP='192.168.142.10'
# 获取客户端服务器的IP
AgentIP=`ip a show dev ens33|grep -w inet|awk '{print $2}'|awk -F '/' '{print $1}'`
# 配置文件
zabbix_config='/etc/zabbix/zabbix_agentd.conf'
# 获取数据
case $1 in Centos6)checkAgent=`rpm -qa | grep 'zabbix-agent'`if [ -z $checkAgent ];thenif [ $sys_num -eq 64 ];thenrpm -ivh https://repo.zabbix.com/zabbix/4.2/rhel/6/x86_64/zabbix-agent-4.2.6-1.el6.x86_64.rpm if [ -z $checkAgent ];thensed -i "s/Server=127.0.0.1/Server=$ServerIP/" $zabbix_configsed -i "s/ServerActive=127.0.0.1/ServerActive=$ServerIP/" $zabbix_configsed -i "s/Hostname=Zabbix server/Hostname=$AgentIP/" $zabbix_configservice zabbix-agent restartelseecho 'Zabbix-agent install failed ! please run again .'fielserpm -ivh https://repo.zabbix.com/zabbix/4.2/rhel/6/i386/zabbix-agent-4.2.6-1.el6.i686.rpmif [ -z $checkAgent ];thensed -i "s/Server=127.0.0.1/Server=$ServerIP/" $zabbix_configsed -i "s/ServerActive=127.0.0.1/ServerActive=$ServerIP/" $zabbix_configsed -i "s/Hostname=Zabbix server/Hostname=$AgentIP/" $zabbix_configservice zabbix-agent restartelseecho 'Zabbix-agent install failed ! please run again .'fifielseecho "Zabbix-agent has been installed in this system !"fi ;; Centos7)checkAgent=`rpm -qa | grep 'zabbix-agent'`if [ -z $checkAgent ];thenif [ $sys_num -eq 64 ];thenrpm -ivh https://repo.zabbix.com/zabbix/4.2/rhel/7/x86_64/zabbix-agent-4.2.6-1.el7.x86_64.rpmif [ -z $checkAgent ];thensed -i "s/Server=127.0.0.1/Server=$ServerIP/" $zabbix_configsed -i "s/ServerActive=127.0.0.1/ServerActive=$ServerIP/" $zabbix_configsed -i "s/Hostname=Zabbix server/Hostname=$AgentIP/" $zabbix_configsystemctl restart zabbix-agentelseecho 'Zabbix-agent install failed ! please run again .'fi           elserpm -ivh https://repo.zabbix.com/zabbix/4.2/rhel/7/x86_64/zabbix-agent-4.2.6-1.el7.x86_64.rpmif [ -z $checkAgent ];thensed -i "s/Server=127.0.0.1/Server=$ServerIP/" $zabbix_configsed -i "s/ServerActive=127.0.0.1/ServerActive=$ServerIP/" $zabbix_configsed -i "s/Hostname=Zabbix server/Hostname=$AgentIP/" $zabbix_configelseecho 'Zabbix-agent install failed ! please run again .'fifielseecho "Zabbix-agent has been installed in this system !"fi;;RedHat6)checkAgent=`rpm -qa | grep 'zabbix-agent'`if [ -z $checkAgent ];thenif [ $sys_num -eq 64 ];thenrpm -ivh https://repo.zabbix.com/zabbix/4.2/rhel/6/x86_64/zabbix-agent-4.2.6-1.el6.x86_64.rpm if [ -z $checkAgent ];thensed -i "s/Server=127.0.0.1/Server=$ServerIP/" $zabbix_configsed -i "s/ServerActive=127.0.0.1/ServerActive=$ServerIP/" $zabbix_configsed -i "s/Hostname=Zabbix server/Hostname=$AgentIP/" $zabbix_configservice zabbix-agent restartelseecho 'Zabbix-agent install failed ! please run again .'fielserpm -ivh https://repo.zabbix.com/zabbix/4.2/rhel/6/i386/zabbix-agent-4.2.6-1.el6.i686.rpmif [ -z $checkAgent ];thensed -i "s/Server=127.0.0.1/Server=$ServerIP/" $zabbix_configsed -i "s/ServerActive=127.0.0.1/ServerActive=$ServerIP/" $zabbix_configsed -i "s/Hostname=Zabbix server/Hostname=$AgentIP/" $zabbix_configservice zabbix-agent restartelseecho 'Zabbix-agent install failed ! please run again .'fifielseecho "Zabbix-agent has been installed in this system !"fi ;; RedHat7)checkAgent=`rpm -qa | grep 'zabbix-agent'`if [ -z $checkAgent ];thenif [ $sys_num -eq 64 ];thenrpm -ivh https://repo.zabbix.com/zabbix/4.2/rhel/7/x86_64/zabbix-agent-4.2.6-1.el7.x86_64.rpmif [ -z $checkAgent ];thensed -i "s/Server=127.0.0.1/Server=$ServerIP/" $zabbix_configsed -i "s/ServerActive=127.0.0.1/ServerActive=$ServerIP/" $zabbix_configsed -i "s/Hostname=Zabbix server/Hostname=$AgentIP/" $zabbix_configsystemctl restart zabbix-agentelseecho 'Zabbix-agent install failed ! please run again .'fi           elserpm -ivh https://repo.zabbix.com/zabbix/4.2/rhel/7/x86_64/zabbix-agent-4.2.6-1.el7.x86_64.rpmif [ -z $checkAgent ];thensed -i "s/Server=127.0.0.1/Server=$ServerIP/" $zabbix_configsed -i "s/ServerActive=127.0.0.1/ServerActive=$ServerIP/" $zabbix_configsed -i "s/Hostname=Zabbix server/Hostname=$AgentIP/" $zabbix_configelseecho 'Zabbix-agent install failed ! please run again .'fifielseecho "Zabbix-agent has been installed in this system !"fi;;Ubuntu)checkAgent=`dpkg -l | grep zabbix-agent`if [ -z $checkAgent ];thenapt-get install zabbix-agentif [ -z $checkAgent ];thensed -i "s/Server=127.0.0.1/Server=$ServerIP/" $zabbix_configsed -i "s/ServerActive=127.0.0.1/ServerActive=$ServerIP/" $zabbix_configsed -i "s/Hostname=Zabbix server/Hostname=$AgentIP/" $zabbix_configservice zabbix-agent restartelseecho 'Zabbix-agent install failed ! please run again .'fi           elseecho "Zabbix-agent has been installed in this system !"fi;;*) echo "Usage:$0(Centos6|Centos7|Ubuntu|RedHat6|RedHat7)" ;;
esac

该脚本支持 Centos6|Centos7|Ubuntu|RedHat6|RedHat7 安装

脚本中还存在较多冗余的脚本,后期再优化下。

该脚本上传服务器后,授予执行权限:chmod +x installZabbix.sh 然后脚本后面需输入对应操作系统版本,如Ubuntu安装 ,需执行命令: ./installZabbix.sh Ubuntu

自动化安装zabbix-agent的脚本相关推荐

  1. Windows系统一键安装zabbix agent

    下载附件里的zabbix_agents_auto_installer.win.rar,解压后修改AutoInstall.bat里的zabbix_server的IP,以管理员身份运行AutoInstal ...

  2. bat 安装zabbix agent

    公司数百的服务器需要安装zabbix agent,却因公司规章无法使用批量部署软件的情况,你只能静下心来一台台安装.当然也可以使用简便方法安装: 此处的'zabbix agent 2' 为我需要安装的 ...

  3. Windows下安装Zabbix agent

    1.网上下载新版的Windows Agent http://www.zabbix.com/downloads/2.2.1/zabbix_agents_2.2.1.win.zip 2. 解压后找到bin ...

  4. 1 源码安装Zabbix agent 3.4

    1.创建zabbix用户和组 # groupadd zabbix # useradd -g zabbix zabbix -s /sbin/nologin 2.安装支持的类库 # yum -y inst ...

  5. ubuntu内网环境安装zabbix agent

    一.在一台可以连接外网的同系统的ubuntu上制作离线安装包 1.1.通过如下指令下载zabbix agent软件所需要的deb包 $ sudo apt-get -d install zabbix-a ...

  6. windows 安装 zabbix agent 客户端

    下载window客户端 https://assets.zabbix.com/downloads/3.4.0/zabbix_agents_3.4.0.win.zip 在C盘建立目录 C:/zabbix ...

  7. Freebsd安装zabbix agent

    1. 使用WinSCP将zabbix-3.0.2.tar复制到/tmp目录 2. 解压 执行: cd /tmp tar -zxf zabbix-3.0.2.tar.gz 3. 安装 执行: cd za ...

  8. zabbix agent 的两种安装方式

    (一)zabbix-agent介绍和工作原理 1 介绍 zabbix([`zæbiks])是一个基于WEB界面的提供分布式系统监视以及网络监视功能的企业级的开源解决方案.     zabbix能监视各 ...

  9. zabbix agent安装_zabbix agent的安装与配置

    Agent安装 rpm -ivh zabbix-agent-3.2.4-1.el6.x86_64.rpm 安装完成后,zabbix agent端已经安装完成了,zabbix agent端的配置目录位于 ...

  10. zabbix6.0安装教程(四):构建 Zabbix agent

    zabbix6.0安装教程(四):构建 Zabbix agent 目录 一.在 macOS 上构建 Zabbix agent 1. 概述 2. 必要条件 3. 使用共享库构建 agent 二进制文件 ...

最新文章

  1. java 二进制,八进制,十进制,十六进制间相互转换的方法
  2. linux自学笔记--nginx基本配置
  3. 用STM32做个东京奥运奖牌榜
  4. WinDBG 技巧:如何生成Dump 文件(.dump 命令)
  5. 什么是WebSocket,以及如何在Python中使用它?
  6. ubuntu nginx添加站点配置失效处理
  7. javamelody监控java项目_使用javamelody监控javaEE
  8. RIPng原理与实验
  9. 名称不存在或不是目录_大数据从入门到深入:LINUX 04 文档目录管理
  10. 转载:Linux内核探索之路——关于书
  11. 读书笔记202208 TRC2010 Multi-agent model predictive control of signaling split in urban traffic networks
  12. EXCEL长数字显示和转化为文本
  13. 基于PaddleX构建专属行车助手,为交通安全保驾护航
  14. Java-(二)微信小程序授权获取用户信息和手机号码
  15. 银行利率bp是什么意思,利率bp怎么换算
  16. seo关键字优化条例
  17. HiPQTools工具HiPQStitchingTool标定(二)
  18. TP-link wdr7800百M拆解
  19. 机器学习读书笔记:假设检验(二)
  20. 第二次量产成功:KingSton DT 101 G2 8G的量产经历

热门文章

  1. 网络斗地主游戏的完整设计与实现(五)随机发牌功能的实现
  2. 基于WebGL的三维数据可视化大屏开发流 ThingJS
  3. 浏览器没办法播放html文件,ie浏览器使用video标签无法播放mp4文件
  4. PHP for循环执行流程
  5. JMeter入门教程(2) --Jmeter的下载
  6. 黑马程序员,黑马论坛----黑马.Net9期毕业60天,就业率已达100%,平均薪水6236.17元
  7. 图片的版权保护(添加水印)
  8. 图像如何存储在计算机中?
  9. 红帽(redhat)Linux-起源
  10. 用于广告机,闸机设备,自助售货机,工控主机等的rk3288开发板