事先准备四台虚拟机,两台做keepalived,两台做lvs
在以下部署中keeaplived 的两台机器ip分别为:192.168.76.156,192.168.76.172;lvs
的两台机器ip分别为:192.168.76.173,192.168.76.174
安装过程省略
1、keeaplived
1)配置文件
主:
! Configuration File for keepalived
global_defs {
notification_email {
acassen@firewall.loc
}
notification_email_from Alexandre.Cassen@firewall.loc
smtp_server 127.0.0.1
smtp_connect_timeout 30
router_id LVS_1
}
vrrp_instance VI_1 {
state MASTER
interface ens33
lvs_sync_daemon_interface eth0
virtual_router_id 51
priority 150
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
192.168.76.201
}
}
virtual_server 192.168.76.201 80 {
delay_loop 6
lb_algo wrr
lb_kind DR
nat_mask 255.255.255.255
persistence_timeout 300
protocol TCP
real_server 192.168.76.173 80 {
weight 1
TCP_CHECK {
connect_timeout 8
nb_get_retry 3
delay_before_retry 3
connect_port 80
}
}
real_server 192.168.76.174 80 {
weight 1
TCP_CHECK {
connect_timeout 8
nb_get_retry 3
delay_before_retry 3
conect_port 80
}
}
}
备:
! Configuration File for keepalived
global_defs {
notification_email {
acassen@firewall.loc
}
notification_email_from Alexandre.Cassen@firewall.loc
smtp_server 127.0.0.1
smtp_connect_timeout 30
router_id LVS_2
}
vrrp_instance VI_1 {
state BACKUP
interface ens33
lvs_sync_daemon_interface eth0
virtual_router_id 51
priority 100
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
192.168.76.201
}
}
virtual_server 192.168.76.201 80 {
delay_loop 6
lb_algo wrr
lb_kind DR
nat_mask 255.255.255.255
persistence_timeout 300
protocol TCP
real_server 192.168.76.173 80 {
weight 1
TCP_CHECK {
connect_timeout 8
nb_get_retry 3
delay_before_retry 3
connect_port 80
}
}
real_server 192.168.76.174 80 {
weight 1
TCP_CHECK {
connect_timeout 8
nb_get_retry 3
delay_before_retry 3
connect_port 80
}
}
}
2)重启服务
/etc/init.d/keepalived start
2、两台lvs均配置
1)
cd /etc/sysconfig/network-scripts/
vim ifcfg-lo:10
2)vim /etc/sysctl.conf
sysctl -p
3)写好http测试页面
yum install httpd -y
echo "hello,173" > /var/www/html/index.html
echo "hello,174" > /var/www/html/index/html
4)测试
IP a
结果:主keepalived 上有浮动ip 192.168.76.201,备keepalived上没有浮动ip,页面输入192.168.76.201发现“hello,1730”,“hello,174” 轮询
关闭主keeplaived ,关闭主服务ser的httpd,备上出现浮动ip,在页面输入192.168.76.201
,出现“hello,174”