LVS Configuration Management Based on saltstack

Source: Internet
Author: User
Tags saltstack

Pre-reading

Environment Description

Commencement

Configure the saltstack LVS Module

Configure pillar

Compile states

Application configuration

Summary

Previously, due to work requirements, I wrote the LVS remote execution module of saltstack, The LVS service status management module and the LVS server status management module, and submitted them to the official saltstack loadblance (DR) module) and RealServer configuration management.


Pre-reading?


LVS-DR mode configuration details, it is worth noting that the LVS-DR mode work in the data link layer, the description of the need to enable ip_forward, in fact, there is no need for details, see LVS Dr mode Principle Analysis

Environment Description

The three servers are used for the LVS cluster. The host name is loadblance and the corresponding IP address is 192.168.36.10. The host name is web-01 and web-02 and the host name is 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 to eth1 port of LVS

The most important thing is that the loadblance host is Linux, and you have installed ipvsadm, Windows/Unix, and other hosts. It's not my fault ......

Commencement

Note


All of the following operations are performed on the master


Configure the saltstack LVS Module

If the salt version used already contains the LVS module, ignore the content in this section. Test method:

Salt 'lvs 'cmd. Run "Python-C' import salt. modules. LVS '"

If importerror is output, it indicates that the module is not installed and you need to perform the following operations:


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

Schedlc: 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

Compile 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-enice'] + & quot;: & quot; + each_lvs ['name']}

-Enable: True

-Type: ETH

-Proto: None

-Ipaddr: {each_lvs ['vip ']}

-Netmask: 255.255.255.255.255


{% Set service_address = each_lvs ['vip '] + & quot;: & quot; + 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'] + & quot;: & quot; + 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: {& quot; lo & quot; + & quot;: & quot; + each_lvs ['name']}

-Enable: True

-Type: ETH

-Proto: None

-Ipaddr: {each_lvs ['vip ']}

-Netmask: 255.255.255.255.255

{% Endfor %}

{% Endif %}

/Srv/salt/top. SLS

Base:

'Lvs ':

-LVS. loadblance

'Web-0 *':

-LVS. RealServer

Application configuration

If you have previously configured the LVS module, You need to perform operations on the synchronization module:


Salt 'lvs * 'saltutil. sync_all

Application LVS Configuration:


Salt '*' state. highstate

View the current LVS status:


Salt 'lvs. List

Summary

Through the saltstack LVS module, you can quickly query the LVS status, execute common LVS commands, and complete LVS configuration management. If you need to adjust the RealServer rules or add a new RealServer, you only need to modify/srv/pillar/LVS/loadblance. SLS and then apply the configuration.


The code used in this article has been uploaded to GitHub, the transfer: https://github.com/pengyao/salt-lvs


Powered by redmine? 2006-2014 Jean-Philippe Lang


This article is from the "davideylee" blog and will not be reposted!

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.