Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

keepalived 抢占模式与非抢占模式,是通过哪个参数进行配置区别的 #151

Open
heidsoft opened this issue Feb 23, 2024 · 1 comment

Comments

@heidsoft
Copy link
Owner

Keepalived是一种为了实现Linux服务器高可用的软件,它主要使用的是VRRP(Virtual Router Redundancy Protocol)协议,也就是虚拟路由冗余协议。

VRRP协议可以使得在主路由器出现故障时,备用路由器能够迅速接管网络,保证网络的正常运行。VRRP协议可以确保网络不间断,并且在切换过程中,网络用户无感知。

Keepalived不仅可以用来实现网络服务的高可用,还可以用来实现负载均衡以及故障恢复。

Keepalived的工作原理是,通过VRRP协议,将两台或者多台服务器配置成一组,其中一台作为Master(主),其他的作为Backup(备)。在正常情况下,所有的网络请求都会发送到Master服务器,如果Master服务器出现故障,那么网络请求会自动切换到Backup服务器,从而实现高可用。

在Keepalived中,抢占模式与非抢占模式是通过"nopreempt"参数进行配置区别的。

在配置文件中,如果加上了"nopreempt"这一行,那么就是非抢占模式。如果没有这一行,那么就是抢占模式。

在抢占模式中(preempt_mode),一旦主服务器恢复,它会立即从备份服务器中抢占回虚拟IP,恢复主服务器的角色。而在非抢占模式中(nopreempt),即使主服务器恢复,也要等到备份服务器出现故障或者宕机,才会切换回主服务器。

例如:

vrrp_instance VI_1 {
    state MASTER
    interface eth0
    virtual_router_id 51
    priority 101
    nopreempt   #非抢占模式
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {
        192.168.0.100
    }
}

在上述配置中,由于有"nopreempt"这一行,因此是非抢占模式。如果去掉"nopreempt",则为抢占模式。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant