為雙堆疊叢集設定偏好的通訊協定 (Memcached) - Amazon ElastiCache

本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。

為雙堆疊叢集設定偏好的通訊協定 (Memcached)

針對 Memcached 叢集,您可以使用 IP 探索參數,控制用戶端用來連線至叢集中節點的通訊協定。IP 探索參數可以設為 IPv4 或 IPv6。

IP 探索參數可控制設定取得叢集輸出中使用的 IP 通訊協定。這也會決定用戶端使用的 IP 通訊協定,這些通訊協定支援 ElastiCache for Memcached 叢集的自動探索功能。

變更 IP 探索不會導致連線用戶端停機。但是,該變更需要一些傳播時間。

監控 Java 的 getAvailableNodeEndPoints 輸出,針對 Php 則監控 getServerList 的輸出。一旦這些函數的輸出報告了叢集中使用更新通訊協定的所有節點 IP,就表示變更已完成傳播。

Java 範例:

MemcachedClient client = new MemcachedClient(new InetSocketAddress("xxxx", 11211)); Class targetProtocolType = Inet6Address.class; // Or Inet4Address.class if you're switching to IPv4 Set<String> nodes; do { nodes = client.getAvailableNodeEndPoints().stream().map(NodeEndPoint::getIpAddress).collect(Collectors.toSet()); Thread.sleep(1000); } while (!nodes.stream().allMatch(node -> { try { return finalTargetProtocolType.isInstance(InetAddress.getByName(node)); } catch (UnknownHostException ignored) {} return false; }));

Php 範例:

$client = new Memcached; $client->setOption(Memcached::OPT_CLIENT_MODE, Memcached::DYNAMIC_CLIENT_MODE); $client->addServer("xxxx", 11211); $nodes = []; $target_ips_count = 0; do { # The PHP memcached client only updates the server list if the polling interval has expired and a # command is sent $client->get('test'); $nodes = $client->getServerList(); sleep(1); $target_ips_count = 0; // For IPv4 use FILTER_FLAG_IPV4 $target_ips_count = count(array_filter($nodes, function($node) { return filter_var($node["ipaddress"], FILTER_VALIDATE_IP, FILTER_FLAG_IPV6); })); } while (count($nodes) !== $target_ips_count);

在更新 IP 探索之前建立的任何現有用戶端連線仍會使用舊通訊協定進行連線。一旦在叢集探索命令的輸出中偵測到變更,所有經過驗證的用戶端都會使用新的 IP 通訊協定自動重新連線至叢集。但是,這仍取決於用戶端的操作。