简体   繁体   English

跨多台机器进行Wildfly负载平衡

[英]Wildfly load-balancing across multiple machines

I am trying to configure a wildfly server with a load balancer for learning purposes. 我正在尝试使用负载均衡器配置Wildfly服务器以进行学习。 Here's what I got: 这是我得到的:

  • Three VMs, only accessible by their IPs. 三个VM,只能通过其IP访问。
    • One is 152.238.224.58 - my load balancer 一个是152.238.224.58-我的负载均衡器
    • An other one is 152.238.224.59 - my first backend server 另一个是152.238.224.59-我的第一个后端服务器
    • The last one is 152.238.224.60 - my second backend server 最后一个是152.238.224.60-我的第二台后端服务器

I find the wildfly documentation to be rather poor, but after watching Stuart Douglas's explanation on how the load balancer works, I currently have my first VM running a cluster of servers. 我发现wildfly文档非常差,但是在观看了Stuart Douglas对负载均衡器如何工作的解释之后,我目前拥有了第一台运行服务器集群的VM。 Load balancing works, but everything is on the same VM (the first one). 负载平衡有效,但所有内容都在同一台VM(第一个)上。 What I'd rather have is the load balancer acting as a proxy for the two backend servers. 我更希望负载平衡器充当两个后端服务器的代理。

I've tried the method described on the Wildfly documentation but didn't manage to make it work. 我尝试了Wildfly文档中描述的方法,但没有设法使其起作用。

What would I need to do to have the first VM load-balancing across the two second VMs? 要在两个第二个VM之间实现第一个VM负载平衡,我需要做些什么? To go even further, how difficult would it be to have the first VM act as a load-balancer between VM-2 and VM-3, where VM-2 and VM-3 are clusters (would they then have their own load-balancer?)? 更进一步,让第一个VM充当VM-2和VM-3之间的负载平衡器将是多么困难,其中VM-2和VM-3是群集(如果它们具有自己的负载平衡器, ?)?

Thanks a lot for any indication. 非常感谢您的任何指示。

From WildFly version 10.1 there is a load balancer profile as a part of WildFly installation. 从WildFly 10.1版开始,有一个负载平衡器配置文件作为WildFly安装的一部分。 Just use it. 只需使用它。 I'm providing sample steps here (based on my demo scripts for MS Azure ). 我在这里提供示例步骤(基于我的MS Azure演示脚本 )。

Load balancer 负载均衡器

Use the standalone-load-balancer.xml profile for the load balancer. standalone-load-balancer.xml配置文件用于负载均衡器。 WildFly 10.1 has the profile within the examples. 在示例中,WildFly 10.1具有配置文件。 WildFly 11 has it as a standard profile in the configuration directory. WildFly 11在配置目录中将其作为标准配置文件。

WILDFLY_HOME=/path/to/wildfly
# MY_IP=$(ip route get 8.8.8.8 | awk '{print $NF; exit}')
MY_IP=152.238.224.58

# Skip following command in WildFly 11
cp $WILDFLY_HOME/docs/examples/configs/standalone-load-balancer.xml \
    $WILDFLY_HOME/standalone/configuration/

# run the load balancer profile
$WILDFLY_HOME/bin/standalone.sh -b $MY_IP -bprivate $MY_IP -c standalone-load-balancer.xml

This script uses for communication between worker nodes and load balancer public network. 该脚本用于工作节点与负载均衡器公共网络之间的通信。 If you want to use a private network (highly recommended), then set the correct IP address of the balancer for private interface ( -bprivate ). 如果要使用专用网络(强烈建议),请为private接口( -bprivate )设置平衡器的正确IP地址。

Worker nodes 工作节点

Run the server with the HA (or Full HA) profile, which has modcluster component included. 使用具有modcluster组件的HA(或完整HA)配置文件运行服务器。 If the UDP multicast is working in your environment, the workers should work out of the box without any change. 如果UDP多播在您的环境中正常工作,则工作人员应立即进行工作,而无需进行任何更改。 If it's not the case, then configure the IP address of the load-balancer statically. 如果不是这种情况,请静态配置负载均衡器的IP地址。

WILDFLY_HOME=/path/to/wildfly
MY_IP=$(ip route get 8.8.8.8 | awk '{print $NF; exit}')

# Configure static load balancer IP address.
# This is necessary when UDP multicast doesn't work in your environment.
LOAD_BALANCER_IP=152.238.224.58
$WILDFLY_HOME/bin/jboss-cli.sh <<EOT
embed-server -c=standalone-ha.xml
/subsystem=modcluster/mod-cluster-config=configuration:write-attribute(name=advertise,value=false)
/socket-binding-group=standard-sockets/remote-destination-outbound-socket-binding=proxy1:add(host=$LOAD_BALANCER_IP,port=8090)
/subsystem=modcluster/mod-cluster-config=configuration:list-add(name=proxies,value=proxy1)
EOT

# start the woker node with HA profile
$WILDFLY_HOME/bin/standalone.sh -c standalone-ha.xml -b $MY_IP -bprivate $MY_IP

Again, to make it safe, you should configure MY_IP as an address from the private network. 同样,为了确保安全,您应该将MY_IP配置为来自专用网络的地址。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM