基于keepalived的redis系统master双机热备(读数据负载均衡)设

2019-03-10 14:41

基于keepalived的redis系统master双机热备,读数据负载均衡设置方案

==========================================================================================

硬件:

机器 ip 作用

master 192.168.0.2 redis系统的master主机

slave1 192.168.0.3 redis系统的slave机器,和master组成双机热备 slave2 192.168.0.4

redis系统的slave机器,和slave1构成读数据的负载均衡系统

软件:

keepalived,下载地址:www.keepalived.org

lvs,下载地址:http://www.linuxvirtualserver.org

redis,下载地址:www.redis.io

centos 6.4版本

安装:

不采用编译安装的方式,使用yum安装

1.安装kernel-devel:yum install kernel-devel.这是ipvsadm需要的

2.安装lvs:yum install ipvsadm

3.安装keepalived:yum install keepalived

如果无法联网,请去这里考古寻找自己需要的rpm文件

base:http://tel.mirrors.163.com/centos/6/os/x86_64/Packages/

update:http://tel.mirrors.163.com/centos/6/updates/x86_64/Packages/

下面是需要的rpm文件列表截图

kernel-devel需要的文件

以及需要的证书

lvs需要的文件

keepalived需要的文件

注意,三台机器都需要安装keepalived

配置keepalived:

1.centos必要配置:

/etc/sysctl.conf文件

net.ipv4.ip_forward=1#转发开启

2.keepalived必要配置:

master修改/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_1 { 13. state MASTER

14. interface eth0 #eth0是要绑定的网卡

15. virtual_router_id 100 #同一个vrrp_instance中的值必须一样 16. priority 160 #master的值要高于backup的 17. advert_int 1 18. authentication { 19. auth_type PASS 20. auth_pass 1111 21. }

22. virtual_ipaddress {

23. 192.168.0.5 #用于双机热备的虚拟ip 24. } 25. 26. }

27. virtual_server 192.168.0.5 6379 { 28. delay_loop 3 29. lb_algo wrr 30. lb_kind DR

31. persistence_timeout 30 32. protocol TCP

33. real_server 192.168.0.2 6379 { 34. weight 8

35. notify_down redis服务失败后要执行的脚本的路径/脚本名 #服务失败后要执行的

脚本

36. TCP_CHECK { 37. connect_timeout 1 38. nb_get_retry 3 39. delay_before_retry 3 40. connect_port 6379 41. } 42. } 43. }

slave1修改/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.

13. vrrp_instance VI_1 { 14. state MASTER

15. interface eth0 #eth0是要绑定的网卡

16. virtual_router_id 100 #同一个vrrp_instance中的值必须一样 17. priority 160 #master的值要高于backup的 18. advert_int 1 19. authentication { 20. auth_type PASS 21. auth_pass 1111 22. }

23. virtual_ipaddress {

24. 192.168.0.5 #用于双机热备的虚拟ip 25. }

26. notify_master 将slave重新转换为slave的脚本 27. }

28. vrrp_instance VI_2 {

29. state MASTER #将此slave作为读数据的master

30. interface eth0 31. virtual_router_id 101 32. priority 151 33. advert_int 1 34. authentication { 35. auth_type PASS 36. auth_pass 1111 37. }

38. virtual_ipaddress {

39. 192.168.0.6 #用于读取数据的负载均衡的虚拟ip 40. } 41. }

42. virtual_server 192.168.0.5 6379 { 43. delay_loop 3 44. lb_algo wrr 45. lb_kind DR

46. persistence_timeout 30 47. protocol TCP

48. real_server 192.168.0.2 6379 { 49. weight 1

50. notify_down redis服务失败后要执行的脚本的路径/脚本名 #服务失败后

要执行的脚本

51. TCP_CHECK { 52. connect_timeout 1 53. nb_get_retry 2 54. delay_before_retry 1 55. connect_port 6379 56. } 57. }

58. real_server 192.168.0.3 6379 { 59. weight 8 60. TCP_CHECK { 61. connect_timeout 10 62. nb_get_retry 3 63. delay_before_retry 3 64. connect_port 6379 65. } 66. } 67. }

68. virtual_server 192.168.0.6 6379 { 69. delay_loop 3 70. lb_algo wrr 71. lb_kind DR

72. persistence_timeout 30


基于keepalived的redis系统master双机热备(读数据负载均衡)设.doc 将本文的Word文档下载到电脑 下载失败或者文档不完整,请联系客服人员解决!

下一篇:笔试题答案-南瑞

相关阅读
本类排行
× 注册会员免费下载(下载后可以自由复制和排版)

马上注册会员

注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信: QQ: