开源在于折腾,源码的好与坏各有各的看法,鉴于 CentOS 8 已经 EOL 了,而 CentOS 7 还有至少两年多的时间,所以才有了本篇文章,不过还是希望大家能尽快切换到 Stream 版本或者其他替代发行版本,这样方便安装,今天的文章篇幅相对比较长,而且不太适合新手,另外编译会遇到很多问题,需要有一定的耐心。
正文
本文环境
- CentOS 7.9.2009
- PHP 7.4
- Postgresql 13
- Nginx 1.20
新手建议
新手建议关闭防火墙与 SElinux,不然容易出现意外之外的问题,老手可以忽略。
sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/configsetenforce 0systemctl 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.rpmsed -i "s@https://download.postgresql.org/pub@https://mirrors.huaweicloud.com/postgresql@g" /etc/yum.repos.d/pgdg-redhat-all.repo
安装 postgresql
yum -y install postgresql13-server
启动并初始化数据库
/usr/pgsql-13/bin/postgresql-13-setup initdbsystemctl enable postgresql-13systemctl start postgresql-13
下载源码包
cd /tmp wget https://cdn.zabbix.com/zabbix/sources/stable/6.0/zabbix-6.0.0.tar.gz
解压软件包
tar -zxvf zabbix-6.0.0.tar.gz
创建 Zabbix 用户以及 Zabbix 用户组
groupadd --system zabbixuseradd --system -g zabbix -d /usr/lib/zabbix -s /sbin/nologin -c "Zabbix Monitoring System" zabbix
创建 Zabbix 安装目录
mkdir -p /app/zabbix
解压源码包
tar -zxvf zabbix-6.0.0.tar.gzmv zabbix-6.0.0 /app
开始编译
- prefix 指定安装目录
- enable-server 启用 Zabbix Server
- enable-agent2 启用 Zabbix agent2
- with-postgresql 后端指定数据库为 PG,并指定路径
- net-snmp 支持 snmp 协议
其实有很多参数,大家可以参考 ./configure --help 自行研究
./configure --prefix=/app/zabbix --enable-server --enable-agent2 --with-postgresql=/usr/pgsql-13/bin/pg_config --with-net-snmp
gcc 环境问题
yum -y install gcc-c++
Postgresql 库问题
yum -y install postgresql13-devel
CentOS 7 安装此包会出现报错,分别需要安装 centos-release-scl-rh、epel-release,报错如下两图。
需要 centos-release-scl-rh 源
需要 epel-release 源
yum -y install centos-release-scl-rh epel-release
缺少 net-snmp 源问题
yum -y install net-snmp-devel
缺少libevent 源
yum -y install libevent-devel
缺少 go 环境(如果是第一代 agent,无此问题)
yum -y install golang
经过上面的步骤编译就完成了,如下图
安装
需要注意的是,本文环境编译了 agent2,agent2 是采用了 go 环境,需要通过 go 来下载一些库,国内是无法通过 go 下载库,因此需要设置代理,否则会卡在下图
设置 go 代理 并安装
go env -w GOPROXY=https://goproxy.cn,directmake install
安装完成
整体安装目录
[root@centos7-01 zabbix]# tree /app/zabbix//app/zabbix/├── bin│ └── zabbix_js├── etc│ ├── zabbix_agent2.conf│ ├── zabbix_agent2.d│ │ └── plugins.d│ │ ├── ceph.conf│ │ ├── docker.conf│ │ ├── memcached.conf│ │ ├── modbus.conf│ │ ├── mongodb.conf│ │ ├── mqtt.conf│ │ ├── mysql.conf│ │ ├── oracle.conf│ │ ├── postgres.conf│ │ ├── redis.conf│ │ └── smart.conf│ ├── zabbix_agentd.conf│ ├── zabbix_agentd.conf.d│ ├── zabbix_server.conf│ └── zabbix_server.conf.d├── lib│ └── modules├── sbin│ ├── zabbix_agent2│ ├── zabbix_agentd│ └── zabbix_server└── share ├── man │ └── man8 │ ├── zabbix_agent2.8 │ └── zabbix_server.8 └── zabbix ├── alertscripts └── externalscripts
php 环境
Zabbix 6.0 LTS 需要 php 7.2.5 版本以上,需要安装 remi 源支持 php 7.x
yum -y install https://rpms.remirepo.net/enterprise/remi-release-7.rpmyum install yum-utilsyum-config-manager --disable 'remi-php*'yum-config-manager --enable remi-php74yum -y install php php-fpm
安装 nginx
yum -y install nginx
Nginx 操作部分
创建 zabbix 相关配置文件
首先将 Zabbix 前端文件移动到 /app/zabbix 下
mv /app/ui /app/zabbixvim /etc/nginx/conf.d/zabbix.conf
配置文件如下
server { 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; }}
修改配置文件
vim /etc/nginx/nginx.conf## listen 80 default_server;## listen [::]:80 default_server;
nginx.conf 加注释
zabbix.conf 取消注释
启动 nginx
systemctl enable nginx systemctl start nginx
访问前端
发现前端显示为 502,猜测是由于 php-fpm 没开
启动 php-fpm
systemctl enable php-fpmsystemctl start php-fpm
再次访问前端
发现依然是 502
查看 nginx 日志
通过日志可以发现 socket 文件不存在,所以需要创建一个 php-fpm 的配置
tail -f /var/log/nginx/error.log
创建 zabbix php 相关配置文件
vim /etc/php-fpm.d/zabbix.conf
[zabbix]user = apachegroup = apachelisten = /run/php-fpm/zabbix.socklisten.acl_users = apache,nginxlisten.allowed_clients = 127.0.0.1pm = dynamicpm.max_children = 50pm.start_servers = 5pm.min_spare_servers = 5pm.max_spare_servers = 35pm.max_requests = 200php_value[session.save_handler] = filesphp_value[session.save_path] = /var/lib/php/sessionphp_value[max_execution_time] = 300php_value[memory_limit] = 128Mphp_value[post_max_size] = 16Mphp_value[upload_max_filesize] = 2Mphp_value[max_input_time] = 300php_value[max_input_vars] = 10000
重启 php-fpm 服务
systemctl restart php-fpm
访问正常
前端部分
php 部分安装
通过前端的诊断,根据报错内容去安装相应的 php 扩展插件
yum -y install php-mbstring php-bcmath php-pgsql php-gd php-xml
如不需要LDAP,这个地方可以忽略
重启相关服务
systemctl restart php-fpm nginx
此时可以进入数据库配置部分了
数据库配置及导入相关文件
创建用户及数据库
sudo -u postgres createuser --pwprompt zabbixsudo -u postgres createdb -O zabbix zabbix
导入数据库相关文件
cat /app/database/postgresql/schema.sql | sudo -u zabbix psql zabbixcat /app/database/postgresql/images.sql | sudo -u zabbix psql zabbixcat /app/database/postgresql/data.sql | sudo -u zabbix psql zabbix
导入完成
修改 postgresql 权限文件,将本地权限改为 md5 的验证方式
重启数据库
systemctl restart postgresql-13
前端数据库配置
这里需要注意的是架构部分填 public 即可,如下图
剩余前端配置
填写对应时区和实例名称
如果出现下图问题,基本是目录权限问题,碰到此问题修改目录权限或者下载配置文件拷贝至提示目录即可
默认用户名密码是Admin/zabbix
由于 Zabbix Server 没起来,导致前端显示 Zabbix server 未启动的警告提示
Zabbix 配置
程序文件路径为/app/zabbix/sbin/下
配置文件路径为/app/zabbix/etc/下
制作 Zabbix Server 守护文件
[Unit]Description=Zabbix ServerAfter=syslog.targetAfter=network.targetAfter=postgresql.serviceAfter=pgbouncer.serviceAfter=postgresql-13.service[Service]Environment="CONFFILE=/app/zabbix/etc/zabbix_server.conf"EnvironmentFile=-/etc/sysconfig/zabbix-serverType=forkingRestart=on-failurePIDFile=/tmp/zabbix_server.pidKillMode=control-groupExecStart=/app/zabbix/sbin/zabbix_server -c $CONFFILEExecStop=/bin/kill -SIGTERM $MAINPIDRestartSec=10sTimeoutSec=0[Install]WantedBy=multi-user.target
编辑配置文件
vim /app/zabbix/etc/zabbix_server.conf
制作 zabbix agent2 守护文件
[Unit]Description=Zabbix Agent 2After=syslog.targetAfter=network.target[Service]Environment="CONFFILE=/app/zabbix/etc/zabbix_agent2.conf"EnvironmentFile=-/etc/sysconfig/zabbix_agent2Type=simpleRestart=on-failurePIDFile=/run/zabbix/zabbix_agent2.pidKillMode=control-groupExecStart=/app/zabbix/sbin/zabbix_agent2 -c $CONFFILEExecStop=/bin/kill -SIGTERM $MAINPIDRestartSec=10sUser=zabbixGroup=zabbix[Install]WantedBy=multi-user.target
启动组件
systemctl restart zabbix-server zabbix-agent2
最终效果
首页服务正常
图形正常
dashboard
写在最后
辛苦各位朋友能看到这里了,篇幅是比较长的,如果是完全编译的话更费劲,当然针对一些完全没有外网的朋友相对来说更加的麻烦,有空我会出一个完全离线编译的版本,欢迎大家关注后续的文章哦,谢谢!
版权声明:内容来源于互联网和用户投稿 如有侵权请联系删除