Wednesday, November 27, 2024

Install Zabbix agent 7.x on TrueNAS

 

 In my previous article from 2020 I did mention how to install the Zabbix agent on FreeNAS.

Since then four years have passed and the Zabbix 7 agents are available.

The steps for installation are remained the same, but you won't need to build the agent package yourself, you can use the packages provided from Zabbix for FreeBSD.

So lets see what you have to do now:

 

1. Create the zabbix user via TrueNAS UI, so the daemon can run as the specified user, you can assign the nologin shell to that user

2. Download the binary package from the Zabbix webpage at

https://www.zabbix.com/download_agents?version=7.0+LTS&release=7.0.4&os=FreeBSD&os_version=13.1&hardware=amd64&encryption=GnuTLS&packaging=Archive&show_legacy=0

3. Unpack the /bin and /sbin folders into /usr/local of your TrueNAS server

4. Unpack the /conf/* into /etc

5. Create a use and group zabbix so your agent wont run as root, you need to do this via GUI, otherwiese the account will be gone after reboot

6. Edit your /etc/zabbit_agentd:conf to match your needs

7. Enable daemon

echo 'zabbix_agentd_enable="YES"' >> /etc/rc.conf  
 
8. Create /etc/rc.d/zabbix_agentd:
#!/bin/sh

# PROVIDE: zabbix_agentd
# REQUIRE: DAEMON
# KEYWORD: shutdown
#
# Add the following lines to /etc/rc.conf.local or /etc/rc.conf to
# enable zabbix_agentd:
#
# zabbix_agentd_enable (bool): Set to NO by default.  Set it to YES to
#         enable zabbix_agentd.
#

. /etc/rc.subr

name="zabbix_agentd"
rcvar=zabbix_agentd_enable
start_precmd="zabbix_precmd"
required_files="/etc/zabbix_agentd.conf"

# read configuration and set defaultsc
load_rc_config "$name"
: ${zabbix_agentd_enable="NO"}
#: ${zabbix_agentd_pre:=/etc/${name}.pre.sh}

zabbix_agentd_conf="/etc/zabbix_agentd.conf"

if [ ! -z "$zabbix_agentd_conf" ] ; then
  zabbix_agentd_flags="${zabbix_agentd_flags} -c ${zabbix_agentd_conf}"
  required_files=${zabbix_agentd_conf}
fi

zabbix_precmd()
{
  if [ ! -z "$zabbix_agentd_pre" ] ; then
    if [ -e $zabbix_agentd_pre ] ; then
      . $zabbix_agentd_pre
    fi
  fi
} 
zabbix_agentd_user="zabbix"

command="/usr/local/sbin/${name}" run_rc_command "$1" run_rc_command "$1"
9. Make executable:
 
chmod +x /etc/rc.d/zabbix_agentd
10. Start daemon:
 
/etc/rc.d/zabbix_agentd start
 
11. Make config files persistent and survive reboots:
 
cp /etc/rc.conf /conf/base/etc/
cp /etc/rc.d/zabbix_agentd /conf/base/etc/rc.d/
mkdir /conf/etc/zabbix_agentd
cp /etc/zabbix_agentd.* /conf/base/etc/
cp /etc/zabbix_agentd.* /conf/base/etc/
 
 

Zabbix configuration

Use the template from the zabbix wiki for the host monitoring http://zabbix.org/wiki/File:Template_OS_FreeNAS.xml