大网数据广告活动
服务器运维问答

(Pacemaker) Nginx uses primary IP address instead of virtual IP to communicate with web servers

· 52CE 我爱测

I have set up a two-node cluster (active/passive) with Corosync/Pacemaker and nginx as a reverse proxy. OS is RHEL7 and the machine has only one network interface at the moment. I configured two resources: cluster-vip for the sha…

问题原文

原帖链接 · Litame · CC BY-SA 3.0

I have set up a two-node cluster (active/passive) with Corosync/Pacemaker and nginx as a reverse proxy. OS is RHEL7 and the machine has only one network interface at the moment.

I configured two resources:

  • cluster-vip for the shared virtual IP
  • reverse-proxy for nginx

Here are the declarations of both resources:

pcs resource create cluster-vip ocf:heartbeat:IPaddr2 ip=192.168.0.1 cidr_netmask=24 op monitor interval=30s

pcs resource create reverse-proxy systemd:nginx op monitor interval=5s meta failure-timeout=60s

pcs constraint colocation add reverse-proxy with cluster-vip INFINITY

pcs constraint order cluster-vip then reverse-proxy

Yesterday, I spotted an unexpected behaviour while doing a network capture. When communicating with the clients, the active node uses the virtual IP address (192.168.0.1). When communicating with the web servers located on the internal network, it uses the primary IP address of the interface instead of the vip (192.168.0.2 or 192.168.0.3 depending on the active node).

As a result, I am forced to create two different rules on my firewall (one for node1 and one for node2) instead of just allowing the vip to communicate with the web servers. I plan to add other nodes to the cluster, and it would be convenient not to have to allow every single node one by one and just allow the vip once and for all.

Does this behaviour have a logical explanation? Is there a way to tell pacemaker to only use the vip? And is it good practice? I don't want to do anything stupid, so if you think I should not do that, I would gladly hear why.

Regards

已采纳解答

原帖链接 · Dok · CC BY-SA 3.0

I don't believe this is a question of instructing pacemaker to only use the virtual IP, but rather telling Nginx to only use the virtual IP.

I am no Nginx expert, but reading through their documentation I found a configuration directive named proxy_bind. I believe this might be what you need to set to get the desired behaviour. From the Nginx documentation here.

If your proxy server has several network interfaces, sometimes you might need to choose a particular source IP address for connecting to a proxied server or an upstream. This may be useful if a proxied server behind NGINX is configured to accept connections from particular IP networks or IP address ranges.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2016-05-09)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。