saltstack业务引用

创建一个集群:
mkdir /srv/salt/prod/cluster
把配置放在下面的files里面,
mkdir /srv/salt/prod/cluster/files
cd到files目录下创建配置文件,cd /srv/salt/prod/cluster/files

vim haproxy-outsiade.cfg

global
maxconn 100000
chroot /usr/local/haproxy
uid 99
gid 99
 daemon
nbproc 1
pidfile /usr/local/happroxy/logs/haproxy.pid
log 127.0.0.1 local info

defaults
option http-keep-alive
maxconn 100000
mode http
timeout connect 5000ms
timeout client 50000ms
timeout server 50000ms

listen stats
mode http
bind 0.0.0.0:8888
state enable
stats uri /haproxy-status
stats auth  haproxy:saltstack

frontend frontend_www_example_com
bind 10.0.0.11:80  #还没有安装keepalive先随便写
mode http
option httplog
log global
    default_backend_www_example_com

backend backend_www_example_com
option forwardfor header X-REAL-IP
option httpchk HEAD / HTTP/1.0
balance source
server web-node1 10.0.0.7:8080 check inter 2000 rise 30 fall 15
server web-node1 10.0.0.8:8080 check inter 2000 rise 30 fall 15

haproxy还没起来,要先写haproxy的其他相关配置,要写一个配置文件的管理,一个是服务的管理,因为服务管理依赖配置文件,而且配置文件每个业务都不一样,所以写在这里。

cd /srv/salt/prod/cluster
vim *haproxy-outside.sls
include:
  - haproxy.install
happroxy-service:
  file.managed:
    - name: /etc/haproxy/haproxy.cfg
    - source: salt://cluster/files/haproxy-outside.cfg
    - group: root
    - mode: 644
  service.running:
    - name: haproxy
    - enable: True
    - reload: True
    - require:
      - cmd: haproxy-init
    - watch:
      - file: haproxy-service

下面要给两台机器安装haproxy了,写进top.sls里面去

vim top.sls
base:
  ***
prod:
  'linux-node1.example.com':
    - cluster.haproxy-outside

然后 测试:
salt '*' state.highstate test=True

你可能感兴趣的:(saltstack业务引用)