Complete LVS configuration management based on Saltstack

Source: Internet
Author: User
Tags saltstack

Previously, due to job requirements, Saltstack's LVS remote execution module, LVS Service status Management module and LVS Server Status Management module were written and submitted to Saltstack official loadblance (DR) and Realserver configuration management.
front-facing reading
LVS-DR mode configuration in detail, it should be noted that the LVS-DR mode of work in the data link layer, the text describes the need to open ip_forward, in fact, no need, details see LVS dr Mode principle Analysis
Environment Description
Three servers are used for the LVS cluster, where the host named LVs has the role of loadblance, and the corresponding IP address is 192.168.36.10; The host name web-01 and web-02 hosts the role of Realserver, The corresponding IP addresses are 192.168.36.11 and 192.168.36.12 respectively.
LVs vip:192.168.36.33, port:80, VIP bound at the eth1 port of the LVS
The most important is the Loadblance host for Linux, and has installed Ipvsadm, Windows/unix and other host students please bypass it, this is not my fault ...
Start
Note
All of the following operations are performed on master
Configuring the Saltstack LVS module
If you are using a salt version that already contains the LVS module, please ignore this section and test the method:
Salt ' LVS ' cmd.run "python-c ' Import Salt.modules.lvs '"
If the output has a importerror typeface, it means that the module is not installed and needs to do the following:
test-d/srv/salt/_modules | | Mkdir/srv/salt/_modules
test-d/srv/salt/_states | | Mkdir/srv/salt/_states
wget?https://raw.github.com/saltstack/salt/develop/salt/modules/lvs.py?-o/srv/salt/_modules/lvs.py
Wget?https://raw.github.com/saltstack/salt/develop/salt/states/lvs_service.py?-o/srv/salt/_states/lvs_ service.py
wget?https://raw.github.com/saltstack/salt/develop/salt/states/lvs_server.py?-o/srv/salt/_states/lvs_server.py
Configure Pillar
/srv/pillar/lvs/loadblance.sls
Lvs-loadblance:
-Name:lvstest
vip:192.168.36.33
Vip-nic:eth1
Port:80
Protocol:tcp
Scheduler:wlc
Realservers:
-name:web-01
ip:192.168.36.11
Port:80
Packet_forward_method:dr
Weight:10
-name:web-02
ip:192.168.36.12
Port:80
Packet_forward_method:dr
Weight:30
/srv/pillar/lvs/realserver.sls
Lvs-realserver:
-Name:lvstest
vip:192.168.36.33
/srv/pillar/top.sls
Base
' LVs ':
-Lvs.loadblance
' web-0* ':
-Lvs.realserver

Writing 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
Application Configuration
If the operation of the LVS module is previously configured, the operation of the synchronization module is required:
Salt ' lvs* ' Saltutil.sync_all
To apply the LVS configuration:
Salt ' * ' state.highstate
View LVs Current Status:
Salt ' LVS ' lvs.list
Summarize
by Saltstack LVS module, we can quickly query the LVS status, execute LVS Common instructions and complete the configuration management of LVS. If you need to adjust the Realserver rules or add new realserver, just modify the/srv/pillar/lvs/loadblance.sls and then apply the configuration.

This article was selected from: http://www.spasvo.com/news/html/2014121155049_2.html

Complete LVS configuration management based on Saltstack

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.