Rocky Linux 9.4 部署Zabbix 7.0

Zabbix基本概念

zabbix官方文档

zabbix介绍

下图来自百度百科

image-20230723075025732

用通俗易懂的话来说,Zabbix是一个监控系统,它可以帮助我们实时检查设备的状态,比如服务器、网络设备等。当设备出现问题时,它会及时通知我们,让我们可以采取措施来解决。同时,它还可以把收集到的数据转化成图表和报告,让我们更直观地了解设备的运行情况

zabbix特性

数据采集:Zabbix Agent方式会定期收集设备的各种指标数据,比如CPU使用率、内存占用、网络流量等。这些数据会被Zabbix Server主动获取。

触发检测告警:Zabbix会根据我们事先设定的阈值和触发条件,对采集到的数据进行检测。如果某个指标超过了阈值或满足了触发条件,Zabbix会触发一个告警。Zabbix会根据事先设置的通知方式,比如邮件、短信等,通知相关的人员或团队。这样我们可以及时知道设备出现了问题。

数据存储:Zabbix将采集到的数据存储在数据库中

数据展示:Zabbix提供了丰富的可视化功能,可以将采集到的数据转化成各种图表和报表。这样我们可以直观地了解设备的运行状态和趋势。

zabbix结构

image-20240612002113555

Zabbix-server:收集监控数据,计算是否满足触发条件,向用户发送通知

Zabbix-database:所有配置信息和Zabbix收集到的数据都被存储在数据库中

Zabbix-Web:为了在任何地方和任何平台都能轻松地访问Zabbix,Zabbix提供了基于Web的界面。该界面是

Zabbix Server的一部分,通常跟Zabbix Server运行在同一台物理机器上。

Zabbix-proxy:Zabbix Proxy可以替Zabbix Server收集性能和可用性数据。Proxy代理服务器是Zabbix 软件可选择部署的一部分。当然,Proxy代理服务器可以帮助单台Zabbix Server分担负载压力。

Zabbix-agent:Zabbix Agents监控代理部署在监控目标上,主动监控本地资源和应用(硬件驱动,内存等)

安装Zabbix

节点规划

IP主机名节点操作系统
192.168.200.10zabbix-serverServer节点Rocky Linux 9
192.168.200.20zabbix-agentAgent节点Centos 7.9.2009

主机名配置

一台server节点一台agent节点

[root@localhost ~]# hostnamectl set-hostname zabbix-server
[root@localhost ~]# bash
[root@zabbix-server ~]# 

[root@localhost ~]# hostnamectl set-hostname zabbix-agent
[root@localhost ~]# bash
[root@zabbix-agent ~]# 

配置Zabbix-Server

配置server的YUM源我这里使用的是Rocky Linux 9操作系统,访问官网页面,选择zabbix版本、操作系统、操作系统版本、zabbix组件、数据库和Web服务器

如下图zabbix官方下载说明页面

image-20240611221239552

选择好后第二步就是安装,官方文档也有详细的说明安装步骤,以下配置均参考官方文档

(1)禁用EPEL提供的Zabbix软件包

编辑配置文件 /etc/yum.repos.d/epel.repo 并添加以下语句

[epel]
...
excludepkgs=zabbix*

安装所需版本的zabbix仓库

rpm -Uvh https://repo.zabbix.com/zabbix/7.0/rocky/9/x86_64/zabbix-release-7.0-2.el9.noarch.rpm && yum clean all

查看一下里面的内容,可以看到连接的是官方镜像仓库,有可能因为我们网络不给力可能会下载不了,所以我们更改为阿里云的镜像仓库

vim /etc/yum.repos.d/zabbix.repo 

image-20240611225051557

# 修改完后内容如下
[zabbix]
name=Zabbix Official Repository - $basearch
baseurl=https://mirrors.aliyun.com/zabbix/zabbix/7.0/rocky/9/$basearch/
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX-B5333005

[zabbix-non-supported]
name=Zabbix Official Repository non-supported - $basearch
baseurl=https://mirrors.aliyun.com/zabbix/non-supported/rhel/9/$basearch/
enabled=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX-08EFA7DD
gpgcheck=1

[zabbix-sources]
name=Zabbix Official Repository source code - $basearch
baseurl=https://repo.zabbix.com/zabbix/7.0/rocky/9/SRPMS
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX-B5333005
gpgcheck=1

(2)安装Zabbix Server、Web前端、Agent

