而微软 发表于 2015-11-19 09:25:54

Saltstack配置管理-业务引用haproxy

# mkdir /srv/salt/prod/cluster/files -p
# cd /srv/salt/prod/cluster/files
# ls
haproxy-outside.cfg
# 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
maxconn 100000
mode http
timeout connect 5000ms
timeout client50000ms
timeout server 50000ms

listen stats
mode http
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
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 source                     =========>如果想要轮训则改为roundrobin
server web-node110.0.0.7:8080 check inter 2000 rise 30 fall 15
server web-node210.0.0.8:8080 check inter 2000 rise 30 fall 15


# 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文件
# cat /srv/salt/base/top.sls
base:
'*':
    - init.env_init

prod:
'linux-node1.example.com':
    - cluster.haproxy-outside
'linux-node2.example.com':
    - cluster.haproxy-outside

# salt '*' state.highstate                     ###############高级状态下执行文件###########################

检测是否成功:在浏览器输入
http://10.0.0.7:8888/haproxy-status
http://10.0.0.8:8888/haproxy-status
用户名:haproxy         密码:saltstack
如果能显示haproxy页面即可


页: [1]
查看完整版本: Saltstack配置管理-业务引用haproxy