創(chuàng)建一個(gè)集群:
mkdir /srv/salt/prod/cluster
把配置放在下面的files里面劣像,
mkdir /srv/salt/prod/cluster/files
cd到files目錄下創(chuàng)建配置文件昂秃,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還沒起來(lái)羡洁,要先寫haproxy的其他相關(guān)配置圈暗,要寫一個(gè)配置文件的管理经伙,一個(gè)是服務(wù)的管理蒲稳,因?yàn)榉?wù)管理依賴配置文件湿酸,而且配置文件每個(gè)業(yè)務(wù)都不一樣胳徽,所以寫在這里积锅。
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
下面要給兩臺(tái)機(jī)器安裝haproxy了爽彤,寫進(jìn)top.sls里面去
vim top.sls
base:
***
prod:
'linux-node1.example.com':
- cluster.haproxy-outside
然后 測(cè)試:
salt '*' state.highstate test=True