第 2 章 网络接口和套接字绑定
通过将 Data Grid Server 绑定到 IP 地址,通过网络接口公开 Data Grid Server。然后,您可以将端点配置为使用接口,以便 Data Grid Server 可以处理来自远程客户端应用程序的请求。
2.1. 网络接口
Data Grid Server 将多个端点用于单个 TCP/IP 端口,并自动检测入站客户端请求的协议。您可以配置数据网格服务器如何绑定到网络接口以侦听客户端请求。
互联网协议(IP)地址
XML
<server xmlns="urn:infinispan:server:14.0"> <!-- Selects a specific IPv4 address, which can be public, private, or loopback. This is the default network interface for Data Grid Server. --> <interfaces> <interface name="public"> <inet-address value="${infinispan.bind.address:127.0.0.1}"/> </interface> </interfaces> </server>
JSON
{ "server": { "interfaces": [{ "name": "public", "inet-address": { "value": "127.0.0.1" } }] } }
YAML
server: interfaces: - name: "public" inetAddress: value: "127.0.0.1"
环回地址
XML
<server xmlns="urn:infinispan:server:14.0"> <!-- Selects an IP address in an IPv4 or IPv6 loopback address block. --> <interfaces> <interface name="public"> <loopback/> </interface> </interfaces> </server>
JSON
{ "server": { "interfaces": [{ "name": "public", "loopback": null }] } }
YAML
server: interfaces: - name: "public" loopback: ~
非环回地址
XML
<server xmlns="urn:infinispan:server:14.0"> <!-- Selects an IP address in an IPv4 or IPv6 non-loopback address block. --> <interfaces> <interface name="public"> <non-loopback/> </interface> </interfaces> </server>
JSON
{ "server": { "interfaces": [{ "name": "public", "non_loopback": null }] } }
YAML
server: interfaces: - name: "public" nonLoopback: ~
任何地址
XML
<server xmlns="urn:infinispan:server:14.0"> <!-- Uses the `INADDR_ANY` wildcard address which means Data Grid Server listens for inbound client requests on all interfaces. --> <interfaces> <interface name="public"> <any-address/> </interface> </interfaces> </server>
JSON
{ "server": { "interfaces": [{ "name": "public", "any_address": null }] } }
YAML
server: interfaces: - name: "public" anyAddress: ~
链接本地
XML
<server xmlns="urn:infinispan:server:14.0"> <!-- Selects a link-local IP address in an IPv4 or IPv6 address block. --> <interfaces> <interface name="public"> <link-local/> </interface> </interfaces> </server>
JSON
{ "server": { "interfaces": [{ "name": "public", "link_local": null }] } }
YAML
server: interfaces: - name: "public" linkLocal: ~
站点本地
XML
<server xmlns="urn:infinispan:server:14.0"> <!-- Selects a site-local (private) IP address in an IPv4 or IPv6 address block. --> <interfaces> <interface name="public"> <site-local/> </interface> </interfaces> </server>
JSON
{ "server": { "interfaces": [{ "name": "public", "site_local": null }] } }
YAML
server: interfaces: - name: "public" siteLocal: ~
2.1.1. 匹配和回退策略
数据网格服务器可以枚举主机系统上的所有网络接口,并绑定到与值匹配的接口、主机或 IP 地址,这可能包含用于额外灵活性的正则表达式。
匹配主机
XML
<server xmlns="urn:infinispan:server:14.0"> <!-- Selects an IP address that is assigned to a matching host name. --> <interfaces> <interface name="public"> <match-host value="my_host_name"/> </interface> </interfaces> </server>
JSON
{ "server": { "interfaces": [{ "name": "public", "match-host": { "value": "my_host_name" } }] } }
YAML
server: interfaces: - name: "public" matchHost: value: "my_host_name"
匹配接口
XML
<server xmlns="urn:infinispan:server:14.0"> <!--Selects an IP address assigned to a matching network interface. --> <interfaces> <interface name="public"> <match-interface value="eth0"/> </interface> </interfaces> </server>
JSON
{ "server": { "interfaces": [{ "name": "public", "match-interface": { "value": "eth0" } }] } }
YAML
server: interfaces: - name: "public" matchInterface: value: "eth0"
匹配地址
XML
<server xmlns="urn:infinispan:server:14.0"> <!-- Selects an IP address that matches a regular expression. --> <interfaces> <interface name="public"> <match-address value="132\..*"/> </interface> </interfaces> </server>
JSON
{ "server": { "interfaces": [{ "name": "public", "match-address": { "value": "132\\..*" } }] } }
YAML
server: interfaces: - name: "public" matchAddress: value: "127\\..*"
回退
XML
<server xmlns="urn:infinispan:server:14.0"> <!-- Includes multiple strategies that Data Grid Server tries in the declared order until it finds a match. --> <interfaces> <interface name="public"> <match-host value="my_host_name"/> <match-address value="132\..*"/> <any-address/> </interface> </interfaces> </server>
JSON
{ "server": { "interfaces": [{ "name": "public", "match-host": { "value": "my_host_name" }, "match-address": { "value": "132\\..*" }, "any_address": null }] } }
YAML
server: interfaces: - name: "public" matchHost: value: "my_host_name" matchAddress: value: "132\\..*" anyAddress: ~