51工具盒子

依楼听风雨
笑看云卷云舒,淡观潮起潮落

Zabbix7.0基于wlnmp源单机部署

本文基于wlnmp一键安装包提供的wlnmp源来部署Zabbix7.0单机版本,文中所有安装过程全部都使用yum/dnf方式部署。这种部署方式的好处就是便于后期版本平滑升级,杜绝一次性部署后难以升级的痛点 ,适用于生产环境。

当前环境

系统:Anolis OS 8.9(理论适用于RockyLinux 8.x、AlmaLinux 8.x、OpenCloudOS 8.x)

数据库:MySQL 8.4

php:8.3

注:从Zabbix7.0开始,php版本最低要求为php8.0

1、初始化系统添加epel源
dnf install epel-release -y

|---|-----------------------------| | 1 | dnf install epel-release -y |

替换epel源为国内源
sed -e 's|^metalink=|#metalink=|g' \ -e 's|^#baseurl=https\?://download.fedoraproject.org/pub/epel/|baseurl=https://mirrors.jcut.edu.cn/epel/|g' \ -e 's|^#baseurl=https\?://download.example/pub/epel/|baseurl=https://mirrors.jcut.edu.cn/epel/|g' \ -i.bak \ /etc/yum.repos.d/epel.repo

|-----------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | 1 2 3 4 5 | sed -e 's|^metalink=|#metalink=|g' \ -e 's|^#baseurl=https\?://download.fedoraproject.org/pub/epel/|baseurl=https://mirrors.jcut.edu.cn/epel/|g' \ -e 's|^#baseurl=https\?://download.example/pub/epel/|baseurl=https://mirrors.jcut.edu.cn/epel/|g' \ -i.bak \ /etc/yum.repos.d/epel.repo |

2、添加wlnmp源
curl -fsSL "https://sh.wlnmp.com/wlnmp.sh" | bash

|---|----------------------------------------------------| | 1 | curl -fsSL "https://sh.wlnmp.com/wlnmp.sh" | bash |

3、配置zabbix7.0源

官方源和阿里源任选其一

官方源
rpm -Uvh https://repo.zabbix.com/zabbix/7.0/rhel/8/x86_64/zabbix-release-latest-7.0.el8.noarch.rpm

|---|----------------------------------------------------------------------------------------------------| | 1 | rpm -Uvh https://repo.zabbix.com/zabbix/7.0/rhel/8/x86_64/zabbix-release-latest-7.0.el8.noarch.rpm |

阿里云源
vi /etc/yum.repos.d/zabbix.repo

|---|---------------------------------| | 1 | vi /etc/yum.repos.d/zabbix.repo |


[zabbix] name=Zabbix Official Repository - $basearch baseurl=https://mirrors.aliyun.com/zabbix/zabbix/7.0/rhel/8/$basearch/ enabled=1 gpgcheck=1 gpgkey=https://mirrors.aliyun.com/zabbix/RPM-GPG-KEY-ZABBIX-B5333005 [zabbix-non-supported] name=Zabbix Official Repository (non-supported) - $basearch baseurl=https://mirrors.aliyun.com/zabbix/zabbix/7.0/rhel/8/$basearch/ enabled=1 gpgkey=https://mirrors.aliyun.com/zabbix/RPM-GPG-KEY-ZABBIX gpgcheck=1 [zabbix-unstable] name=Zabbix Official Repository (unstable) - $basearch baseurl=https://mirrors.aliyun.com/zabbix/zabbix/7.0/rhel/8/$basearch/ enabled=0 gpgcheck=1 gpgkey=https://mirrors.aliyun.com/zabbix/RPM-GPG-KEY-ZABBIX-A14FE591 [zabbix-sources] name=Zabbix Official Repository (source code) - $basearch baseurl=https://mirrors.aliyun.com/zabbix/zabbix/7.0/rhel/8/SRPMS enabled=0 gpgkey=https://mirrors.aliyun.com/zabbix/RPM-GPG-KEY-ZABBIX-B5333005 gpgcheck=1 [zabbix-tools] name=Zabbix Official Repository (tools) - $basearch baseurl=https://mirrors.aliyun.com/zabbix/zabbix-tools/rhel/8/$basearch/ enabled=1 gpgkey=https://mirrors.aliyun.com/zabbix/RPM-GPG-KEY-ZABBIX-TOOLS gpgcheck=1

