私のhaproxy.cfg
global
log 127.0.0.1 local0
maxconn 20000
user haproxy
group haproxy
stats socket /var/run/haproxy/haproxy.sock level admin
stats timeout 2m
listen admin
bind *:8080
stats enable
defaults
log global
mode http
option httplog
option dontlognull
retries 3
option redispatch
# timeout http-request 5s
timeout connect 5000
timeout client 60000
timeout server 60000
frontend http-in
bind *:80
default_backend monkey
backend monkey
stats enable
stats uri /haproxy?stats
stats realm Strictly\ Private
stats auth admin:hello
stats auth Another_User:hi
mode http
compression algo gzip
compression type text/html text/plain text/css application/json
balance roundrobin
option httpclose
option forwardfor
default-server inter 1s fall 1
server cd-test-1 1.2.3.4:80 check
server cd-test-2 5.6.7.8:80 check
HAproxy クラスターからノードを無効にするために socat を使用しています。以下はコマンドです
echo "disable server monkey/cd-test-1"| socat stdio /var/run/haproxy/haproxy.sock
上記は私のノードをhaproxyから無効にします。しかし、「cd-test-1」の代わりに IP アドレス (1.2.3.4) を使用すると、No such server が返されます。
これを自動化するためにansibleを使用しています。{{inventory_hostname}} を使用して、コマンドを HAproxy サーバーに委任します。したがって、問題。
- name: Disable {{ inventory_hostname }} in haproxy and letting the services drain
shell: echo "disable server monkey/{{inventory_hostname}}"| socat stdio /var/run/haproxy/haproxy.sock
become_user: root
delegate_to: "{{ item }}"
with_items: groups.haproxy_backend
これにより、「そのようなサーバーはありません」が返されます。そして一緒に移動します。
サーバー名の代わりに IP を使用する際の問題を誰かが見つけてくれますか。非常にばかげたことをしているかもしれません。どんな助けでも大歓迎です。