陈佳浩
陈佳浩
发布于 2024-07-06 / 78 阅读
0
0

Centos7部署高版本zabbix7.0

下载zabbix源码包

[root@zabbix01 ~]# curl -LO https://cdn.zabbix.com/zabbix/sources/stable/7.0/zabbix-7.0.0.tar.gz

解压

[root@zabbix02 ~]# tar xf zabbix-7.0.0.tar.gz
[root@zabbix02 ~]# cd zabbix-7.0.0/

编译安装

执行编译脚本
[root@zabbix02 zabbix-7.0.0]# ./configure --prefix=/apps/zabbix --enable-server --enable-agent --enable-agent2 --with-mysql --with-net-snmp --with-libcurl --with-libxml2 --with-openipmi --enable-webservice

报错需要gcc

checking whether make sets $(MAKE)... (cached) yes
checking build system type... x86_64-pc-linux-gnu
checking host system type... x86_64-pc-linux-gnu
checking for cc... no
checking for c99... no
checking for gcc... no
checking for clang... no
configure: error: in `/root/zabbix-7.0.0':
configure: error: no acceptable C compiler found in $PATH
See `config.log' for more detail

安装gcc

[root@zabbix02 zabbix-7.0.0]# yum -y install gcc

再次执行配置脚本后报错内有找到mysql的库

checking for architecture... linux (linux-gnu)
checking for the linux kernel version... unknown family (3.10.0-1160.el7.x86_64)
checking size of void *... 8
checking for mysql_config... no
checking for mariadb_config... no
configure: error: MySQL library not found

安装mysql-devel,及其依赖

#到清华源下载
[root@zabbix02 zabbix-7.0.0]# curl -LO https://mirrors.tuna.tsinghua.edu.cn/mysql/yum/mysql-8.0-community-el7-x86_64/mysql-community-devel-8.0.38-1.el7.x86_64.rpm
[root@zabbix02 zabbix-7.0.0]# curl -LO https://mirrors.tuna.tsinghua.edu.cn/mysql/yum/mysql-8.0-community-el7-x86_64/mysql-community-libs-8.0.38-1.el7.x86_64.rpm
[root@zabbix02 zabbix-7.0.0]# curl -LO https://mirrors.tuna.tsinghua.edu.cn/mysql/yum/mysql-8.0-community-el7-x86_64/mysql-community-client-plugins-8.0.38-1.el7.x86_64.rp
[root@zabbix02 zabbix-7.0.0]# curl -LO https://mirrors.tuna.tsinghua.edu.cn/mysql/yum/mysql-8.0-community-el7-x86_64/mysql-community-common-8.0.38-1.el7.x86_64.rpm
[root@zabbix02 zabbix-7.0.0]# curl -LO https://mirrors.tuna.tsinghua.edu.cn/mysql/yum/mysql-8.0-community-el7-x86_64/mysql-community-embedded-compat-8.0.38-1.el7.x86_64.rpm
[root@zabbix02 zabbix-7.0.0]# curl -LO https://mirrors.tuna.tsinghua.edu.cn/mysql/yum/mysql-8.0-community-el7-x86_64/mysql-community-libs-compat-8.0.38-1.el7.x86_64.rpm
#安装
[root@zabbix02 zabbix-7.0.0]# yum -y install ./mysql-community-*

再次执行配置脚本报错,没有找到libxml2的库

