Percona安装-Percona Server 8.0 for RHEL 9安装配置及升级迁移详细过程
1. 硬件环境检查
在安装Percona之前,必须对服务器的硬件环境进行全面检查,确保满足Percona Server 8.0的最低要求。更多学习教程www.fgedu.net.cn
# free -h
total used free shared buff/cache available
Mem: 16G 2.1G 12G 8.5M 1.8G 13G
Swap: 8G 0B 8G
# 检查磁盘空间
# df -h
Filesystem Size Used Avail Use% Mounted on
devtmpfs 8G 0 8G 0% /dev
tmpfs 8G 0 8G 0% /dev/shm
tmpfs 8G 8.5M 8G 1% /run
tmpfs 8G 0 8G 0% /sys/fs/cgroup
/dev/sda1 50G 15G 36G 30% /
/dev/sdb1 200G 20G 180G 10% /data
# 检查CPU核心数
# nproc
8
# 检查系统架构
# uname -m
x86_64
2. 操作系统检查
Percona Server 8.0支持RHEL 7.3+、RHEL 8.0+、RHEL 9.0+等操作系统。本文以RHEL 9为例。学习交流加群风哥微信: itpux-com
# cat /etc/redhat-release
Red Hat Enterprise Linux release 9.0 (Plow)
# 检查内核版本
# uname -r
5.14.0-70.22.1.el9_0.x86_64
# 检查SELinux状态
# getenforce
Disabled
# 关闭SELinux(如未关闭)
# vi /etc/selinux/config
SELINUX=disabled
# 检查防火墙状态
# systemctl status firewalld
# 关闭防火墙(生产环境建议开放特定端口而非完全关闭)
# systemctl stop firewalld
# systemctl disable firewalld
3. 安装准备
在安装Percona之前,需要进行一系列准备工作,包括配置YUM仓库、创建用户和组、配置网络等。
# vi /etc/yum.repos.d/percona.repo
[percona-release-x86_64]
name = Percona-Release YUM repository – x86_64
baseurl = https://repo.percona.com/yum/release/$releasever/RPMS/x86_64
enabled = 1
gpgkey = https://repo.percona.com/yum/PERCONA-PACKAGING-KEY
# 清理YUM缓存
# yum clean all
# 创建数据目录
# mkdir -p /data/percona
# chown -R mysql:mysql /data/percona
# 配置网络
# 确保服务器IP地址为192.168.1.51
# ip addr show eth0
2: eth0:
inet 192.168.1.51/24 brd 192.168.1.255 scope global noprefixroute eth0
valid_lft forever preferred_lft forever
inet6 fe80::5054:ff:fe12:3456/64 scope link noprefixroute
valid_lft forever preferred_lft forever
4. Percona软件安装
现在开始安装Percona Server 8.0软件,按照以下步骤进行。
# yum install -y percona-server-server percona-server-client
# 启动Percona服务
# systemctl start mysql
# 设置Percona服务开机自启
# systemctl enable mysql
# 验证Percona服务状态
# systemctl status mysql
● mysql.service – Percona Server
Loaded: loaded (/usr/lib/systemd/system/mysql.service; enabled; vendor preset: disabled)
Active: active (running) since Thu 2026-03-31 10:00:00 CST; 1min ago
Docs: man:mysqld(8)
http://dev.mysql.com/doc/refman/en/using-systemd.html
Process: 12345 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS)
Main PID: 12346 (mysqld)
Status: “Taking your SQL requests now…”
Tasks: 38 (limit: 4915)
Memory: 370.0M
CGroup: /system.slice/mysql.service
└─12346 /usr/sbin/mysqld
Mar 31 10:00:00 fgedudb01 systemd[1]: Starting Percona Server…
Mar 31 10:00:00 fgedudb01 mysqld_pre_systemd[12345]: MYSQLD_PARENT_PID: 12345
Mar 31 10:00:00 fgedudb01 systemd[1]: Started Percona Server.
5. 数据库配置
配置Percona数据库,包括安全设置、参数配置等。
# grep ‘temporary password’ /var/log/mysqld.log
2026-03-31T10:00:00.123456Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: AbCdEfGhIjKlMnOp
# 运行安全配置脚本
# mysql_secure_installation
Securing the MySQL server deployment.
Enter password for user root: AbCdEfGhIjKlMnOp
The existing password for the user account root has expired. Please set a new password.
New password:
Re-enter new password:
The password strength is 100.
Do you wish to continue with the password provided?(Press y|Y for Yes, any other key for No) : Y
By default, a MySQL installation has an anonymous user, allowing anyone
To log into MySQL 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? (Press y|Y for Yes, any other key for No) : 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? (Press y|Y for Yes, any other key for No) : Y
Success.
By default, MySQL 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? (Press y|Y for Yes, any other key for No) : 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? (Press y|Y for Yes, any other key for No) : Y
Success.
All done! If you’ve completed all of the above steps, your MySQL
Installation should now be secure.
Thanks for using MySQL!
# vi /etc/my.cnf
# 添加以下配置
[mysqld]
datadir=/data/percona
socket=/var/lib/mysql/mysql.sock
bind-address=0.0.0.0
port=3306
max_connections=1000
innodb_buffer_pool_size=4G
innodb_log_file_size=512M
innodb_file_per_table=1
skip-name-resolve
character-set-server=utf8mb4
collation-server=utf8mb4_unicode_ci
# 重启Percona服务
# systemctl restart mysql
# 验证配置
# mysql -u root -p -e “SHOW VARIABLES LIKE ‘datadir’;”
Enter password:
+—————+—————-+| Variable_name | Value |+—————+—————-+| datadir | /data/percona/ |+—————+—————-+
6. 测试验证
创建测试数据库和表,验证Percona功能正常。学习交流加群风哥QQ113257174
# mysql -u root -p
# 创建数据库
mysql> CREATE DATABASE fgedudb;
# 创建用户
mysql> CREATE USER ‘fgedu’@’%’ IDENTIFIED BY ‘fgedu123’;
# 授权
mysql> GRANT ALL PRIVILEGES ON fgedudb.* TO ‘fgedu’@’%’;
# 刷新权限
mysql> FLUSH PRIVILEGES;
# 连接到测试数据库
mysql> USE fgedudb;
# 创建测试表
mysql> CREATE TABLE fgedu_employees (
-> id INT PRIMARY KEY AUTO_INCREMENT,
-> name VARCHAR(100),
-> salary DECIMAL(10,2)
-> );
# 插入测试数据
mysql> INSERT INTO fgedu_employees (name, salary) VALUES (‘张三’, 5000.00);
mysql> INSERT INTO fgedu_employees (name, salary) VALUES (‘李四’, 6000.00);
mysql> INSERT INTO fgedu_employees (name, salary) VALUES (‘王五’, 7000.00);
# 查询测试数据
mysql> SELECT * FROM fgedu_employees;
+—-+——+——–+
| id | name | salary |
+—-+——+——–+
| 1 | 张三 | 5000.0 |
| 2 | 李四 | 6000.0 |
| 3 | 王五 | 7000.0 |
+—-+——+——–+
7. 备份配置
配置Percona数据库备份策略,确保数据安全。
# mkdir -p /backup/percona
# chown -R mysql:mysql /backup/percona
# 执行备份
# 以root用户执行
# mysqldump -u root -p fgedudb > /backup/percona/fgedudb_backup_20260331.sql
# 验证备份文件
# ls -la /backup/percona/
-rw-r–r– 1 root root 123456 Mar 31 10:20 fgedudb_backup_20260331.sql
# 创建备份脚本
# vi /root/backup_percona.sh
#!/bin/bash
DATE=$(date +%Y%m%d)
BACKUP_DIR=”/backup/percona”
# 创建备份目录(如果不存在)
mkdir -p $BACKUP_DIR
# 执行备份
mysqldump -u root -p’your_password’ fgedudb > $BACKUP_DIR/fgedudb_backup_$DATE.sql
# 保留最近7天的备份
find $BACKUP_DIR -name “fgedudb_backup_*.sql” -mtime +7 -delete
# 给脚本添加执行权限
# chmod +x /root/backup_percona.sh
# 添加到crontab
# crontab -e
# 添加以下内容(每天凌晨2点执行备份)
0 2 * * * /root/backup_percona.sh
8. 升级迁移
Percona数据库的升级和迁移过程。
# 1. 备份数据库
# mysqldump -u root -p –all-databases > /backup/percona/all_databases_backup.sql
# 2. 停止Percona服务
# systemctl stop mysql
# 3. 升级Percona
# yum update -y percona-server-server percona-server-client
# 4. 启动Percona服务
# systemctl start mysql
# 5. 运行升级脚本
# mysql_upgrade -u root -p
# 6. 验证升级结果
# mysql -u root -p -e “SELECT VERSION();”
Enter password:
+—————+| VERSION() |+—————+| 8.0.36-28-log |+—————+
# 从旧版本Percona迁移到Percona Server 8.0
# 1. 在旧系统上创建备份
# mysqldump -u root -p –all-databases > /backup/percona/all_databases_backup.sql
# 2. 将备份文件复制到新系统
# scp /backup/percona/all_databases_backup.sql root@192.168.1.51:/backup/percona/
# 3. 在新系统上恢复备份
# mysql -u root -p < /backup/percona/all_databases_backup.sql
# 4. 验证迁移结果
# mysql -u root -p -e "SELECT * FROM fgedudb.fgedu_employees;"
9. 总结
本文详细介绍了Percona Server 8.0 for RHEL 9的安装、配置、升级和迁移过程。通过按照本文的步骤操作,可以成功部署Percona数据库并确保其稳定运行。from:fengge
– 定期备份数据库,建议每天执行一次全备份
– 监控数据库性能,定期检查数据库日志和错误信息
– 定期更新Percona版本,确保系统安全性和性能
– 合理规划数据库存储,避免空间不足
– 配置合适的参数,优化数据库性能
– 对于生产环境,建议部署主从复制架构,提高可用性和可靠性
本文由风哥教程整理发布,仅用于学习测试使用,转载注明出处:http://www.fgedu.net.cn/10327.html