yum install zabbix-server-mysql zabbix-web-mysql zabbix-nginx-conf zabbix-sql-scripts zabbix-selinux-policy zabbix-agent -y

(3)创建初始数据库

zabbix文档没有写这一步,他只做了简单提醒让启动并运行数据库服务器

安装数据库

yum install -y mariadb  mariadb-server

启动mariadb

systemctl enable mariadb --now

初始化mariadb数据库

[root@zabbix-server ~]# mysql_secure_installation # 初始化脚本

NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!

In order to log into MariaDB to secure it, we'll need the current
password for the root user. If you've just installed MariaDB, and
haven't set the root password yet, you should just press enter here.

Enter current password for root (enter for none):  # 按回车设置或更改root用户的密码
OK, successfully used password, moving on...

Setting the root password or using the unix_socket ensures that nobody
can log into the MariaDB root user without the proper authorisation.

You already have your root account protected, so you can safely answer 'n'.

Switch to unix_socket authentication [Y/n] y  # 切换到unix_socket身份验证
Enabled successfully!
Reloading privilege tables..
 ... Success!


You already have your root account protected, so you can safely answer 'n'.

Change the root password? [Y/n] y # 更改root密码
New password: 
Re-enter new password: 
Password updated successfully!
Reloading privilege tables..
 ... Success!


By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB without having to have a user account created for
them.  This is intended only for testing, and to make the installation
go a bit smoother.  You should remove them before moving into a
production environment.

Remove anonymous users? [Y/n] y # 删除匿名用户
 ... Success!

Normally, root should only be allowed to connect from 'localhost'.  This
ensures that someone cannot guess at the root password from the network.

Disallow root login remotely? [Y/n] n  # 限制root远程登录
 ... skipping.

By default, MariaDB comes with a database named 'test' that anyone can
access.  This is also intended only for testing, and should be removed
before moving into a production environment.

Remove test database and access to it? [Y/n] y # 删除测试数据库和访问权限
 - Dropping test database...
 ... Success!
 - Removing privileges on test database...
 ... Success!

Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.

Reload privilege tables now? [Y/n] y  # 重新加载权限表
 ... Success!

Cleaning up...

All done!  If you've completed all of the above steps, your MariaDB
installation should now be secure.

Thanks for using MariaDB!

在数据库上运行以下代码

# 登陆数据库
mysql -uroot -p
# 创建名为zabbix的数据库,并设置字符集为utf8mb4,排序规则为utf8mb4_bin
create database zabbix character set utf8mb4 collate utf8mb4_bin;
# 创建名为zabbix的用户,并设置其密码为'000000'
create user zabbix@localhost identified by '000000';
# 授予zabbix用户在zabbix数据库上的所有权限
grant all privileges on zabbix.* to zabbix@localhost;
# 设置全局变量log_bin_trust_function_creators为1
set global log_bin_trust_function_creators = 1;
# 退出MariaDB
quit;

导入初始架构和数据,系统将提示您输入新创建的密码

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

导入数据库架构后禁用log_bin_trust_function_creators选项

# 登陆mysql
mysql -uroot -p
# 设置全局变量log_bin_trust_function_creators为0
set global log_bin_trust_function_creators = 0;
# 退出MariaDB
quit;

(4)Zabbix server配置数据库

编辑配置文件 /etc/zabbix/zabbix_server.conf

DBPassword=password  # zabbix数据库密码

(5)为Zabbix前端配置PHP

编辑配置文件 /etc/nginx/conf.d/zabbix.conf 取消注释并设置“listen”和“server_name”指令。

# listen 8080;
# server_name example.com;

(6)启动Zabbix server和agent进程

启动Zabbix server和agent进程,并为它们设置开机自启:

systemctl enable zabbix-server zabbix-agent nginx php-fpm --now

(7)放行端口

放行80(nginx),8080(zabbix自定义端口),10050(agent端口),3306(数据库端口)

firewall-cmd --add-port=80/tcp --permanent
firewall-cmd --add-port=10050/tcp --permanent
firewall-cmd --add-port=8080/tcp --permanent
firewall-cmd --add-port=3306/tcp --permanent
firewall-cmd --reload

(8)浏览器访问

http://本机IP:8080/setup.php

(9)配置zabbix

  1. 选择语言

image-20240611233939374

  1. 检查必要条件,默认下一步

image-20240611234115475

  1. 配置数据库连接

image-20240611234336130

  1. 设置zabbix主机名称、时区、主题

image-20240611234735865

  1. 安装前汇总

image-20240611234759958

  1. 完成安装

