How to use distributed transactions with SQL Server on Docker

https://docs.microsoft.com/en-us/sql/linux/sql-server-linux-configure-msdtc-docker?view=sqlallproducts-allversions

还是 only SQL2019才支持.

APPLIES TO: SQL Server (Linux only) Azure SQL Database Azure SQL Data Warehouse Parallel Data Warehouse

This article explains how to set up SQL Server Linux containers on Docker for distributed transactions.

Starting with SQL Server 2019 preview, container images support the Microsoft Distributed Transaction Coordinator (MSDTC) required for distributed transactions. To understand the communications requirements for MSDTC, see How to configure the Microsoft Distributed Transaction Coordinator (MSDTC) on Linux. This article explains the special requirements and scenarios related to SQL Server Docker containers.

Configuration

To enable MSDTC transaction in containers for docker, you must set two new environment variables:

  • MSSQL_RPC_PORT: the TCP port that RPC endpoint mapper service binds to and listens on.
  • MSSQL_DTC_TCP_PORT: the port that MSDTC service is configured to listen on.

Pull and run

The following example shows how to use these environment variables to pull and run a single SQL Server container configured for MSDTC. This allows it to communicate with any application on any hosts.

bashCopy
docker run \
-e 'ACCEPT_EULA=Y' -e 'MSSQL_SA_PASSWORD=<YourStrong!Passw0rd>' \
-e 'MSSQL_RPC_PORT=135' -e 'MSSQL_DTC_TCP_PORT=51000' \
-p 51433:1433 -p 135:135 -p 51000:51000 \
-d mcr.microsoft.com/mssql/server:2019-CTP2.3-ubuntu

Important

The previous command only works for Docker running on Linux. For Docker on Windows, the Windows host already listens on port 135. You can remove the -p 135:135 parameter for Docker on Windows, but it has a few limitations. The resulting container can then not be used for distributed transactions that involve the host; it can participate only in distributed transactions among docker containers on the host.

In this command, the RPC Endpoint Mapper service has been bound to port 135, and the MSDTC service has been bound to port 51000 within docker virtual network. SQL Server TDS communication occurs on port 1433 within docker virtual network. These ports have been externally exposed to host as TDS port 51433, RPC endpoint mapper port 135, and MSDTC port 51000.

Note

The RPC Endpoint Mapper and MSDTC port do not have to be the same on the host and the container. So while RPC Endpoint Mapper port was configured to be 135 on container, it could potentially be mapped to port 13501 or any other available port on the host server.

Configure the firewall

In order to communicate with and through the host, you must also configure the firewall on the host server for the containers. Open the firewall for all ports that docker container exposes for external communication. In the previous example, this would be ports 135, 51433, and 51000. These are the ports on the host itself and not the ports they map to in the container. So, if RPC Endpoint mapper port 51000 of container was mapped to host port 51001, then port 51001 (not 51000) should be opened in the firewall for communication with the host.

The following example shows how to create these rules on Ubuntu.

bashCopy
sudo ufw allow from any to any port 51433 proto tcp
sudo ufw allow from any to any port 51000 proto tcp
sudo ufw allow from any to any port 135 proto tcp

The following example shows how this could be done on Red Hat Enterprise Linux (RHEL):

bashCopy
sudo firewall-cmd --zone=public --add-port=51999/tcp --permanent
sudo firewall-cmd --zone=public --add-port=51433/tcp --permanent
sudo firewall-cmd --zone=public --add-port=135/tcp --permanent
sudo firewall-cmd --reload

Configure port routing on the host

In the previous example, because a single Docker container maps RPC port 135 to port 135 on the host, distributed transactions with the host should now work with no further configuration. Note that it is possible to directly use port 135 in the container, because SQL Server runs with elevated privileges in a container. For SQL Server outside of a container, a different ephemeral port must be used and traffic to port 135 must then be routed to that port.

However, if you did decide to map the container's port 135 to a different port on the host, such as 13500, then you have to configure port routing on the host. This enables the docker container to participate in distributed transactions with the host and with other external servers. For more information, see Configure port routing.

Next steps

For more information about MSDTC on Linux, see How to configure the Microsoft Distributed Transaction Coordinator (MSDTC) on Linux.

