【问题标题】:How pass a list of my vagrant virtual machines to my haproxy.cfg using chef templates?如何使用厨师模板将我的流浪虚拟机列表传递给我的 haproxy.cfg?
【发布时间】:2016-08-06 03:13:55
【问题描述】:

我有两个 vagrant 虚拟机,每个虚拟机都有自己的私有 IP 地址。我希望能够使用模板将虚拟机作为厨师食谱中的服务器列表传递。

haproxy.cfg.erb

那是我的 haproxy.cfg.erb 没有默认和全局部分。我的每个 vagrant vm 都有一个在 vagrant 文件中定义的私有 ip。如果我尝试卷曲 loadbalacer 的 ip,则会引发 503 错误

503 服务不可用

没有可用于处理此请求的服务器。

【问题讨论】:

  • 不确定你在问什么。你的意思是如何在 Ruby 中创建一个字符串数组?
  • frontend http-in bind *:80 default_backend http-backend backend http-backend mode http stats enable stats uri /haproxy?stats balance roundrobin option httpclose option forwardfor http-check expect status 200 服务器 :80 check
  • 那是我的 haproxy.cfg.erb...我的每个 vagrant 节点都有一个私有 ip,我的负载均衡器也是如此。现在,当我尝试卷曲我的负载均衡器 ip 时,它会抛出 503 错误
  • 为什么要重新发明轮子?您是否尝试过使用 haproxy 社区食谱?它可以根据节点标签和其他属性来管理服务器列表。 github.com/hw-cookbooks/haproxy
  • 我的 vagrant VM 有私有 ip。不知何故,我无法在我的模板中获得正确的 ip,node.ipaddress 是 ohai 地址

标签: chef-infra haproxy


【解决方案1】:

如果在 vagrant VM 中使用 ifconfig 可以查看分配的私有 IP:-

[vagrant@default-centos ~]$ ifconfig
enp0s3: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
    inet 10.0.2.15  netmask 255.255.255.0  broadcast 10.0.2.255
    inet6 fe80::a00:27ff:fec3:36f0  prefixlen 64  scopeid 0x20<link>
    ether 08:00:27:c3:36:f0  txqueuelen 1000  (Ethernet)
    RX packets 37365  bytes 48794691 (46.5 MiB)
    RX errors 0  dropped 0  overruns 0  frame 0
    TX packets 6475  bytes 549951 (537.0 KiB)
    TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

enp0s8: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
    inet 192.168.13.101  netmask 255.255.255.0  broadcast 192.168.13.255
    inet6 fe80::a00:27ff:fe1a:2ec5  prefixlen 64  scopeid 0x20<link>
    ether 08:00:27:1a:2e:c5  txqueuelen 1000  (Ethernet)
    RX packets 17  bytes 1948 (1.9 KiB)
    RX errors 0  dropped 0  overruns 0  frame 0
    TX packets 35  bytes 5197 (5.0 KiB)
    TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

那么分配的私有ip地址就可以被OHAI访问了,比如:-

node[:network][:interfaces][:enp0s8][:addresses].detect{|k,v| v[:family] == "inet" }.first

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-12-11
    • 1970-01-01
    • 1970-01-01
    • 2013-11-03
    • 2021-07-16
    • 1970-01-01
    • 1970-01-01
    • 2021-07-26
    相关资源
    最近更新 更多