??????дStates
/srv/salt/lvs/loadblance.sls
# config lvs
{% if 'lvs-loadblance' in pillar %}
{% for each_lvs in pillar['lvs-loadblance'] %}
# config lvs vip
{{each_lvs['name']}}-vip:
network.managed:
- name: {{each_lvs['vip-nic'] + ":" + each_lvs['name']}}
- enable: True
- type: eth
- proto: none
- ipaddr: {{each_lvs['vip']}}
- netmask: 255.255.255.255
{% set service_address = each_lvs['vip'] + ":" + each_lvs['port']|string() %}
{{each_lvs['name']}}-service:
lvs_service.present:
- protocol: {{each_lvs['protocol']}}
- service_address: {{service_address}}
- scheduler: {{each_lvs['scheduler']}}
{% for each_rs in each_lvs['realservers'] %}
{% set server_address = each_rs['ip'] + ":" + each_rs['port']|string() %}
{{each_rs['name']}}-server:
lvs_server.present:
- protocol: {{each_lvs['protocol']}}
- service_address: {{service_address}}
- server_address: {{server_address}}
- packet_forward_method: {{each_rs['packet_forward_method']}}
- weight: {{each_rs['weight']}}
{% endfor %}
{% endfor %}
{% endif %}
/srv/salt/lvs/realserver.sls
# ignore arp
net.ipv4.conf.all.arp_ignore:
sysctl.present:
- value: 1
net.ipv4.conf.lo.arp_ignore:
sysctl.present:
- value: 1
net.ipv4.conf.all.arp_announce:
sysctl.present:
- value: 2
net.ipv4.conf.lo.arp_announce:
sysctl.present:
- value: 2
# config lvs vip
{% if 'lvs-realserver' in pillar %}
{% for each_lvs in pillar['lvs-realserver'] %}
lvs-vip:
network.managed:
- name: {{"lo" + ":" + each_lvs['name']}}
- enable: True
- type: eth
- proto: none
- ipaddr: {{each_lvs['vip']}}
- netmask: 255.255.255.255
{% endfor %}
{% endif %}
/srv/salt/top.sls
base:
'lvs':
- lvs.loadblance
'web-0*':
- lvs.realserver
???????????
????????????? ????LVS??? ????????????????????????:
????salt 'lvs*' saltutil.sync_all
???????LVS????:
????salt '*' state.highstate
??????LVS?????:
????salt 'lvs' lvs.list
???????
???????SaltStack LVS??飬??????????LVS???????LVS??????????LVS?????ù???????????????RealServer?????????μ?RealServer?? ??????? /srv/pillar/lvs/loadblance.sls ???????????ü???.