[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
maxconn 100000
mode http
timeout connect 5000ms
timeout client 50000ms
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-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‘:
- cluster.haproxy-outside
[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页面即可
老男孩网址:http://www.etiantian.org
qq:406564728
欢迎交流
本文出自 “linux” 博客,请务必保留此出处http://chenjisong.blog.51cto.com/7858025/1714333
原文地址:http://chenjisong.blog.51cto.com/7858025/1714333