[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
- 第一章:saltstack的基本介紹
- 第二章:saltstack的安裝部署
- 第一節:在centos7系統上安裝saltstack工具
- 第二節:在windows server 2008上安裝salt-minion
- 第三章: saltstack的配置管理
- 第一節:salt-master配置
- 第二節:salt-minion配置
- 第三節:了解YAML
- 第四節:salt-master配置文件詳解
- 第五節:了解Jinja2
- 第六節:配置普通用戶可以運行saltstack的模塊
- 第四章:遠程執行
- 第一節:遠程執行基礎介紹
- 第二節:目標定位
- 一、全局及正則表達式匹配
- 二、列表匹配
- 三、Grains
- 四: Pillar
- 五:subnet and ip
- 六:組合匹配
- 七: node group
- 第三節:常用模塊
- 一、查看幫助
- 二、Network模塊
- 三、Service模塊
- 四:State模塊
- 五、Cron模塊
- 六、File模塊
- 七、iptables模塊
- 八、pkg包管理
- 第四節:Salt其他命令
- 一、salt-cp(拷貝文件)
- 二、salt-ssh
- 三、salt-key
- 第五節:saltstack返回程序
- 第一節:返回保持到數據庫(mysql)
- 第五章:配置管理
- 第一節:簡單入門
- 第二節:狀態間關系
- 第六章:數據系統
- 第一節:grains
- 第二節:pillar
- 第七章:saltstack配置管理
- 第一節:系統初始化操作
- 第二節:功能模塊
- 一、haproxy模塊
- 二、keepalived模塊
- 三、nginx模塊
- 四: pcre模塊
- 五: zlib模塊
- 六:user模塊
- 七:php模塊
- 第三節:業務模塊
- 第一節:haproxy代理
- 第二節:keepalived業務
- 第八章:自動化管理工具saltstack
- 第一節:文件管理
- 第二節:軟件管理
- 第三節:服務管理
- 第四節:sysctl模塊管理