|----------------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | [zabbix] name=Zabbix Official Repository - $basearch baseurl=https://mirrors.aliyun.com/zabbix/zabbix/7.0/rhel/8/$basearch/ enabled=1 gpgcheck=1 gpgkey=https://mirrors.aliyun.com/zabbix/RPM-GPG-KEY-ZABBIX-B5333005 [zabbix-non-supported] name=Zabbix Official Repository (non-supported) - $basearch baseurl=https://mirrors.aliyun.com/zabbix/zabbix/7.0/rhel/8/$basearch/ enabled=1 gpgkey=https://mirrors.aliyun.com/zabbix/RPM-GPG-KEY-ZABBIX gpgcheck=1 [zabbix-unstable] name=Zabbix Official Repository (unstable) - $basearch baseurl=https://mirrors.aliyun.com/zabbix/zabbix/7.0/rhel/8/$basearch/ enabled=0 gpgcheck=1 gpgkey=https://mirrors.aliyun.com/zabbix/RPM-GPG-KEY-ZABBIX-A14FE591 [zabbix-sources] name=Zabbix Official Repository (source code) - $basearch baseurl=https://mirrors.aliyun.com/zabbix/zabbix/7.0/rhel/8/SRPMS enabled=0 gpgkey=https://mirrors.aliyun.com/zabbix/RPM-GPG-KEY-ZABBIX-B5333005 gpgcheck=1 [zabbix-tools] name=Zabbix Official Repository (tools) - $basearch baseurl=https://mirrors.aliyun.com/zabbix/zabbix-tools/rhel/8/$basearch/ enabled=1 gpgkey=https://mirrors.aliyun.com/zabbix/RPM-GPG-KEY-ZABBIX-TOOLS gpgcheck=1 |

4、安装nginx、php、mysql、zabbix-server、zabbix-web
dnf install zabbix-server-mysql zabbix-web-mysql zabbix-sql-scripts -y

|---|------------------------------------------------------------------------| | 1 | dnf install zabbix-server-mysql zabbix-web-mysql zabbix-sql-scripts -y |


dnf install wnginx wphp83 wmysql84 -y

|---|---------------------------------------| | 1 | dnf install wnginx wphp83 wmysql84 -y |


dnf install wphp83-ldap -y

|---|----------------------------| | 1 | dnf install wphp83-ldap -y |

5、启动MySQL并创建库
/etc/init.d/mysql start

|---|-------------------------| | 1 | /etc/init.d/mysql start |


mysql -uroot -p mysql> create database zabbix character set utf8mb4 collate utf8mb4_bin; mysql> create user zabbix@127.0.0.1 identified by 'whsir'; mysql> grant all privileges on zabbix.* to zabbix@127.0.0.1; mysql> set global log_bin_trust_function_creators = 1; mysql> exit

|-------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | 1 2 3 4 5 6 | mysql -uroot -p mysql> create database zabbix character set utf8mb4 collate utf8mb4_bin; mysql> create user zabbix@127.0.0.1 identified by 'whsir'; mysql> grant all privileges on zabbix.* to zabbix@127.0.0.1; mysql> set global log_bin_trust_function_creators = 1; mysql> exit |

注1:这里MySQL为什么使用的是127.0.0.1而不是localhost,如果使用localhost,在安装完成仪表盘后,可能会在底部看到zabbix server is not running; the informantion displayed may not be current提示。

注2:默认root密码为空,请自行修改root密码。

6、导入zabbix数据库
zcat /usr/share/zabbix-sql-scripts/mysql/server.sql.gz | mysql --default-character-set=utf8mb4 -uzabbix -p zabbix -h127.0.0.1

