基本是按照官方文档走,但有些步骤根据实际情况有所修改

依赖:

  • 数据库
    MariaDB --- 10.5.00-10.8.X
    MySQL --- 8.0.X 之一
  • 前端
    Apache --- 1.3.12 或更高版本
    PHP --- 7.2.5 或更高版本 --- 不支持 PHP 8.0

1.环境准备

  • 关闭防火墙及selinux
# 关闭防火墙并禁止自启

systemctl stop firewalld
systemctl disable firewalld


# 关闭selinux,关完后需要重启生效
sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config

[root@localhost ~]# grep -Ev '^#|^$' /etc/selinux/config

SELINUX=disabled
  • 安装php,centos7默认的是5.4,所以要安装remi库来安装php7.4

yum install -y yum-utils # yum增强工具,不装的话php启用库命令不生效

yum install -y epel-release

yum install -y http://rpms.remirepo.net/enterprise/remi-release-7.rpm # 安装Remi存储库

yum-config-manager --enable remi-php74 # 启用Remi存储库来使用PHP 7

yum install -y php php-cli php-fpm php-mysql php-xml php-zip php-gd php-mbstring php-json php-curl # 安装PHP 8及其相关的扩展
  • 安装mariadb10.5

[root@localhost ~]# rpm -qa | grep mariadb 
mariadb-libs-5.5.68-1.el7.x86_64
[root@localhost ~]# rpm -e --nodeps mariadb-libs-5.5.68-1.el7.x86_64 #删除自带的包

[root@localhost ~]# vi /etc/yum.repos.d/MariaDB.repo
[mariadb]
name = MariaDB
baseurl = https://mirrors.tuna.tsinghua.edu.cn/mariadb/yum/10.6/centos7-amd64/
gpgkey =  https://mirrors.tuna.tsinghua.edu.cn/mariadb/yum/RPM-GPG-KEY-MariaDB
gpgcheck = 1


[root@localhost ~]# yum clean all


[root@localhost ~]# yum list | grep mariadb #最好看一下是否有可用的包了

[root@localhost ~]# yum install -y mariadb-server
[root@localhost ~]# mariadb --version
mariadb  Ver 15.1 Distrib 10.6.14-MariaDB, for Linux (x86_64) using readline 5.1


systemctl start mariadb
systemctl enable mariadb

[root@localhost ~]# mariadb-secure-installation #初始化密码 回车-y-y-n-y-y-y


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):
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
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
New password:123456
Re-enter new password:123456
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] n
 ... skipping.

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] y
 ... Success!

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!

2.安装Zabbix6.0的rpm包

阿里下载:https://mirrors.aliyun.com/zabbix/zabbix/6.0/rhel/8/x86_64/


rpm -Uvh https://mirrors.aliyun.com/zabbix/zabbix/6.0/rhel/8/x86_64/zabbix-release-6.0-4.el8.noarch.rpm

获取https://mirrors.aliyun.com/zabbix/zabbix/6.0/rhel/8/x86_64/zabbix-release-6.0-4.el8.noarch.rpm
警告:/var/tmp/rpm-tmp.yHf7If: 头V4 RSA/SHA512 Signature, 密钥 ID a14fe591: NOKEY
准备中...                          ################################# [100%]
正在升级/安装...
   1:zabbix-release-6.0-4.el8         ################################# [100%]
  • 修改Zabbix仓库源,安装完rpm包会自动生成zabbix.repo
  • 将软件源地址从https://repo.zabbix.com更改为https://mirrors.aliyun.com/zabbix

sed -i 's#https://repo.zabbix.com#https://mirrors.aliyun.com/zabbix#' /etc/yum.repos.d/zabbix.repo

[root@localhost yum.repos.d]# cat /etc/yum.repos.d/zabbix.repo
[zabbix]
name=Zabbix Official Repository - $basearch
baseurl=https://mirrors.aliyun.com/zabbix/zabbix/6.0/rhel/8/$basearch/
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX-A14FE591

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

[zabbix-unstable]
name=Zabbix Official Repository (unstable) - $basearch
baseurl=https://mirrors.aliyun.com/zabbix/zabbix/5.5/rhel/8/$basearch/
enabled=0
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX-A14FE591

- agent2源

sed -i 's#https://repo.zabbix.com#https://mirrors.aliyun.com/zabbix#' /etc/yum.repos.d/zabbix-agent2-plugins.repo

[root@localhost ~]# cat /etc/yum.repos.d/zabbix-agent2-plugins.repo
[zabbix-agent2-plugins]
name=Zabbix Official Repository (Agent2 Plugins) - $basearch
baseurl=https://mirrors.aliyun.com/zabbix/zabbix-agent2-plugins/1/rhel/8/$basearch/
enabled=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX
gpgcheck=1
  • 清除缓存
yum clean all

3.安装Zabbix server,Web前端,agent(zabbix-sql-scripts用来快速生成一个数据库的)


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

# 如果提示依赖包版本过低,可以用dnf安装,虽然能安装成功,但是因为依赖版本过低,zabbix的功能会有影响,可以通过更改成centos8的软件源,升级依赖解决

yum install -y dnf # yum的升级版,用这个装zabbix

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

4.创建初始数据库,安装完zabbix会自动生成server.sql.gz

[root@localhost ~]# mysql -uroot -p
MariaDB [(none)]> create database zabbix character set utf8 collate utf8_bin; #创建一个名为"zabbix"的数据库,使用utf8字符集和排序规则,这里区别于官方的utf8mb4,用utf8mb4会导致后面数据库导入数据报错
MariaDB [(none)]> create user zabbix@localhost identified by '123456'; # 在数据库中创建一个名为"zabbix"的用户,该用户只能通过localhost连接,并设置密码为"123456"
MariaDB [(none)]> grant all privileges on zabbix.* to zabbix@localhost; # 将"zabbix"用户赋予在"zabbix"数据库上的所有权限,但仅限于通过localhost连接
MariaDB [(none)]> set global log_bin_trust_function_creators = 1; #允许使用CREATE FUNCTION语句创建函数的用户不需要SUPER权限
MariaDB [(none)]> quit;

5.导入初始架构和数据,系统将提示您输入数据库的密码123456

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

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

  • 作用是禁用MySQL中二进制日志记录的函数创建者的信任机制
[root@localhost ~]# mysql -uroot -p
MariaDB [(none)]> set global log_bin_trust_function_creators = 0;
MariaDB [(none)]> quit;

7.配置Zabbix-server数据库密码,zabbix_server.conf文件位置与官方不同,需要注意

[root@localhost ~]# vi /etc/zabbix_server.conf
[root@localhost ~]# grep -Ev '^$|^#' /etc/zabbix_server.conf
LogFile=/var/log/zabbixsrv/zabbix_server.log
LogFileSize=0
PidFile=/run/zabbixsrv/zabbix_server.pid
DBName=zabbix
DBUser=zabbix
DBPassword=123456 #改这个
DBSocket=/var/lib/mysql/mysql.sock
Timeout=4
AlertScriptsPath=/var/lib/zabbixsrv/alertscripts
ExternalScripts=/var/lib/zabbixsrv/externalscripts
LogSlowQueries=3000
TmpDir=/var/lib/zabbixsrv/tmp
StatsAllowedIP=127.0.0.1
TLSCipherPSK=kECDHEPSK+AES128:kPSK+AES128 #还有这个,不改启动会报错,按理说默认是不加密的才对

8.配置监听,去掉注释就是nginx代理,通过8080访问,可以不理

  • 去掉两个注释
[root@localhost ~]# vi /etc/nginx/conf.d/zabbix.conf
# listen 8080;
# server_name example.com;

9.启动zabbix服务并设置开机自启

systemctl restart zabbix-server zabbix-agent nginx php-fpm

# 设置开启自启报错就是前面依赖有问题啦

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

10.最后就可以通过IP地址访问zabbix了

http://10.0.0.10/

默认账号密码
Admin
zabbix

11.第二台Centos7主机安装agent(装完后网页添加主机即可)

阿里下载:https://mirrors.aliyun.com/zabbix/zabbix/6.0/rhel/7/x86_64/

仓库源改成阿里云的

[root@zabbix-agent ~]# rpm -Uvh https://mirrors.aliyun.com/zabbix/zabbix/6.0/rhel/7/x86_64/zabbix-release-6.0-4.el7.noarch.rpm

[root@zabbix-agent ~]# sed -i 's#https://repo.zabbix.com#https://mirrors.aliyun.com/zabbix#' /etc/yum.repos.d/zabbix.repo
[root@zabbix-agent ~]# sed -i 's#https://repo.zabbix.com#https://mirrors.aliyun.com/zabbix#' /etc/yum.repos.d/zabbix-agent2-plugins.repo

[root@zabbix-agent ~]# yum clean all
[root@zabbix-agent ~]# yum install -y zabbix-agent2 zabbix-agent2-plugin-*
[root@zabbix-agent ~]# grep -Ev '^$|^#' /etc/zabbix/zabbix_agentd.conf
PidFile=/run/zabbix/zabbix_agentd.pid
LogFile=/var/log/zabbix/zabbix_agentd.log
LogFileSize=0
Server=10.0.0.10 # zabbix-server被动地址
ServerActive=10.0.0.10 # 主动模式地址,建议不用,主动模式对客户机负载较高
Hostname=zabbix-agent # 本地主机名
Include=/etc/zabbix/zabbix_agentd.d/*.conf

systemctl restart zabbix-agent2
systemctl enable zabbix-agent2

12.简单的自动发现功能使用

  • 1.点击自动发现

名称:测试组
由agent代理程序自动发现:默认
IP范围:10.0.0.1-254
更新间隔:10s
检查:

  - 检查类型:zabbix客户端
  - 端口范围:10050
  - 键值:system.hostname # 这个可以拿去server端用命令测试,会返回相应的值,命令如下:zabbix_get -s 10.0.0.50 -k system.hostname

设备唯一性准则:IP地址
主机名称:Zabbix 客户端 "system.hostname" #其实就是上面的返回值,也可以用别的
可见的名称:主机名称

然后点击更新就可以

  • 2.添加发现动作

名称:测试组

然后点击操作,添加

操作:

  - 添加主机
  - 添加到主机群组: 测试组
  - 链接到模板: Linux by Zabbix agent
  - 启用主机

然后点击更新就可以了

  • 3.静等一会,就能自动添加主机了