root privilege.
SO_BINDTODEVICE socket option is used for binding sockets to network
devices and requires root privilege. However, this is not essential
for the lifecheck mechanism itself, so we use this function only when
pgpool-II has root privilege.
If pgpool-II has root privilege, log message says like;
wd_create_hb_recv_socket: bind receive socket to device :eth0
otherwise,
is_usable_bindtodevice: setsockopt(SO_BINDTODEVICE) requires root privilege
wd_create_hb_recv_socket: couldn't bind receive socket to device :eth0
</p>
<ul>
<li>
- In heartbeat mode, watchdog monitors other pgpool-II process by using heartbeat signal.
+ In heartbeat mode, watchdog monitors other pgpool-II processes by using heartbeat signal.
Watchdog receives heartbeat signals sent by other pgpool-II periodically.
- If there are no signal for a certain period, watchdog regards it as failure of the pgpool-II.
- For redundancy you can use multiple network interface devices for heartbeat exchange between pgpool-IIs.
- This mode is default and recommended one.
+ If there are no signal for a certain period, watchdog regards this as failure of the pgpool-II.
+ For redundancy you can use multiple network connections for heartbeat exchange between pgpool-IIs.
+ This is the default mode and recommended.
</li>
<li>
In query mode, watchdog monitors pgpool-II's service rather than process.
</p>
</dd>
-<dt><a name="HEARTBEAT_DEVICE"></a>heartbeat_device<font color="red">0</font> <span class="version">V3.3 -</span></dt>
+<dt><a name="HEARTBEAT_DESTINATION"></a>heartbeat_destination<font color="red">0</font> <span class="version">V3.3 -</span></dt>
<dd>
<p>
- This option specifies the network device name for sending heartbeat signals.
- You can use multiple devices.
- The number at the end of the parameter name is referred as "device number",
+ This option specifies the destination of heartbeat signals bu IP address or hostname.
+ You can use multiple destination.
+ The number at the end of the parameter name is referred as "destination number",
and it starts from 0.
- If you want to set mutiple destination (<a href="HEARTBEAT_DESTINATION">heartbeat_destiationN</a>) for one device,
- specify the device name repeatedly using different numbers.
This works only heartbeat mode.
</p>
<p>
</p>
</dd>
-<dt><a name="HEARTBEAT_DESTINATION"></a>heartbeat_destination<font color="red">0</font> <span class="version">V3.3 -</span></dt>
+<dt><a name="HEARTBEAT_DESTINATION_PORT"></a>heartbeat_destination_port<font color="red">0</font> <span class="version">V3.3 -</span></dt>
<dd>
<p>
- This option specifies the destination of heartbeat signals which is sent from the device specified by
- <a href="HEARTBEAT_DEVICE">heartbeat_deviceX</a>. Use IP address or hostname.
- The number at the end of the parameter name is referred as "device number",
+ This option specifies the port number of destination of heartbeat signals
+ which is specified by <a href="HEARTBEAT_DESTINATION">heartbeat_destinationX</a>.
+ This is usually the same value as <a href="WD_HEARTBEAT_PORT">wd_heartbeat_port</a>
+ You must use another value if the port number is unusable on a certain host or
+ there are more than two pgpool-IIs in a host.
+ The number at the end of the parameter name is referred as "destination number",
and it starts from 0.
This works only heartbeat mode.
</p>
</p>
</dd>
-<dt><a name="HEARTBEAT_DESTINATION_PORT"></a>heartbeat_destination_port<font color="red">0</font> <span class="version">V3.3 -</span></dt>
+<dt><a name="HEARTBEAT_DEVICE"></a>heartbeat_device<font color="red">0</font> <span class="version">V3.3 -</span></dt>
<dd>
<p>
- This option specifies the port number of destination of heartbeat signals which is sent from the device specified by
- <a href="HEARTBEAT_DEVICE">heartbeat_deviceX</a>.
- This is usually the same value of <a href="WD_HEARTBEAT_PORT">wd_heartbeat_port</a>
- You must set another value if the port number is unusable or there are more than two pgpool-IIs in a host.
- The number at the end of the parameter name is referred as "device number",
+ This option specifies the network device name for sending heartbeat signals to
+ destination specified by <a href="HEARTBEAT_DESTINATION">heartbeat_destinationX</a>.
+ You can use the same device for different distinations.
+ The number at the end of the parameter name is referred as "destination number",
and it starts from 0.
This works only heartbeat mode.
+ In addition, this works only when pgpool-II has root privilege and are running on Linux,
+ because this uses SO_BINDTODEVICE socket option.
</p>
<p>
You need to restart pgpool-II if you change this value.
</p>
</dd>
</dl>
-</dl>
<h4>Configuration of query mode</h4>
<ul>
<li>
ハートビートモードでは、watchdog はハートビート信号を用いて 他の pgpool-II プロセスの死活監視を行います。
- watchdog は、他の pgpool-II の watchdog より定期的に送られるハートビート信号を受け取り、これが一定期間以上途切れた場合にはその pgpool-II プロセスに障害が発生したと判断します。
- å\86\97é\95·æ\80§ã\82\92é«\98ã\82\81ã\82\8bã\81\9fã\82\81ã\80\81è¤\87æ\95°ã\81®ã\83\8dã\83\83ã\83\88ã\83¯ã\83¼ã\82¯ã\82¤ã\83³ã\82¿ã\83\95ã\82§ã\83¼ã\82¹ã\83\87ã\83\90ã\82¤ã\82¹を用いたハートビート交換が可能です。
+ watchdog は、他の pgpool-II の watchdog より定期的に送られるハートビート信号を受け取り、これが一定期間以上途切れた場合には当該 pgpool-II プロセスに障害が発生したと判断します。
+ å\86\97é\95·æ\80§ã\82\92é«\98ã\82\81ã\82\8bã\81\9fã\82\81ã\81«ã\80\81è¤\87æ\95°ã\81®ã\83\8dã\83\83ã\83\88ã\83¯ã\83¼ã\82¯を用いたハートビート交換が可能です。
デフォルトではこのモードで動作し、これが推奨設定です。
</li>
<li>
</p>
</dd>
-<dt><a name="HEARTBEAT_DEVICE"></a>heartbeat_device<font color="red">0</font> <span class="version">V3.3 ~</span></dt>
+<dt><a name="HEARTBEAT_DESTINATION"></a>heartbeat_destination<font color="red">0</font> <span class="version">V3.3 ~</span></dt>
<dd>
<p>
- ハートビートの送受信に用いるネットワークデバイス名を指定します。
- 複数のデバイスが設定可能です。
- 数値の部分はデバイスの番号です。
- デバイス毎に 0 からの連番にします。
- 1つのデバイスに複数のハートビート送信先(<a href="HEARTBEAT_DESTINATION">heartbeat_destiationN</a>)を設定する場合は、重複するデバイス名を異なる番号で指定してください。
+ ハートビート信号の送り先を、ホスト名か IP で指定します。
+ 複数の送り先が指定可能です。
+ 数値の部分は送り先の番号です。0 からの連番にします。
ハートビートモードの場合のみ有効です。
</p>
<p>
</p>
</dd>
-<dt><a name="HEARTBEAT_DESTINATION"></a>heartbeat_destination<font color="red">0</font> <span class="version">V3.3 ~</span></dt>
+<dt><a name="HEARTBEAT_DESTINATION_PORT"></a>heartbeat_destination_port<font color="red">0</font> <span class="version">V3.3 ~</span></dt>
<dd>
<p>
- <a href="HEARTBEAT_DEVICE">heartbeat_deviceX</a>に指定したデバイスから送るハートビート信号の宛先を、ホスト名か IP で指定します。
- 数値の部分はデバイスの番号です。
- デバイス毎に 0 からの連番にします。
+ <a href="HEARTBEAT_DESTINATION">heartbeat_destinationX</a>に指定したハートビート信号の送り先のポート番号を指定します。
+ 通常は <a href="WD_HEARTBEAT_PORT">wd_heartbeat_port</a> と同じ値を指定します。
+ そのポート番号が使用できないホストや、同じホストで複数の pgpool-II を動作させる場合には、異なる値を指定する必要があります。
+ 数値の部分は送り先の番号です。0 からの連番にします。
ハートビートモードの場合のみ有効です。
</p>
<p>
</p>
</dd>
-<dt><a name="HEARTBEAT_DESTINATION_PORT"></a>heartbeat_destination_port<font color="red">0</font> <span class="version">V3.3 ~</span></dt>
+<dt><a name="HEARTBEAT_DEVICE"></a>heartbeat_device<font color="red">0</font> <span class="version">V3.3 ~</span></dt>
<dd>
<p>
- <a href="HEARTBEAT_DEVICE">heartbeat_deviceX</a>に指定したデバイスから送るハートビート信号の宛先のポート番号を指定します。
- 通常は <a href="WD_HEARTBEAT_PORT">wd_heartbeat_port</a> と同じ値を指定します。
- そのポート番号が使用できないホストや、同じホストで複数の pgpool-II を動作させる場合には、異なる値を指定する必要があります。
- 数値の部分はデバイスの番号です。
- デバイス毎に 0 からの連番にします。
+ <a href="HEARTBEAT_DESTINATION">heartbeat_destinationX</a>に指定した送り先とのハートビートの送受信に用いるネットワークデバイス名を指定します。
+ 数値の部分は送り先の番号です。デバイス毎に 0 からの連番にします。
+ 複数の異なる送り先に同じデバイスを設定することが可能です。
ハートビートモードの場合のみ有効です。
+ また、SO_BINDTODEVICE ソケットオプションを使用しているため、pgpool-II が Linux で root 権限で起動している場合のみ有効です。
</p>
<p>
このパラメータを変更した時には pgpool-II を再起動してください。
wd_heartbeat_deadtime = 30
# Deadtime interval for heartbeat signal (sec)
# (change requires restart)
-heartbeat_device0 = 'eth0'
- # Name of NIC device 0 using for
- # sending/receiving heartbeat signal
- # (change requires restart)
-heartbeat_destination_ip0 = 'host0_ip1'
- # Destination host name or IP address
- # for sending heartbeat signal using NIC device 0.
+heartbeat_destination = 'host0_ip1'
+ # Host name or IP address of destination 0
+ # for sending heartbeat signal.
# (change requires restart)
heartbeat_destination_port0 = 9694
- # Destination port number for sending heartbeat
- # signal to destination 0. Usually this is the
- # same of wd_heartbeat_port.
+ # Port number of destination 0 for sending
+ # heartbeat signal. Usually this is the
+ # same as wd_heartbeat_port.
# (change requires restart)
-#heartbeat_device1 = 'eth1'
+heartbeat_device0 = 'eth0'
+ # Name of NIC device using for
+ # sending/receiving heartbeat signal
+ # to/from destination 0.
+ # This works only when pgpool has root privilege.
+ # (change requires restart)
+
#heartbeat_destination_ip1 = 'host0_ip2'
#heartbeat_destination_port1 = 9694
+#heartbeat_device1 = 'eth1'
# -- query mode --
wd_heartbeat_deadtime = 30
# Deadtime interval for heartbeat signal (sec)
# (change requires restart)
-heartbeat_device0 = 'eth0'
- # Name of NIC device 0 using for
- # sending/receiving heartbeat signal
- # (change requires restart)
-heartbeat_destination0 = 'host0_ip1'
- # Destination host name or IP address
- # for sending heartbeat signal using NIC device 0.
+heartbeat_destination = 'host0_ip1'
+ # Host name or IP address of destination 0
+ # for sending heartbeat signal.
# (change requires restart)
heartbeat_destination_port0 = 9694
- # Destination port number for sending heartbeat
- # signal to destination 0. Usually this is the
- # same of wd_heartbeat_port.
+ # Port number of destination 0 for sending
+ # heartbeat signal. Usually this is the
+ # same as wd_heartbeat_port.
# (change requires restart)
-#heartbeat_device1 = 'eth1'
-#heartbeat_destination1 = 'host0_ip2'
+heartbeat_device0 = 'eth0'
+ # Name of NIC device using for
+ # sending/receiving heartbeat signal
+ # to/from destination 0.
+ # This works only when pgpool has root privilege.
+ # (change requires restart)
+
+#heartbeat_destination_ip1 = 'host0_ip2'
#heartbeat_destination_port1 = 9694
+#heartbeat_device1 = 'eth1'
# -- query mode --
wd_heartbeat_deadtime = 30
# Deadtime interval for heartbeat signal (sec)
# (change requires restart)
-heartbeat_device0 = 'eth0'
- # Name of NIC device 0 using for
- # sending/receiving heartbeat signal
- # (change requires restart)
-heartbeat_destination0 = 'host0_ip1'
- # Destination host name or IP address
- # for sending heartbeat signal using NIC device 0.
+heartbeat_destination = 'host0_ip1'
+ # Host name or IP address of destination 0
+ # for sending heartbeat signal.
# (change requires restart)
heartbeat_destination_port0 = 9694
- # Destination port number for sending heartbeat
- # signal to destination 0. Usually this is the
- # same of wd_heartbeat_port.
+ # Port number of destination 0 for sending
+ # heartbeat signal. Usually this is the
+ # same as wd_heartbeat_port.
# (change requires restart)
-#heartbeat_device1 = 'eth1'
-#heartbeat_destination1 = 'host0_ip2'
+heartbeat_device0 = 'eth0'
+ # Name of NIC device using for
+ # sending/receiving heartbeat signal
+ # to/from destination 0.
+ # This works only when pgpool has root privilege.
+ # (change requires restart)
+
+#heartbeat_destination_ip1 = 'host0_ip2'
#heartbeat_destination_port1 = 9694
+#heartbeat_device1 = 'eth1'
# -- query mode --
wd_heartbeat_deadtime = 30
# Deadtime interval for heartbeat signal (sec)
# (change requires restart)
-heartbeat_device0 = 'eth0'
- # Name of NIC device 0 using for
- # sending/receiving heartbeat signal
- # (change requires restart)
-heartbeat_destination0 = 'host0_ip1'
- # Destination host name or IP address
- # for sending heartbeat signal using NIC device 0.
+heartbeat_destination = 'host0_ip1'
+ # Host name or IP address of destination 0
+ # for sending heartbeat signal.
# (change requires restart)
heartbeat_destination_port0 = 9694
- # Destination port number for sending heartbeat
- # signal to destination 0. Usually this is the
- # same of wd_heartbeat_port.
+ # Port number of destination 0 for sending
+ # heartbeat signal. Usually this is the
+ # same as wd_heartbeat_port.
# (change requires restart)
-#heartbeat_device1 = 'eth1'
-#heartbeat_destination1 = 'host0_ip2'
+heartbeat_device0 = 'eth0'
+ # Name of NIC device using for
+ # sending/receiving heartbeat signal
+ # to/from destination 0.
+ # This works only when pgpool has root privilege.
+ # (change requires restart)
+
+#heartbeat_destination_ip1 = 'host0_ip2'
#heartbeat_destination_port1 = 9694
+#heartbeat_device1 = 'eth1'
# -- query mode --
return(-1);
}
if (context == INIT_CONFIG || (context == RELOAD_CONFIG ))
- {
strlcpy(WD_HB_IF(slot).if_name, str, WD_MAX_IF_NAME_LEN);
- pool_config->num_hb_if = slot + 1;
- }
}
/* this must be prior to hertbeat_destination */
}
if (context == INIT_CONFIG || (context == RELOAD_CONFIG ))
+ {
WD_HB_IF(slot).dest_port = atoi(yytext);
+ pool_config->num_hb_if = slot + 1;
+ }
}
else if (!strncmp(key, "heartbeat_destination", 21) &&
CHECK_CONTEXT(INIT_CONFIG|RELOAD_CONFIG, context) &&
return(-1);
}
if (context == INIT_CONFIG || (context == RELOAD_CONFIG ))
- {
strlcpy(WD_HB_IF(slot).if_name, str, WD_MAX_IF_NAME_LEN);
- pool_config->num_hb_if = slot + 1;
- }
}
/* this must be prior to hertbeat_destination */
}
if (context == INIT_CONFIG || (context == RELOAD_CONFIG ))
+ {
WD_HB_IF(slot).dest_port = atoi(yytext);
+ pool_config->num_hb_if = slot + 1;
+ }
}
else if (!strncmp(key, "heartbeat_destination", 21) &&
CHECK_CONTEXT(INIT_CONFIG|RELOAD_CONFIG, context) &&
static int hton_wd_hb_packet(WdHbPacket * to, WdHbPacket * from);
static int ntoh_wd_hb_packet(WdHbPacket * to, WdHbPacket * from);
static int packet_to_string_hb(WdHbPacket pkt, char *str, int maxlen);
+static bool is_usable_bindtodevice(void);
/* create socket for sending heartbeat */
int
close(sock);
return -1;
}
-/*
-#if defined(SO_BINDTODEVICE)
+
+ if (is_usable_bindtodevice())
{
struct ifreq i;
strlcpy(i.ifr_name, hb_if.if_name, sizeof(i.ifr_name));
}
pool_log("wd_create_hb_send_socket: bind send socket to device: %s", i.ifr_name);
}
-#endif
-*/
+ else
+ pool_log("wd_create_hb_send_socket: couldn't bind send socket to device: %s", hb_if.if_name);
+
#if defined(SO_REUSEPORT)
{
int one = 1;
close(sock);
return -1;
}
-/*
-#if defined(SO_BINDTODEVICE)
+
+ if (is_usable_bindtodevice())
{
struct ifreq i;
strlcpy(i.ifr_name, hb_if.if_name, sizeof(i.ifr_name));
}
pool_log("wd_create_hb_recv_socket: bind receive socket to device: %s", i.ifr_name);
}
-#endif
-*/
+ else
+ pool_log("wd_create_hb_recv_socket: couldn't bind receive socket to device: %s", hb_if.if_name);
#if defined(SO_REUSEPORT)
{
if (fcntl(sock, F_SETFD, FD_CLOEXEC) < 0) {
pool_error("wd_create_hb_recv_socket: setting close-on-exec flag failed. reason: %s",
- strerror(errno));
- close(sock);
- return -1;
- }
+ strerror(errno)); close(sock); return -1; }
return sock;
}
}
/* fork heartbeat receiver child */
-pid_t wd_hb_receiver(int fork_wait_time, WdHbIf hb_if)
+pid_t
+wd_hb_receiver(int fork_wait_time, WdHbIf hb_if)
{
int sock;
pid_t pid = 0;
}
/* fork heartbeat sender child */
-pid_t wd_hb_sender(int fork_wait_time, WdHbIf hb_if)
+pid_t
+wd_hb_sender(int fork_wait_time, WdHbIf hb_if)
{
int sock;
pid_t pid = 0;
}
/* convert packet to string and return length of the string */
-static int packet_to_string_hb(WdHbPacket pkt, char *str, int maxlen)
+static int
+packet_to_string_hb(WdHbPacket pkt, char *str, int maxlen)
{
int len;
len = snprintf(str, maxlen, "status=%d tv_sec=%ld tv_usec=%ld from=%s",
return len;
}
+
+static bool
+is_usable_bindtodevice(void)
+{
+#if defined(SO_BINDTODEVICE)
+ if (geteuid() != 0)
+ {
+ pool_log("is_usable_bindtodevice: setsockopt(SO_BINDTODEVICE) requies root privilege");
+ return false;
+ }
+ else
+ {
+ return true;
+ }
+#else
+ pool_log("is_usable_bindtodevice: couldn't setsockopt(SO_BINDTODEVICE) in this platform");
+ return false;
+#endif
+}