使用容器自动交付SQL Server生产数据环境

There has been a lot of buzz about Docker and containers this year, and earlier this Fall Microsoft released container support in Windows Server 2016. WinDocks is a team of former Microsoft engineers, and we released an independent port of Docker’s open source in March of 2016. Full disclosure, I am a co-founder at WinDocks.

今年以来,关于Docker和容器的热议很多,今年秋天早些时候,Microsoft在Windows Server 2016中发布了对容器的支持。WinDocks是前微软工程师组成的团队,我们于2016年3月发布了一个独立的Docker开源端口全面披露,我是WinDocks的联合创始人。

In this article we’ll take a look at the basics of containers, and the most popular use by SQL Server DBAs.

在本文中,我们将介绍容器的基础知识以及SQL Server DBA最受欢迎的用法。

Docker,容器和SQL Server (Docker, Containers, and the SQL Server)

Containers originated in 2000, with the introduction of BSD UNIX “jails,” providing process and user isolation for application multi-tenancy. In the spring of 2013 Docker Inc introduced a new Linux design that won industry-wide support by Red Hat, Amazon AWS, Azure, and Google Cloud. In a move that would portend Microsoft’s embrace of Linux, the company announced plans to incorporate Docker support into Windows Server 2016. My firm, WinDocks, also organized to deliver a first-class solution for the SQL Server community.

容器起源于2000年,引入了BSD UNIX“*”,为应用程序多租户提供了流程和用户隔离。 在2013年Spring,Docker Inc推出了一种新的Linux设计,该设计赢得了Red Hat,Amazon AWS,Azure和Google Cloud的全行业支持。 为了预示微软对Linux的支持,微软宣布了将Docker支持纳入Windows Server 2016的计划。我的公司WinDocks也组织了为SQL Server社区提供一流解决方案的计划。

Both IIS and SQL Server have had strong multi instance support for years, so it’s reasonable to ask “why use containers?” A SQL Server container is a named instance with a new level of speed, economy, and portability.

IIS和SQL Server多年来都具有强大的多实例支持,因此问“为什么使用容器”是合理的。 SQL Server容器是具有新级别的速度,经济性和可移植性的命名实例。

Speed: SQL Server containers are instantiated in seconds with data and specific configurations. Containers are well suited for short-lived instances needed by Developers and QA, and can be deleted and replaced on-demand.

速度: SQL Server容器可在几秒钟内实例化数据和特定配置。 容器非常适合开发人员和质量检查人员需要的短期实例,可以按需删除和替换。

Economy: development and QA teams use isolated containers on a shared VM, and typically reduce the number of VMs used by a factor of 5-10x. VM maintenance is simplified, and Microsoft license costs are dramatically reduced.

经济:开发和质量保证团队在共享的VM上使用隔离的容器,通常将使用的VM数量减少5到10倍。 简化了VM维护,并大大降低了Microsoft许可成本。

Portability: container images are immutable, and can be moved between systems or a public cloud.

可移植性:容器映像是不可变的,可以在系统或公共云之间移动。

SQL Server containers are also part of a rapidly growing industry-wide ecosystem of software and services, as Docker’s design is supported by Red Hat, Microsoft, AWS, Google, and other leading firms. It makes sense to explore use of SQL Server containers simply to be aligned with industry trends.

SQL Server容器也是快速增长的全行业软件和服务生态系统的一部分,因为Docker的设计得到了Red Hat,Microsoft,AWS,Google和其他领先公司的支持。 探索SQL Server容器的使用以使其与行业趋势保持一致是很有意义的。

SQL Server容器简介 (An Introduction to SQL Server Containers)

Containers are defined by Dockerfiles which include a sequence of steps to build a container. In this example the Docker file specifies use of SQL Server 2014 standard, and a NetApp Snap Mount command mounts the LUN to the host with an environment variable for the ContainerID. The MOUNTDB command then mounts the database to the container. Finally, a SQL Server script is run to configure user accounts.

容器由Dockerfiles定义,其中包括构建容器的一系列步骤。 在此示例中,Docker文件指定使用SQL Server 2014标准,并且NetApp Snap Mount命令使用具有ContainerID的环境变量将LUN安装到主机。 然后,MOUNTDB命令将数据库安装到容器。 最后,运行SQL Server脚本来配置用户帐户。

使用容器自动交付SQL Server生产数据环境

Databases can be managed using two methods. Databases can be copied and run “in container,” using an ADDDB command. Alternatively, databases are mounted using the MOUNTDB command. Mounts are preferred for large databases, to avoid copying data across the network and consuming server storage. Snapshots and clones support multiple containers, with one mount to each clone. Both methods deliver good performance. A 1 TB database can be mounted and delivered in less than 1 minute. In other cases, up to 30 databases totaling 400 GB can be run “in container” in 2 minutes.

可以使用两种方法来管理数据库。 可以使用ADDDB命令复制数据库并“在容器中”运行。 或者,可以使用MOUNTDB命令挂载数据库。 对于大型数据库,首选挂载,以避免通过网络复制数据和消耗服务器存储。 快照和克隆支持多个容器,每个克隆都有一个容器。 两种方法均具有良好的性能。 可以在不到1分钟的时间内安装和交付1 TB数据库。 在其他情况下,可以在2分钟内“在容器中”运行多达30个总计400 GB的数据库。

