aws rds监控慢sql_使用AWS CLI部署AWS RDS SQL Server

aws rds监控慢sql

This article deploys a new AWS RDS SQL Server using the AWS CLI command: create-db-instance.

本文使用AWS CLI命令create-db-instance部署了新的AWS RDS SQL Server

介绍 (Introduction)

Amazon Web Services (AWS) gives a managed database service RDS for Microsoft SQL Server. Previously, we deployed the RDS instance using the AWS console. Suppose you deploy RDS instance frequently, it might be cumbersome for you to go through console RDS wizard, choose required options and deploy it. We can stop RDS service when it is not being used, but it can be stopped for a maximum of seven days. RDS automatically starts the RDS instance for maintenance purposes. In this case, you can create the lambda function to start and stop SQL instances automatically.

Amazon Web Services(AWS)为Microsoft SQL Server提供了托管数据库服务RDS。 以前,我们使用AWS控制台部署RDS实例。 假设您经常部署RDS实例,那么通过控制台RDS向导,选择所需的选项并进行部署可能会很麻烦。 我们可以在不使用RDS服务时将其停止,但是最多可以停止7天。 RDS会出于维护目的自动启动RDS实例。 在这种情况下,您可以创建lambda函数来自动启动和停止SQL实例。

In my case, usually, I drop RDS instance after preparing a demo for my article. You can also terminate an RDS instance after completing your testing. In this case, it is a wise decision to use AWS CLI scripts and configure your instances.

就我而言,通常是在为我的文章准备演示之后删除RDS实例。 您也可以在完成测试后终止RDS实例。 在这种情况下,明智的选择是使用AWS CLI脚本并配置实例。

The following articles can be helpful in understanding RDS SQL Server:

以下文章可能有助于理解RDS SQL Server:

In this article, we will deploy an AWS RDS SQL Server using the AWS CLI script.

在本文中,我们将使用AWS CLI脚本部署AWS RDS SQL Server。

先决条件 (Pre-requisites)

AWS Shell console

使用AWS CLI部署AWS RDS SQL Server (Using the AWS CLI to deploy an AWS RDS SQL Server)

We will use the CLI command create-db-instance to deploy RDS instances. We can deploy all supported RDS databases using this command. I will go through the option in AWS Web console and its similar argument in the CLI create-db-instance command.

我们将使用CLI命令create-db-instance部署RDS实例。 我们可以使用此命令部署所有受支持的RDS数据库。 我将在AWS Web控制台中使用该选项,并在CLI create-db-instance命令中使用其类似参数。

引擎选项 (Engine options)

In the AWS console RDS wizard, you need to select the engine type and its corresponding edition. For SQL Server, we have the following supported editions.

在AWS控制台RDS向导中,您需要选择引擎类型及其对应的版本。 对于SQL Server,我们具有以下受支持的版本。

Engine options AWS RDS SQL Server

In the below table, we can see the CLI argument for the SQL Server edition. For example, if we want to create a new RDS instance for SQL Server express edition, we specify sqlserver-ex.

在下表中,我们可以看到SQL Server版本的CLI参数。 例如,如果要为SQL Server Express版本创建新的RDS实例,则可以指定sqlserver-ex。

CLI argument

SQL Server edition

Equivalent CLI option

Engine

Express edition

sqlserver-ex

Web edition

sqlserver-web

Standard edition

sqlserver-se

Enterprise edition

sqlserver-ee

CLI参数

SQL Server版本

等效的CLI选项

发动机

速成版

sqlserver-ex

网络版

sqlserver-web

标准版

sqlserver-se

企业版

sqlserver-ee


(Version
)

AWS RDS supports different SQL Server versions from 2012 to 2017 along with different levels. You need to specify which version you require in the new AWS RDS SQL Server. We need to select the version depending upon the features. We also need to consider that RDS does not support all SQL Server features. Features such as Data Quality Services, log shipping, file table, maintenance plans are not supported.

