saltstack-haproxy业务引用

在上篇文章说了如何去安装haproxy,这里就说一下怎么去应用。

1、和上次一样,仍然把haproxy的配置文件放在/srv/salt/package/haproxy/files/目录下。

wKioL1iG1BOjZIgzAAAO1HMu-94184.png

这里也贴一下配置文件的内容:

wKiom1iG1DzTRgBWAAAqg6vESGQ649.png

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
global                       #全局配置            
maxconn  100000               #最大连接数 
chroot  / usr / local / haproxy
uid  99
gid  99
daemon                       #以后台形式运行haproxy 
nbproc  1                     #启动1个haproxy实例 
pidfile  / usr / local / haproxy / logs / haproxy.pid      #pid存放路径 
log  127.0 . 0.1  local3 info    #日志输出 
#后端设置 
defaults                     #默认配置 
option http - keep - alive
maxconn  100000
mode http                    #所处理的级别.默认采用http模式 
timeout connect  5000ms
timeout client  50000ms
timeout server  50000ms
#开启haproxy Status状态监控,增加验证 
listen stats
mode http
bind  0.0 . 0.0 : 8888
stats enable
stats uri        / haproxy - status      #监控页面url 
stats auth      haproxy:saltstack    #监控页面user:passwd 
#前端设置 
frontend frontend_www_example_com
bind  192.168 . 1.100 : 80
mode http
option httplog
log  global
default_backend backend_www_example_com
#后端设置 
defaults                     #默认配置 
option http - keep - alive
maxconn  100000
mode http                    #所处理的级别.默认采用http模式 
timeout connect  5000ms
timeout client  50000ms
timeout server  50000ms
#开启haproxy Status状态监控,增加验证 
listen stats
mode http
bind  0.0 . 0.0 : 8888
stats enable
stats uri        / haproxy - status      #监控页面url 
stats auth      haproxy:saltstack    #监控页面user:passwd 
#前端设置 
frontend frontend_www_example_com
bind  192.168 . 1.100 : 80
mode http
option httplog
log  global
default_backend backend_www_example_com
#后端设置 
backend backend_www_example_com
option forwardfor header X - REAL - IP   #获得客户端真实ip 
option httpchk HEAD  /  HTTP / 1.0
balance roundrobin                   #轮训算法
server web - node1  192.168 . 1.12 : 8080  check inter  2000  rise  30  fall  15
server web - node2  192.168 . 1.13 : 8080  check inter  2000  rise  30  fall  15

2、编写sls模块文件

在上次的基础上,在后面加上:

wKioL1iG1Xigh-igAAANJYLhZTw028.png

1
2
3
4
5
6
7
8
9
10
11
12
13
haproxy - config:
   file .managed:
     -  name:  / etc / haproxy / haproxy.cfg
     -  source: salt: / / package / haproxy / files / haproxy.cfg
     -  user: root
     -  group: root
     -  mode:  644
   service.running:
     -  name: haproxy
     -  enable:  True
     -  reload True
     -  watch:
       -  file : haproxy - config

3、执行命令:

1
salt  'salt-minion'  state.sls package.haproxy

wKioL1iG1fniFA0kAAAclhYRVOg784.png

中间可以看到更新的内容:

wKiom1iG1fiD95DWAAALtGdFwZU401.png

4、验证

wKiom1iG1fjCv6YxAAAKczZLz2w234.png



本文转自 sykmiao 51CTO博客,原文链接:http://blog.51cto.com/syklinux/1894024,如需转载请自行联系原作者

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值