编写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 ,然后应用配置即可.