849 字
4 分钟
Zabbix6源码编译-openEuler24
一、环境准备
1.1 配置主机名
hostnamectl set-hostname zabbix-serverlogout# 重新登录后提示符变为[root@zabbix-server ~]#1.2 安装编译工具及依赖库
dnf install -y gcc make tar gcc-c++dnf install -y mariadb-devel pcre-devel libevent-devel OpenIPMI-devel此处未安装
net-snmp-devel,因为编译时会禁用 SNMP 以避免符号冲突。若确实需要 SNMP 监控,请自行安装net-snmp-devel并移除编译参数中的--without-net-snmp。
1.3 安装 Web 服务基础包
dnf install -y httpd mariadb-server mariadbsystemctl enable --now httpd1.4 创建 Zabbix 用户与目录
groupadd --system zabbixuseradd --system -g zabbix -d /usr/lib/zabbix -s /sbin/nologin -c "Zabbix Monitoring System" zabbixmkdir -p /app/zabbix/logschown -R zabbix:zabbix /app/zabbix二、数据库安装与配置
2.1 启动 MariaDB
systemctl enable --now mariadb2.2 创建 Zabbix 数据库和用户
mysql执行以下 SQL:
create database zabbix character set utf8 collate utf8_bin;grant all privileges on zabbix.* to zabbix@'%' identified by 'zabbix';grant all privileges on zabbix.* to zabbix@localhost identified by 'zabbix';quit;三、编译安装 Zabbix Server 与 Agent
3.1 下载源码
cd /usr/srcwget https://cdn.zabbix.com/zabbix/sources/stable/6.0/zabbix-6.0.44.tar.gztar -xzf zabbix-6.0.44.tar.gzcd zabbix-6.0.443.2 配置编译参数
./configure --prefix=/app/zabbix \ --enable-server --enable-agent \ --with-mysql --without-net-snmp --with-openipmi若提示缺少依赖,根据错误信息安装对应的 -devel 包。
3.3 编译并安装
make && make install四、导入数据库架构
cd /usr/src/zabbix-6.0.44/database/mysqlmysql -uzabbix -p'zabbix' zabbix < schema.sqlmysql -uzabbix -p'zabbix' zabbix < images.sqlmysql -uzabbix -p'zabbix' zabbix < data.sql五、配置 Zabbix Server
编辑 /app/zabbix/etc/zabbix_server.conf:
DBHost=localhostDBName=zabbixDBUser=zabbixDBPassword=zabbix其他参数保持默认即可。
六、配置本机 Zabbix Agent
编辑 /app/zabbix/etc/zabbix_agentd.conf:
Server=127.0.0.1ServerActive=127.0.0.1Hostname=Zabbix-server七、创建 systemd 服务
7.1 Zabbix Server
/usr/lib/systemd/system/zabbix-server.service:
[Unit]Description=Zabbix ServerAfter=network.target mariadb.service
[Service]User=zabbixGroup=zabbixType=forkingExecStart=/app/zabbix/sbin/zabbix_server -c /app/zabbix/etc/zabbix_server.confExecStop=/bin/kill -SIGTERM $MAINPIDPIDFile=/tmp/zabbix_server.pidRestart=on-failure
[Install]WantedBy=multi-user.target7.2 Zabbix Agent
/usr/lib/systemd/system/zabbix-agent.service:
[Unit]Description=Zabbix AgentAfter=network.target
[Service]User=zabbixGroup=zabbixType=forkingExecStart=/app/zabbix/sbin/zabbix_agentd -c /app/zabbix/etc/zabbix_agentd.confExecStop=/bin/kill -SIGTERM $MAINPIDPIDFile=/tmp/zabbix_agentd.pidRestart=on-failure
[Install]WantedBy=multi-user.target八、启动与验证
systemctl daemon-reloadsystemctl enable --now zabbix-serversystemctl enable --now zabbix-agent检查端口:
netstat -ntpl | grep 10051 # Servernetstat -ntpl | grep 10050 # Agent九、部署 Web 前端
9.1 安装 PHP 与 PHP-FPM
dnf install -y php php-fpm php-gd php-mysqlnd php-bcmath php-xml php-mbstring9.2 配置 PHP 时区
编辑 /etc/php.ini:
[Date]date.timezone = PRC9.3 配置 PHP-FPM 池
/etc/php-fpm.d/zabbix.conf:
[zabbix]user = apachegroup = apachelisten = /run/php-fpm/zabbix.socklisten.acl_users = apachepm = dynamicpm.max_children = 50pm.start_servers = 5pm.min_spare_servers = 5pm.max_spare_servers = 35php_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] = 10000php_value[date.timezone] = Asia/Shanghai9.4 启动 PHP-FPM
systemctl enable --now php-fpm9.5 部署前端
cp -rf /usr/src/zabbix-6.0.44/ui/* /var/www/html/chmod 777 /var/www/html/confchown -R apache:apache /var/www/html/9.6 配置 Apache
/etc/httpd/conf.d/zabbix.conf:
Alias /zabbix /var/www/html
<Directory "/var/www/html"> Options FollowSymLinks AllowOverride None Require all granted
<FilesMatch \.php$> SetHandler "proxy:unix:/run/php-fpm/zabbix.sock|fcgi://localhost" </FilesMatch></Directory>重启 httpd:
systemctl restart httpd十、完成 Web 安装向导
- 浏览器访问
http://服务器IP/zabbix - 按向导检查环境
- 数据库连接:
- 类型:MySQL
- 主机:localhost
- 数据库名:zabbix
- 用户:zabbix / 密码:zabbix
- 完成向导
- 默认登录:用户名
Admin,密码zabbix
十一、添加被监控节点(Agent 源码编译版)
11.1 安装依赖
在 agent 节点上:
dnf install -y gcc make tar gcc-c++ pcre-devel11.2 创建用户与目录
groupadd --system zabbixuseradd --system -g zabbix -d /usr/lib/zabbix -s /sbin/nologin zabbixmkdir -p /app/zabbixchown -R zabbix:zabbix /app/zabbix11.3 编译安装 Agent
cd /usr/srcwget https://cdn.zabbix.com/zabbix/sources/stable/6.0/zabbix-6.0.44.tar.gztar -xzf zabbix-6.0.44.tar.gzcd zabbix-6.0.44./configure --prefix=/app/zabbix --enable-agentmake install11.4 配置 Agent
编辑 /app/zabbix/etc/zabbix_agentd.conf:
Server=192.168.200.10ServerActive=192.168.200.10Hostname=Zabbix-agent11.5 创建 systemd 服务
同 7.2,保存为 /usr/lib/systemd/system/zabbix-agent.service,然后启动:
systemctl daemon-reloadsystemctl enable --now zabbix-agentnetstat -ntpl | grep 1005011.6 在 Web 界面添加主机
登录 Zabbix 前端 → 配置 → 主机 → 创建主机,主机名需与 Agent 配置文件 Hostname 一致,IP 填实际地址,端口 10050,套用模板(如 Linux by Zabbix agent)。
注意事项
- 数据库密码
zabbix仅为演示,生产环境务必使用强密码并限制远程访问 - 防火墙需放行 80、10050、10051 端口
- 如需 SNMP 监控,需重新编译并带上
--with-net-snmp - 首次登录后立即修改 Admin 默认密码
Zabbix6源码编译-openEuler24
https://blog.xeu.asia/posts/zabbix6-compile-openeuler/