Skip to content

Instantly share code, notes, and snippets.

@AloPress
Last active October 14, 2020 09:37
Show Gist options
  • Save AloPress/34a57c7c8e5641c6d80eb88c5811e4d5 to your computer and use it in GitHub Desktop.
Save AloPress/34a57c7c8e5641c6d80eb88c5811e4d5 to your computer and use it in GitHub Desktop.
Installing Zabbix Agent 4.0.1 from source on macOS Mojave with the addition of PCRE 8.42 and libiconv 1.15

Install macOS Command Line Tools

xcode-select --install

Agent log folder and log files

sudo mkdir -p /var/run/zabbix
sudo mkdir -p /var/log/zabbix
sudo touch /var/run/zabbix/zabbix_agentd.pid
sudo touch /var/log/zabbix/zabbix_agentd.log

Create Zabbix user

sudo dscl . -create /Groups/zabbix gid 301
sudo dscl . -create /Groups/zabbix RealName "Zabbix Server Group"
sudo dscl . -create /Groups/zabbix passwd "*"
sudo dscl . -create /Users/zabbix
sudo dscl . -create /Users/zabbix uid 301
sudo dscl . -create /Users/zabbix gid 301
sudo dscl . -create /Users/zabbix NFSHomeDirectory /var/empty
sudo dscl . -create /Users/zabbix UserShell /usr/bin/false
sudo dscl . -create /Users/zabbix RealName "Zabbix Server"
sudo dscl . -create /Users/zabbix passwd "*"

Install PCRE version 8.42 in this example

curl --remote-name ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.42.tar.gz

Extract the archive and move into the folder.

tar -xzvf pcre-8.42.tar.gz
sudo mv pcre-8.42 /etc/pcre-8.42

Configure, compile and install into /etc/pcre-8.42

cd /etc/pcre-8.42
sudo ./configure --prefix=/etc/pcre-8.42
sudo make
sudo make install

Create a symbolic link to /usr/local/pcre

sudo ln -s /etc/pcre-8.42 /usr/local/pcre

Install libiconv library version 1.15 in this example

curl --remote-name https://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.15.tar.gz

Extract the archive and move into the folder.

tar -xzvf libiconv-1.15.tar.gz
sudo mv libiconv-1.15 /etc/libiconv-1.15

Configure, compile and install into /etc/libiconv-1.15

cd /etc/libiconv-1.15
sudo ./configure --prefix=/etc/libiconv-1.15
sudo make
sudo make install

Create a symbolic link to /usr/local/pcre

sudo ln -s /etc/libiconv-1.15 /usr/local/libiconv

Install Zabbix agent source

curl -L https://sourceforge.net/projects/zabbix/files/ZABBIX%20Latest%20Stable/4.0.1/zabbix-4.0.1.tar.gz/download -o zabbix-4.0.1.tar.gz
tar -zxvpf zabbix-4.0.1.tar.gz

Switch to the tarball directory

cd zabbix-4.0.1

Make the installation directories and run the configure script with the –enable-agent switch

sudo mkdir -p /usr/local/etc /usr/local/sbin
sudo ./configure --enable-agent --with-libpcre=/etc/pcre-8.42 --with-iconv=/etc/libiconv-1.15/
sudo make
sudo make install

Copy the configuration file to the local etc directory:

sudo cp ./conf/zabbix_agentd.conf /usr/local/etc/

Copy the daemon file to the local sbin directory

sudo cp ./src/zabbix_agent/zabbix_agentd /usr/local/sbin
sudo nano /usr/local/etc/zabbix_agentd.conf

Start the agent:

/usr/local/sbin/zabbix_agentd

Check Zabbix Agent version

/usr/local/sbin/zabbix_agentd -V

Sample configuration /usr/local/etc/zabbix_agentd.conf

Server= IP
ServerActive= IP
Hostname=arvuti FQDN
PidFile=/var/run/zabbix/zabbix_agentd.pid
LogFile=/var/log/zabbix/zabbix_agentd.log
EnableRemoteCommands=0
DebugLevel=3
LogFileSize=1
HostMetadata=["macos"]

Create an autostart script to automatically launch Zabbix /etc/startzabbix.sh

sudo nano /etc/startzabbix.sh
#!/bin/bash
sudo mkdir -p /var/run/zabbix
sudo touch /var/run/zabbix/zabbix_agentd.pid
sudo chmod 757 /var/run/zabbix/zabbix_agentd.pid
/usr/local/sbin/zabbix_agentd
sudo chmod a+x /etc/startzabbix.sh

Create LaunchDaemon to autostart Zabbix Agent /Library/LaunchDaemons/autostart.zabbix_agent.plist

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
 
<dict>
<key>Label</key>
<string>autostart.zabbix_agent</string>
<key>RunAtLoad</key>
<true/>
<key>ProgramArguments</key>
 
<array>
<string>sh</string>
<string>/etc/startzabbix.sh</string>
</array>
</dict>
</plist>

Load LaunchDaemon plist

sudo nano /Library/LaunchDaemons/autostart.zabbix_agent.plist
sudo launchctl load /Library/LaunchDaemons/autostart.zabbix_agent.plist
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment