部署背景
以前部署使用的zabbix6.0 默认装的都是MariaDB ,但是MariaDB在日常维护过程,比较不方便。
在重启服务时,如果InnoDB 需要将内存(Buffer Pool)中修改过但还没写到磁盘的数据全部刷入磁盘。如果innodb_buffer_pool_size 很大且写入频繁,这个过程会很久。
如果重启是因为崩溃(Crash)或异常终止,MariaDB 启动时会进行 Crash Recovery。如果有未提交的大事务,它必须逐条回滚。
而且原有的服务器装在了HDD上,硬盘读写也不给力,这次重新新建,也顺便将其迁移到SSD存储上。
环境
OS: Centos 8.5.2.111
部署过程
系统的安装不再叙述。
设置网络ip地址/DNS等
[root@localhost]# ip add
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group defaul t qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: ens192: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group de fault qlen 1000
link/ether 00:50:56:8c:80:f3 brd ff:ff:ff:ff:ff:ff
inet 10.165.44.16/24 brd 10.165.44.255 scope global noprefixroute ens192
valid_lft forever preferred_lft forever
inet6 fe80::3105:fddd:357a:49e5/64 scope link noprefixroute
valid_lft forever preferred_lft forever
[root@localhost]# vi /etc/sysconfig/network-scripts/ifcfg-ens192
TYPE=Ethernet
PROXY_METHOD=none
BROWSER_ONLY=no
BOOTPROTO=none
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_FAILURE_FATAL=no
IPV6_ADDR_GEN_MODE=stable-privacy
NAME=ens192
UUID=4536252b-62ef-41db-9a9f-9ff8983587aa
DEVICE=ens192
ONBOOT=yes
IPADDR=10.165.44.16
NETMASK=255.255.255.0
GATEWAY=10.165.44.1
DNS1=10.165.32.21
DNS2=223.5.5.5
IPV6_PRIVACY=no
[root@localhost]#systemctl restart NetworkManager
注:
ONBOOT=yes 需要注意开启,否则网卡将不会在系统启动时自动激活
部署源
交互式选择源(各大高校、大厂的都列在里面,省去了自己找源和 配置文件等繁琐的事情),更加方便。
bash <(curl -sSL https://gitee.com/SuperManito/LinuxMirrors/raw/main/ChangeMirrors.sh)
直接运行,选择对应的源即可;如果没有安装curl,自行使用 yum install curl 安装一下。
测试源
[root@localhost]# yum makecache
CentOS Linux 8.5.2111 - AppStream 10 kB/s | 4.3 kB 00:00
CentOS Linux 8.5.2111 - BaseOS 19 kB/s | 3.9 kB 00:00
CentOS Linux 8.5.2111 - Extras 5.3 kB/s | 1.5 kB 00:00
CentOS Linux 8.5.2111 - PowerTools 28 kB/s | 4.3 kB 00:00
Extra Packages for Enterprise Linux 8 - x86_64 17 kB/s | 4.0 kB 00:00
MySQL 8.0 Community Server 7.0 kB/s | 3.0 kB 00:00
MySQL Connectors Community 7.9 kB/s | 3.0 kB 00:00
MySQL Tools Community 7.9 kB/s | 3.0 kB 00:00
Zabbix Official Repository - x86_64 13 kB/s | 3.0 kB 00:00
Zabbix Official Repository (non-supported) - x8 22 kB/s | 2.9 kB 00:00
Zabbix Official Repository (Agent2 Plugins) - x 7.1 kB/s | 2.9 kB 00:00
基本配置
关闭防火墙
systemctl stop firewalld.service
开机不启动防火墙
systemctl disable firewalld.service
关闭linux 内核安全措施
setenforce 0
关闭日后linux 内核安全启动措施
sed -i "s/SELINUX=enforcing/SELINUX=disabled/g" /etc/selinux/config
防火墙状态
systemctl status firewalld
systemctl status selinux-autorelabel
修改hostname
hostnamectl set-hostname 修改的主机名字
修改dns
echo "nameserver 223.5.5.5" > /etc/resolv.conf # 阿里云 DNS 按需修改
安装mysql
yum remove -y mysql #卸载之前安装的mysql
下载
wget https://dev.mysql.com/get/mysql80-community-release-el8-1.noarch.rpm
如果没有安装wget 运行安装 yum install wget
yum install mysql80-community-release-el8-1.noarch.rpm
yum module disable mysql
yum install mysql-community-server --nogpgcheck
执行完以后,修改mysql配置
[root@localhost ~]# vi /etc/my.cnf
##找到底下这一行,注释掉
default-authentication-plugin=mysql_native_password
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
#以下配置,根据自己需求修改,我是16G内存的主机,如果监控的主机数量不多,可以适当降低一半或者更多
innodb_buffer_pool_size = 4G
innodb_log_file_size = 512M
innodb_log_buffer_size = 32M
innodb_file_per_table = 1
max_connections = 500
# 字符集
character-set-server = utf8mb4
collation-server = utf8mb4_general_ci
mysql初始化
[root@localhost ~]# mysql -V
mysql Ver 8.0.45 for Linux on x86_64 (MySQL Community Server - GPL)
[root@localhost ~]# systemctl restart mysqld
[root@localhost ~]# service mysqld status
Redirecting to /bin/systemctl status mysqld.service
● mysqld.service - MySQL Server
Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor pres>
Active: active (running) since Wed 2026-03-11 22:56:38 EDT; 4h 12min ago
Docs: man:mysqld(8)
http://dev.mysql.com/doc/refman/en/using-systemd.html
Process: 1233 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0>
Main PID: 3171 (mysqld)
Status: "Server is operational"
Tasks: 90 (limit: 101099)
Memory: 1.9G
CGroup: /system.slice/mysqld.service
└─3171 /usr/sbin/mysqld
3月 11 22:56:34 localhost.localdomain systemd[1]: Starting MySQL Server...
3月 11 22:56:38 localhost.localdomain systemd[1]: Started MySQL Server.
lines 1-15/15 (END)
确认服务正常运行后,查看安装时的临时密码
具体命令:grep 'temporary password' /var/log/mysqld.log
[root@localhost ~]# grep 'temporary password' /var/log/mysqld.log
2026-03-12T01:58:06.853656Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: -0>CoSFSADAS
记录临时密码后,用临时密码登陆进去修改密码
[root@localhost ~]# mysql -u root -p
ALTER USER 'root'@'localhost' IDENTIFIED BY 'yourPassWord'; #创建一个复杂一点的密码,如果想使用简单一点的密码,方便记录,可以先修改一个复杂的密码,再修改密码复杂度。
因为MySQL 默认的密码策略会检查密码的长度、复杂度(是否包含大小写字母、数字、特殊符号)等。
修改完密码后,可以再降低密码复杂度,再修改
SET GLOBAL validate_password.length = 6; -- 密码最小长度设为6
SET GLOBAL validate_password.mixed_case_count = 0; -- 不需要大小写混合
SET GLOBAL validate_password.number_count = 0; -- 不需要包含数字
SET GLOBAL validate_password.special_char_count = 0; -- 不需要特殊符号
-- 重新设置密码
ALTER USER 'root'@'localhost' IDENTIFIED BY 'zabbix';
-- 刷新权限(确保生效)
FLUSH PRIVILEGES;
grant all privileges on *.* to 'root'@'%' with grant option; #授权
exit #退出mysql
初始化mysql
用刚修改的密码重新验证登陆一下,开始初始化配置
mysql -u root -p
mysql> create database zabbix character set utf8mb4 collate utf8mb4_bin; # 创建zabbix数据库
mysql> create user zabbix@localhost identified WITH sha256_password BY 'password'; #创建zabbix数据库密码password
mysql> grant all privileges on zabbix.* to zabbix@localhost;
mysql> set global log_bin_trust_function_creators = 1;
mysql>use mysql;
mysql>delete from user where user=' ';
mysql>flush privileges;
mysql> quit;
部署zabbix
rpm -Uvh https://repo.zabbix.com/zabbix/6.0/rhel/8/x86_64/zabbix-release-6.0-4.el8.noarch.rpm
dnf clean all
cd /etc/yum.repos.d
vim zabbix.repo
# repo文件开始
[zabbix]
name=Zabbix Official Repository - $basearch
#baseurl=https://repo.zabbix.com/zabbix/6.0/rhel/8/$basearch/
baseurl=https://mirrors.tuna.tsinghua.edu.cn/zabbix/zabbix/6.0/rhel/8/x86_64/
#上面是 zabbix清华源
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://repo.zabbix.com/non-supported/rhel/8/$basearch/
baseurl=https://mirrors.tuna.tsinghua.edu.cn/zabbix/non-supported/rhel/8/x86_64/
#上面是 zabbix-non-supported清华源
enabled=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX
gpgcheck=1
[zabbix-unstable]
name=Zabbix Official Repository (unstable) - $basearch
baseurl=https://repo.zabbix.com/zabbix/5.5/rhel/8/$basearch/
enabled=0
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX-A14FE591
# repo文件结束
vim zabbix-agent2-plugins.repo
# repo文件开始
[zabbix-agent2-plugins]
name=Zabbix Official Repository (Agent2 Plugins) - $basearch
#baseurl=https://repo.zabbix.com/zabbix-agent2-plugins/1/rhel/8/$basearch/
baseurl=https://mirrors.tuna.tsinghua.edu.cn/zabbix/zabbix-agent2-plugins/1/rhel/8/x86_64/
# agent2清华源
enabled=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX
gpgcheck=1
# repo文件结束
安装zabbix模块
dnf install zabbix-server-mysql zabbix-web-mysql zabbix-apache-conf zabbix-sql-scripts zabbix-selinux-policy zabbix-agent2
导入初始化数据库脚本
zcat /usr/share/zabbix-sql-scripts/mysql/server.sql.gz | mysql --default-character-set=utf8mb4 -uzabbix -p zabbix
mysql -u root -p
mysql> set global log_bin_trust_function_creators =
mysql> quit;
配置启动zabbix
vim /etc/zabbix/zabbix_server.conf # 取消注释 DBPassword= 并设置数据库密码
重启zabbix服务
启动服务
systemctl restart zabbix-server zabbix-agent2 httpd php-fpm
systemctl enable zabbix-server zabbix-agent2 httpd php-fpm
修复php 7.2问题并进入zabbix
启动服务后,正常可以进入web,但是web提示php低于7.3,无法进入。
# 用 PHP 下载 Composer
php -r "copy('https://getcomposer.org/composer.phar', '/usr/local/bin/composer');"
# 赋予执行权限
chmod +x /usr/local/bin/composer
# 验证 Composer
composer -V
# 进入 Zabbix 前端目录
cd /usr/share/zabbix
# 执行安装(跳过所有检查)
composer install --ignore-platform-reqs --no-dev --no-interaction
# 配置 PHP 并重启服务
cat >> /etc/php.ini << EOF
max_execution_time = 300
memory_limit = 128M
post_max_size = 16M
upload_max_filesize = 2M
max_input_time = 300
date.timezone = Asia/Shanghai
short_open_tag = On
EOF
# 重启服务
systemctl restart zabbix-server zabbix-agent2 httpd php-fpm
systemctl enable zabbix-server zabbix-agent2 httpd php-fpm
默认账号:Admin 密码:zabbix