Red Hat Cluster が Cluster ID またはクラスターマルチキャストアドレス、もしくはその両方を計算する方法
Environment
- Red Hat Enterprise Linux Server 5 (および High Availability と Resilient Storage アドオン)
- Red Hat Enterprise Linux Server 6 (および High Availability と Resilient Storage アドオン)
Issue
- Red Hat Cluster が Cluster ID またはクラスターマルチキャストアドレス、およびその両方を計算する方法は?
Resolution
cluster_id またはマルチキャストアドレス、もしくはその両方を指定しない場合は、Red Hat Cluster ソフトウェア (特に Cluster Manager cman) がプログラムによって生成します。
cman は、マルチキャストアドレスの上位 16 ビットを 239.192 で形成し、下位 16 ビットをクラスター名のハッシュである cluster ID に基づいて形成します。
Diagnostic Steps
以下は、マルチキャストアドレスを計算するソースコードのセクションです。
family = ainfo->ai_family;
freeaddrinfo(ainfo);
if (family == AF_INET) {
//default multicast address calculate method
snprintf(addr, sizeof(addr), "239.192.%d.%d", cluster_id>> 8, cluster_id % 0xFF);
return addr;
}
if (family == AF_INET6) {
snprintf(addr, sizeof(addr), "ff15::%x", cluster_id);
return addr;
}
以下は同様の表現です (bash スタイルの構文)。
$ cluster_id=39407
$ echo "233.192.$((${cluster_id}/256)).$((${cluster_id}%255))"
233.192.153.137
cluster ID の場合、cman の man ページでは、クラスター名のハッシュから生成されると記載しています。以下は、cluster ID を決定するコードのセクションです (コメント追記)。
注意: Bitwise Operation on wikipedia の情報です。
-
RHEL 5
static uint16_t generate_cluster_id(char *name) { int i; int value = 0; //Step through each ASCII character of the cluster name for (i=0; i<strlen(name); i++) { //binary left-shift 1 place value <<= 1; //Add ASCII char value (A=65, B=66, a=97, b=98,etc) value += name[i]; } //bitwise AND calculate value with 0xFFFF (65535) to keep value <=65535 P_MEMB("Generated cluster id for '%s' is %d\n", name, value & 0xFFFF); return value & 0xFFFF; } -
RHEL 6 は
use_hashed_cluster_id フラグ(プライベート bz#574886) を有効にし、以下の関数を使用して、クラスター id 値を指定します。uint16_t fnv_hash(char *str) { unsigned char *s = (unsigned char *)str; uint32_t hval = FNV_32_INIT; uint32_t ret; /* * FNV-1a hash each octet in the buffer */ while (*s) { /* * xor the bottom with the current octet */ hval ^= (uint32_t)*s++; /* * multiply by the 32 bit FNV magic prime mod 2^32 */ hval *= FNV_32_PRIME; } /* * Use XOR folding as recommended by authors of algorithm * to create a different hash size that is a power of two */ ret = (hval >> 16) ^ (hval & 0xFFFF); return (ret); }
現在の cluster ID は、cman_tool を使用して問い合わせることができます。
# cman_tool status |grep Id
Cluster Id:39407
cluster ID は cluster.conf に指定した ID で上書きできます。
注意: これを変更した場合は、クラスターを完全に再起動する必要があります。
<cman cluster_id="39407"/>
This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.
Welcome! Check out the Getting Started with Red Hat page for quick tours and guides for common tasks.
