keepalived双主模式轻松构建
考虑到keepalived高可用,
备节点的机器基本上属于空闲状态,
很浪费硬件资源,所以我们可以让keepalived互为主备,
跑多个实例
第一个节点配置
vim /etc/keepalived/keepalived.conf
global_defs {
router_id LVS_KEEP01
}
#第一个业务 为主
vrrp_instance VI_1 {
state MASTER
interface eth0
lvs_sync_daemon_inteface eth0
virtual_router_id 51
priority 150
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
10.125.192.100
10.125.192.101
virtual_server 10.125.192.100 80 {
delay_loop 6
lb_algo wrr
lb_kind DR
nat_mask 255.255.255.0
persistence_timeout 10
protocol TCP
real_server 10.125.192.2 80 {
weight 1
inhibit_on_failure
TCP_CHECK {
connect_timeout 8
nb_get_retry 3
delay_before_retry 3
connect_port 80
}
}
real_server 10.125.192.3 80 {
weight 1
inhibit_on_failure
TCP_CHECK {
connect_timeout 8
nb_get_retry 3
delay_before_retry 3
connect_port 80
}
}
}
}
}
vrrp_instance VI_2 {
state BACKUP
interface eth0
lvs_sync_daemon_inteface eth0
virtual_router_id 52
priority 100
advert_int 1
authentication {
auth_type PASS
auth_pass 2222
}
virtual_ipaddress {
10.125.192.102
10.125.192.103
}
}
virtual_server 10.125.192.102 80 {
delay_loop 6
lb_algo wrr
lb_kind DR
nat_mask 255.255.255.0
persistence_timeout 10
protocol TCP
real_server 10.125.192.5 80 {
weight 1
inhibit_on_failure
TCP_CHECK {
connect_timeout 8
nb_get_retry 3
delay_before_retry 3
connect_port 80
}
}
real_server 10.125.192.6 80 {
weight 1
inhibit_on_failure
TCP_CHECK {
connect_timeout 8
nb_get_retry 3
delay_before_retry 3
connect_port 80
}
}
}
第二个节点配置
vim /etc/keepalived/keepalived.conf
global_defs {
router_id LVS_KEEP01
}
#第一个业务 为备
vrrp_instance VI_1 {
state BACKUP
interface eth0
lvs_sync_daemon_inteface eth0
virtual_router_id 51
priority 100
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
10.125.192.100
10.125.192.101
}
}
virtual_server 10.125.192.100 80 {
delay_loop 6
lb_algo wrr
lb_kind DR
nat_mask 255.255.255.0
persistence_timeout 10
protocol TCP
real_server 10.125.192.2 80 {
weight 1
inhibit_on_failure
TCP_CHECK {
connect_timeout 8
nb_get_retry 3
delay_before_retry 3
connect_port 80
}
}
real_server 10.125.192.3 80 {
weight 1
inhibit_on_failure
TCP_CHECK {
connect_timeout 8
nb_get_retry 3
delay_before_retry 3
connect_port 80
}
}
}
#第二个业务为主
vrrp_instance VI_2 {
state MASTER
interface eth0
lvs_sync_daemon_inteface eth0
virtual_router_id 52
priority 150
advert_int 1
authentication {
auth_type PASS
auth_pass 2222
}
virtual_ipaddress {
10.125.192.102
10.125.192.103
}
}
virtual_server 10.125.192.102 80 {
delay_loop 6
lb_algo wrr
lb_kind DR
nat_mask 255.255.255.0
persistence_timeout 10
protocol TCP
real_server 10.125.192.5 80 {
weight 1
inhibit_on_failure
TCP_CHECK {
connect_timeout 8
nb_get_retry 3
delay_before_retry 3
connect_port 80
}
}
real_server 10.125.192.6 80 {
weight 1
inhibit_on_failure
TCP_CHECK {
connect_timeout 8
nb_get_retry 3
delay_before_retry 3
connect_port 80
}
}
}
上一篇: js判断对象是否为空对象的几种方法
下一篇: Nginx FastCGI的运行原理