標籤:saltstack haproxy
[[email protected] ~]# mkdir /srv/salt/prod/cluster/files -p
[[email protected] ~]# cd /srv/salt/prod/cluster/files
[[email protected] files]# ls
haproxy-outside.cfg
[[email protected] 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
[[email protected] 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檔案
[[email protected] 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
[[email protected] 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
Saltstack組態管理-業務引用haproxy