🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
[admin@master ~]$ sudo mkdir /srv/salt/prod/cluster 1) 编写配置文件 [admin@master ~]$ sudo mkdir /srv/salt/prod/cluster/files ~~~ [admin@master files]$ cat haproxy-outside.cfg global log 127.0.0.1 local2 chroot /usr/local/haproxy pidfile /usr/local/haproxy/haproxy.pid maxconn 100000 daemon nbproc 1 defaults option http-keep-alive maxconn 100000 mode http log global option httplog timeout http-request 10s timeout queue 1m timeout connect 10s timeout client 1m timeout server 1m timeout http-keep-alive 10s timeout check 10s ######################################################### listen status mode http bind *:8888 stats enable stats hide-version stats uri /haproxy-status stats auth haproxy:saltstack stats admin if TRUE stats realm Haproxy\ Statistics #stats scope . #--------------------------------------------------------------------- # main frontend which proxys to the backends #--------------------------------------------------------------------- #frontend main *:5000 # acl url_static path_beg -i /static /images /javascript /stylesheets # acl url_static path_end -i .jpg .gif .png .css .js # # use_backend static if url_static # default_backend app #--------------------------------------------------------------------- ###################################################################### frontend frontend_www_example_com bind 10.2.11.170:80 mode http option httplog log global default_backend backend_www_example_com ####################################################### backend backend_www_example_com option forwardfor header X-REAL-IP option httpchk HEAD / HTTP/1.0 balance roundrobin server web01.51yuki.cn 10.2.11.207:8080 check inter 2000 rise 30 fall 15 server web02.51yuki.cn 10.2.11.206:8080 check inter 2000 rise 30 fall 15 ~~~ 2)编写sls文件 ~~~ [admin@master cluster]$ sudo vim haproxy-outside.sls include: - haproxy.install_ha haproxy-service: file.managed: - name: /etc/haproxy/haproxy.cfg - source: salt://cluster/files/haproxy-outside.cfg - user: root - group: root - mode: 644 service.running: - name: haproxy - enable: True - reload: True - require: - cmd: haproxy-init - watch: - file: haproxy-service ~ ~~~ 最好编写top.sls文件 [admin@master base]$ sudo vim top.sls base: "*": - init.env_init prod: "proxy01.test.com" - cluster.haproxy-outside "proxy02.test.com" - cluster.haproxy-outside 执行 [admin@master base]$ sudo salt '*' state.highstate