从2012年到2017年,AWS RDS支持不同SQL Server版本以及不同的级别。 您需要在新的AWS RDS SQL Server中指定所需的版本。 我们需要根据功能选择版本。 我们还需要考虑RDS并不支持所有SQL Server功能。 不支持数据质量服务,日志传送,文件表,维护计划等功能。

RDS version

For my demonstration, I choose SQL Server version 14.00.3281.6.v1. In the CLI, we need to specify the version in the format as 14.00.3281.6.v1.

为了演示,我选择了SQL Server版本14.00.3281.6.v1。 在CLI中,我们需要以14.00.3281.6.v1的格式指定版本。

You can refer to SQL Server Versions Supported in RDS for a complete list of supported SQL versions and their similar RDS argument.

您可以参考RDS支持SQL Server版本,以获取受支持SQL版本及其相似的RDS参数的完整列表。

数据库实例标识符
(DB instance identifier
)

It is the name for your DB instance. It is a unique name for all databases in the AWS account.

它是您的数据库实例的名称。 它是AWS账户中所有数据库的唯一名称。

  • Its name must contain a minimum of 1 and a maximum of 63 letters, numbers or hyphens

    名称必须包含至少1个字符,最多63个字母,数字或连字符
  • Its first character must be a letter

    它的第一个字符必须是字母
  • You cannot use two consecutive hyphens

    您不能使用两个连续的连字符
  • The instance name must not end with a hyphen

    实例名称不能以连字符结尾

DB instance identifier

In the CLI command, we will use argument –db-instance-identifier along with DB instance name.

在CLI命令中,我们将使用–db-instance-identifier参数以及数据库实例名称。

数据库凭证 (DB credentials)

We need a master username and password for the RDS instance. By default, RDS uses the admin username. This admin user has the maximum permissions for your instance. In the web console, you specify these details in the credential settings page.

我们需要RDS实例的主用户名和密码。 默认情况下,RDS使用管理员用户名。 此管理员用户具有您实例的最大权限。 在Web控制台中,您可以在“凭据设置”页面中指定这些详细信息。

DB credentials

In the AWS CLI, we specify the following arguments.

在AWS CLI中,我们指定以下参数。

  • –master-username: Specify the master username –master-username:指定主用户名
  • –master-user-password: Specify the password for the admin user –master-user-password :指定管理员用户的密码

数据库实例大小 (DB instance size)

It is the CPU and memory capacity for your RDS server. AWS provides various DB instance class depending upon the CPU and memory configurations. Your AWS RDS SQL Server cost also varies depending upon the instance class you have selected.

它是RDS服务器的CPU和内存容量。 AWS根据CPU和内存配置提供各种数据库实例类。 您的AWS RDS SQL Server成本也会根据您选择的实例类而有所不同。

DB instance size

We can use argument –db-instance-class in the CLI command to specify the DB instance class. For a free-tier account, we can use db.t2.micro having 1 vCPU and 1 GiB memory. I will specify value db.t2.micro for the –db-instance-class argument. You can refer to AWS docs to understand all Available DB Instance Classes.

我们可以在CLI命令中使用参数–db-instance-class来指定数据库实例类。 对于免费帐户,我们可以使用具有1个vCPU和1个GiB内存的db.t2.micro。 我将为–db-instance-class参数指定值db.t2.micro。 您可以参考AWS文档以了解所有可用的数据库实例类。

储存类型和大小 (Storage type and size)

AWS RDS SQL Server supports two storage types.

AWS RDS SQL Server支持两种存储类型。

  • General-purpose (SSD): It is useful for most of the workloads and provides up to 3000 IOPS. It is default storage provided for RDS and is cost-effective storage 通用(SSD):对于大多数工作负载有用,并提供高达3000 IOPS。 它是为RDS提供的默认存储,是经济高效的存储
  • Provisioned storage (SSD): it is suitable for IO intensive workloads 预置存储(SSD):适用于IO密集型工作负载

We can use a maximum of 16TiB of storage in any of the storage classes specified above. It uses a minimum of 20GiB of storage.

