
开源在于折腾,源码的好与坏各有各的看法,鉴于 CentOS 8 已经 EOL 了,而 CentOS 7 还有至少两年多的时间,所以才有了本篇文章,不过还是希望大家能尽快切换到 Stream 版本或者其他替代发行版本,这样方便安装,今天的文章篇幅相对比较长,而且不太适合新手,另外编译会遇到很多问题,需要有一定的耐心。
新手建议关闭防火墙与 SElinux,不然容易出现意外之外的问题,老手可以忽略。
sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config
setenforce 0
systemctl stop firewalld && systemctl disable firewalld建议更新下软件 yum update -y
yum -y install wget vim 由于 Zabbix 6.0 LTS 的官方要求为 postgresql 13,所以需要导入 postgresql 13 的源
yum -y install https://download.postgresql.org/pub/repos/yum/reporpms/EL-7-x86_64/pgdg-redhat-repo-latest.noarch.rpm
sed -i "s@https://download.postgresql.org/pub@https://mirrors.huaweicloud.com/postgresql@g" /etc/yum.repos.d/pgdg-redhat-all.repoyum -y install postgresql13-server/usr/pgsql-13/bin/postgresql-13-setup initdb
systemctl enable postgresql-13
systemctl start postgresql-13cd /tmp
wget https://cdn.zabbix.com/zabbix/sources/stable/6.0/zabbix-6.0.0.tar.gztar -zxvf zabbix-6.0.0.tar.gzgroupadd --system zabbix
useradd --system -g zabbix -d /usr/lib/zabbix -s /sbin/nologin -c "Zabbix Monitoring System" zabbixmkdir -p /app/zabbixtar -zxvf zabbix-6.0.0.tar.gz
mv zabbix-6.0.0 /app./configure --prefix=/app/zabbix --enable-server --enable-agent2 --with-postgresql=/usr/pgsql-13/bin/pg_config --with-net-snmpgcc 环境问题

Postgresql 库问题

CentOS 7 安装此包会出现报错,分别需要安装 、,报错如下两图。
缺少 net-snmp 源问题

缺少libevent 源

缺少 go 环境(如果是第一代 agent,无此问题)

经过上面的步骤编译就完成了,如下图

需要注意的是,本文环境编译了 agent2,agent2 是采用了 go 环境,需要通过 go 来下载一些库,国内是无法通过 go 下载库,因此需要设置代理,否则会卡在下图

Zabbix 6.0 LTS 需要 php 7.2.5 版本以上,需要安装 remi 源支持 php 7.x
/app/zabbix
mv /app/ui /app/zabbix
vim /etc/nginx/conf.d/zabbix.confserver {
listen 80;
# server_name example.com;
root /app/zabbix/ui;
index index.php;
location = /favicon.ico {
log_not_found off;
}
location / {
try_files $uri $uri/ =404;
}
location /assets {
access_log off;
expires 10d;
}
location ~ /\.ht {
deny all;
}
location ~ /(api\/|conf[^\.]|include|locale|vendor) {
deny all;
return 404;
}
location ~ [^/]\.php(/|$) {
fastcgi_pass unix:/run/php-fpm/zabbix.sock;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_index index.php;
fastcgi_param DOCUMENT_ROOT /app/zabbix/ui;
fastcgi_param SCRIPT_FILENAME /app/zabbix/ui$fastcgi_script_name;
fastcgi_param PATH_TRANSLATED /app/zabbix/ui$fastcgi_script_name;
include fastcgi_params;
fastcgi_param QUERY_STRING $query_string;
fastcgi_param REQUEST_METHOD $request_method;
fastcgi_param CONTENT_TYPE $content_type;
fastcgi_param CONTENT_LENGTH $content_length;
fastcgi_intercept_errors on;
fastcgi_ignore_client_abort off;
fastcgi_connect_timeout 60;
fastcgi_send_timeout 180;
fastcgi_read_timeout 180;
fastcgi_buffer_size 128k;
fastcgi_buffers 4 256k;
fastcgi_busy_buffers_size 256k;
fastcgi_temp_file_write_size 256k;
}
}发现是前端显示为 502,猜测是由于 php-fpm 没开

systemctl enable php-fpm
systemctl start php-fpmtail -f /var/log/nginx/error.log
vim /etc/php-fpm.d/zabbix.conf[zabbix]
user = apache
group = apache
listen = /run/php-fpm/zabbix.sock
listen.acl_users = apache,nginx
listen.allowed_clients = 127.0.0.1
pm = dynamic
pm.max_children = 50
pm.start_servers = 5
pm.min_spare_servers = 5
pm.max_spare_servers = 35
pm.max_requests = 200
php_value[session.save_handler] = files
php_value[session.save_path] = /var/lib/php/session
php_value[max_execution_time] = 300
php_value[memory_limit] = 128M
php_value[post_max_size] = 16M
php_value[upload_max_filesize] = 2M
php_value[max_input_time] = 300
php_value[max_input_vars] = 10000
systemctl restart php-fpm 
yum -y install php-mbstring php-bcmath php-pgsql php-gd php-xml
systemctl restart php-fpm nginx 创建用户及数据库
导入数据库相关文件
修改 postgresql 权限文件将本地权限改为 md5 的验证方式
重启数据库 这里需要注意的是架构部分填 public 即可,如下图





程序文件路径为 下配置文件路径为 下
[Unit]
Description=Zabbix Server
After=syslog.target
After=network.target
After=postgresql.service
After=pgbouncer.service
After=postgresql-13.service
[Service]
Environment="CONFFILE=/app/zabbix/etc/zabbix_server.conf"
EnvironmentFile=-/etc/sysconfig/zabbix-server
Type=forking
Restart=on-failure
PIDFile=/tmp/zabbix_server.pid
KillMode=control-group
ExecStart=/app/zabbix/sbin/zabbix_server -c $CONFFILE
ExecStop=/bin/kill -SIGTERM $MAINPID
RestartSec=10s
TimeoutSec=0
[Install]
WantedBy=multi-user.target
vim /app/zabbix/etc/zabbix_server.conf
systemctl restart zabbix-server zabbix-agent2