[官网]How to use distributed transactions with SQL Server on Docker的更多相关文章

  1. [官网]How to configure the Microsoft Distributed Transaction Coordinator (MSDTC) on Linux

    How to configure the Microsoft Distributed Transaction Coordinator (MSDTC) on Linux APPLIES TO: SQL ...

  2. 1.1 Introduction中 Apache Kafka™ is a distributed streaming platform. What exactly does that mean?(官网剖析)(博主推荐)

    不多说,直接上干货! 一切来源于官网 http://kafka.apache.org/documentation/ Apache Kafka™ is a distributed streaming p ...

  3. [ActionScript 3.0] Away3D 官网实例

    /* Dynamic tree generation and placement in a night-time scene Demonstrates: How to create a height ...

  4. Gearman研习笔记(1) ------ 官网介绍要点摘录

    之前的项目里使用过消息中间件(公司提供的MQ服务)来做分发,因为MQ是基于消息的,并不是专业的任务分发器,在一些复杂场景上使用起来并不恰当. 后来听组长说了下Gearman(听名字还以为是Ironma ...

  5. 【原】Zookeeper 概述 + 官网 Overview 翻译

    分布式应用 分布式应用 distributed application可以在给定时间(同时)在网络中的多个系统上运行,通过协调它们以快速有效的方式完成特定任务. (a), (b): a distrib ...

  6. 1.2 Use Cases中 Commit Log官网剖析(博主推荐)

    不多说,直接上干货! 一切来源于官网 http://kafka.apache.org/documentation/ Commit Log 提交日志 Kafka can serve as a kind ...

  7. 1.2 Use Cases中 Log Aggregation官网剖析(博主推荐)

    不多说,直接上干货! 一切来源于官网 http://kafka.apache.org/documentation/ Log Aggregation 日志聚合 Many people use Kafka ...

  8. 1.2 Use Cases中 Metrics官网剖析(博主推荐)

    不多说,直接上干货! 一切来源于官网 http://kafka.apache.org/documentation/ Metrics 指标 Kafka is often used for operati ...

  9. 1.1 Introduction中 Putting the Pieces Together官网剖析(博主推荐)

    不多说,直接上干货! 一切来源于官网 http://kafka.apache.org/documentation/ Putting the Pieces Together 拼在一起 This comb ...

随机推荐

  1. 《生命》第三集:Mammals (哺乳动物)

    南极零下四十度的情况下,威德尔海豹能深潜到冰下捕食,并且教自己的小宝宝如何下水,看了这个才知道,海豹居然是哺乳动物,小海豹看着挺萌的. 长鼻鼩是一种很活跃的生物,而且会自己设计路线,建立迷宫,帮助自己 ...

  2. Set replication in Hadoop

    I was trying loading file using hadoop API as an experiment. I want to set replication to minimum as ...

  3. 阿里中间件——消息中间件Notify和MetaQ

    3.1.Notify Notify是淘宝自主研发的一套消息服务引擎,是支撑双11最为核心的系统之一,在淘宝和支付宝的核心交易场景中都有大量使用.消息系统的核心作用就是三点:解耦,异步和并行.下面让我以 ...

  4. Linux的基础命令

    -shutdown –h now(root用户才有效)     立即关机 -shutdown –r now(root用户才有效)     立即重新启动计算机 -reboot               ...

  5. Loj #6069. 「2017 山东一轮集训 Day4」塔

    Loj #6069. 「2017 山东一轮集训 Day4」塔 题目描述 现在有一条 $ [1, l] $ 的数轴,要在上面造 $ n $ 座塔,每座塔的坐标要两两不同,且为整点. 塔有编号,且每座塔都 ...

  6. C#事件の事件解析

    事件(event)是基于windows消息处理机制的类,封装的更好,让开发者无须知道底层的消息处理机制,就可以开发出强大的基于事件的应用程序来.委托(delegate)委托可以理解成为函数指针,不同的 ...

  7. 因PHP漏洞,超过4.5万个中国网站被攻击

    因PHP漏洞,超过4.5万个中国网站被攻击 日前据外媒ZDNet了解,超过4.5万个中国网站受到了试图进入网络服务器的不法分子攻击. 此次黑客利用中国网络安全公司VulnSpy在ExploitDB上发 ...

  8. [CQOI2018]解锁屏幕

    嘟嘟嘟 这题感觉真的很简单-- \(O(n ^ 2 logn)\)的做法特别好理解,但得开O2. 看数据范围,肯定是状压dp.但刚开始我没想通状压啥,因为点与点之间还有顺序问题.但后来发现这个顺序是子 ...

  9. Python:Day21

    序列化 我们把对象(变量)从内存中变成可存储或可传输的过程称之为序列化 json模块

  10. 006_ansible1.9.6版本的安装

    一.Linux的安装 cd /usr/local/src && wget https://pypi.python.org/packages/source/a/ansible/ansib ...