在上面指定的任何存储类中,我们最多可以使用16TiB的存储。 它至少使用20GiB的存储空间。

DB storage

In the CLI command, we use the following arguments for storage class and size.

在CLI命令中,我们将以下参数用于存储类和大小。

  • –storage-type: specify Standard or GP2 for storage class –storage-type:为存储类指定标准或GP2
  • –allocated-storage: specify your storage size as per your database size. We specify the size in GiB unit –allocated-storage:根据数据库大小指定存储大小。 我们以GiB单位指定尺寸

虚拟私有云(VPC) (Virtual Private Cloud (VPC))

VPC is a networking component of the AWS. It is a crucial parameter while creating the RDS instance. In the below screenshot, we can see the default VPC for the new RDS instance.

VPC是AWS的网络组件。 在创建RDS实例时,它是关键参数。 在下面的屏幕截图中,我们可以看到新RDS实例的默认VPC。

  • Note: We cannot modify VPC after a database is created in AWS注意:在AWS中创建数据库后,我们无法修改VPC

Virtual Private Cloud (VPC)

We will use argument –vpc-security-group-ids for the RDS instance VPC.

我们将对RDS实例VPC使用参数–vpc-security-group-ids

子网组 (Subnet group)

Each VPC is associated with the subnet group. Specify the subnet group for your RDS instance using CLI argument –db-subnet-group-name

每个VPC与子网组关联。 使用CLI参数–db-subnet-group-name为RDS实例指定子网组

Subnet group

可公开访问 (Publicly Accessible)

By default, AWS RDS SQL Server allows connection to your database from the Amazon EC2 and other services inside your VPC. We can allow connections from outside VPC to allocate a public IP address to it. I want to connect my RDS from the laptop outside the VPC network, therefore change the configuration using the –publicly-accessible. If you do not want public access, you can use argument –no- publicly-accessible

默认情况下,AWS RDS SQL Server允许从Amazon EC2和VPC内的其他服务连接到数据库。 我们可以允许来自外部VPC的连接为其分配公共IP地址。 我想从VPC网络外部的笔记本电脑连接我的RDS,因此请使用–public-accessible更改配置 如果您不希望公共访问,则可以使用参数–no- public -accessible

Publicly Accessible

DB参数组 (DB parameter group)

We can define a parameter group for the RDS instance. A parameter group is a set of SQL instance configurations. By default, RDS creates a default parameter group and assigns it to your instance. We cannot modify the default parameter group. You can create a new custom group with configurations and apply them to the DB parameter group.

我们可以为RDS实例定义一个参数组。 参数组是一组SQL实例配置。 默认情况下,RDS创建一个默认参数组并将其分配给您的实例。 我们无法修改默认参数组。 您可以使用配置创建一个新的自定义组,并将其应用于数据库参数组。

If you use a custom parameter group, you can use the argument –- DBParameterGroups to specify it.

如果使用自定义参数组,则可以使用参数-DBParameterGroups进行指定。

DB parameter group

数据库选项组 (DB option group)

AWS RDS uses the option group to enable certain features such as integration service, reporting service. We can create a custom option group and assign it to the RDS instance using CLI argument –option-group-name.

AWS RDS使用选项组来启用某些功能,例如集成服务,报告服务。 我们可以创建一个自定义选项组,并使用CLI参数–option-group-name将其分配给RDS实例

DB option group

自动备份和备份保留期 (Automatic backups and backup retention period)

AWS RDS SQL Server automatically takes the database backup and maintains for you as per defined backup retention period.

AWS RDS SQL Server自动进行数据库备份,并按照定义的备份保留期限为您维护。

Automatic back and backup retention period

We can choose the backup retention period as per our requirement. By default, RDS uses 7 days retention period. In the AWS CLI, we will use –backup-retention-period argument to specify the number of days (positive number only). For my demo RDS instance, I do not want any backups, so I specified the value as zero. The zero value in this argument tells RDS to disable automatic backups.

