• zabbix agent 6.0安装脚本


    脚本如下:

    #!/bin/bash
    
    # Function to install Zabbix Agent 2 on RHEL 6
    install_zabbix_rhel6() {
      # Check if the Zabbix repository is already installed
      if rpm -q zabbix-release &>/dev/null; then
        echo "Zabbix repository is already installed."
      else
        # Install Zabbix repository
        rpm -Uvh https://repo.zabbix.com/zabbix/6.0/rhel/6/x86_64/zabbix-release-6.0-4.el6.noarch.rpm
        if [ $? -eq 0 ]; then
          echo "Zabbix repository installed successfully."
        else
          echo "Error installing Zabbix repository. Exiting."
          exit 1
        fi
      fi
    
      # Check if Zabbix Agent 2 is already installed
      if rpm -q zabbix-agent2 &>/dev/null; then
        echo "Zabbix Agent 2 is already installed."
      else
        # Install Zabbix Agent 2
        yum clean all
        yum install zabbix-agent2 zabbix-agent2-plugin-* -y
        if [ $? -eq 0 ]; then
          echo "Zabbix Agent 2 installed successfully."
        else
          echo "Error installing Zabbix Agent 2. Exiting."
          exit 1
        fi
      fi
      # Modify Zabbix Agent 2 configuration
      read -p "Enter the desired hostname for Zabbix Agent: " hostname
      sed -i "s/^Server=.*/Server=10.99.50.112/" /etc/zabbix/zabbix_agent2.conf
      sed -i "s/^ServerActive=.*/ServerActive=10.99.50.112/" /etc/zabbix/zabbix_agent2.conf
      sed -i "s/^Hostname=.*/Hostname=$hostname/" /etc/zabbix/zabbix_agent2.conf
      # Enable and start Zabbix Agent 2
      service zabbix-agent2 restart
      chkconfig --level 35 zabbix-agent2 on
    }
    
    # Function to install Zabbix Agent 2 on RHEL 7
    install_zabbix_rhel7() {
      echo "Installing Zabbix Agent 2 on RHEL 7"
      # Check if Zabbix repository is already installed
      if rpm -q zabbix-release &>/dev/null; then
        echo "Zabbix repository is already installed."
      else
        # Install Zabbix repository
        rpm -Uvh https://repo.zabbix.com/zabbix/6.0/rhel/7/x86_64/zabbix-release-6.0-4.el7.noarch.rpm
        if [ $? -eq 0 ]; then
          echo "Zabbix repository installed successfully."
        else
          echo "Error installing Zabbix repository. Exiting."
          exit 1
        fi
      fi
    
      # Check if Zabbix Agent 2 is already installed
      if rpm -q zabbix-agent2 &>/dev/null; then
        echo "Zabbix Agent 2 is already installed."
      else
        # Install Zabbix Agent 2
        yum clean all
        yum install zabbix-agent2 zabbix-agent2-plugin-* -y
        if [ $? -eq 0 ]; then
          echo "Zabbix Agent 2 installed successfully."
        else
          echo "Error installing Zabbix Agent 2. Exiting."
          exit 1
        fi
      fi
      # Modify Zabbix Agent 2 configuration
      read -p "Enter the desired hostname for Zabbix Agent: " hostname
      sed -i "s/^Server=.*/Server=10.99.50.112/" /etc/zabbix/zabbix_agent2.conf
      sed -i "s/^ServerActive=.*/ServerActive=10.99.50.112/" /etc/zabbix/zabbix_agent2.conf
      sed -i "s/^Hostname=.*/Hostname=$hostname/" /etc/zabbix/zabbix_agent2.conf
      # Enable and start Zabbix Agent 2
      systemctl enable zabbix-agent2
      systemctl start zabbix-agent2
    }
    
    # Function to install Zabbix Agent 2 on RHEL 8
    install_zabbix_rhel8() {
      echo "Installing Zabbix Agent 2 on RHEL 8"
      # Check if the Zabbix repository is already installed
      if rpm -q zabbix-release &>/dev/null; then
        echo "Zabbix repository is already installed."
      else
        # Install Zabbix repository
        rpm -Uvh https://repo.zabbix.com/zabbix/6.0/rhel/8/x86_64/zabbix-release-6.0-4.el8.noarch.rpm
        if [ $? -eq 0 ]; then
          echo "Zabbix repository installed successfully."
        else
          echo "Error installing Zabbix repository. Exiting."
          exit 1
        fi
      fi
    
      # Check if Zabbix Agent 2 is already installed
      if rpm -q zabbix-agent2 &>/dev/null; then
        echo "Zabbix Agent 2 is already installed."
      else
        # Install Zabbix Agent 2
        dnf clean all
        dnf install zabbix-agent2 zabbix-agent2-plugin-* -y
        if [ $? -eq 0 ]; then
          echo "Zabbix Agent 2 installed successfully."
        else
          echo "Error installing Zabbix Agent 2. Exiting."
          exit 1
        fi
      fi
      # Modify Zabbix Agent 2 configuration
      read -p "Enter the desired hostname for Zabbix Agent: " hostname
      sed -i "s/^Server=.*/Server=10.99.50.112/" /etc/zabbix/zabbix_agent2.conf
      sed -i "s/^ServerActive=.*/ServerActive=10.99.50.112/" /etc/zabbix/zabbix_agent2.conf
      sed -i "s/^Hostname=.*/Hostname=$hostname/" /etc/zabbix/zabbix_agent2.conf
      # Enable and start Zabbix Agent 2
      systemctl enable zabbix-agent2
      systemctl start zabbix-agent2
    }
    
    # Install Zabbix repository based on the selected OS version
    echo "Select the operating system version:"
    options=("RHEL 6" "RHEL 7" "RHEL 8" "Quit")
    select opt in "${options[@]}"; do
      case "$opt" in
        "RHEL 6")
          install_zabbix_rhel6
          break
          ;;
        "RHEL 7")
          install_zabbix_rhel7
          break
          ;;
        "RHEL 8")
          install_zabbix_rhel8
          break
          ;;
        "Quit")
          echo "Exiting."
          exit 0
          ;;
        *)
          echo "Invalid option. Please select a valid option."
          ;;
      esac
    done  
    
    
    echo "Zabbix Agent 2 installation and configuration complete."
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59
    • 60
    • 61
    • 62
    • 63
    • 64
    • 65
    • 66
    • 67
    • 68
    • 69
    • 70
    • 71
    • 72
    • 73
    • 74
    • 75
    • 76
    • 77
    • 78
    • 79
    • 80
    • 81
    • 82
    • 83
    • 84
    • 85
    • 86
    • 87
    • 88
    • 89
    • 90
    • 91
    • 92
    • 93
    • 94
    • 95
    • 96
    • 97
    • 98
    • 99
    • 100
    • 101
    • 102
    • 103
    • 104
    • 105
    • 106
    • 107
    • 108
    • 109
    • 110
    • 111
    • 112
    • 113
    • 114
    • 115
    • 116
    • 117
    • 118
    • 119
    • 120
    • 121
    • 122
    • 123
    • 124
    • 125
    • 126
    • 127
    • 128
    • 129
    • 130
    • 131
    • 132
    • 133
    • 134
    • 135
    • 136
    • 137
    • 138
    • 139
    • 140
    • 141
    • 142
    • 143
    • 144
    • 145
    • 146
    • 147
    • 148
    • 149
    • 150
    • 151
    • 152
    • 153
    • 154
  • 相关阅读:
    vue3中遇到的问题
    Node.js 入门教程 26 npm 依赖与开发依赖 & 27 Node.js 包运行器 npx
    python删除集合(set)元素时,remove和discard的区别
    Docker 创建网络
    浅析Linux内核高端内存
    【Harmony OS】【ArkUI】ets开发 创建视图与构建布局
    《Head First HTML与CSS》学习笔记
    由小见大!不规则造型按钮解决方案
    运动控制:音圈电机
    nginx、apache流量日志分析
  • 原文地址:https://blog.csdn.net/zyj81092211/article/details/134038715