本文档风哥主要介绍PolarDB云原生架构与核心特性,包括PolarDB云原生架构概念、PolarDB核心特性、PolarDB产品系列、系统硬件要求、操作系统要求、网络要求、安装前期准备、安装具体过程、安装后配置、架构部署实战、性能优化实战、高可用配置实战等内容,风哥教程参考PolarDB官方文档内容编写,适合DBA人员在学习和测试中使用,如果要应用于生产环境则需要自行确认。更多视频教程www.fgedu.net.cn
Part01-基础概念与理论知识
1.1 PolarDB云原生架构概念
PolarDB是阿里云自主研发的云原生关系型数据库,采用存算分离架构,具有高性能、高可用、弹性扩展等特点。存算分离架构将计算节点和存储节点分离,计算节点负责处理SQL请求,存储节点负责数据存储和管理。这种架构使得PolarDB能够实现计算和存储的独立扩展,提高资源利用率,降低成本。
- 存算分离:计算节点和存储节点分离,独立扩展
- 一写多读:主节点负责写操作,多个只读节点负责读操作
- 弹性扩展:计算节点可快速扩容,存储自动增长
- 高可用:多可用区部署,自动故障切换
- 高性能:并行查询、IMCI列存、X-Engine等技术
1.2 PolarDB核心特性
PolarDB的核心特性包括:
- 存算分离:计算和存储分离,独立扩展,提高资源利用率
- 一写多读:主节点负责写操作,多个只读节点负责读操作,提高并发处理能力
- 弹性扩展:计算节点可快速扩容,存储自动增长,无需人工干预
- 高可用:多可用区部署,自动故障切换,RPO=0,RTO<30秒
- 高性能:并行查询、IMCI列存、X-Engine等技术,提升查询性能
- HTAP:支持OLTP和OLAP混合负载,满足实时分析需求
- 兼容性:100%兼容MySQL和PostgreSQL,降低迁移成本
- 安全:TDE加密、SSL、审计日志、数据脱敏等安全特性
1.3 PolarDB产品系列
PolarDB产品系列包括三个版本:
- PolarDB MySQL版:100%兼容MySQL,适合通用OLTP场景
- PolarDB PostgreSQL版:100%兼容PostgreSQL,高度兼容Oracle,适合Oracle迁移场景
- PolarDB-X:分布式MySQL,适合海量数据、高并发场景
Part02-生产环境规划与建议
2.1 系统硬件要求
PolarDB生产环境的硬件要求:
– CPU:至少8核,推荐16核以上
– 内存:至少16GB,推荐32GB以上
– 存储:系统盘至少100GB SSD
# 存储节点硬件要求
– 存储类型:SSD云盘
– 存储容量:根据实际数据量选择,支持自动扩容
– IOPS:根据业务需求选择,推荐10000 IOPS以上
# 网络要求
– 网络带宽:至少1Gbps,推荐10Gbps
– 网络延迟:尽可能低,推荐<1ms
2.2 操作系统要求
PolarDB支持的操作系统:
- 主要系统:Oracle Linux 9.3 / RHEL 9.3 / 8.x / 7.x
- 可选系统:国产麒麟操作系统 Kylin v10 SP3、欧拉操作系统
2.3 网络要求
PolarDB生产环境的网络要求:
– VPC网络:建议使用专有网络VPC
– 子网:计算节点和存储节点在同一子网
– 安全组:开放必要的端口,如3306(MySQL)、5432(PostgreSQL)
# 网络参数
– 网络带宽:至少1Gbps
– 网络延迟:<1ms
– 网络稳定性:99.99%以上
Part03-生产环境项目实施方案
3.1 安装前期准备
3.1.1 系统环境检查
$ cat /etc/redhat-release
Oracle Linux Server release 9.3
# 检查CPU核心数
$ nproc
16
# 检查内存大小
$ free -h
total used free shared buff/cache available
Mem: 32G 2.5G 28G 100M 1.5G 29G
# 检查磁盘空间
$ df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda1 100G 10G 90G 10% /
# 检查网络状态
$ ping -c 3 fgedu.net.cn
PING fgedu.net.cn (192.168.1.100) 56(84) bytes of data.
64 bytes from fgedu.net.cn (192.168.1.100): icmp_seq=1 ttl=64 time=0.5ms
64 bytes from fgedu.net.cn (192.168.1.100): icmp_seq=2 ttl=64 time=0.4ms
64 bytes from fgedu.net.cn (192.168.1.100): icmp_seq=3 ttl=64 time=0.4ms
# 检查防火墙状态
$ systemctl status firewalld
● firewalld.service – firewalld – dynamic firewall daemon
Loaded: loaded (/usr/lib/systemd/system/firewalld.service; enabled; vendor preset: enabled)
Active: active (running) since Wed 2026-03-31 10:00:00 CST; 1h ago
# 关闭防火墙(生产环境建议配置防火墙规则,而非直接关闭)
$ systemctl stop firewalld
$ systemctl disable firewalld
3.1.2 系统参数配置
$ vi /etc/sysctl.conf
# 添加以下参数
fs.file-max = 6815744
kernel.sem = 250 32000 100 128
kernel.shmmni = 4096
kernel.shmall = 1073741824
kernel.shmmax = 4398046511104
net.core.netdev_max_backlog = 16384
net.core.rmem_default = 262144
net.core.rmem_max = 4194304
net.core.wmem_default = 262144
net.core.wmem_max = 1048576
net.ipv4.tcp_max_syn_backlog = 8192
net.ipv4.tcp_slow_start_after_idle = 0
net.ipv4.tcp_tw_reuse = 1
net.ipv4.ip_local_port_range = 9000 65535
# 应用系统参数
$ sysctl -p
# 修改限制文件
$ vi /etc/security/limits.conf
# 添加以下参数
* soft nofile 65536
* hard nofile 65536
* soft nproc 65536
* hard nproc 65536
3.2 安装具体过程
使用图形化安装方式安装PolarDB:
$ wget https://openpolardb.com/download/polardb-mysql-8.0.28.tar.gz
# 解压安装包
$ tar -zxvf polardb-mysql-8.0.28.tar.gz
# 进入安装目录
$ cd polardb-mysql-8.0.28
# 运行图形化安装程序
$ ./install.sh
# 图形界面安装步骤:
# 步骤1:欢迎界面 – 点击”下一步”
# 步骤2:许可协议 – 选择”接受”,点击”下一步”
# 步骤3:安装类型 – 选择”典型安装”,点击”下一步”
# 步骤4:安装位置 – 设置安装路径为”/polardb/app”,点击”下一步”
# 步骤5:数据存储位置 – 设置数据路径为”/polardb/fgdata”,点击”下一步”
# 步骤6:数据库参数 – 设置数据库端口为3306,点击”下一步”
# 步骤7:密码设置 – 设置root密码和fgedu用户密码,点击”下一步”
# 步骤8:准备安装 – 检查安装配置,点击”安装”
# 步骤9:安装完成 – 点击”完成”
3.3 安装后配置
3.3.1 配置归档模式
$ mysql -u root -p
Enter password:
# 查看当前归档模式
mysql> show variables like ‘log_bin’;
+—————+——-+
| Variable_name | Value |
+—————+——-+
| log_bin | ON |
+—————+——-+
# 查看归档日志目录
mysql> show variables like ‘log_bin_basename’;
+——————+————————–+
| Variable_name | Value |
+——————+————————–+
| log_bin_basename | /polardb/fgdata/binlog |
+——————+————————–+
# 配置归档保留时间
mysql> set global binlog_expire_logs_seconds = 2592000; — 30天
Query OK, 0 rows affected (0.00 sec)
3.3.2 配置远程登录
$ mysql -u root -p
Enter password:
# 创建远程登录用户
mysql> create user ‘fgedu’@’%’ identified by ‘Fgedu123!’;
Query OK, 0 rows affected (0.01 sec)
# 授予权限
mysql> grant all privileges on *.* to ‘fgedu’@’%’ with grant option;
Query OK, 0 rows affected (0.00 sec)
# 刷新权限
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
# 测试远程连接
$ mysql -u fgedu -p -h 192.168.1.100
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 10
Server version: 8.0.28 PolarDB MySQL
Copyright (c) 2000, 2023, Oracle and/or its affiliates.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type ‘help;’ or ‘\h’ for help. Type ‘\c’ to clear the current input statement.
mysql> exit
Bye
3.3.3 参数优化
$ vi /polardb/app/my.cnf
# 添加以下参数
[mysqld]
bind-address = 0.0.0.0
port = 3306
datadir = /polardb/fgdata
socket = /polardb/fgdata/mysql.sock
pid-file = /polardb/fgdata/mysql.pid
log-error = /polardb/fgdata/error.log
# 性能参数
innodb_buffer_pool_size = 16G
innodb_log_file_size = 2G
innodb_flush_method = O_DIRECT
innodb_io_capacity = 2000
innodb_io_capacity_max = 4000
innodb_buffer_pool_instances = 16
# 连接参数
max_connections = 2000
wait_timeout = 3600
interactive_timeout = 3600
# 日志参数
log_bin = /polardb/fgdata/binlog
binlog_format = ROW
expire_logs_days = 30
# 重启PolarDB
$ systemctl restart polardb
Part04-生产案例与实战讲解
4.1 架构部署实战
部署PolarDB一写多读架构:
$ ./install.sh –role=master –port=3306 –datadir=/polardb/fgdata/master
# 部署只读节点1
$ ./install.sh –role=slave –port=3307 –datadir=/polardb/fgdata/slave1 –master-host=192.168.1.100 –master-port=3306
# 部署只读节点2
$ ./install.sh –role=slave –port=3308 –datadir=/polardb/fgdata/slave2 –master-host=192.168.1.100 –master-port=3306
# 查看集群状态
$ mysql -u root -p -h 192.168.1.100 -P 3306 -e “show replica status\G”
*************************** 1. row ***************************
Replica_IO_State: Waiting for source to send event
Source_Host: 192.168.1.100
Source_Port: 3306
Source_User: repl
Source_Password: Repl123!
Source_Log_File: binlog.000001
Read_Source_Log_Pos: 123456
Relay_Log_File: relay-bin.000001
Relay_Log_Pos: 123456
Relay_Source_Log_File: binlog.000001
Replica_IO_Running: Yes
Replica_SQL_Running: Yes
Replicate_Do_DB:
Replicate_Ignore_DB:
Replicate_Do_Table:
Replicate_Ignore_Table:
Replicate_Wild_Do_Table:
Replicate_Wild_Ignore_Table:
Last_Errno: 0
Last_Error:
Skip_Counter: 0
Exec_Source_Log_Pos: 123456
Relay_Log_Space: 123456
Until_Condition: None
Until_Log_File:
Until_Log_Pos: 0
Source_SSL_Allowed: No
Source_SSL_CA_File:
Source_SSL_CA_Path:
Source_SSL_Cert:
Source_SSL_Cipher:
Source_SSL_Key:
Seconds_Behind_Source: 0
Source_SSL_Verify_Server_Cert: No
Last_IO_Errno: 0
Last_IO_Error:
Last_SQL_Errno: 0
Last_SQL_Error:
Replicate_Ignore_Server_Ids:
Source_Server_Id: 1
Source_UUID: 12345678-1234-1234-1234-1234567890ab
Source_Info_File: /polardb/fgdata/slave1/relay-log.info
SQL_Delay: 0
SQL_Remaining_Delay: NULL
Replica_SQL_Running_State: Replica has read all relay log; waiting for more updates
Source_Retry_Count: 86400
Source_Bind:
Last_IO_Error_Timestamp:
Last_SQL_Error_Timestamp:
Source_SSL_Crl:
Source_SSL_Crlpath:
Retrieved_Gtid_Set:
Executed_Gtid_Set:
Auto_Position: 1
Replicate_Rewrite_DB:
Channel_Name:
Source_TLS_Version:
Source_public_key_path:
Get_Source_public_key: 0
Network_Namespace:
4.2 性能优化实战
优化PolarDB性能:
$ mysql -u root -p -e “set global innodb_parallel_read_threads = 8;”
# 启用IMCI列存
$ mysql -u root -p -e “alter table fgedu.tb_user add columnstore index idx_user_id(user_id);”
# 优化查询
$ mysql -u root -p -e “explain select * from fgedu.tb_user where user_id = 1;”
+—-+————-+———+————+——+—————+———–+———+——-+——+———-+——-+
| id | select_type | table | partitions | type | possible_keys | key | key_len | ref | rows | filtered | Extra |
+—-+————-+———+————+——+—————+———–+———+——-+——+———-+——-+
| 1 | SIMPLE | tb_user | NULL | ref | idx_user_id | idx_user_id | 4 | const | 1 | 100.00 | NULL |
+—-+————-+———+————+——+—————+———–+———+——-+——+———-+——-+
# 监控性能
$ mysql -u root -p -e “show global status like ‘Innodb_rows%’;”
+———————-+——-+
| Variable_name | Value |
+———————-+——-+
| Innodb_rows_read | 10000 |
| Innodb_rows_inserted | 5000 |
| Innodb_rows_updated | 2000 |
| Innodb_rows_deleted | 500 |
+———————-+——-+
4.3 高可用配置实战
配置PolarDB高可用:
$ vi /polardb/app/my.cnf
# 添加以下参数
[mysqld]
server-id = 1
log_bin = /polardb/fgdata/binlog
binlog_format = ROW
gtid_mode = ON
enforce_gtid_consistency = ON
# 配置半同步复制
$ mysql -u root -p -e “set global rpl_semi_sync_master_enabled = 1;”
$ mysql -u root -p -e “set global rpl_semi_sync_slave_enabled = 1;”
# 测试故障切换
# 模拟主节点故障
$ systemctl stop polardb
# 查看从节点状态
$ mysql -u root -p -h 192.168.1.101 -P 3307 -e “show replica status\G”
# 提升从节点为主节点
$ mysql -u root -p -h 192.168.1.101 -P 3307 -e “stop replica;”
$ mysql -u root -p -h 192.168.1.101 -P 3307 -e “reset master;”
# 重新配置其他从节点
$ mysql -u root -p -h 192.168.1.102 -P 3308 -e “change master to master_host=’192.168.1.101′, master_port=3307, master_user=’repl’, master_password=’Repl123!’, master_auto_position=1;”
$ mysql -u root -p -h 192.168.1.102 -P 3308 -e “start replica;”
Part05-风哥经验总结与分享
5.1 生产最佳实践
PolarDB生产最佳实践:
- 架构选择:根据业务需求选择合适的PolarDB版本,如MySQL版、PostgreSQL版或PolarDB-X
- 硬件配置:选择高性能的CPU、内存和存储,确保足够的IOPS
- 网络配置:使用高带宽、低延迟的网络,确保计算节点和存储节点之间的通信顺畅
- 参数优化:根据业务负载调整参数,如innodb_buffer_pool_size、max_connections等
- 监控告警:配置监控系统,监控关键指标,设置合理的告警阈值
- 备份恢复:定期备份数据,测试恢复流程,确保数据安全
- 安全配置:启用TDE加密、SSL、审计日志等安全特性,保护数据安全
5.2 常见问题与解决
PolarDB常见问题与解决方法:
- 连接失败:检查网络连接、防火墙配置、用户权限等
- 性能下降:检查慢SQL、索引使用情况、系统资源使用情况等
- 故障切换失败:检查复制状态、网络连接、配置文件等
- 存储空间不足:监控存储空间使用情况,及时扩容
- 备份失败:检查备份路径权限、存储空间、网络连接等
5.3 未来发展趋势
PolarDB未来发展趋势:
- 智能化:引入AI技术,实现数据库自治,自动优化参数和查询
- 云原生深化:进一步融合云原生技术,提供更弹性、更高效的数据库服务
- 多模支持:支持更多数据类型和处理模式,满足不同业务需求
- 生态完善:加强与其他云服务的集成,提供更完整的解决方案
- 国产化替代:助力企业实现数据库国产化替代,提升数据安全
本文由风哥教程整理发布,仅用于学习测试使用,转载注明出处:http://www.fgedu.net.cn/10327.html
