LVS:html
node01:
ifconfig eth0:8 192.168.150.100/24node
node02~node03:
1)修改內核:
echo 1 > /proc/sys/net/ipv4/conf/eth0/arp_ignore
echo 1 > /proc/sys/net/ipv4/conf/all/arp_ignore
echo 2 > /proc/sys/net/ipv4/conf/eth0/arp_announce
echo 2 > /proc/sys/net/ipv4/conf/all/arp_announce
2)設置隱藏的vip:
ifconfig lo:3 192.168.150.100 netmask 255.255.255.255
RS中的服務:
node02~node03:
yum install httpd -y
service httpd start
vi /var/www/html/index.html
from 192.168.150.1x瀏覽器
LVS服務配置
node01:
yum install ipvsadm
ipvsadm -A -t 192.168.150.100:80 -s rr
ipvsadm -a -t 192.168.150.100:80 -r 192.168.150.12 -g -w 1
ipvsadm -a -t 192.168.150.100:80 -r 192.168.150.13 -g -w 1
ipvsadm -ln網絡
驗證:
瀏覽器訪問 192.168.150.100 看到負載 瘋狂F5
node01:
netstat -natp 結論看不到socket鏈接
node02~node03:
netstat -natp 結論看到不少的socket鏈接
node01:
ipvsadm -lnc 查看偷窺記錄本
TCP 00:57 FIN_WAIT 192.168.150.1:51587 192.168.150.100:80 192.168.150.12:80
FIN_WAIT: 鏈接過,偷窺了全部的包
SYN_RECV: 基本上lvs都記錄了,證實lvs沒事,必定是後邊網絡層出問題
socket
keepalived實驗:
主機: node01~node04oop
node01:
ipvsadm -C
ifconfig eth0:8 downurl
----------------------------
node01,node04:
yum install keepalived ipvsadm -y
配置:
cd /etc/keepalived/
cp keepalived.conf keepalived.conf.bak
vi keepalived.conf
node01:
vrrp:虛擬路由冗餘協議!
vrrp_instance VI_1 {
state MASTER // node04 BACKUP
interface eth0
virtual_router_id 51
priority 100 // node04 50
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
192.168.150.100/24 dev eth0 label eth0:3
}
}
virtual_server 192.168.150.100 80 {
delay_loop 6
lb_algo rr
lb_kind DR
nat_mask 255.255.255.0
persistence_timeout 0
protocol TCPcode
real_server 192.168.150.12 80 {
weight 1
HTTP_GET {
url {
path /
status_code 200
}
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
}
}
real_server 192.168.150.13 80 {
weight 1
HTTP_GET {
url {
path /
status_code 200
}
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
}
}
scp ./keepalived.conf root@node04:`pwd`router