|---|--------------------------------------------------------------------------------------------------------------------------------| | 1 | zcat /usr/share/zabbix-sql-scripts/mysql/server.sql.gz | mysql --default-character-set=utf8mb4 -uzabbix -p zabbix -h127.0.0.1 |

我这里密码为whsir

注意:set global log_bin_trust_function_creators = 1;仅在数据导入前临时设置。数据导入完成后,默认log_bin_trust_function_creators为0即可。

7、优化MySQL并重启数据库

使用**吴昊开发的** MySQL my.cnf配置文件生成器https://dbcnf.wlnmp.com/,如果没有特殊需求,仅填写CPU、内存生成MySQL 8.4配置文件即可。
/etc/init.d/mysql restart

|---|---------------------------| | 1 | /etc/init.d/mysql restart |


8、配置zabbix-server数据库账号密码
sed -i s/"# DBPassword="/DBPassword=whsir/ /etc/zabbix/zabbix_server.conf sed -i s/"# DBHost=localhost"/DBHost=127.0.0.1/ /etc/zabbix/zabbix_server.conf

|-----|----------------------------------------------------------------------------------------------------------------------------------------------------------| | 1 2 | sed -i s/"# DBPassword="/DBPassword=whsir/ /etc/zabbix/zabbix_server.conf sed -i s/"# DBHost=localhost"/DBHost=127.0.0.1/ /etc/zabbix/zabbix_server.conf |

9、启动zabbix-server并设置自启动
systemctl enable zabbix-server systemctl start zabbix-server

|-----|--------------------------------------------------------------| | 1 2 | systemctl enable zabbix-server systemctl start zabbix-server |

10、设置目录权限
chown -R www.www /usr/share/zabbix/ chown -R www.www /etc/zabbix/

|-----|-------------------------------------------------------------------| | 1 2 | chown -R www.www /usr/share/zabbix/ chown -R www.www /etc/zabbix/ |

11、配置php并启动
sed -i s/"max_input_time = 60"/"max_input_time = 300"/ /usr/local/php/etc/php.ini sed -i s/"max_execution_time = 30"/"max_execution_time = 300"/ /usr/local/php/etc/php.ini sed -i s/"post_max_size = 8M"/"post_max_size = 16M"/ /usr/local/php/etc/php.ini

|-------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | 1 2 3 | sed -i s/"max_input_time = 60"/"max_input_time = 300"/ /usr/local/php/etc/php.ini sed -i s/"max_execution_time = 30"/"max_execution_time = 300"/ /usr/local/php/etc/php.ini sed -i s/"post_max_size = 8M"/"post_max_size = 16M"/ /usr/local/php/etc/php.ini |


/etc/init.d/php-fpm83 restart

|---|-------------------------------| | 1 | /etc/init.d/php-fpm83 restart |

12、配置nginx并启动
sed -i s#"root html;"#"root /usr/share/zabbix/;"# /usr/local/nginx/conf/vhost/demo.conf sed -i s/"#include enable-php83.conf;"/"include enable-php83.conf;"/ /usr/local/nginx/conf/vhost/demo.conf

|-----|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | 1 2 | sed -i s#"root html;"#"root /usr/share/zabbix/;"# /usr/local/nginx/conf/vhost/demo.conf sed -i s/"#include enable-php83.conf;"/"include enable-php83.conf;"/ /usr/local/nginx/conf/vhost/demo.conf |

域名或IP,结合实际情况配置server_name
/etc/init.d/nginx restart

|---|---------------------------| | 1 | /etc/init.d/nginx restart |

13、安装配置zabbix-agent、zabbix-get并启动服务设置开机自启
dnf install zabbix-agent zabbix-get -y

|---|----------------------------------------| | 1 | dnf install zabbix-agent zabbix-get -y |


systemctl enable zabbix-agent systemctl start zabbix-agent

|-----|------------------------------------------------------------| | 1 2 | systemctl enable zabbix-agent systemctl start zabbix-agent |

