keepalived 实战

两个节点:10.0.2.18   和 10.0.2.19

1、安装:yum install -y keepalived

2、查看配置文件位置:rpm -qc keepalived

3、修改配置文件:

 

10.0.2.18上的配置文件:
global_defs {
  router_id zcylb
}
vrrp_instance VI_1 {
  state MASTER
  interface enp0s3
  unicast_peer {
      10.0.2.19
  }
  virtual_router_id 51
  priority 100 advert_int 1
  authentication {
    auth_type PASS
    auth_pass 1111
  }
  virtual_ipaddress {
        10.0.2.250 dev enp0s3    
  }
}

其中 10.0.2.250 是我随便设的一个没有被使用的ip,因为我的网卡叫enp0s3,所以配置文件里写的是enp0s3



10.0.2.19上的配置文件:
global_defs {
  router_id zcylb
}
vrrp_instance VI_1 {
  state BACKUP
  interface enp0s3
  unicast_peer {
      10.0.2.18
  }
  virtual_router_id 51
  priority 90
  advert_int 1
  authentication {
    auth_type PASS
    auth_pass 1111
  }
  virtual_ipaddress {
      10.0.2.250 dev enp0s3
  }
}

 

 

4、启动keepalived

service keepalived start

5、查看效果

 

 

 

 keepalived 实战

 

 6、停掉master的keepalived

service keepalived stop  , 发现虚拟ip漂移了

注:在启停keepalived时,也可以查看日志 

tail -f /var/log/messages

 

上一篇:由菱形继承产生的编译错误


下一篇:策略模式