keepalived双主模式(互为主备)

考虑到keepalived高可用,备节点的机器基本上属于空闲状态,很浪费硬件资源,所以我们可以让keepalived互为主备,跑多个实例

第一个节点配置
vim /etc/keepalived/keepalived.conf
global_defs {
notification_email {
[email protected]
}
notification_email_from [email protected]
smtp_server 127.0.0.1
smtp_connect_timeout 30
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 {
notification_email {
[email protected]
}
notification_email_from [email protected]
smtp_server 127.0.0.1
smtp_connect_timeout 30
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
    }
}

}

猜你喜欢

转载自blog.csdn.net/bjgaocp/article/details/88417428