├── .project ├── LICENSE.md ├── README.md ├── images └── title.png └── scripts ├── install-agent2.sh ├── install.sh └── movedb.sh /.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | install-zabbix 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | BSD 3-Clause License 2 | 3 | Copyright (c) 2018, Steven P. Goldsmith 4 | All rights reserved. 5 | 6 | Redistribution and use in source and binary forms, with or without 7 | modification, are permitted provided that the following conditions are met: 8 | 9 | * Redistributions of source code must retain the above copyright notice, this 10 | list of conditions and the following disclaimer. 11 | 12 | * Redistributions in binary form must reproduce the above copyright notice, 13 | this list of conditions and the following disclaimer in the documentation 14 | and/or other materials provided with the distribution. 15 | 16 | * Neither the name of the copyright holder nor the names of its 17 | contributors may be used to endorse or promote products derived from 18 | this software without specific prior written permission. 19 | 20 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 21 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 24 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 26 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 27 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 28 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ![Title](images/title.png) 2 | 3 | Install Zabbix is a set of scripts to install/upgrade Zabbix 6.4.x from source on Ubuntu 4 | 22.04 and probably other Debian derived distributions. You can of course use 5 | various methods to install Zabbix Server, but this method gives you the ultimate 6 | flexibility. In addition, there are no deb packages for ARM32 based platforms hence 7 | building from source is the only method. The scripts allow: 8 | * Install and secure MySQL server 9 | * Import Zabbix data into MySQL 10 | * Install Java 17 JDK for the Java gateway and enable in build 11 | * Patch source to fix "plugins/proc/procfs_linux.go:248:6: constant 1099511627776 overflows int" on 32 bit systems 12 | * Install Zabbix Server 13 | * Create zbx_monitor user for local MySQL monitoring (just configure and add 'Template DB MySQL by Zabbix agent 2' template to 'Zabbix server') 14 | * Install Zabbix Agent 2 15 | * Create systemd services for both Zabbix Server and Agent 2 16 | * Move MySQL data directory (optional) 17 | * Install Zabbix Agent 2 on clients (optional) 18 | 19 | **Important note:** Before upgrading Zabbix see [Upgrade from sources](https://www.zabbix.com/documentation/current/en/manual/installation/upgrade/sources). 20 | To be on the safe side I would [export](https://www.zabbix.com/documentation/current/en/manual/xml_export_import) Zabbix 21 | server configuration, shut down Zabbix server service and [backup](https://linuxconfig.org/linux-commands-to-backup-and-restore-mysql-database) 22 | MySQL database. If you are using a VM just make a snapshot before upgrading and rollback 23 | if you have problems. As always, you should test upgrade on a VM first if possible. 24 | 25 | **Upgrading error** If you get ```The Zabbix database version does not match current requirements. Your database version: 6010048. Required version: 6020000. Please contact your system administrator.``` 26 | in UI and ```[Z3005] query failed: [1419] You do not have the SUPER privilege and binary logging is enabled (you *might* want to use the less safe log_bin_trust_function_creators variable) [create trigger hosts_insert after insert on hosts``` 27 | in log. 28 | * `sudo service zabbix-server stop` 29 | * `sudo mysql -u root` 30 | * `SET GLOBAL log_bin_trust_function_creators = 1;` 31 | * `commit;` 32 | * `quit` 33 | * `sudo service zabbix-server start` 34 | * Check /tmp/zabbix_server.log 35 | 36 | More [configuration](https://techexpert.tips/category/zabbix) options! 37 | 38 | ## Download project 39 | * `cd ~/` 40 | * `git clone --depth 1 https://github.com/sgjava/install-zabbix.git` 41 | 42 | ## Install script 43 | This assumes a fresh OS install. You should try the scripts out on a VM to play 44 | with configuration prior to doing final install. Upgrade is performed if existing 45 | install detected and configuration is saved to `/usr/local/etc/zabbix_server.conf.bak` 46 | and `/usr/local/etc/zabbix_agent2.conf.bak` 47 | * `cd ~/install-zabbix/scripts` 48 | * Change configuration values as needed 49 | * `./install.sh` 50 | * Check log file for errors 51 | * Navigate to http://hostname/zabbix 52 | * Get DB password from script and finalize front end configuration 53 | * Login using Admin/zabbix 54 | 55 | To stop and start Zabbix server 56 | * `sudo service zabbix-server stop` 57 | * `sudo service zabbix-server start` 58 | 59 | ## Move DB script 60 | This assumes you ran install.sh above. It's handy to move the MySQL data directory 61 | to a NFS share if you are running Zabbix Server off an SD card for instance. 62 | * `cd ~/install-zabbix/scripts` 63 | * Change configuration values as needed 64 | * `./movedb.sh` 65 | * Check log file for errors 66 | 67 | If you plan on using a NFS mount for your MySQL data directory you will need to 68 | do the following: 69 | * `sudo nano /etc/systemd/system/multi-user.target.wants/mysql.service` 70 | * Add `remote-fs.target` to `After` 71 | * Add `RequiresMountsFor=/your/mount/dir` to `[Unit]` section 72 | * `sudo systemctl daemon-reload` 73 | 74 | To stop and start MySQL server 75 | * `sudo service mysql stop` 76 | * `sudo service mysql start` 77 | 78 | These changes can be removed during `apt upgrade`, so if you see mysql fail to start after reboot add service changes back in. 79 | 80 | ## Install Agent 2 script 81 | Install Zabbix Agent 2 script on client. Make sure to change configuration to point to 82 | your Zabbix server before running. You can always configure manually should you forget. 83 | Upgrade is performed if existing install detected and configuration is saved to `/usr/local/etc/zabbix_agent2.conf.bak` 84 | * `cd ~/install-zabbix/scripts` 85 | * Change configuration values as needed 86 | * `./install-agent2.sh` 87 | * Check log file for errors 88 | 89 | To stop and start Zabbix Agent 2 90 | * `sudo service zabbix-agent2 stop` 91 | * `sudo service zabbix-agent2 start` 92 | -------------------------------------------------------------------------------- /images/title.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sgjava/install-zabbix/3e3005e64a8ad5231149c7972afaa68a7d2f1b7c/images/title.png -------------------------------------------------------------------------------- /scripts/install-agent2.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # Created on June 7, 2020 4 | # 5 | # @author: sgoldsmith 6 | # 7 | # Install Zabbix Agent 2 on Ubuntu 22.05. This may work on other versions and 8 | # Debian like distributions. Change variables below to suit your needs. This 9 | # script will detect previous install and upgrade the agent. 10 | # 11 | # Steven P. Goldsmith 12 | # sgjava@gmail.com 13 | # 14 | 15 | # Zabbix Server URL 16 | zabbixurl="https://cdn.zabbix.com/zabbix/sources/stable/6.4/zabbix-6.4.10.tar.gz" 17 | 18 | # Just Zabbix server archive name 19 | zabbixarchive=$(basename "$zabbixurl") 20 | 21 | # Where to put Zabbix source 22 | srcdir="/usr/local/src" 23 | 24 | # Zabbix agent configuration 25 | zabbixconf="/usr/local/etc/zabbix_agent2.conf" 26 | 27 | # Zabbix host 28 | zabbixhost="192.168.1.69" 29 | 30 | # Temp dir for downloads, etc. 31 | tmpdir="$HOME/temp" 32 | 33 | # stdout and stderr for commands logged 34 | logfile="$PWD/install-agent2.log" 35 | rm -f $logfile 36 | 37 | # Simple logger 38 | log(){ 39 | timestamp=$(date +"%m-%d-%Y %k:%M:%S") 40 | echo "$timestamp $1" 41 | echo "$timestamp $1" >> $logfile 2>&1 42 | } 43 | 44 | log "Removing temp dir $tmpdir" 45 | rm -rf "$tmpdir" >> $logfile 2>&1 46 | mkdir -p "$tmpdir" >> $logfile 2>&1 47 | 48 | # Download Zabbix source 49 | log "Downloading $zabbixarchive to $tmpdir" 50 | wget -q --directory-prefix=$tmpdir "$zabbixurl" >> $logfile 2>&1 51 | log "Extracting $zabbixarchive to $tmpdir" 52 | tar -xf "$tmpdir/$zabbixarchive" -C "$tmpdir" >> $logfile 2>&1 53 | # Remove .gz 54 | filename="${zabbixarchive%.*}" 55 | # Remove .tar 56 | filename="${filename%.*}" 57 | sudo -E mv "$tmpdir/$filename" "${srcdir}" >> $logfile 2>&1 58 | 59 | # Install Zabbix Agent 2 60 | log "Installing Zabbix Agent 2..." 61 | if [ -f /etc/systemd/system/zabbix-agent2.service ]; then 62 | # Stop existing service 63 | sudo -E service zabbix-agent2 stop >> $logfile 2>&1 64 | log "Saving existing configuration to ${zabbixconf}.bak" 65 | sudo -E mv "${zabbixconf}" "${zabbixconf}.bak" 66 | else 67 | # Use latest golang 68 | log "Adding Go repository..." 69 | sudo -E add-apt-repository ppa:longsleep/golang-backports -y >> $logfile 2>&1 70 | sudo -E apt update >> $logfile 2>&1 71 | sudo -E groupadd zabbix >> $logfile 2>&1 72 | sudo -E useradd -g zabbix -s /bin/bash zabbix >> $logfile 2>&1 73 | sudo -E apt-get -y install build-essential pkg-config libpcre3-dev libz-dev golang-go >> $logfile 2>&1 74 | fi 75 | cd "${srcdir}/${filename}" >> $logfile 2>&1 76 | # Patch source to fix "plugins/proc/procfs_linux.go:248:6: constant 1099511627776 overflows int" on 32 bit systems 77 | log "Patching source to work on 32 bit platforms..." 78 | sed -i 's/strconv.Atoi(strings.TrimSpace(line\[:len(line)-2\]))/strconv.ParseInt(strings.TrimSpace(line[:len(line)-2]),10,64)/' src/go/plugins/proc/procfs_linux.go >> $logfile 2>&1 79 | # Cnange configuration options here 80 | sudo -E ./configure --enable-agent2 --prefix=/usr/local >> $logfile 2>&1 81 | sudo -E make install >> $logfile 2>&1 82 | # Configure Zabbix agent 2 83 | sudo -E sed -i "s|Server=127.0.0.1|Server=$zabbixhost|g" "$zabbixconf" >> $logfile 2>&1 84 | sudo -E sed -i "s|ServerActive=127.0.0.1|ServerActive=$zabbixhost|g" "$zabbixconf" >> $logfile 2>&1 85 | sudo -E sed -i "s|Hostname=|#Hostname=|g" "$zabbixconf" >> $logfile 2>&1 86 | 87 | # Install Zabbix agent 2 service 88 | if [ ! -f /etc/systemd/system/zabbix-agent2.service ]; then 89 | log "Installing Zabbix Agent 2 Service..." 90 | sudo tee -a /etc/systemd/system/zabbix-agent2.service > /dev/null <> $logfile 2>&1 107 | fi 108 | 109 | # Start up Zabbix Agent 2 110 | log "Starting Zabbix Agent 2..." 111 | sudo -E service zabbix-agent2 start >> $logfile 2>&1 112 | log "Removing temp dir $tmpdir" 113 | rm -rf "$tmpdir" >> $logfile 2>&1 114 | -------------------------------------------------------------------------------- /scripts/install.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # Created on June 5, 2020 4 | # 5 | # @author: sgoldsmith 6 | # 7 | # Install dependencies, mysql, Zabbix Server 6.2.x and Zabbix Agent 2 on Ubuntu 8 | # 22.05. This may work on other versions and Debian like distributions. 9 | # 10 | # Change variables below to suit your needs. 11 | # 12 | # Steven P. Goldsmith 13 | # sgjava@gmail.com 14 | # 15 | 16 | # MySQL root password 17 | dbroot="rootZaq!2wsx" 18 | 19 | # Zabbix user MySQL password 20 | dbzabbix="zabbixZaq!2wsx" 21 | 22 | # MySQL database monitoring user 23 | monzabbix="monzabbixZaq!2wsx" 24 | 25 | # Zabbix Server URL 26 | zabbixurl="https://cdn.zabbix.com/zabbix/sources/stable/6.4/zabbix-6.4.10.tar.gz" 27 | 28 | # Just Zabbix server archive name 29 | zabbixarchive=$(basename "$zabbixurl") 30 | 31 | # Where to put Zabbix source 32 | srcdir="/usr/local/src" 33 | 34 | # PHP timezone 35 | phptz="America/New_York" 36 | 37 | # Zabbix server configuration 38 | zabbixconf="/usr/local/etc/zabbix_server.conf" 39 | 40 | #Zabbix agent configuration 41 | zabbixagentconf="/usr/local/etc/zabbix_agent2.conf" 42 | 43 | # Get architecture 44 | arch=$(uname -m) 45 | 46 | # Temp dir for downloads, etc. 47 | tmpdir="$HOME/temp" 48 | 49 | # stdout and stderr for commands logged 50 | logfile="$PWD/install.log" 51 | rm -f $logfile 52 | 53 | # Simple logger 54 | log(){ 55 | timestamp=$(date +"%m-%d-%Y %k:%M:%S") 56 | echo "$timestamp $1" 57 | echo "$timestamp $1" >> $logfile 2>&1 58 | } 59 | 60 | log "Removing temp dir $tmpdir" 61 | rm -rf "$tmpdir" >> $logfile 2>&1 62 | mkdir -p "$tmpdir" >> $logfile 2>&1 63 | 64 | if [ ! -f /etc/systemd/system/zabbix-server.service ]; then 65 | log "Installing MySQL..." 66 | sudo -E apt-get -y update >> $logfile 2>&1 67 | sudo -E apt-get -y install mysql-server mysql-client >> $logfile 2>&1 68 | # Secure MySQL, create zabbix DB, zabbix user and zbx_monitor user. 69 | sudo -E mysql --user=root <<_EOF_ 70 | SET GLOBAL log_bin_trust_function_creators = 1; 71 | ALTER USER 'root'@'localhost' IDENTIFIED BY '${dbroot}'; 72 | DELETE FROM mysql.user WHERE User=''; 73 | DELETE FROM mysql.user WHERE User='root' AND Host NOT IN ('localhost', '127.0.0.1', '::1'); 74 | DROP DATABASE IF EXISTS test; 75 | DELETE FROM mysql.db WHERE Db='test' OR Db='test\\_%'; 76 | CREATE DATABASE zabbix CHARACTER SET UTF8 COLLATE UTF8_BIN; 77 | CREATE USER 'zabbix'@'%' IDENTIFIED BY '${dbzabbix}'; 78 | GRANT ALL PRIVILEGES ON zabbix.* TO 'zabbix'@'%'; 79 | CREATE USER 'zbx_monitor'@'%' IDENTIFIED BY '${monzabbix}'; 80 | GRANT USAGE,REPLICATION CLIENT,PROCESS,SHOW DATABASES,SHOW VIEW ON *.* TO 'zbx_monitor'@'%'; 81 | FLUSH PRIVILEGES; 82 | _EOF_ 83 | 84 | else 85 | # Stop existing service 86 | sudo -E service zabbix-server stop >> $logfile 2>&1 87 | log "Saving existing configuration to ${zabbixconf}.bak" 88 | sudo -E mv "${zabbixconf}" "${zabbixconf}.bak" 89 | # Stop existing service 90 | sudo -E service zabbix-agent2 stop >> $logfile 2>&1 91 | log "Saving existing configuration to ${zabbixagentconf}.bak" 92 | sudo -E mv "${zabbixagentconf}" "${zabbixagentconf}.bak" 93 | fi 94 | 95 | # ARM 32 96 | if [ "$arch" = "armv7l" ]; then 97 | jdkurl="https://cdn.azul.com/zulu-embedded/bin/zulu17.46.19-ca-jdk17.0.9-linux_aarch32hf.tar.gz" 98 | javahome=/usr/lib/jvm/jdk17 99 | # ARM 64 100 | elif [ "$arch" = "aarch64" ]; then 101 | jdkurl="https://cdn.azul.com/zulu/bin/zulu21.30.15-ca-jdk21.0.1-linux_aarch64.tar.gz" 102 | javahome=/usr/lib/jvm/jdk21 103 | # X86_32 104 | elif [ "$arch" = "i586" ] || [ "$arch" = "i686" ]; then 105 | jdkurl="https://cdn.azul.com/zulu/bin/zulu17.46.19-ca-fx-jdk17.0.9-linux_i686.tar.gz" 106 | javahome=/usr/lib/jvm/jdk17 107 | # X86_64 108 | elif [ "$arch" = "x86_64" ]; then 109 | jdkurl="https://cdn.azul.com/zulu/bin/zulu21.30.15-ca-fx-jdk21.0.1-linux_x64.tar.gz" 110 | javahome=/usr/lib/jvm/jdk21 111 | fi 112 | export javahome 113 | # Just JDK archive name 114 | jdkarchive=$(basename "$jdkurl") 115 | 116 | # Install Zulu Java JDK 117 | log "Downloading $jdkarchive to $tmpdir" 118 | wget -q --directory-prefix=$tmpdir "$jdkurl" >> $logfile 2>&1 119 | log "Extracting $jdkarchive to $tmpdir" 120 | tar -xf "$tmpdir/$jdkarchive" -C "$tmpdir" >> $logfile 2>&1 121 | log "Removing $javahome" 122 | sudo -E rm -rf "$javahome" >> $logfile 2>&1 123 | # Remove .gz 124 | filename="${jdkarchive%.*}" 125 | # Remove .tar 126 | filename="${filename%.*}" 127 | sudo mkdir -p /usr/lib/jvm >> $logfile 2>&1 128 | log "Moving $tmpdir/$filename to $javahome" 129 | sudo -E mv "$tmpdir/$filename" "$javahome" >> $logfile 2>&1 130 | sudo -E update-alternatives --install "/usr/bin/java" "java" "$javahome/bin/java" 1 >> $logfile 2>&1 131 | sudo -E update-alternatives --install "/usr/bin/javac" "javac" "$javahome/bin/javac" 1 >> $logfile 2>&1 132 | sudo -E update-alternatives --install "/usr/bin/jar" "jar" "$javahome/bin/jar" 1 >> $logfile 2>&1 133 | sudo -E update-alternatives --install "/usr/bin/javadoc" "javadoc" "$javahome/bin/javadoc" 1 >> $logfile 2>&1 134 | # See if JAVA_HOME exists and if not add it to /etc/environment 135 | if grep -q "JAVA_HOME" /etc/environment; then 136 | log "JAVA_HOME already exists, deleting" 137 | sudo sed -i '/JAVA_HOME/d' /etc/environment 138 | fi 139 | # Add JAVA_HOME to /etc/environment 140 | log "Adding JAVA_HOME to /etc/environment" 141 | sudo -E sh -c 'echo "JAVA_HOME=$javahome" >> /etc/environment' 142 | . /etc/environment 143 | log "JAVA_HOME = $JAVA_HOME" 144 | 145 | # Download Zabbix source 146 | log "Downloading $zabbixarchive to $tmpdir" 147 | wget -q --directory-prefix=$tmpdir "$zabbixurl" >> $logfile 2>&1 148 | log "Extracting $zabbixarchive to $tmpdir" 149 | tar -xf "$tmpdir/$zabbixarchive" -C "$tmpdir" >> $logfile 2>&1 150 | # Remove .gz 151 | filename="${zabbixarchive%.*}" 152 | # Remove .tar 153 | filename="${filename%.*}" 154 | sudo -E mv "$tmpdir/$filename" "${srcdir}" >> $logfile 2>&1 155 | 156 | if [ ! -f /etc/systemd/system/zabbix-server.service ]; then 157 | # Import Zabbix data 158 | log "Importing Zabbix data..." 159 | cd "${srcdir}/${filename}/database/mysql" >> $logfile 2>&1 160 | sudo -E mysql -u zabbix -p zabbix --password=$dbzabbix < schema.sql >> $logfile 2>&1 161 | sudo -E mysql -u zabbix -p zabbix --password=$dbzabbix < images.sql >> $logfile 2>&1 162 | sudo -E mysql -u zabbix -p zabbix --password=$dbzabbix < data.sql >> $logfile 2>&1 163 | # Insert macro values to monitor 'Zabbix server' MySQL DB (just add 'Template DB MySQL by Zabbix agent 2') 164 | sudo -E mysql --user=root <<_EOF_ 165 | SET GLOBAL log_bin_trust_function_creators = 0; 166 | _EOF_ 167 | 168 | # Install webserver 169 | log "Installing Apache and PHP..." 170 | sudo -E apt-get -y install fping apache2 php libapache2-mod-php php-cli php-mysql php-mbstring php-gd php-xml php-bcmath php-ldap mlocate >> $logfile 2>&1 171 | sudo -E updatedb >> $logfile 2>&1 172 | # Get php.ini file location 173 | phpini=$(locate php.ini 2>&1 | head -n 1) 174 | # Update settings in php.ini 175 | sudo -E sed -i 's/max_execution_time = 30/max_execution_time = 300/g' "$phpini" >> $logfile 2>&1 176 | sudo -E sed -i 's/memory_limit = 128M/memory_limit = 256M/g' "$phpini" >> $logfile 2>&1 177 | sudo -E sed -i 's/post_max_size = 8M/post_max_size = 32M/g' "$phpini" >> $logfile 2>&1 178 | sudo -E sed -i 's/max_input_time = 60/max_input_time = 300/g' "$phpini" >> $logfile 2>&1 179 | sudo -E sed -i "s|;date.timezone =|date.timezone = $phptz|g" "$phpini" >> $logfile 2>&1 180 | sudo -E service apache2 restart >> $logfile 2>&1 181 | 182 | # Use latest golang 183 | log "Adding Go repository..." 184 | sudo -E add-apt-repository ppa:longsleep/golang-backports -y >> $logfile 2>&1 185 | sudo -E apt update >> $logfile 2>&1 186 | # Install Zabbix 187 | log "Installing Zabbix Server..." 188 | # Create group and user 189 | sudo -E addgroup --system --quiet zabbix >> $logfile 2>&1 190 | sudo -E adduser --quiet --system --disabled-login --ingroup zabbix --home /var/lib/zabbix --no-create-home zabbix >> $logfile 2>&1 191 | # Create user home 192 | sudo -E mkdir -m u=rwx,g=rwx,o= -p /var/lib/zabbix >> $logfile 2>&1 193 | sudo -E chown zabbix:zabbix /var/lib/zabbix >> $logfile 2>&1 194 | sudo -E apt-get -y install build-essential libmysqlclient-dev libssl-dev libsnmp-dev libevent-dev pkg-config golang-go >> $logfile 2>&1 195 | sudo -E apt-get -y install libopenipmi-dev libcurl4-openssl-dev libxml2-dev libssh2-1-dev libpcre3-dev >> $logfile 2>&1 196 | sudo -E apt-get -y install libldap2-dev libiksemel-dev libcurl4-openssl-dev libgnutls28-dev >> $logfile 2>&1 197 | fi 198 | cd "${srcdir}/${filename}" >> $logfile 2>&1 199 | # Patch source to fix "plugins/proc/procfs_linux.go:248:6: constant 1099511627776 overflows int" on 32 bit systems 200 | log "Patching procfs_linux.go to work on 32 bit platforms..." 201 | sed -i 's/strconv.Atoi(strings.TrimSpace(line\[:len(line)-2\]))/strconv.ParseInt(strings.TrimSpace(line[:len(line)-2]),10,64)/' src/go/plugins/proc/procfs_linux.go >> $logfile 2>&1 202 | # Patch db.c to fix https://support.zabbix.com/si/jira.issueviews:issue-html/ZBX-23145/ZBX-23145 203 | log "Patching db.c to prevent spamming log..." 204 | sed -i '/MYSQL_OPT_RECONNECT/d' src/libs/zbxdb/db.c >> $logfile 2>&1 205 | sed -i '/Cannot set MySQL reconnect option/d' src/libs/zbxdb/db.c >> $logfile 2>&1 206 | # Cnange configuration options here 207 | sudo -E ./configure --enable-server --enable-agent2 --enable-ipv6 --with-mysql --with-openssl --with-net-snmp --with-openipmi --with-libcurl --with-libxml2 --with-ssh2 --with-ldap --enable-java --prefix=/usr/local >> $logfile 2>&1 208 | sudo -E make install >> $logfile 2>&1 209 | # Configure Zabbix server 210 | sudo -E chmod ug+s /usr/bin/fping 211 | sudo -E chmod ug+s /usr/bin/fping6 212 | sudo -E sed -i "s/# DBPassword=/DBPassword=$dbzabbix/g" "$zabbixconf" >> $logfile 2>&1 213 | sudo -E sed -i "s|# FpingLocation=/usr/sbin/fping|FpingLocation=/usr/bin/fping|g" "$zabbixconf" >> $logfile 2>&1 214 | sudo -E sed -i "s|# Fping6Location=/usr/sbin/fping6|Fping6Location=/usr/bin/fping6|g" "$zabbixconf" >> $logfile 2>&1 215 | sudo -E sed -i "s/# StartPingers=1/StartPingers=10/g" "$zabbixconf" >> $logfile 2>&1 216 | 217 | # Install Zabbix server service 218 | if [ ! -f /etc/systemd/system/zabbix-server.service ]; then 219 | log "Installing Zabbix Server Service..." 220 | sudo tee -a /etc/systemd/system/zabbix-server.service > /dev/null <> $logfile 2>&1 238 | 239 | # Install Zabbix agent 2 service 240 | log "Installing Zabbix Agent 2 Service..." 241 | sudo tee -a /etc/systemd/system/zabbix-agent2.service > /dev/null <> $logfile 2>&1 258 | else 259 | # Remove front end 260 | sudo -E rm -rf /var/www/html/zabbix 261 | fi 262 | # Installing Zabbix front end 263 | log "Installing Zabbix PHP Front End..." 264 | cd "${srcdir}/${filename}" >> $logfile 2>&1 265 | sudo -E mv "${srcdir}/${filename}/ui" /var/www/html/zabbix >> $logfile 2>&1 266 | sudo -E chown -R www-data:www-data /var/www/html/zabbix >> $logfile 2>&1 267 | # Start up Zabbix 268 | log "Starting Zabbix Server..." 269 | sudo -E service zabbix-server start >> $logfile 2>&1 270 | log "Starting Zabbix Agent 2..." 271 | sudo -E service zabbix-agent2 start >> $logfile 2>&1 272 | log "Removing temp dir $tmpdir" 273 | rm -rf "$tmpdir" >> $logfile 2>&1 274 | -------------------------------------------------------------------------------- /scripts/movedb.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # 3 | # Created on June 6, 2020 4 | # 5 | # @author: sgoldsmith 6 | # 7 | # Move MySQL database directory from default location to another location. This 8 | # script assumes you ran install.sh already. 9 | # 10 | # Steven P. Goldsmith 11 | # sgjava@gmail.com 12 | # 13 | 14 | # MySQL data destination directory 15 | destdir="/tmp" 16 | 17 | # stdout and stderr for commands logged 18 | logfile="$PWD/movedb.log" 19 | rm -f $logfile 20 | 21 | # Simple logger 22 | log(){ 23 | timestamp=$(date +"%m-%d-%Y %k:%M:%S") 24 | echo "$timestamp $1" 25 | echo "$timestamp $1" >> $logfile 2>&1 26 | } 27 | 28 | # Shut down Zabbix 29 | log "Stopping Zabbix Server..." 30 | sudo -E service zabbix-server stop >> $logfile 2>&1 31 | log "Stopping Zabbix Agent 2..." 32 | sudo -E service zabbix-agent2 stop >> $logfile 2>&1 33 | # Shut down MySQL 34 | log "Stopping MySQL..." 35 | sudo -E service mysql stop >> $logfile 2>&1 36 | 37 | # Copy MySQL data directory 38 | log "Copying MySQL data directory..." 39 | sudo rsync -av /var/lib/mysql "$destdir" >> $logfile 2>&1 40 | # Remove MySQL data directory 41 | log "Removing MySQL data directory..." 42 | sudo rm -rf /var/lib/mysql 43 | # Change location of MySQL data directory 44 | sudo -E sed -i "s|# datadir = /var/lib/mysql|datadir = $destdir/mysql|g" /etc/mysql/mysql.conf.d/mysqld.cnf >> $logfile 2>&1 45 | # Start MySQL 46 | log "Starting MySQL..." 47 | sudo -E service mysql start >> $logfile 2>&1 48 | # Start up Zabbix 49 | log "Starting Zabbix Server..." 50 | sudo -E service zabbix-server start >> $logfile 2>&1 51 | log "Starting Zabbix Agent 2..." 52 | sudo -E service zabbix-agent2 start >> $logfile 2>&1 53 | --------------------------------------------------------------------------------