1. yum install keepalived -y

配置文件

  1. global_defs {
  2. notification_email {
  3. acassen@firewall.loc
  4. failover@firewall.loc
  5. sysadmin@firewall.loc
  6. }
  7. notification_email_from Alexandre.Cassen@firewall.loc
  8. smtp_server 192.168.200.1
  9. smtp_connect_timeout 30
  10. router_id LVS_DEVEL ####################### 重点 host
  11. vrrp_skip_check_adv_addr
  12. vrrp_strict
  13. vrrp_garp_interval 0
  14. vrrp_gna_interval 0
  15. }
  16. vrrp_instance VI_1 {
  17. state MASTER ####################### 重点 备份服务器改为BACKUP
  18. interface eth0 ####################### 网卡
  19. virtual_router_id 51 ################## 主备必须相同
  20. priority 100 ######################### 主备不同优先级,主机值较大,备份机较小
  21. advert_int 1 ######################### 每一秒检测主机是否存活
  22. authentication { ###################### 认证
  23. auth_type PASS
  24. auth_pass 1111
  25. }
  26. virtual_ipaddress { ################## 虚拟IP地址
  27. 192.168.200.16
  28. 192.168.200.17
  29. 192.168.200.18
  30. }
  31. }
  32. virtual_server 10.10.10.2 1358 {
  33. delay_loop 6
  34. lb_algo rr
  35. lb_kind NAT
  36. persistence_timeout 50
  37. protocol TCP
  38. sorry_server 192.168.200.200 1358
  39. real_server 192.168.200.2 1358 {
  40. weight 1
  41. HTTP_GET {
  42. url {
  43. path /testurl/test.jsp
  44. digest 640205b7b0fc66c1ea91c463fac6334d
  45. }
  46. url {
  47. path /testurl2/test.jsp
  48. digest 640205b7b0fc66c1ea91c463fac6334d
  49. }
  50. url {
  51. path /testurl3/test.jsp
  52. digest 640205b7b0fc66c1ea91c463fac6334d
  53. }
  54. connect_timeout 3
  55. retry 3
  56. delay_before_retry 3
  57. }
  58. }
  59. real_server 192.168.200.3 1358 {
  60. weight 1
  61. HTTP_GET {
  62. url {
  63. path /testurl/test.jsp
  64. digest 640205b7b0fc66c1ea91c463fac6334c
  65. }
  66. url {
  67. path /testurl2/test.jsp
  68. digest 640205b7b0fc66c1ea91c463fac6334c
  69. }
  70. connect_timeout 3
  71. retry 3
  72. delay_before_retry 3
  73. }
  74. }
  75. }
  1. # 先启动nginx
  2. systemctl start keepalived