背景
Amazon Aurora MySQL 提供了比社区 MySQL 5.7 更长达一年的免费扩展支持,但该版本将于 2023 年 10 月 31 日终止。如果您需要更多时间完成升级,可以选择 Amazon RDS 扩展支持,提供最多 28 个月的额外支持,直到 2027 年 2 月扩展支持结束。
RDS 蓝绿升级
在进行 RDS 升级时,使用蓝绿部署是一种最佳实践,特别是在原集群开启了二进制日志记录(binlog_format)的情况下。升级操作主要涉及升级主要或次要数据库引擎版本、更改数据库参数或在暂存环境中更改模式。准备就绪后,可以将暂存环境提升为新的生产数据库环境,通常情况下停机时间不会超过一分钟。更多详细信息请参考 AWS 官方文档。
创建参数组
在进行升级之前,首先需要创建新的数据库参数组。以下是通过 Python 脚本创建数据库参数组的示例:
创建 DB 参数组
import boto3
def create_db_parameter_group(cluster_name):
# 创建 Boto3 客户端
client = boto3.client('rds')
# 构建 CreateDBParameterGroup 的参数
params = {
"DBParameterGroupFamily": "aurora-mysql8.0",
"DBParameterGroupName": f"{cluster_name}-mysql8",
"Description": f"{cluster_name} db parameter group"
}
# 发送 CreateDBParameterGroup 请求
response = client.create_db_parameter_group(**params)
# 检查响应结果
if response['ResponseMetadata']['HTTPStatusCode'] == 200:
print("DB parameter group created successfully!")
else:
print("Failed to create DB parameter group. Error:", response['ResponseMetadata']['HTTPStatusCode'])
create_db_parameter_group("test-cluster-v1")
创建集群参数组
import boto3
def create_db_cluster_parameter_group(cluster_name):
# 创建 Boto3 客户端
client = boto3.client('rds')
# 构建 CreateDBClusterParameterGroup 的参数
params = {
"DBClusterPar服务器托管网ameterGroupName": f"{cluster_name}-mysql8",
"DBParameterGroupFamily": "aurora-mysql8.0",
"Description": f"{cluster_name} cluster parameter group"
}
# 发送 CreateDBClusterParameterGroup 请求
response = client.create_db_cluster_parameter_group(**params)
# 检查响应结果
if response['ResponseMetadata']['HTTPStatusCode'] == 200:
print("DB cluster parameter group created successfully!")
else:
print("Failed to create DB cluster parameter group. Error:", response['ResponseMetadata']['HTTPStatusCode'])
create_db_cluster_parameter_group("test-cluster-v1")
修改参数组
在创建参数组后,可以根据需要修改参数(启用性能详情为例子)。以下是通过 Python 脚本修改数据库参数组的示例:
修改 DB 参数组
import boto3
def modify_db_parameter_group(DBParameterGroupName):
# 创建Boto3客户端
client = boto3.client('rds')
# 构建ModifyDBParameterGroup的参数
params = {
"DBParameterGroupName": DBParameterGroupName,
"Parameters": [
{
"ApplyMethod": "immediate", #'immediate'|'pending-reboot'
"ParameterName": "performance_schema",
"ParameterValue": "1"
},
{
"ApplyMethod": "pending-reboot",
"ParameterName": "performance-schema-consumer-events-waits-current",
"ParameterValue": "ON"
},
{
"ApplyMethod": "pending-reboot",
"ParameterName": "performance-schema-instrument",
"ParameterValue": "wait/% = ON"
},
{
"ApplyMethod": "pending-reboot",
"ParameterName": "performance_schema_consumer_global_instrumentation",
"ParameterValue": "1"
},
{
"ApplyMethod": "pending-reboot",
"ParameterName": "performance_schema_consumer_thread_instrumentation",
"ParameterValue": "1"
}
]
}
# 发送ModifyDBParameterGroup请求
response = client.modify_db_parameter_group(**params)
# 检查响应结果
if response['ResponseMetadata']['HTTPStatusCode'] == 200:
print("DB parameter group modified successfully!")
else:
print("Failed to modify DB parameter group. Error:", response['ResponseMetadata']['HTTPStatusCode'])
modify_db_parameter_group("test-cluster-v1-mysql8")
修改集群参数组
import boto3
def modify_db_cluster_parameter_group(DBClusterParameterGroupName):
# 创建Boto3客户端
client = boto3.client('rds')
# 构建ModifyDBClusterParameterGroup的参数
params = {
"DBClusterParameterGroupName": DBClusterParameterGroupName,
"Parameters": [
{
"ApplyMethod": "pending-reboot",
"ParameterName": "binlog_format",
"ParameterValue": "ROW"
},
{
"ApplyMethod": "pending-reboot",
"ParameterName": "performance_schema",
"ParameterValue": "1"
},
{
"ApplyMethod": "pending-reboot",
"ParameterName": "performance-schema-consumer-events-waits-current",
"ParameterValue": "ON"
},
{
"ApplyMethod": "pending-reboot",
"ParameterName": "performance-schema-instrument",
"ParameterValue": "wait/% = ON"
},
{
"ApplyMethod": "pending-reboot",
"ParameterName": "performance_schema_consumer_global_instrumentation",
"ParameterValue": "1"
},
{
"ApplyMethod": "pending-reboot",
"ParameterName": "performance_schema_consumer_thread_instrumentation",
"ParameterValue": "1"
}
]
}
# 发送ModifyDBClusterParameterGroup请求服务器托管网
response = client.modify_db_cluster_parameter_group(**params)
# 检查响应结果
if response['ResponseMetadata']['HTTPStatusCode'] == 200:
print("DB cluster parameter group modified successfully!")
else:
print("Failed to modify DB cluster parameter group. Error:", response['ResponseMetadata']['HTTPStatusCode'])
modify_db_cluster_parameter_group("test-cluster-v1-mysql8")
创建绿环境
创建绿环境是蓝绿部署中的关键步骤,以下是通过 Python 脚本创建蓝绿环境的示例:
import boto3
def create_blue_green_deployment(cluster_name):
# 创建 Boto3 客户端
client = boto3.client('rds')
# 构建 CreateBlueGreenDeployment 的参数
params = {
"BlueGreenDeploymentName": f"{cluster_name}-green",
"Source": f"arn:aws:rds:us-east-1:830710710665:cluster:{cluster_name}",
"TargetDBClusterParameterGroupName": f"{cluster_name}-mysql8",
"TargetDBParameterGroupName": f"{cluster_name}-mysql8",
"TargetEngineVersion": "8.0.mysql_aurora.3.05.0"
}
# 发送 CreateBlueGreenDeployment 请求
response = client.create_blue_green_deployment(**params)
# 检查响应结果
if response['ResponseMetadata']['HTTPStatusCode'] == 200:
print("Blue-green deployment created successfully!")
else:
print("Failed to create blue-green deployment. Error:", response['Responsemetadata']['HTTPStatusCode'])
create_blue_green_deployment("test-cluster-v1")
排查创建绿环境报错
在创建绿环境时,可能会遇到一些错误。以下是通过 Python 脚本排查错误并获取详细信息的示例:
import boto3
def detect_abnormal_green_environment(db_instance_identifier):
# 创建 Boto3 客户端
client = boto3.client('rds')
# 查询 upgrade-prechecks.log 文件是否存在
response = client.describe_db_log_files(DBInstanceIdentifier=db_instance_identifier)
log_files = response['DescribeDBLogFiles']
log_file_exists = any(log_file['LogFileName'] == 'upgrade-prechecks.log' for log_file in log_files)
if log_file_exists:
# 下载日志文件
params = {
'DBInstanceIdentifier': db_instance_identifier,
'LogFileName': 'upgrade-prechecks.log',
}
response = client.download_db_log_file_portion(**params)
# 将日志内容写入文件
with open('upgrade_prechecks.log', 'w') as file:
file.write(response['LogFileData'])
# 读取日志文件内容
with open('upgrade_prechecks.log', 'r') as file:
log_content = file.readlines()
# 查找包含特定内容的行及后续两行
error_lines = []
for i, line in enumerate(log_content):
if '"level": "Error"' in line:
error_lines.append(line.strip())
error_lines.extend(log_content[i + 1:i + 3])
# 打印结果
for line in error_lines:
print(line)
else:
print("upgrade-prechecks.log file does not exist.")
detect_abnormal_green_environment('test-cluster-v1-green-ce44ac')
报错处理
在排查错误后,可能需要针对不同的错误进行处理。以下是一些可能遇到的错误和解决方案的示例:
FULLTEXT 索引问题
如果遇到 FULLTEXT 索引问题,错误信息可能如下:
"level": "Error",
"dbObject": "bi-test.posting_copy",
"description": "Table `bi-test.posting_copy` contains dangling FULLTEXT index. Kindly recreate the table before upgrade."
解决方案:
CREATE TABLE `bi-test`.`posting_copy_new` LIKE `bi-test`.`posting_copy`;
INSERT INTO `bi-test`.`posting_copy_new` SELECT * FROM `bi-test`.`posting_copy`;
RENAME TABLE `bi-test`.`posting_copy` TO `bi-test`.`posting_copy_old`;
RENAME TABLE `bi-test`.`posting_copy_new` TO `bi-test`.`posting_copy`;
DROP TABLE `bi-test`.`posting_copy_old`;
Index 长度问题
如果遇到 Index 长度问题,错误信息可能如下:
"level": "Error",
"dbObject": "bi-pda.posting",
"description": "Index `title` from `bi-pda.posting` has Index length 2000 > 767 bytes, which will cause error after upgradation. Consider changing the row_format of the tables to dynamic and restart the upgrade."
解决方案:
- 登录到数据库服务器上,并打开数据库客户端。
- 执行以下命令以更改表的行格式为 dynamic:
ALTER TABLE `bi-pda`.`posting` ROW_FORMAT=DYNAMIC;
- 确保命令执行成功后,重新启动数据库升级过程。
FTS 索引问题
如果遇到 FTS 索引问题,错误信息可能如下:
"level": "Error",
"dbObject": "bi-test.reco_eval_2",
"description": " The auxiliary tables of FTS indexes on the table 'bi-test.reco_eval_2' are created in system table-space due to https://bugs.mysql.com/bug.php?id=72132. In MySQL8.0, DDL queries executed on this table shall cause database unavailability. To avoid that, drop and recreate all the FTS indexes on the table or rebuild the table using ALTER TABLE query before the upgrade."
解决方案:
使用 ALTER TABLE
查询重建表:
ALTER TABLE `bi-test`.`reco_eval_2` ENGINE=InnoDB;
根据以上内容,您可以撰写一篇详细的博文,帮助他人更好地进行 RDS 升级和蓝绿部署。
服务器托管,北京服务器托管,服务器租用 http://www.fwqtg.net
机房租用,北京机房租用,IDC机房托管, http://www.fwqtg.net
文章目录 1、Zookeeper Java客户端实战 1.1、 Zookeeper 原生Java客户端使用 1.2、 Curator开源客户端使用 2、 Zookeeper在分布式命名服务中的实战 2.1、 分布式API目录 2.2、 分布式节点的命名 2.3…