image-20240611234818154

  1. 登陆,默认用户名Admin密码zabbix

image-20240611234856223

image-20240611234953888

配置Zabbix-agent

在官网选择zabbix服务平台

image-20240611235232086

(1)配置zabbix仓库

rpm -Uvh https://repo.zabbix.com/zabbix/7.0/rhel/7/x86_64/zabbix-release-7.0-1.el7.noarch.rpm && yum clean all

还是一样,修改仓库地址为阿里云镜像仓库

vim /etc/yum.repos.d/zabbix.repo 
# 修改完后的内容如下
[zabbix]
name=Zabbix Official Repository - $basearch
baseurl=https://mirrors.aliyun.com/zabbix/zabbix/7.0/rhel/7/$basearch/
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX-B5333005

[zabbix-non-supported]
name=Zabbix Official Repository non-supported - $basearch
baseurl=https://mirrors.aliyun.com/zabbix/non-supported/rhel/7/$basearch/
enabled=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX
gpgcheck=1

[zabbix-debuginfo]
name=Zabbix Official Repository debuginfo - $basearch
baseurl=https://repo.zabbix.com/zabbix/7.0/rhel/7/$basearch/debuginfo/
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX-B5333005
gpgcheck=1

[zabbix-sources]
name=Zabbix Official Repository source code - $basearch
baseurl=https://repo.zabbix.com/zabbix/7.0/rhel/7/SRPMS
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX-B5333005
gpgcheck=1

(2)下载Zabbix Agent

yum install -y zabbix-agent

(3)修改Zabbix Agent配置文件

vim /etc/zabbix/zabbix_agentd.conf 
# 修改如下内容
Server=zabbix-server IP        # 这里写Zabbix-server 节点的IP(被动监控)
ServerActive=zabbix-server IP  # 这里写Zabbix-server 节点的IP(主动监控)
Hostname=zabbix-agent          # 被监控的主机名

(4)启动Zabbix agent进程

systemctl enable zabbix-agent --now

(5)放行端口

# 放行10050端口
firewall-cmd --add-port=10050/tcp --permanent
firewall-cmd --reload

(6)登陆zabbix监控平台添加主机

左侧栏 >> 数据采集 >> 主机 >> 创建主机(右上角)

image-20240612000830359

添加完后查看zabbix-server节点的日志文件

image-20240612001024802

启动成功,再次刷新zabbix页面,可用性已经变为绿色了

image-20240612001112224

一些问题

乱码

在zabbix服务端找到defines.inc.php文件;找不到的可以使用find 方法查找

find / -name defines.inc.php

找到这个目录进入,这里需要修改两处地方

vim /usr/share/zabbix/include/defines.inc.php
#修改两处地方;
#修改一:可以查找到这个单词“ZBX_GRAPH_FONT_NAME”,默认应该是在72行;
原:define('ZBX_GRAPH_FONT_NAME',           'graphfont'); // font file name
改为:define('ZBX_GRAPH_FONT_NAME',           'zabbix'); // font file name

#修改二:可以查找到这个单词“ZBX_FONT_NAME”,默认应该是在113行;
原:define('ZBX_FONT_NAME', 'graphfont');
改为:define('ZBX_FONT_NAME', 'zabbix');

将Windows的字体上传到服务器上并放到指定目录

首先我们现在windows上找到存放字体的地方,默认的位置在 C:\Windows\Fonts 目录下;
找到之后我们可以找出自己想要的字体,但是为了能看懂还是选择中文较好;

image-20240612005112822

上传至服务器上,这个一般就存放到 /usr/share/zabbix/assets/fonts/ 目录下

mv /root/simkai.ttf /usr/share/zabbix/assets/fonts/zabbix.ttf
# 重启服务
systemctl restart zabbix-server.service

image-20240612005337263

不能选中文

安装zh_CN语言包

dnf install langpacks-zh_CN.noarch

安装glibc-common实现对语言包的识别

dnf reinstall glibc-common

测试安装是否成功,如果看到zh_CN语言已安装,则表示成功

locale -a | grep zh_CN

安装完成后,回到web页面刷新,可以看到中文语言已可以选中

上述内容参考:

解决Zabbix 5.0不能选择中文和中文乱码问题 - 不羁的罗恩 - 博客园 (cnblogs.com)

Zabbix下载安装页面官方文档

【zabbix】解决zabbix在web页面显示中文乱码问题_zabbix网页乱码-CSDN博客

  • 11
    点赞
  • 30
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值