LVS+Keepalive实现Apache与MySQL负载均衡跟读写分离
主机 ip
router 192.168.10.254 192.168.24.254
web分发器 192.168.24.1
mysql分发器 192.168.24.2
web服务器1 192.168.24.10
web服务器2 192.168.24.20
mysql1(写) 192.168.24.30
mysql2(读) 192.168.24.40
mysql3(读) 192.168.24.50
web vip 192.168.24.250
mysql vip 192.168.24.251
分发器配置:
web分发器 mysql分发器把端口跟ip改了就可以了
! Configuration File for keepalived
global_defs {
router_id lllll
}
vrrp_sync_group http {
group {
apache
}
}
vrrp_instance apache {
state MASTER
interface eth0
virtual_router_id 222
priority 180
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
192.168.18.250
}
}
virtual_server 192.168.18.250 80 {
delay_loop 6
lb_algo rr
lb_kind DR #DR模式用这个
lb_kind TUN #TUN模式写这个
# persistence_timeout 3600
protocol TCP
real_server 192.168.24.10 80 {
weight 1
TCP_CHECK {
connect_timeout 3
connect_port 80
}
}
real_server 192.168.24.20 80 {
weight 1
TCP_CHECK {
connect_timeout 3
connect_port 80
}
}
}
mysql的配置就不做介绍了之前有,在读写分离的php里,把写的数据库ip指向主服务器,读的数据库ip写成vip就可以了,要是有错误的话看看vip对不对,mysql数据库的权限给没给对。