Corosync的安全IPTables规则

我有两个运行Corosync和Pacemaker的HA负载均衡器( hollywood和狼人)。 eth1接口连接到WAN, eth0连接到LAN,使用虚拟IP作为后端服务器的网关。 hollywoodeth1 IP为xxx.xxx.195.45wolfmaneth1 IP为xxx.xxx.195.46bindnetaddr中的bindnetaddr是xxx.xxx.195.32 ,与WAN的networking地址相同,Corosync端口是默认的5405

两台服务器上的相关IP表规则是:

 *filter --flush :INPUT DROP --append INPUT --protocol udp --destination-port 5404 --jump ACCEPT --append INPUT --protocol udp --destination-port 5405 --jump ACCEPT 

这个设置似乎工作正常,但最初我添加了--in-interface eth1--source xxx.xxx.195.46wolfman ,并且 – 把--source xxx.xxx.195.45hollywood 。 大多数情况下,这似乎工作,但重新启动被动平衡器有时会中断负载平衡器之间的通信,将这些错误写入syslog:

[TOTEM]由于操作系统或networking故障,Totem无法形成群集。 此消息最常见的原因是本地防火墙configuration不正确。

所以看来,无论我简单地相信所有Corosyncstream量直接在eth1的两个负载均衡器之间是错误的,还是其他问题正在导致问题。

我想locking在IPTables端口5404/5405只是集群。 我需要做些什么才能做到这一点?

按要求编辑: corosync.conf 。 这是除bindnetaddr之外的所有默认Ubuntu。

 # Please read the openais.conf.5 manual page totem { version: 2 # How long before declaring a token lost (ms) token: 3000 # How many token retransmits before forming a new configuration token_retransmits_before_loss_const: 10 # How long to wait for join messages in the membership protocol (ms) join: 60 # How long to wait for consensus to be achieved before starting a new round of membership configuration (ms) consensus: 3600 # Turn off the virtual synchrony filter vsftype: none # Number of messages that may be sent by one processor on receipt of the token max_messages: 20 # Limit generated nodeids to 31-bits (positive signed integers) clear_node_high_bit: yes # Disable encryption secauth: off # How many threads to use for encryption/decryption threads: 0 # Optionally assign a fixed node id (integer) # nodeid: 1234 # This specifies the mode of redundant ring, which may be none, active, or passive. rrp_mode: none interface { # The following values need to be set based on your environment ringnumber: 0 bindnetaddr: xxx.xxx.195.32 mcastaddr: 226.94.1.1 mcastport: 5405 } } amf { mode: disabled } service { # Load the Pacemaker Cluster Resource Manager ver: 0 name: pacemaker } aisexec { user: root group: root } logging { fileline: off to_stderr: yes to_logfile: no to_syslog: yes syslog_facility: daemon debug: off timestamp: on logger_subsys { subsys: AMF debug: off tags: enter|leave|trace1|trace2|trace3|trace4|trace6 } } 

默认情况下,Corosync使用IP多播在节点之间进行通信:

 mcastaddr: 226.94.1.1 mcastport: 5405 

将防火墙configuration为允许多播通信:

 # iptables -A INPUT -p igmp -j ACCEPT # iptables -A INPUT -m addrtype --dst-type MULTICAST -j ACCEPT 

# iptables -A INPUT -p udp -m state --state NEW -m multiport --dports 5404,5405 -j ACCEPT

或切换到单播 。

在使用多播通信(Corosync的默认设置)时,应该允许IGMP通信,允许Corosync数据包使用比其他答案更具体的规则。 以下规则就足够了(假定OUTPUT链不阻止任何stream量):

 iptables -A INPUT -p igmp -i $corosync_interface -j ACCEPT for src_addr in $ip_addr_self $ip_addr_partner1 $ip_addr_partner2; do iptables -A INPUT -i $corosync_interface -s $src_addr -d $ip_addr_self \ -p udp --source-port $(($corosync_port - 1)) \ --destination-port $corosync_port -j ACCEPT iptables -A INPUT -i $corosync_interface -s $src_addr -d $ip_addr_mcast \ -p udp --source-port $(($corosync_port - 1)) \ --destination-port $corosync_port -j ACCEPT done 

在这个例子中,假定以下variables被定义:

  • $corosync_interface :Corosync使用的networking接口
  • $ip_addr_self :Corosync本地绑定的IP地址(在corosync.conf指定为bindnetaddr
  • $ip_addr_partner1$ip_addr_partner2 :其他Corosync节点的IP地址 – 如果集群有三个以上的节点,可以添加更多。
  • $ip_addr_mcast :用于Corosync的多播地址(在corosync.conf指定为mcastaddr
  • $corosync_port :Corosync使用的(目标)端口(在corosync.conf指定为mcastport

在一个节点上,Corosync使用的接口是Open vSwitch网桥的成员端口,其中一些组播数据包在网桥的接口上接收,而不是具有IP地址的组播数据包。 因此,我不得不添加一个允许在这个接口上组播数据包的附加规则:

 for src_addr in $ip_addr_self $ip_addr_partner1 $ip_addr_partner2; do iptables -A INPUT -i $bridge_interface -s $src_addr -d $ip_addr_mcast -p udp --source-port $(($corosync_port - 1)) --destination-port $corosync_port -j ACCEPT done 

如果OUTPUT链默认不接受数据包,则需要添加允许发送IGMPstream量并允许发送Corosync数据包的规则:

 iptables -A OUTPUT -p igmp -o $corosync_interface -j ACCEPT for dst_addr in $ip_addr_self $ip_addr_mcast $ip_addr_partner1 $ip_addr_partner2; do iptables -A OUTPUT o $corosync_interface -s $ip_addr_self -d $dst_addr \ -p udp --source-port $(($corosync_port - 1)) \ --destination-port $corosync_port -j ACCEPT done