Users are limited to operations on their container and its private file system. The example below shows a Docker client building a container with MSSQL-2014 and venture.mdf. This example includes SQL sa credentials, which is optional. A unique ContainerID and container port are provided, and the container behaves just like any SQL Server instance and is available to SQL Management Studio and all other standard tools.

用户只能在其容器及其专用文件系统上进行操作。 下面的示例显示了一个Docker客户端使用MSSQL-2014和venture.mdf构建容器。 此示例包括SQL sa凭据,这是可选的。 提供了唯一的ContainerID和容器端口,并且该容器的行为与任何SQL Server实例一样,可用于SQL Management Studio和所有其他标准工具。

使用容器自动交付SQL Server生产数据环境

在共享服务器上支持复杂的应用程序环境 (Supporting Complex Application Environments on a Shared Server)

While containers are great for delivery of SQL Server environments, they support the full development stack with .NET and a range of open source frameworks. Support of a globally distributed development team is achieved efficiently with a single shared server hosting both .NET and SQL Server environments.

尽管容器非常适合提供SQL Server环境,但它们支持.NET和一系列开放源代码框架的完整开发堆栈。 单个托管.NET和SQL Server环境的共享服务器可有效地实现对全球分布式开发团队的支持。

Once the SQL Server container is available, the port and connection credentials can be edited in the .NET web.config file, as shown here:

一旦SQL Server容器可用,就可以在.NET web.config文件中编辑端口和连接凭据,如下所示:

使用容器自动交付SQL Server生产数据环境

In most cases a PowerShell script will be used to automate this process. The script generates the SQL Server container, parses the connection string details, pulls the latest code from Git hub, edits the webconfig file, and then builds and starts the .NET container. Each developer can run the script on demand, or the delivery of environments can be handled by a DevOps engineer. Upon completion the script can distribute environments to the team via email.

在大多数情况下,将使用PowerShell脚本来自动执行此过程。 该脚本生成SQL Server容器,解析连接字符串详细信息,从Git集线器中提取最新代码,编辑webconfig文件,然后构建并启动.NET容器。 每个开发人员都可以按需运行脚本,或者由DevOps工程师处理环境的交付。 完成后,脚本可以通过电子邮件将环境分发给团队。

A shared VM can support up to 20 simultaneous running containerized environments, each provisioned in just 100 seconds. The front-end and back-end teams can replicate bugs quickly and validate tests by simply choosing the appropriate branch in the build script.

共享的VM最多可以支持20个同时运行的容器化环境,每个环境仅需100秒即可配置。 前端和后端团队只需在构建脚本中选择适当的分支即可快速复制错误并验证测试。

使用容器自动交付SQL Server生产数据环境

One user supports up to twenty SQL Server containers on an 8 core server with 96 GB of RAM, with each container supporting twenty five databases totaling 400 GB. Prior to adopting containers it took over an hour to build each VM. Now each container is provisioned in under two minutes. They benefit from a 20x reduction in VMs, a 5:1 reduction in CPU cores, and dramatic financial savings in MS license costs.

一个用户在具有96 GB RAM的8核服务器上最多支持20个SQL Server容器,每个容器支持25个数据库,总计400 GB。 在采用容器之前,要花一个多小时来构建每个VM。 现在,在不到两分钟的时间内配置了每个容器。 他们受益于VM减少20倍,CPU内核减少5:1以及MS许可成本的巨大财务节省。

While SQL Server containers are most commonly used for support of Development and QA, other uses are emerging. Containers provide efficient support for DR Testing, and some are applying containers for support of back-end systems for legacy apps, such as SAP or MS Dynamics. Looking ahead, SQL Server containers can also be expected to be used in support of Continuous Integration and Delivery pipelines. AWS, Azure, and other leaders are investing heavily to popularize automated build and testing for software delivery, and SQL Server containers are particularly well suited for this emerging use case.

尽管SQL Server容器最常用于支持开发和质量检查,但其他用途正在兴起。 容器为灾难恢复测试提供了有效的支持,并且一些容器正在应用容器以支持传统应用程序(例如SAP或MS Dynamics)的后端系统。 展望未来,SQL Server容器也有望用于支持持续集成和交付管道。 AWS,Azure和其他领导者正在大力投资以普及用于软件交付的自动化构建和测试,并且SQL Server容器特别适合这种新兴用例。

结论 (Conclusions)

Containers are a dramatic step forward for support of developers and test, and the ability to support SQL Server in containers should be a boon for Windows based software development. SQL Server environments can be provided daily, with the latest production data, using simple automated processes. Developers should be happy with daily, on-demand access to fresh isolated environments. Management should be happy with added productivity, and cutting Microsoft license bill in half!

容器是支持开发人员和测试的重要一步,而在容器中支持SQL Server的能力应该是基于Windows的软件开发的福音。 可以每天使用简单的自动化流程为SQL Server环境提供最新的生产数据。 开发人员应对每日按需访问新鲜的隔离环境感到满意。 管理层应该对提高生产力感到满意,并将Microsoft许可费用减少一半!

Methods used for working with SQL Server data, and use of file shares to support delivery of production databases with containers will be explained in the next article, How to use Windows hosted file shares to support SQL Server containers

下一篇文章如何使用Windows托管的文件共享来支持SQL Server容器 ,将介绍用于处理SQL Server数据以及使用文件共享来支持使用容器传递生产数据库的方法。

参考资料 (References)

翻译自: https://www.sqlshack.com/automate-delivery-of-sql-server-production-data-environments-using-containers/