73. protocol TCP
74. real_server 192.168.0.2 6379 { 75. weight 8 76. TCP_CHECK { 77. connect_timeout 10 78. nb_get_retry 3 79. delay_before_retry 3 80. connect_port 6379 81. } 82. }
83. real_server 192.168.0.3 6379 { 84. weight 7 85. TCP_CHECK { 86. connect_timeout 10 87. nb_get_retry 3 88. delay_before_retry 3 89. connect_port 6379 90. } 91. } 92. }
slave2修改/etc/keepalived/keepalived.conf为如下
[plain] view plaincopy 1. ! Configuration File for keepalived 2.
3. global_defs {
4. notification_email { 5. 邮箱 6. }
7. notification_email_from 邮箱 8. smtp_server 邮箱服务器地址 9. smtp_connect_timeout 30 10. router_id LVS_DEVEL 11. }
12. vrrp_instance VI_2 { 13. state BACKUP 14. interface eth0 15. virtual_router_id 101 16. priority 149 17. advert_int 1 18. authentication {
19. auth_type PASS 20. auth_pass 1111 21. }
22. virtual_ipaddress { 23. 192.168.0.6 24. } 25. }
26. virtual_server 192.168.0.6 6379 { 27. delay_loop 3 28. lb_algo wrr 29. lb_kind DR
30. persistence_timeout 30 31. protocol TCP
32. real_server 192.168.0.2 6379 { 33. weight 8 34. TCP_CHECK { 35. connect_timeout 10 36. nb_get_retry 3 37. delay_before_retry 3 38. connect_port 6379 39. } 40. }
41. real_server 192.168.0.3 6379 { 42. weight 7 43. TCP_CHECK { 44. connect_timeout 10 45. nb_get_retry 3 46. delay_before_retry 3 47. connect_port 6379 48. } 49. } 50. }
配置redis:
master无需特殊配置 slave1则设置为master的从机 slave2则需要设置为192.168.0.5的从机,否则在master失效后slave2会无法继续读取数据
需要的脚本: 在master执行的脚本:
[plain] view plaincopy 1. #!/usr/bin/env bash
2. ervice keepalived stop #需要用户具有权限,不中断keepalived服务虚拟ip无法转移
在slave1执行的脚本: [plain] view plaincopy 1. #!/usr/bin/env bash 2.
3. /usr/local/bin/redis-cli -h 127.0.0.1 -p 6379 slaveof NO ONE #将slave1转换为
redis的
slave1第二个脚本,在master服务重启后将slave1重新转换为slave状态
最终效果: 192.168.0.5 提供了redis的双机热备服务,192.168.0.6则提供了数据读取的负载均衡 [plain] view plaincopy 1. #!/usr/bin/env bash 2.
3. /usr/local/bin/redis-cli slaveof 192.168.0.2 6379 #将slave1重新转换为redis的
slave
需要注意,master每次需要先启动redis服务然后再启动keepalived
==========================================================================================
基于keepalived、redis sentinel的高可用redis集群【修改版】
2013年12月12日 ? 综合 ? 共 5289字 ? 字号 小 中 大 ? 评论关闭 原方案地址原方案
硬件
机器名 IP master 192.168.0.2 slave1 192.168.0.3 slave2 192.168.0.4 作用 redis的master服务器 redis的slave服务器 redis的slave服务器 keepalived和redis sentinel服务器,承载192.168.0.5【虚拟IP:route1 写redis的VIP【虚拟ip】,做写的双机热备192.168.0.7】 的主master指定 keepalived和redis sentinel服务器,承载192.168.0.6【虚拟IP:route2 读redis的VIP,做读的负载均衡和写的双机192.168.0.8】 热备的master备份路由指定 详细的keepalived配置,route1
! Configuration File for keepalived
global_defs {
notification_email { 邮箱 }
notification_email_from 邮箱@bitauto.com smtp_server 邮箱服务器地址 smtp_connect_timeout 30 router_id LVS_DEVEL }
vrrp_instance VI_1 { state MASTER interface eth1 virtual_router_id 100 priority 150 advert_int 1 authentication { auth_type PASS auth_pass 1111 }
virtual_ipaddress { 192.168.0.7 } }
vrrp_instance VI_2 { state BACKUP interface eth1 virtual_router_id 101 priority 101 advert_int 1 authentication { auth_type PASS auth_pass 1111 }
virtual_ipaddress { 192.168.0.8 } }
virtual_server 192.168.0.7 6379 { delay_loop 3 lb_algo rr lb_kind DR
persistence_timeout 15 protocol TCP
real_server 192.168.0.4 6379 { weight 4
notify_up /home/wind/redis_up.sh MISC_CHECK {
misc_path \ misc_timeout 5