負(fù)載均衡集群介紹
LVS介紹
LVS的調(diào)度算法
所有機(jī)器上操作
[root@wsl1 ~]# systemctl stop firewalld
[root@wsl1 ~]# systemctl disable firewalld
[root@wsl1 ~]# systemctl start iptables
[root@wsl1 ~]# iptables -F
[root@wsl1 ~]# service iptables save
iptables: Saving firewall rules to /etc/sysconfig/iptables:[ 確定 ]
分發(fā)器上操作
$IPVSADM -A -t 192.168.147.144:80 -s wlc -p 3 (-s為指定調(diào)度算法璃诀,-p為指定鏈接超時時間)
[root@wsl3 ~]# yum install -y ipvsdam
[root@wsl3 ~]# vim /usr/local/sbin/lvs_nat.sh
#! /bin/bash
# director 服務(wù)器上開啟路由轉(zhuǎn)發(fā)功能
echo 1 > /proc/sys/net/ipv4/ip_forward
# 關(guān)閉icmp的重定向
echo 0 > /proc/sys/net/ipv4/conf/all/send_redirects
echo 0 > /proc/sys/net/ipv4/conf/default/send_redirects
# 注意區(qū)分網(wǎng)卡名字,阿銘的兩個網(wǎng)卡分別為ens33和ens37
echo 0 > /proc/sys/net/ipv4/conf/ens33/send_redirects
echo 0 > /proc/sys/net/ipv4/conf/ens37/send_redirects
# director 設(shè)置nat防火墻
iptables -t nat -F
iptables -t nat -X
iptables -t nat -A POSTROUTING -s 172.16.230.0/24 -j MASQUERADE
# director設(shè)置ipvsadm
IPVSADM='/usr/sbin/ipvsadm'
$IPVSADM -C
$IPVSADM -A -t 172.16.79.144:80 -s rr
$IPVSADM -a -t 172.16.79.144:80 -r 172.16.230.131:80 -m -w 1
$IPVSADM -a -t 172.16.79.144:80 -r 172.16.230.132:80 -m -w 1
[root@wsl3 ~]# sh /usr/local/sbin/lvs_nat.sh
測試
WSL:~ Martin.Wang$ curl 172.16.79.144 |head -4
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 614 100 614 0 0 265k 0 --:--:-- --:--:-- --:--:-- 299k
<!DOCTYPE html>
<html>
<head>
<title>Welcome to MASTER!</title>
WSL:~ Martin.Wang$ curl 172.16.79.144 |head -4
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 614 100 614 0 0 266k 0 --:--:-- --:--:-- --:--:-- 299k
<!DOCTYPE html>
<html>
<head>
<title>Welcome to BACKUP!</title>
WSL:~ Martin.Wang$ curl 172.16.79.144 |head -4
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 614 100 614 0 0 298k 0 --:--:-- --:--:-- --:--:-- 599k
<!DOCTYPE html>
<html>
<head>
<title>Welcome to MASTER!</title>
WSL:~ Martin.Wang$ curl 172.16.79.144 |head -4
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 614 100 614 0 0 237k 0 --:--:-- --:--:-- --:--:-- 299k
<!DOCTYPE html>
<html>
<head>
<title>Welcome to BACKUP!</title>
[root@wsl3 network-scripts]# ipvsadm -ln
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags
-> RemoteAddress:Port Forward Weight ActiveConn InActConn
TCP 172.16.79.144:80 rr
-> 172.16.230.131:80 Masq 1 1 4
-> 172.16.230.132:80 Masq 1 0 4
擴(kuò)展
lvs 三種模式詳解 http://www.it165.net/admin/html/201401/2248.html
lvs幾種算法 http://www.aminglinux.com/bbs/thread-7407-1-1.html
關(guān)于arp_ignore和 arp_announce http://www.cnblogs.com/lgfeng/archive/2012/10/16/2726308.html
lvs原理相關(guān)的 http://blog.csdn.net/pi9nc/article/details/23380589