This Bash script automates the process of replacing Zabbix Agent 1 with Zabbix Agent 2 on Ubuntu systems. It ensures that Zabbix Agent 2 is installed and configured correctly, and if Zabbix Agent 1 is present, it will be removed.
- Checks and installs any missing dependencies.
- Adds the official Zabbix repository.
- Installs Zabbix Agent 2.
- Configures Zabbix Agent 2 using user-provided server IP and hostname.
- Removes Zabbix Agent 1 if it is installed.
- Backs up the old Zabbix Agent 1 configuration.
- Ensures the script is executed with root privileges.
- The script must be run on Ubuntu.
- You must have
sudoprivileges to execute this script.
-
Download the script from your GitHub repository and make it executable:
wget https://raw.githubusercontent.com/svds12343/zabbixagent-replace/main/zabbixagentreplace.sh chmod +x zabbixagentreplace.sh
-
Run the script using
sudo:sudo ./zabbixagentreplace.sh
-
Follow the prompts to enter the Zabbix Server IP and the hostname for the Zabbix Agent.
- All operations are logged to
/var/log/replace_zabbix_agent.log.
- Check for root privileges: The script checks if it is run as root and stops if it isn't.
- Check and install dependencies: The script installs
wget,dpkg,apt, andsystemctlif they are missing. - Replace Zabbix Agent 1 with Zabbix Agent 2:
- Stops and removes Zabbix Agent 1, if installed.
- Backs up the configuration file of Zabbix Agent 1 to
/etc/zabbix/zabbix_agentd.conf.bak. - Installs Zabbix Agent 2.
- Configures Zabbix Agent 2 with the server IP and hostname provided by the user.
- Starts Zabbix Agent 2 and enables it to start at boot.
- Handle cases where Zabbix Agent 1 is not installed:
- Directly installs and configures Zabbix Agent 2 if neither agent is initially present.
- Check the log file at
/var/log/replace_zabbix_agent.logfor detailed error messages. - Ensure you have network connectivity and access to Zabbix repositories.