目的:使用lvs+keepalived架构架构实现后端web服务器(该web服务器要求搭建wordpress博客站)的负载均衡
最终客户端访问域名 我的名字.wordpress.cn 能够访问搭建的博客站 ,达到负载均衡的目的
IP | 主机名 | 角色 |
192.168.26.101 | rs1 | 后端真实服务器/nginx |
192.168.26.102 | rs2 | 后端真实服务器/nginx |
192.168.26.103 | master | keepalived服务器master |
192.168.26.104 | backup | keepalived服务器backup |
192.168.26.105 | nfs | Nfs服务器 |
192.168.26.201 | web | 数据库服务器 |
192.168.26.12 | cesi | 客户端 |
一.基础环境搭建
1.1master配置
1.1.1安装配置keepalived
[root@master ~]# yum -y install keepalived
[root@master ~]# cat /etc/keepalived/keepalived.conf
! Configuration File for keepalived global_defs { router_id master } vrrp_instance VI_1 { state MASTER interface ens33 virtual_router_id 51 priority 150 advert_int 1 authentication { auth_type PASS auth_pass 1111 } virtual_ipaddress { 192.168.26.222/24 dev ens33 label ens33:1 } } virtual_server 192.168.26.222 80 { delay_loop 6 lb_algo wrr lb_kind DR # persistence_timeout 50 protocol TCP real_server 192.168.26.101 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.26.102 80 { weight 1 HTTP_GET { url { path / status_code 200 } } connect_timeout 3 nb_get_retry 3 delay_before_retry 3 } }
1.1.2查看下ipvsadm -ln是否帮你自动添加了lvs集群规则
[root@master ~]# systemctl restart keepalived.service #生效 [root@master ~]# yum -y install ipvsadm
[root@master ~]# ipvsadm -ln #查看当前ipvs模块中记录的连接
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags
-> RemoteAddress:Port Forward Weight ActiveConn InActConn
TCP 192.168.26.222:80 wrr
-> 192.168.26.101:80 Route 1 0 0
-> 192.168.26.102:80 Route 1 0 0
1.2Backup配置
[root@backup ~]# yum -y install keepalived
[root@backup ~]# cat /etc/keepalived/keepalived.conf
! Configuration File for keepalived
global_defs {
router_id backup
}
vrrp_instance VI_1 {
state BACKUP
interface ens33
virtual_router_id 51
priority 100
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
192.168.26.222/24 dev ens33 label ens33:1
}
}
virtual_server 192.168.26.222 80 {
delay_loop 6
lb_algo wrr
lb_kind DR
# persistence_timeout 50
protocol TCP
real_server 192.168.26.101 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.26.102 80 {
weight 1
HTTP_GET {
ur