Agent和Agent 2对比参见官方文档:https://www.zabbix.com/documentation/7.0/zh/manual/appendix/agent_comparison

14、Zabbix仪表盘安装

访问http://IP或设置好的域名地址,进行仪表盘安装流程

①修改语言为中文


②确保前置检查必要条件没有问题,然后下一步


③这里配置数据库主机及密码,取消TLS加密选项


④时区改为上海


⑤没问题,直接下一步即可


⑥如果此处提示无法创建配置文件,表示/etc/zabbix/权限没有设置www,按照本文顺序操作,不会出现这类问题,点击完成即可


⑦安装完成,默认登录帐号为Admin ,密码zabbix



15、配置中文字体

Zabbix7.0如何前期版本一样,在安装完成后图形字体都是方块显示,需要手动配置中文字体。

①配置中文字体

下载中文字体,我这里使用的是阿里巴巴普惠体2.0 ,当然你也可以从Windows上找个中文字体上传上来,可参考https://blog.whsir.com/post-5965.html
curl -o /usr/share/zabbix/assets/fonts/AlibabaPuHuiTi-2-65-Medium.ttf https://down.whsir.com/downloads/AlibabaPuHuiTi-2-65-Medium.ttf

|---|---------------------------------------------------------------------------------------------------------------------------------------| | 1 | curl -o /usr/share/zabbix/assets/fonts/AlibabaPuHuiTi-2-65-Medium.ttf https://down.whsir.com/downloads/AlibabaPuHuiTi-2-65-Medium.ttf |

②刷下字体权限
chown www.www /usr/share/zabbix/assets/fonts/AlibabaPuHuiTi-2-65-Medium.ttf

|---|-----------------------------------------------------------------------------| | 1 | chown www.www /usr/share/zabbix/assets/fonts/AlibabaPuHuiTi-2-65-Medium.ttf |

③修改zabbix配置文件
vi /usr/share/zabbix/include/defines.inc.php

|---|----------------------------------------------| | 1 | vi /usr/share/zabbix/include/defines.inc.php |

找到以下两处内容
define('ZBX_GRAPH_FONT_NAME', 'graphfont'); define('ZBX_FONT_NAME', 'graphfont');

|-----|-----------------------------------------------------------------------------------| | 1 2 | define('ZBX_GRAPH_FONT_NAME', 'graphfont'); define('ZBX_FONT_NAME', 'graphfont'); |

改成
define('ZBX_GRAPH_FONT_NAME', 'AlibabaPuHuiTi-2-65-Medium'); define('ZBX_FONT_NAME', 'AlibabaPuHuiTi-2-65-Medium');

|-----|---------------------------------------------------------------------------------------------------------------------| | 1 2 | define('ZBX_GRAPH_FONT_NAME', 'AlibabaPuHuiTi-2-65-Medium'); define('ZBX_FONT_NAME', 'AlibabaPuHuiTi-2-65-Medium'); |

保存退出,然后直接刷新页面就好了,至此Zabbix7.0基于wlnmp源单机部署完成

16、地理地图卡顿优化(补充)

操作Zabbix7.0时,偶尔会出现卡顿,这是因为,仪表盘首页中的地理地图会请求https://a.tile.openstreetmap.org/地址,因为该地址在某些场景下是访问不了,所以通过F12请求会发现大量的报错。

GET https://a.tile.openstreetmap.org/11/1160/628.png net::ERR_CONNECTION_TIMED_OUT
zabbix.php:708
GET https://a.tile.openstreetmap.org/11/1161/627.png net::ERR_CONNECTION_TIMED_OUT
zabbix.php:708
GET https://c.tile.openstreetmap.org/11/1160/627.png net::ERR_CONNECTION_TIMED_OUT
zabbix.php:708
GET https://b.tile.openstreetmap.org/11/1161/628.png net::ERR_CONNECTION_TIMED_OUT

为保障使用顺畅,建议删除"地理地图"组件。


赞(2)
未经允许不得转载:工具盒子 » Zabbix7.0基于wlnmp源单机部署