由于双机热备会有一台机器正常状态下会一直闲置,造成资源浪费,
通过双主热备吧所有机器都使用起来。
原理就是域名绑定多个虚拟 ip 通过 DNS 轮询,每个实例绑定一个相对于自己是 Master 的虚拟 ip,
并且实例间互为主备关系

实例一配置:

  1. global_defs {
  2. router_id keep_171
  3. }
  4. vrrp_instance VI_1 {
  5. state MASTER
  6. interface ens33
  7. virtual_router_id 51
  8. priority 100
  9. advert_int 1
  10. authentication {
  11. auth_type PASS
  12. auth_pass 1111
  13. }
  14. virtual_ipaddress {
  15. 192.168.1.161
  16. }
  17. }
  18. vrrp_instance VI_2 {
  19. state BACKUP
  20. interface ens33
  21. virtual_router_id 52
  22. priority 80
  23. advert_int 1
  24. authentication {
  25. auth_type PASS
  26. auth_pass 1111
  27. }
  28. virtual_ipaddress {
  29. 192.168.1.162
  30. }
  31. }

实例二配置

  1. global_defs {
  2. router_id keep_172
  3. }
  4. vrrp_instance VI_1 {
  5. state BACKUP
  6. interface ens33
  7. virtual_router_id 51
  8. priority 80
  9. advert_int 1
  10. authentication {
  11. auth_type PASS
  12. auth_pass 1111
  13. }
  14. virtual_ipaddress {
  15. 192.168.1.161
  16. }
  17. }
  18. vrrp_instance VI_2 {
  19. state MASTER
  20. interface ens33
  21. virtual_router_id 52
  22. priority 100
  23. advert_int 1
  24. authentication {
  25. auth_type PASS
  26. auth_pass 1111
  27. }
  28. virtual_ipaddress {
  29. 192.168.1.162
  30. }
  31. }

重启两条Keepalived

  1. # 重启Keepalived
  2. systemctl restart keepalived