问题1:编译报错“snmp.c:21:11: fatal error: net-snmp/net-snmp-config.h: No such file or directory”

编译参数

./configure -prefix=/usr/local/zabbix -sysconfdir=/etc/zabbix/ -enable-server -enable-agent -with-net-snmp=/usr/local/snmp/bin/net-snmp-config -with-libcurl -with-mysql=/usr/local/mysql/bin/mysql_config -with-libxml2

编译错误信息

snmp.c:21:11: fatal error: net-snmp/net-snmp-config.h: No such file or directory
 # include <net-snmp/net-snmp-config.h>
           ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
compilation terminated.
make[3]: *** [Makefile:473: snmp.o] Error 1
make[3]: Leaving directory '/root/zabbix-8.0.0/src/libs/zbxsnmp'
make[2]: *** [Makefile:659: all-recursive] Error 1
make[2]: Leaving directory '/root/zabbix-8.0.0/src/libs'
make[1]: *** [Makefile:517: all-recursive] Error 1
make[1]: Leaving directory '/root/zabbix-8.0.0/src'
make: *** [Makefile:570: all-recursive] Error 1

解决方法
安装SNMP开发包

CentOS/RHEL/Rocky
yum install -y net-snmp-devel
或者dnf install -y net-snmp-devel

Debian/Ubuntu
apt install -y libsnmp-dev

问题2:MySQL8.0升级8.4后启动Zabbix Server报错

错误信息

zabbix_server[5843]: /usr/local/zabbix/sbin/zabbix_server: error while loading shared libraries: libmysqlclient.so.21: cannot open shared object file: No such file or directory

解决方法
重新编译安装Zabbix,指定MySQL链接库,编译参数如下

MYSQL_CONFIG=/usr/local/mysql/bin/mysql_config
MYSQL_LFLAGS=$($MYSQL_CONFIG --libs | tr ' ' '\n' | grep '^-L' | sort -u | tr '\n' ' ')
MYSQL_RPATH=$($MYSQL_CONFIG --libs | tr ' ' '\n' | grep '^-L' | sort -u | sed 's|^-L|-Wl,-rpath,|' | tr '\n' ' ')

./configure -prefix=/usr/local/zabbix -sysconfdir=/etc/zabbix/ -enable-server -enable-agent -with-net-snmp=/usr/local/snmp/bin/net-snmp-config -with-libcurl --with-mysql="$MYSQL_CONFIG" LDFLAGS="$MYSQL_LFLAGS $MYSQL_RPATH" -with-libxml2

问题3:编译报错“cannot find pkg-config package for libpcre2”

configure: error: cannot find pkg-config package for libpcre2

解决方法
安装PCRE2正则库的开发包

CentOS/RHEL/Rocky
yum install pcre2-devel

Debian/Ubuntu
apt install libpcre2-dev

问题4:CentOS 7编译报错“zbxsupervisor_client.h:49:2: error: unknown type name ‘_Atomic’”

编译错误信息

Making all in zbxdbsyncer
make[3]: Entering directory `/root/zabbix-8.0.0/src/libs/zbxdbsyncer'
gcc -std=gnu11 -DHAVE_CONFIG_H -I../../../include/common -I../../../include -I../../../src     -g -O2   -MT libzbxdbsyncer_a-dbsyncer.o -MD -MP -MF .deps/libzbxdbsyncer_a-dbsyncer.Tpo -c -o libzbxdbsyncer_a-dbsyncer.o `test -f 'dbsyncer.c' || echo './'`dbsyncer.c
In file included from dbsyncer.c:33:0:
../../../include/zbxsupervisor_client.h:49:2: error: unknown type name ‘_Atomic’
  _Atomic zbx_supervisor_runstate_t *runstate;
  ^
../../../include/zbxsupervisor_client.h:49:36: error: expected ‘:’, ‘,’, ‘;’, ‘}’ or ‘__attribute__’ before ‘*’ token
  _Atomic zbx_supervisor_runstate_t *runstate;
                                    ^
make[3]: *** [libzbxdbsyncer_a-dbsyncer.o] Error 1
make[3]: Leaving directory `/root/zabbix-8.0.0/src/libs/zbxdbsyncer'
make[2]: *** [all-recursive] Error 1
make[2]: Leaving directory `/root/zabbix-8.0.0/src/libs'
make[1]: *** [all-recursive] Error 1
make[1]: Leaving directory `/root/zabbix-8.0.0/src'
make: *** [all-recursive] Error 1

解决方法
1. 查看当前gcc版本(应该是4.8.5)
gcc --version | head -1

2. yum切换到vault归档源

sed -i 's|^mirrorlist=|#mirrorlist=|; s|^#\s*baseurl=http://mirror.centos.org|baseurl=http://vault.centos.org|' /etc/yum.repos.d/CentOS-*.repo
yum clean all && yum makecache
yum install -y centos-release-scl

3. 修正SCL源并安装devtoolset-9(gcc9)

sed -i 's|^mirrorlist=|#mirrorlist=|; s|^#\s*baseurl=http://mirror.centos.org|baseurl=http://vault.centos.org|' /etc/yum.repos.d/CentOS-SCLo-*.repo 2>/dev/null
yum clean all
yum install -y devtoolset-9-gcc devtoolset-9-gcc-c++ devtoolset-9-binutils

4. 启用devtoolset-9

scl enable devtoolset-9 bash
echo 'source /opt/rh/devtoolset-9/enable' > /etc/profile.d/devtoolset.sh
chmod +x /etc/profile.d/devtoolset.sh
gcc --version | head -1  # 查看版本,应显示9.3.x

5. 重新编译

标签: none