天天看點

Saltstack配置管理-業務引用haproxy

[root@linux-node1 ~]# mkdir /srv/salt/prod/cluster/files -p

[root@linux-node1 ~]# cd /srv/salt/prod/cluster/files

[root@linux-node1 files]# ls

haproxy-outside.cfg

[root@linux-node1 files]# cat /srv/salt/prod/cluster/files/haproxy-outside.cfg             ==============================================>haproxy的配置檔案

global

maxconn 100000

chroot /usr/local/haproxy

uid 99  

gid 99 

daemon

nbproc 1 

pidfile /usr/local/haproxy/logs/haproxy.pid 

log 127.0.0.1 local3 info

defaults

option http-keep-alive

mode http

timeout connect 5000ms

timeout client  50000ms

timeout server 50000ms

listen stats

bind 0.0.0.0:8888

stats enable

stats uri     /haproxy-status 

stats auth    haproxy:saltstack

frontend frontend_www_example_com

bind 10.0.0.11:80

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 source                     =========>如果想要輪訓則改為roundrobin

server web-node1  10.0.0.7:8080 check inter 2000 rise 30 fall 15

server web-node2  10.0.0.8:8080 check inter 2000 rise 30 fall 15

[root@linux-node1 cluster]# cat /srv/salt/prod/cluster/haproxy-outside.sls              =====================>業務引用haproxy的檔案

include:                        

  - haproxy.install                 ###################先包含安裝####################

haproxy-service:                    ######################申明id######################

  file.managed:                     ####################檔案管理子產品及方法#############

    - name: /etc/haproxy/haproxy.cfg     ###########指定haproxy的配置檔案##############

    - source: salt://cluster/files/haproxy-outside.cfg    #####salt中的配置檔案#########

    - user: root

    - group: root

    - mode: 644

  service.running:                   #################子產品和方法############              

    - name: haproxy                  ##################名稱#################

    - enable: True                   ###############開機自動啟動###########

    - reload: True                   ###############是否允許重載###########

    - require:                       

      - cmd: haproxy-init            ###########依賴某個腳本#############

    - watch:                         ########監控haproxy-service的file狀态############# 

      - file: haproxy-service        ########監控haproxy-service的file狀态#############

haproxy項目中的top file檔案

[root@linux-node1 files]# cat /srv/salt/base/top.sls 

base:

  '*':

    - init.env_init

prod:

  'linux-node1.example.com':

    - cluster.haproxy-outside

  'linux-node2.example.com':

[root@linux-node1 files]# salt '*' state.highstate                       ###############進階狀态下執行檔案###########################

檢測是否成功:在浏覽器輸入

http://10.0.0.7:8888/haproxy-status

http://10.0.0.8:8888/haproxy-status

使用者名:haproxy         密碼:saltstack

如果能顯示haproxy頁面即可

qq:406564728

     本文轉自陳繼松 51CTO部落格,原文連結:http://blog.51cto.com/chenjisong/1714333,如需轉載請自行聯系原作者

下一篇: NFS服務搭建