我们可以根据需要选择备份保留期。 默认情况下,RDS使用7天的保留期。 在AWS CLI中,我们将使用–backup-retention-period参数指定天数(仅正数)。 对于我的演示RDS实例,我不需要任何备份,因此我将该值指定为零。 此参数中的零值告诉RDS禁用自动备份。

时区 (TimeZone)

If you need a specific requirement for the time zone and collation, we can specify them while creating the RDS instance. By default, it uses Universal Coordinated Time (UTC).

如果您需要时区和排序规则的特定要求,我们可以在创建RDS实例时指定它们。 默认情况下,它使用世界标准时间(UTC)。

You can refer to the article, Local Time Zone for Microsoft SQL Server DB Instances for supported time zones and use –timezone to specify required time zone other than a default time zone.

您可以参考文章“ Microsoft SQL Server数据库实例的本地时区”以了解受支持的时区,并使用–timezone指定默认时区以外的所需时区。

TimeZone

We can combine the arguments for the CLI command rds create-db-instance and execute them to create a new AWS RDS SQL Server instance.

我们可以组合CLI命令rds create-db-instance的参数并执行它们以创建新的AWS RDS SQL Server实例。

>aws rds create-db-instance –engine sqlserver-ex –engine-version 14.00.3281.6.v1 –db-instance-identifier sqlserverrds –allocated-storage 20 –db-instance-class db.t2.micro –db-subnet-group default-vpc-9c710fe6 –master-username admin –master-user-password admin1234 –backup-retention-period 0 –storage-type standard –port 1433 –publicly-accessible –profile production

> aws rds create-db-instance –引擎sqlserver-ex –engine-version 14.00.3281.6.v1 –db-instance-identifier sqlserverrds –已分配存储20 –db-instance-class db.t2.micro –db-subnet-组default-vpc-9c710fe6 –主用户名admin –主用户密码admin1234 –备份保留期限0 –存储类型标准–端口1433 –可公开访问–配置文件生产

This command gives the output in a JSON format and returns all configurations with default and custom values for your RDS instance.

此命令以JSON格式提供输出,并返回RDS实例具有默认值和自定义值的所有配置。

AWS console output

Similarly, in the below screenshot we get configurations like MultiAZ, Engine version, read replica, option group.

同样,在下面的屏幕截图中,我们获得了诸如MultiAZ,引擎版本,只读副本,选项组之类的配置。

AWS console output details

You can connect to the AWS web console and refresh the RDS dashboard. You can see that the new instance is being created.

您可以连接到AWS Web控制台并刷新RDS仪表板。 您可以看到正在创建新实例。

Refresh the RDS dashboard

If you do not need this instance, you can select it and delete the instance from the Actions menu.

如果不需要此实例,则可以选择它并从“ 操作”菜单中删除该实例。

delete the instance

It asks you a confirmation, and you need to enter delete me keyword as a token of confirmation.

它要求您进行确认,您需要输入Delete me关键字作为确认令牌。

Confirmation prompt

It starts deleting the AWS RDS SQL Server. It takes a few minutes, and after that, you can refresh the RDS dashboard. It removes the entry for deleted RDS.

它开始删除AWS RDS SQL Server。 这需要几分钟,然后,您可以刷新RDS仪表板。 它删除已删除的RDS的条目。

deleted instance

结论 (Conclusion)

In this article, we deployed a new AWS RDS SQL Server using AWS CLI commands. We simulated the web console RDS wizard with a similar argument of CLI. It is an excellent way to use the CLI command to be efficient, productive by saving time and deployment efforts.

在本文中,我们使用AWS CLI命令部署了新的AWS RDS SQL Server。 我们使用类似CLI的参数模拟了Web控制台RDS向导。 通过节省时间和部署工作,这是使用CLI命令高效高效的绝佳方法。

翻译自: https://www.sqlshack.com/deploying-an-aws-rds-sql-server-using-the-aws-cli/

aws rds监控慢sql

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值