Zabbix 6.0 源码编译安装手册(openEuler 24.03 + MariaDB)
一、环境准备
1.1 配置主机名
[root@localhost ~]# hostnamectl set-hostname zabbix-server[root@localhost ~]# logout# 重新登录后提示符变为[root@zabbix-server ~]#1.2 安装编译工具及依赖库
[root@zabbix-server ~]# dnf install -y gcc make tar gcc-c++[root@zabbix-server ~]# 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 服务基础包(httpd 和 MariaDB)
[root@zabbix-server ~]# dnf install -y httpd mariadb-server mariadb[root@zabbix-server ~]# systemctl start httpd[root@zabbix-server ~]# systemctl enable httpd1.4 创建 Zabbix 用户与目录
[root@zabbix-server ~]# groupadd --system zabbix[root@zabbix-server ~]# useradd --system -g zabbix -d /usr/lib/zabbix -s /sbin/nologin -c "Zabbix Monitoring System" zabbix[root@zabbix-server ~]# mkdir -p /app/zabbix/logs[root@zabbix-server ~]# chown -R zabbix:zabbix /app/zabbix二、数据库安装与配置
2.1 启动 MariaDB 并设置开机自启
[root@zabbix-server ~]# systemctl start mariadb[root@zabbix-server ~]# systemctl enable mariadb2.2 创建 Zabbix 数据库和用户
[root@zabbix-server ~]# 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 下载源码包
[root@zabbix-server ~]# cd /usr/src[root@zabbix-server src]# wget https://cdn.zabbix.com/zabbix/sources/stable/6.0/zabbix-6.0.44.tar.gz[root@zabbix-server src]# tar -xzf zabbix-6.0.44.tar.gz[root@zabbix-server src]# cd zabbix-6.0.443.2 配置编译参数
- 禁用 SNMP 监控(推荐,以绕过符号问题)
[root@zabbix-server zabbix-6.0.44]# ./configure --prefix=/app/zabbix \> --enable-server --enable-agent --with-mysql --without-net-snmp --with-openipmi若配置过程中提示缺少其他依赖,请根据错误信息安装对应的 -devel 包。
3.3 编译并安装
[root@zabbix-server zabbix-6.0.44]# make && make install四、导入数据库架构
[root@zabbix-server ~]# cd /usr/src/zabbix-6.0.44/database/mysql[root@zabbix-server mysql]# mysql -uzabbix -p'zabbix' zabbix < schema.sql[root@zabbix-server mysql]# mysql -uzabbix -p'zabbix' zabbix < images.sql[root@zabbix-server mysql]# mysql -uzabbix -p'zabbix' zabbix < data.sql五、配置 Zabbix Server
编辑配置文件 /app/zabbix/etc/zabbix_server.conf:
[root@zabbix-server ~]# vi /app/zabbix/etc/zabbix_server.conf设置以下参数(根据实际情况调整):
DBHost=localhostDBName=zabbixDBUser=zabbixDBPassword=zabbix其他参数可保持默认。
六、配置 Zabbix Agent(本机)
编辑配置文件 /app/zabbix/etc/zabbix_agentd.conf:
[root@zabbix-server ~]# vi /app/zabbix/etc/zabbix_agentd.conf修改以下参数:
Server=127.0.0.1 # 允许哪个 Server 主动连接本 AgentServerActive=127.0.0.1 # 本 Agent 主动向哪个 Server 发送数据Hostname=Zabbix-server # 本机在 Zabbix 前端显示的名称保存退出。
七、创建 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八、启动服务并验证
8.1 重新加载 systemd 并启动服务
[root@zabbix-server ~]# systemctl daemon-reload[root@zabbix-server ~]# systemctl start zabbix-server[root@zabbix-server ~]# systemctl enable zabbix-server[root@zabbix-server ~]# systemctl start zabbix-agent[root@zabbix-server ~]# systemctl enable zabbix-agent8.2 检查端口监听
- Server 默认监听
10051端口:Terminal window [root@zabbix-server ~]# netstat -ntpl | grep 10051tcp 0 0 0.0.0.0:10051 0.0.0.0:* LISTEN 12345/zabbix_server - Agent 默认监听
10050端口:看到相应端口即表示启动成功。Terminal window [root@zabbix-server ~]# netstat -ntpl | grep 10050tcp 0 0 0.0.0.0:10050 0.0.0.0:* LISTEN 12346/zabbix_agentd
九、部署 Web 前端
9.1 安装 PHP 及 PHP-FPM
[root@zabbix-server ~]# 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 并设置开机自启
[root@zabbix-server ~]# systemctl start php-fpm[root@zabbix-server ~]# systemctl enable php-fpm9.5 复制前端文件到 Web 目录
[root@zabbix-server ~]# cp -rf /usr/src/zabbix-6.0.44/ui/* /var/www/html/[root@zabbix-server ~]# chmod 777 /var/www/html/conf[root@zabbix-server ~]# chown -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>9.7 重启 httpd 使配置生效
[root@zabbix-server ~]# systemctl restart httpd十、完成 Web 安装向导
- 打开浏览器,访问
http://你的服务器IP/zabbix。 - 按照向导检查环境(所有 PHP 扩展应已满足)。
- 数据库连接信息:
- 数据库类型:MySQL
- 主机:
localhost - 端口:留空
- 数据库名:
zabbix - 用户名:
zabbix - 密码:
zabbix
- 后续步骤保持默认,完成安装。
- 登录 Zabbix 前端:用户名 Admin,密码 zabbix。
十一、添加被监控机器(二进制编译安装版)
若需要将其他服务器作为被监控节点(Zabbix Agent),请按照以下步骤在目标机器上操作。
11.1 安装编译工具、依赖库及 HTTP 服务(可选)
登录 zabbix-agent 节点,执行:
[root@zabbix-agent ~]# dnf install -y gcc make tar gcc-c++[root@zabbix-agent ~]# dnf install -y pcre-devel[root@zabbix-agent ~]# dnf install -y httpd # 可选,如果需要 Web 服务[root@zabbix-agent ~]# systemctl start httpd[root@zabbix-agent ~]# systemctl enable httpd11.2 创建 Zabbix 用户与目录
[root@zabbix-agent ~]# groupadd --system zabbix[root@zabbix-agent ~]# useradd --system -g zabbix -d /usr/lib/zabbix -s /sbin/nologin zabbix[root@zabbix-agent ~]# mkdir -p /app/zabbix[root@zabbix-agent ~]# chown -R zabbix:zabbix /app/zabbix11.3 下载 Zabbix 源码并编译安装 zabbix-agent
[root@zabbix-agent ~]# cd /usr/src[root@zabbix-agent src]# wget https://cdn.zabbix.com/zabbix/sources/stable/6.0/zabbix-6.0.44.tar.gz[root@zabbix-agent src]# tar -xzf zabbix-6.0.44.tar.gz[root@zabbix-agent src]# cd zabbix-6.0.44[root@zabbix-agent zabbix-6.0.44]# ./configure --prefix=/app/zabbix --enable-agent[root@zabbix-agent zabbix-6.0.44]# make install11.4 修改 Agent 配置文件
编辑 /app/zabbix/etc/zabbix_agentd.conf:
[root@zabbix-agent ~]# vi /app/zabbix/etc/zabbix_agentd.conf修改以下参数(根据实际 Zabbix Server IP 调整):
Server=192.168.200.10 # Zabbix Server 的 IPServerActive=192.168.200.10 # Zabbix Server 的 IPHostname=Zabbix-agent # 该 Agent 在 Zabbix 前端显示的名称保存退出。
11.5 创建 systemd 服务单元
创建文件 /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.target11.6 启动 zabbix-agent 并验证
[root@zabbix-agent ~]# systemctl daemon-reload[root@zabbix-agent ~]# systemctl start zabbix-agent[root@zabbix-agent ~]# systemctl enable zabbix-agent[root@zabbix-agent ~]# netstat -ntpl | grep 10050tcp 0 0 0.0.0.0:10050 0.0.0.0:* LISTEN 12345/zabbix_agentd看到 10050 端口监听即表示 Agent 启动成功。
11.7 在 Zabbix Server Web 界面添加主机
登录 Zabbix 前端,进入 配置 → 主机 → 创建主机,填写主机名称(需与配置文件中 Hostname 一致)、可见名、群组,IP 地址填写 Agent 的实际 IP,端口 10050,然后添加模板(如 Linux by Zabbix agent),即可开始监控该节点。