In the Domain Name System (DNS), a SRV record (service location record) is a type of resource record that enables a client to specify a name that indicates a service, protocol, and domain. 在域名系统(DNS)中,SRV记录(服务位置记录)是一种资源记录,它使客户端能够指定一个表示服务、协议和域的名称。A DNS lookup on the name returns a reply containing the names of multiple available servers in the domain that provide the required service. 对名称的DNS查找会返回一个回复,其中包含域中提供所需服务的多个可用服务器的名称。For information about DNS SRV, including how a record defines the preference order of the listed servers, see RFC 2782.有关DNS SRV的信息,包括记录如何定义所列服务器的首选项顺序,请参阅RFC 2782。
MySQL supports the use of DNS SRV records for connecting to servers. MySQL支持使用DNS SRV记录连接到服务器。A client that receives a DNS SRV lookup result attempts to connect to the MySQL server on each of the listed hosts in order of preference, based on the priority and weighting assigned to each host by the DNS administrator. 接收DNS SRV查找结果的客户端尝试根据DNS管理员分配给每个主机的优先级和权重,按优先顺序连接到每个列出的主机上的MySQL服务器。A failure to connect occurs only if the client cannot connect to any of the servers.只有当客户端无法连接到任何服务器时,才会发生连接失败。
When multiple MySQL instances, such as a cluster of servers, provide the same service for your applications, DNS SRV records can be used to assist with failover, load balancing, and replication services. 当多个MySQL实例(如服务器集群)为您的应用程序提供相同的服务时,DNS SRV记录可用于协助故障转移、负载平衡和复一致性务。It is cumbersome for applications to directly manage the set of candidate servers for connection attempts, and DNS SRV records provide an alternative:应用程序直接管理连接尝试的候选服务器集很麻烦,DNS SRV记录提供了一种替代方案:
DNS SRV records enable a DNS admininstrator to map a single DNS domain to multiple servers. DNS SRV记录使DNS管理员能够将单个DNS域映射到多个服务器。DNS SRV records also can be updated centrally by administrators when servers are added or removed from the configuration or when their host names are changed.当在配置中添加或删除服务器或更改其主机名时,管理员也可以集中更新DNS SRV记录。
Central management of DNS SRV records eliminates the need for individual clients to identify each possible host in connection requests, or for connections to be handled by an additional software component. DNS SRV记录的集中管理消除了单个客户端在连接请求中识别每个可能主机的需要,也消除了由额外软件组件处理连接的需要。An application can use the DNS SRV record to obtain information about candidate MySQL servers, instead of managing the server information itself.应用程序可以使用DNS SRV记录来获取有关候选MySQL服务器的信息,而不是管理服务器信息本身。
DNS SRV records can be used in combination with connection pooling, in which case connections to hosts that are no longer in the current list of DNS SRV records are removed from the pool when they become idle.DNS SRV记录可以与连接池结合使用,在这种情况下,与不再在当前DNS SRV记录列表中的主机的连接在空闲时将从池中删除。
MySQL supports use of DNS SRV records to connect to servers in these contexts:MySQL支持在以下情况下使用DNS SRV记录连接到服务器:
Several MySQL Connectors implement DNS SRV support; connector-specific options enable requesting DNS SRV record lookup both for X Protocol connections and for classic MySQL protocol connections. 几个MySQL连接器实现了DNS SRV支持;特定于连接器的选项允许为X协议连接和经典MySQL协议连接请求DNS SRV记录查找。For general information, see Connections Using DNS SRV Records. 有关一般信息,请参阅使用DNS SRV记录的连接。For details, see the documentation for individual MySQL Connectors.有关详细信息,请参阅单个MySQL连接器的文档。
The C API provides a C API提供了一个类似于mysql_real_connect_dns_srv()
function that is similar to mysql_real_connect()
, except that the argument list does not specify the particular host of the MySQL server to connect to. mysql_real_connect()
的mysql_real_connect_dns_srv()
函数,只是参数列表没有指定要连接到的MySQL服务器的特定主机。Instead, it names a DNS SRV record that specifies a group of servers. See mysql_real_connect_dns_srv().相反,它命名了一个指定一组服务器的DNS SRV记录。请参阅mysql_real_connect_dns_srv()
。
The mysql client has a mysql客户端有一个--dns-srv-name
option to indicate a DNS SRV record that specifies a group of servers. --dns-srv-name
选项,用于指示指定一组服务器的DNS SRV记录。See Section 4.5.1, “mysql — The MySQL Command-Line Client”.请参阅第4.5.1节,“mysql——mysql命令行客户端”。
A DNS SRV name consists of a service, protocol, and domain, with the service and protocol each prefixed by an underscore:DNS SRV名称由服务、协议和域组成,服务和协议均以下划线作为前缀:
_service
._protocol
.domain
The following DNS SRV record identifies multiple candidate servers, such as might be used by clients for establishing X Protocol connections:以下DNS SRV记录标识了多个候选服务器,例如客户端可能用于建立X协议连接的服务器:
Name TTL Class Priority Weight Port Target _mysqlx._tcp.example.com. 86400 IN SRV 0 5 33060 server1.example.com. _mysqlx._tcp.example.com. 86400 IN SRV 0 10 33060 server2.example.com. _mysqlx._tcp.example.com. 86400 IN SRV 10 5 33060 server3.example.com. _mysqlx._tcp.example.com. 86400 IN SRV 20 5 33060 server4.example.com.
Here, 这里,mysqlx
indicates the X Protocol service and tcp
indicates the TCP protocol. mysqlx
表示X协议服务,tcp表示tcp协议。A client can request this DNS SRV record using the name 客户端可以使用名称_mysqlx._tcp.example.com
. _mysqlx._tcp.example.com
请求此DNS SRV记录。。The particular syntax for specifying the name in the connection request depends on the type of client. For example, a client might support specifying the name within a URI-like connection string or as a key-value pair.在连接请求中指定名称的特定语法取决于客户端的类型。例如,客户端可能支持在类似URI的连接字符串中或作为键值对指定名称。
A DNS SRV record for classic protocol connections might look like this:经典协议连接的DNS SRV记录可能如下:
Name TTL Class Priority Weight Port Target _mysql._tcp.example.com. 86400 IN SRV 0 5 3306 server1.example.com. _mysql._tcp.example.com. 86400 IN SRV 0 10 3306 server2.example.com. _mysql._tcp.example.com. 86400 IN SRV 10 5 3306 server3.example.com. _mysql._tcp.example.com. 86400 IN SRV 20 5 3306 server4.example.com.
Here, the name 在这里,mysql
designates the classic MySQL protocol service, and the port is 3306 (the default classic MySQL protocol port) rather than 33060 (the default X Protocol port).mysql
这个名字表示经典mysql协议服务,端口是3306(默认的经典mysql协议端口),而不是33060(默认的X协议端口)。
When DNS SRV record lookup is used, clients generally must apply these rules for connection requests (there may be client- or connector-specific exceptions):当使用DNS SRV记录查找时,客户端通常必须对连接请求应用这些规则(可能存在客户端或连接器特定的例外):
The request must specify the full DNS SRV record name, with the service and protocol names prefixed by underscores.请求必须指定完整的DNS SRV记录名称,服务和协议名称以下划线作为前缀。
The request must not specify multiple host names.请求不得指定多个主机名。
The request must not specify a port number.请求不得指定端口号。
Only TCP connections are supported. Unix socket files, Windows named pipes, and shared memory cannot be used.仅支持TCP连接。无法使用Unix套接字文件、Windows命名管道和共享内存。
For more information on using DNS SRV based connections in X DevAPI, see Connections Using DNS SRV Records.有关在X DevAPI中使用基于DNS SRV的连接的更多信息,请参阅使用DNS SRV记录的连接。