Package libxml-2.0 was not found in the pkg-config search path.
Perhaps you should add the directory containing `libxml-2.0.pc'
to the PKG_CONFIG_PATH environment variable
No package 'libxml-2.0' found
checking for xmlReadMemory in -lxml2... no
configure: error: Not found libxml2 library

安装libxml2的开发包

[root@zabbix02 zabbix-7.0.0]# yum -y install libxml2-devel

再次执行配置脚本报错,,没有找到net-snmp-config工具

checking pkg-config is at least version 0.9.0... yes
checking for pkg-config... (cached) /usr/bin/pkg-config
checking pkg-config is at least version 0.9.0... yes
checking for xmlReadMemory in -lxml2... yes
checking for net-snmp-config... no
configure: error: Invalid Net-SNMP directory - unable to find net-snmp-config

安装net-snmp的开发包

[root@zabbix02 zabbix-7.0.0]# yum -y install net-snmp-devel

再次执行配置脚本报错,没有找到 OPENIPMI 相关的头文件 ipmiif.h,但没有成功找到

checking for localname in struct snmp_session... yes
checking for DES privacy protocol support... yes
checking for OPENIPMI support... no
configure: error: Invalid OPENIPMI directory - unable to find ipmiif.h

安装OpenIPMI开发包

[root@zabbix02 zabbix-7.0.0]# yum -y install OpenIPMI-devel

再次执行配置脚本报错,无法使用libevent

checking for OPENIPMI support... yes
checking for zlib support... yes
checking for pthread.h... (cached) yes
checking for process shared libpthread support... yes
checking for libevent support... no
configure: error: Unable to use libevent (libevent check failed)

安装libevent开发包

[root@zabbix02 zabbix-7.0.0]# yum -y install libevent-devel

再次执行配置脚本报错,没有GO语言环境

checking for pthread.h... (cached) yes
checking for process shared libpthread support... yes
checking for libevent support... yes
checking for go... no
configure: error: Unable to find "go" executable in path

安装GO语言

[root@zabbix02 zabbix-7.0.0]# yum -y install go

再次执行配置脚本报错,没有找到Curl的开发库

checking for libevent support... yes
checking for go... go
checking for gawk... (cached) gawk
checking for curl-config... no
configure: error: Curl library not found

安装

[root@zabbix02 zabbix-7.0.0]# yum -y install libcurl-devel

再次执行配置脚本,执行成功

  Enable proxy:          no

  Enable agent:          no

  Enable agent 2:        yes

  Enable web service:    yes

  Enable Java gateway:   no

  LDAP support:          no
  IPv6 support:          no
  cmocka support:        no

  yaml support:          no

***********************************************************
*            Now run 'make install'                       *
*                                                         *
*            Thank you for using Zabbix!                  *
*              <https://www.zabbix.com>                   *
***********************************************************
开始编译
[root@zabbix02 zabbix-7.0.0]# make install

编译报错,代码中使用了 EVDNS_BASE_INITIALIZE_NAMESERVERS 这个宏或常量,但是编译器找不到它的定义

你正在使用的 libevent 版本可能不包含 EVDNS_BASE_INITIALIZE_NAMESERVERS这个宏或常量

scoverer_async.o `test -f 'discoverer_async.c' || echo './'`discoverer_async.c
discoverer_async.c: In function ‘discovery_async_poller_dns_init’:
discoverer_async.c:39:76: error: ‘EVDNS_BASE_INITIALIZE_NAMESERVERS’ undeclared (first use in this function)
  if (NULL == (poller_config->dnsbase = evdns_base_new(poller_config->base, EVDNS_BASE_INITIALIZE_NAMESERVERS)))
                                                                            ^
discoverer_async.c:39:76: note: each undeclared identifier is reported only once for each function it appears in

编译安装新版本libevent

[root@zabbix02 ~]# wget https://github.com/libevent/libevent/releases/download/release-2.1.12-stable/libevent-2.1.12-stable.tar.gz
[root@zabbix02 libevent-2.1.12-stable]# tar xf libevent-2.1.12-stable.tar.gz
[root@zabbix02 libevent-2.1.12-stable]# cd libevent-2.1.12-stable/
[root@zabbix02 libevent-2.1.12-stable]# ./configure
[root@zabbix02 libevent-2.1.12-stable]# make && make install

再次执行make

[root@zabbix02 zabbix-7.0.0]# make clean
[root@zabbix02 zabbix-7.0.0]# make install

编译报错,checks_snmp.c 文件中遇到了两个未声明的标识符错误:NETSNMP_CALLBACK_OP_SEC_ERRORNETSNMP_CALLBACK_OP_RESEND。这些标识符通常是 Net-SNMP 库中定义的常量,当前 net-snmp的库中可能不包含

cc -std=gnu11 -DHAVE_CONFIG_H -I../../../include/common -I../../../include     -I/usr/include/libxml2   -I/usr/local/include -I/usr/lib64/perl5/CORE -I. -I/usr/include   -g -O2   -MT libzbxpoller_a-checks_snmp.o -MD -MP -MF .deps/libzbxpoller_a-checks_snmp.Tpo -c -o libzbxpoller_a-checks_snmp.o `test -f 'checks_snmp.c' || echo './'`checks_snmp.c
checks_snmp.c: In function ‘asynch_response’:
checks_snmp.c:2652:8: error: ‘NETSNMP_CALLBACK_OP_SEC_ERROR’ undeclared (first use in this function)
   case NETSNMP_CALLBACK_OP_SEC_ERROR:
        ^
checks_snmp.c:2652:8: note: each undeclared identifier is reported only once for each function it appears in
checks_snmp.c:2656:8: error: ‘NETSNMP_CALLBACK_OP_RESEND’ undeclared (first use in this function)
   case NETSNMP_CALLBACK_OP_RESEND:
        ^

编译安装新版本net-snmp

#先卸载刚才安装的旧版net-snmp
[root@zabbix01 zabbix-7.0.0]# yum autoremove -y net-snmp*
[root@zabbix02 net-snmp-5.9.4]# curl -LO https://jaist.dl.sourceforge.net/project/net-snmp/net-snmp/5.9.4/net-snmp-5.9.4.zip
[root@zabbix02 net-snmp-5.9.4]# unzip net-snmp-5.9.4.zip
[root@zabbix02 net-snmp-5.9.4]# cd net-snmp-5.9.4
[root@zabbix02 net-snmp-5.9.4]# make clean
[root@zabbix02 net-snmp-5.9.4]# ./configure --prefix=/usr/local/net-snmp --with-default-snmp-version="2"
[root@zabbix02 net-snmp-5.9.4]# make &&make install

创建软连接

[root@zabbix01 net-snmp-5.9.4]# ln -s /usr/local/net-snmp/lib/* /usr/lib64/
[root@zabbix01 net-snmp-5.9.4]# ln -s /usr/local/net-snmp/lib/pkgconfig/* /usr/lib64/pkgconfig/
[root@zabbix01 net-snmp-5.9.4]# ln -s /usr/local/net-snmp/include /usr/include/net-snmp
[root@zabbix01 net-snmp-5.9.4]# ln -s /usr/local/net-snmp/bin/* /usr/bin/

再次执行make,前面卸载net-snmp的时候,OpenIPMI-devel也被卸载掉了,重装一下

[root@zabbix02 zabbix-7.0.0]# yum -y install OpenIPMI-devel
[root@zabbix02 zabbix-7.0.0]# make clean
[root@zabbix02 zabbix-7.0.0]# make install

启动

创建数据库

mysql> create database zabbix character set utf8mb4 collate utf8mb4_bin;
mysql> create user 'zabbix'@'%' identified by 'PASSWD';
mysql> grant all privileges on zabbix.* to 'zabbix'@'%';
mysql> use zabbix;
mysql> source schema.sql
mysql> source images.sql
mysql> source data.sql

配置连接数据库

[root@zabbix02 mysql]# grep -Ev "^#|^$" /apps/zabbix/etc/zabbix_server.conf|grep DB
DBHost=10.0.0.203
DBName=zabbix
DBUser=zabbix
DBPassword=PASSWD
DBPort=3306

修改日志和Pid文件路径

[root@zabbix02 mysql]# grep -E "^LogFile|^PidFile" /apps/zabbix/etc/zabbix_server.conf
LogFile=/apps/zabbix/tmp/zabbix_server.log
PidFile=/apps/zabbix/tmp/zabbix_server.pid
[root@zabbix02 mysql]# mkdir /apps/zabbix/tmp/

创建zabbix用户

[root@zabbix02 mysql]# useradd zabbix
[root@zabbix02 mysql]# chown -R zabbix.zabbix /apps/zabbix

启动zabbix-server

[root@zabbix02 mysql]# vim /usr/lib/systemd/system/zabbix-server.service
[Unit]  
Description=Zabbix Server  
After=network.target  
  
[Service]  
Type=forking  
PIDFile=/apps/zabbix/tmp/zabbix_server.pid
User=zabbix  
Group=zabbix  
ExecStart=/apps/zabbix/sbin/zabbix_server -c /apps/zabbix/etc/zabbix_server.conf
ExecStop=/bin/kill -SIGTERM $MAINPID  
Restart=on-failure  
  
[Install]  
WantedBy=multi-user.target
[root@zabbix02 mysql]# systemctl daemon-reload
[root@zabbix02 mysql]# systemctl start zabbix-server.service

启动失败,查看日志,必须要数据库8.00.30版本以上

 19281:20240705:145520.193 using configuration file: /apps/zabbix/etc/zabbix_server.conf
 19281:20240705:145520.244  
 19281:20240705:145520.244 Unable to start Zabbix server due to unsupported MySQL database version (5.07.44).
 19281:20240705:145520.244 Must be at least (8.00.30).
 19281:20240705:145520.244 Use of supported database version is highly recommended.
 19281:20240705:145520.244 Override by setting AllowUnsupportedDBVersions=1 in Zabbix server configuration file at your own risk.
 19281:20240705:145520.244  
 19281:20240705:145520.305 Zabbix Server stopped. Zabbix 7.0.0 (revision 49955f1fb5c).

重新安装个8.00.30版本以上的mysql就好了

另外zabbix-server日志中会提示一条

 19554:20240705:150048.781 for a discovery process with 5 workers, the user limit of 1024 file descriptors is insufficient. The maximum number of concurrent checks per worker has been reduced to 122

这个根据需要进行修改

修改zabbix-agent2的配置文件

[root@zabbix01 zabbix-7.0.0]# grep -Ev "^#|^$" /apps/zabbix/etc/zabbix_agent2.conf 
PidFile=/apps/zabbix/tmp/zabbix_agent2.pid
LogFile=/apps/zabbix/tmp/zabbix_agent2.log
Server=10.0.0.121,10.0.0.122
ServerActive=10.0.0.121,10.0.0.122
ControlSocket=/apps/zabbix/tmp/agent.sock
Include=./zabbix_agent2.d/plugins.d/*.conf

启动zabbix-agent2

[root@zabbix01 zabbix-7.0.0]# vim /usr/lib/systemd/system/zabbix-agent2.service
[Unit]  
Description=Zabbix Agent  
After=network.target  
  
[Service]  
Type=simple  
User=zabbix  
Group=zabbix  
PIDFile=/apps/zabbix/tmp/zabbix_agentd.pid  
ExecStart=/apps/zabbix/sbin/zabbix_agent2 -c /apps/zabbix/etc/zabbix_agent2.conf  
Restart=on-abort  
  
[Install]  
WantedBy=multi-user.target
[root@zabbix02 mysql]# systemctl daemon-reload
[root@zabbix02 mysql]# systemctl start zabbix-agent2.service

准备zabbix前端

安装nginx
[root@zabbix02 ~]# bash install_nginx.sh
安装PHP

最低要求的 PHP 版本已从 7.4.0 提升至 8.0.0

#下载源码包
[root@zabbix02 php-8.3.8]# curl -LO https://www.php.net/distributions/php-8.3.8.tar.gz
[root@zabbix02 php-8.3.8]# tar xf php-8.3.8.tar.gz
[root@zabbix02 php-8.3.8]# cd php-8.3.8
执行配置脚本
[root@zabbix02 php-8.3.8]# ./configure --prefix=/usr/local/php --sysconfdir=/etc/php --with-openssl --with-zlib --with-bz2 --with-curl --enable-bcmath --enable-gd --with-webp --with-jpeg --with-mhash --enable-mbstring --with-imap-ssl --with-mysqli --enable-exif --with-ffi --with-zip --enable-sockets --with-pcre-jit --enable-fpm --with-pdo-mysql --enable-pcntl

执行配置脚本,报错系统无法找到满足要求的 SQLite3 版本(至少为 3.7.7)

checking whether to enable the SQLite3 extension... yes
checking for sqlite3 >= 3.7.7... no
configure: error: Package requirements (sqlite3 >= 3.7.7) were not met:

No package 'sqlite3' found

Consider adjusting the PKG_CONFIG_PATH environment variable if you
installed software in a non-standard prefix.

安装 sqlite开发库

yum -y install sqlite-devel

再次执行配置脚本,报错系统检测到需要 BZip2支持,但在默认路径下没有找到 BZip2

checking whether to enable bc style precision math functions... yes
checking for BZip2 support... yes
checking for BZip2 in default path... not found
configure: error: Please reinstall the BZip2 distribution

安装 zip2开发库

[root@zabbix02 php-8.3.8]# yum -y install bzip2-devel

再次执行配置脚本,报错系统需要找到 libffi 库且其版本需要大于或等于 3.0.11,但是并没有找到满足条件的库

checking whether to enable EXIF (metadata from images) support... yes
checking for FFI support... yes
checking for libffi >= 3.0.11... no
configure: error: Package requirements (libffi >= 3.0.11) were not met:

No package 'libffi' found

Consider adjusting the PKG_CONFIG_PATH environment variable if you
installed software in a non-standard prefix.

安装 libffi开发库

[root@zabbix02 php-8.3.8]# yum -y install libffi-devel

再次执行配置脚本,报错系统没有找到 libpng

checking for zlib... yes
checking for libpng... no
configure: error: Package requirements (libpng) were not met:

No package 'libpng' found

Consider adjusting the PKG_CONFIG_PATH environment variable if you
installed software in a non-standard prefix.

安装 libpng开发库

[root@zabbix02 php-8.3.8]# yum -y install libpng-devel

再次执行配置脚本,报错系统没有找到 libwebp 库,或者找到的版本低于所需的 0.2.0

checking for libpng... yes
checking for libwebp >= 0.2.0... no
configure: error: Package requirements (libwebp >= 0.2.0) were not met:

No package 'libwebp' found

Consider adjusting the PKG_CONFIG_PATH environment variable if you
installed software in a non-standard prefix.

安装 libwebp 开发库

[root@zabbix02 php-8.3.8]# yum -y install libwebp-devel

再次执行配置脚本,报错系统没有找到 libjpeg

checking for libwebp >= 0.2.0... yes
checking for libjpeg... no
configure: error: Package requirements (libjpeg) were not met:

No package 'libjpeg' found

Consider adjusting the PKG_CONFIG_PATH environment variable if you
installed software in a non-standard prefix.

安装 libjpeg开发库

[root@zabbix02 php-8.3.8]# yum -y install libjpeg-devel

再次执行配置脚本,报错系统没有找到 oniguruma

checking whether to enable multibyte regex support (requires oniguruma)... yes
checking for oniguruma... no
configure: error: Package requirements (oniguruma) were not met:

No package 'oniguruma' found

Consider adjusting the PKG_CONFIG_PATH environment variable if you
installed software in a non-standard prefix.

安装 oniguruma开发库

[root@zabbix02 php-8.3.8]# yum -y install oniguruma-devel

再次执行配置脚本,报错系统没有找到符合要求的 libzip 库版本

checking for zip archive read/write support... yes
checking for libzip >= 0.11 libzip != 1.3.1 libzip != 1.7.0... no
configure: error: Package requirements (libzip >= 0.11 libzip != 1.3.1 libzip != 1.7.0) were not met:

No package 'libzip' found
No package 'libzip' found
No package 'libzip' found

Consider adjusting the PKG_CONFIG_PATH environment variable if you
installed software in a non-standard prefix.

安装 libzip开发库

[root@zabbix02 php-8.3.8]# wget ftp://ftp.icm.edu.pl/packages/linux-pbone/rpms.remirepo.net/enterprise/7/remi/x86_64/libzip5-devel-1.10.0-1.el7.remi.x86_64.rpm
[root@zabbix02 php-8.3.8]# wget ftp://ftp.icm.edu.pl/packages/linux-pbone/rpms.remirepo.net/enterprise/7/remi/x86_64/libzip5-1.10.0-1.el7.remi.x86_64.rpm
[root@zabbix02 php-8.3.8]# yum -y install ./libzip5-*

再次执行配置脚本,执行成功

config.status: creating sapi/fpm/status.html
config.status: creating sapi/phpdbg/phpdbg.1
config.status: creating sapi/cgi/php-cgi.1
config.status: creating ext/phar/phar.1
config.status: creating ext/phar/phar.phar.1
config.status: creating main/php_config.h
config.status: executing default commands

+--------------------------------------------------------------------+
| License:                                                           |
| This software is subject to the PHP License, available in this     |
| distribution in the file LICENSE. By continuing this installation  |
| process, you are bound by the terms of this license agreement.     |
| If you do not agree with the terms of this license, you must abort |
| the installation process at this point.                            |
+--------------------------------------------------------------------+

Thank you for using PHP.
开始编译
[root@zabbix02 php-8.3.8]# make && make install

编译成功

Installing shared extensions:     /usr/local/php/lib/php/extensions/no-debug-non-zts-20230831/
Installing PHP CLI binary:        /usr/local/php/bin/
Installing PHP CLI man page:      /usr/local/php/php/man/man1/
Installing PHP FPM binary:        /usr/local/php/sbin/
Installing PHP FPM defconfig:     /etc/php/
Installing PHP FPM man page:      /usr/local/php/php/man/man8/
Installing PHP FPM status page:   /usr/local/php/php/php/fpm/
Installing phpdbg binary:         /usr/local/php/bin/
Installing phpdbg man page:       /usr/local/php/php/man/man1/
Installing PHP CGI binary:        /usr/local/php/bin/
Installing PHP CGI man page:      /usr/local/php/php/man/man1/
Installing build environment:     /usr/local/php/lib/php/build/
Installing header files:          /usr/local/php/include/php/
Installing helper programs:       /usr/local/php/bin/
  program: phpize
  program: php-config
Installing man pages:             /usr/local/php/php/man/man1/
  page: phpize.1
  page: php-config.1
Installing PDO headers:           /usr/local/php/include/php/ext/pdo/
准备配置文件

准备PHP配置文件

[root@zabbix02 php-8.3.8]# mv /etc/php/php-fpm.d/www.conf.default /etc/php/php-fpm.d/www.conf
[root@zabbix02 php-8.3.8]# mv /etc/php/php-fpm.conf.default /etc/php/php-fpm.conf
[root@zabbix02 php-8.3.8]# ln -s /usr/local/php/bin/* /usr/bin/
[root@zabbix02 php-8.3.8]# cp ./sapi/fpm/php-fpm.service /lib/systemd/system/
[root@zabbix02 php-8.3.8]# cp php.ini-development /usr/local/php/lib/php.ini
[root@zabbix02 php-8.3.8]# ln -s /usr/local/php/lib/php.ini /etc/php.ini

准备nginx配置文件

[root@zabbix01 zabbix-7.0.0]# cat /apps/nginx/conf/nginx.conf
user  zabbix;
worker_processes  1;

error_log  /apps/nginx/logs/error.log warn;

events {
    worker_connections  1024;
}


http {
    include     /apps/nginx/conf.d/*.conf;
    include       mime.types;
    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';
    access_log  /apps/nginx/logs/access.log  main;
    default_type  application/octet-stream;
    sendfile        on;
    keepalive_timeout  65;
}
[root@zabbix01 zabbix-7.0.0]# cat /apps/nginx/conf.d/zabbix.conf 
server {
        listen 80;
        server_name localhost;
        root /apps/nginx/html;
        index index.php;
        location ~ \.php$ {
                index index.php;
                fastcgi_pass 127.0.0.1:9000;
                fastcgi_index index.php;
                fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                include fastcgi_params;
        }
}

重启nginx

systemctl restart nginx

启动php-fpm

[root@zabbix02 php-8.3.8]# systemctl daemon-reload
[root@zabbix02 php-8.3.8]# systemctl enable --now php-fpm

这时php启动没有报错,但查看状态是failed

修改service文件

[root@zabbix01 php-8.3.8]# vim /usr/lib/systemd/system/php-fpm.service
ProtectSystem=full   #将这一行修改为ProtectSystem=false
[root@zabbix01 php-8.3.8]# systemctl daemon-reload
[root@zabbix01 php-8.3.8]# systemctl start php-fpm

拷贝前端文件到nginx目录下

[root@zabbix02 ~]# rm -rf /apps/nginx/html
[root@zabbix02 ~]# cp -r zabbix-7.0.0/ui /apps/nginx/html
[root@zabbix02 ~]# chown -R zabbix.zabbix /apps/nginx

浏览器访问,可以打开zabbix前端

细节配置
安装gettext扩展

在访问前端时,发现选择语言时有报错Translations are unavailable because the PHP gettext module is missing.

说明我们的PHP在编译时没有启用gettext扩展

重新编译PHP

[root@zabbix02 ~]# cd php-8.3.8/
[root@zabbix02 php-8.3.8]# make clean
[root@zabbix02 php-8.3.8]# ./configure --prefix=/usr/local/php --sysconfdir=/etc/php --with-openssl --with-zlib --with-bz2 --with-curl --enable-bcmath --enable-gd --with-webp --with-jpeg --with-mhash --enable-mbstring --with-imap-ssl --with-mysqli --enable-exif --with-ffi --with-zip --enable-sockets --with-pcre-jit --enable-fpm --with-pdo-mysql --enable-pcntl --with-gettext
[root@zabbix02 php-8.3.8]# make && make install

为php扩展准备构建环境

[root@zabbix02 php-8.3.8]# cd ext/gettext
[root@zabbix02 gettext]# phpize

构建时报错,在配置PHP扩展时无法找到 autoconf工具

Configuring for:
PHP Api Version:         20230831
Zend Module Api No:      20230831
Zend Extension Api No:   420230831
Cannot find autoconf. Please check your autoconf installation and the
$PHP_AUTOCONF environment variable. Then, rerun this script.

安装

[root@zabbix02 gettext]# yum -y install autoconf

再次执行成功

[root@zabbix02 gettext]# phpize
Configuring for:
PHP Api Version:         20230831
Zend Module Api No:      20230831
Zend Extension Api No:   420230831

执行配置脚本

[root@zabbix02 gettext]# ./configure --with-php-config=/usr/local/php/bin/php-config

执行成功

checking whether to build shared libraries... yes
checking whether to build static libraries... no

creating libtool
appending configuration tag "CXX" to libtool
configure: patching config.h.in
configure: creating ./config.status
config.status: creating config.h

编译安装

make &&make install

执行成功

See any operating system documentation about shared libraries for
more information, such as the ld(1) and ld.so(8) manual pages.
----------------------------------------------------------------------

Build complete.
Don't forget to run 'make test'.

Installing shared extensions:     /usr/local/php/lib/php/extensions/no-debug-non-zts-20230831/

重启php-fpm

[root@zabbix02 gettext]# systemctl restart php-fpm

再次访问,可以修改语言

选择完语言后,提示
- 所要求的最小PHP post大小是16M (配置项"post_max_size")。
- 所要求的最小PHP脚本执行时间是300 (配置项 "max_execution_time")。
- 所要求的PHP脚本最小解析时间是300 (配置项"max_input_time")。
- PHP gd FreeType不支持

按照要求修改配置文件

[root@zabbix02 ~]# grep -E "^post_max_size|^max_execution_time|^max_input_time" /etc/php.ini
max_execution_time = 300
max_input_time = 300
post_max_size = 16M

解决PHP gd FreeType不支持

下载解压freetype源码包

[root@zabbix02 ~]# curl -LO https://jaist.dl.sourceforge.net/project/freetype/freetype2/2.13.2/freetype-2.13.2.tar.xz
[root@zabbix02 ~]# tar xf freetype-2.13.2.tar.xz
[root@zabbix02 ~]# cd freetype-2.13.2

执行配置脚本

[root@zabbix02 freetype-2.13.2]# ./configure

执行成功,这里会有一个WARNING,可以不予理会

Library configuration:
  external zlib: yes (pkg-config)
  bzip2:         yes (autoconf test)
  libpng:        yes (pkg-config)
  harfbuzz:      no
  brotli:        no
  pthread:       yes

configure: WARNING:
  `make refdoc' will fail since pip package `docwriter' is not installed.
  To install, run `pip install docwriter', or to use a Python
  virtual environment, run `make refdoc-venv' (requires pip package
  `virtualenv').  These operations require Python >= 3.5.

编译安装

[root@zabbix02 freetype-2.13.2]# make && make install

安装成功

/usr/bin/install -c -m 644 /root/freetype-2.13.2/include/ft2build.h                  \
          /usr/local/include/freetype2/ft2build.h
/usr/bin/install -c -m 644 ./builds/unix/ftconfig.h                        \
          /usr/local/include/freetype2/freetype/config/ftconfig.h
/usr/bin/install -c -m 644 /root/freetype-2.13.2/objs/ftmodule.h                          \
          /usr/local/include/freetype2/freetype/config/ftmodule.h
/usr/bin/install -c -m 644 ./builds/unix/ftoption.h                        \
          /usr/local/include/freetype2/freetype/config/ftoption.h
/usr/bin/install -c -m 644 ./builds/unix/freetype2.m4          \
          /usr/local/share/aclocal/freetype2.m4
/usr/bin/install -c -m 644 ./builds/unix/freetype2.pc             \
          /usr/local/lib/pkgconfig/freetype2.pc

重新编译PHP

[root@zabbix02 ~]# cd php-8.3.8/
[root@zabbix02 php-8.3.8]# make clean
[root@zabbix02 php-8.3.8]# export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig:$PKG_CONFIG_PATH
[root@zabbix02 php-8.3.8]# ./configure --prefix=/usr/local/php --sysconfdir=/etc/php --with-openssl --with-zlib --with-bz2 --with-curl --enable-bcmath --enable-gd --with-webp --with-jpeg --with-mhash --enable-mbstring --with-imap-ssl --with-mysqli --enable-exif --with-ffi --with-zip --enable-sockets --with-pcre-jit --enable-fpm --with-pdo-mysql --enable-pcntl --with-gettext --with-freetype
[root@zabbix02 php-8.3.8]# make && make install

重启PHP

[root@zabbix02 freetype-2.13.2]# systemctl restart php-fpm

web页面继续后续步骤时,还会有个报错,无法创建/apps/nginx/html/conf/zabbix.conf.php

需要修改PHP配置文件,将php的运行用户改为zabbix然后重启zabbix

[root@zabbix01 php-8.3.8]# grep -E "^user|^group" /etc/php/php-fpm.d/www.conf 
user = zabbix
group = zabbix
[root@zabbix01 php-8.3.8]# systemctl restart php-fpm

评论