基于keepalived的redis系统master双机热备读数据负载均
衡设
基于keepalived的redis系统master双机热备读数据负载均衡设置方案==============================================================================
============
硬件
机器 ip 作用master 192. 168.0.2 redis系统的master主机slave1 192. 168.0.3 redis系统的slave机器和master组成双机热备slave2 192. 168.0.4redis系统的slave机器和slave1构成读数据的负载均衡系统
软件keepalived下载地址 www.keepalived.orglvs下载地址 http://www. l inuxvirtualserver.orgredis下载地址 www.redis. iocentos 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/下面是需要的r pm文件列表截图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. not ificat ion_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. not ificat ion_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. authenticat ion { 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_t imeout 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
感谢您的阅读祝您生活愉快。
艾云怎么样?艾云是一家去年年底成立的国人主机商家,商家主要销售基于KVM虚拟架构的VPS服务,机房目前有美国洛杉矶、圣何塞和英国伦敦,目前商家推出了一些年付特价套餐,性价比非常高,洛杉矶套餐低至85元每年,给500M带宽,可解奈飞,另外圣何塞也有特价机器;1核/1G/20G SSD/3T/2.5Gbps,有需要的朋友以入手。点击进入:艾云官方网站艾云vps促销套餐:KVM虚拟架构,自带20G的防御...
搬瓦工怎么样?这几天收到搬瓦工发来的邮件,告知香港pccw机房(HKHK_1)即将关闭,这也不算是什么出乎意料的事情,反而他不关闭我倒觉得奇怪。因为目前搬瓦工香港cn2 GIA 机房和香港pccw机房价格、配置都一样,可以互相迁移,但是不管是速度还是延迟还是丢包率,搬瓦工香港PCCW机房都比不上香港cn2 gia 机房,所以不知道香港 PCCW 机房存在还有什么意义?关闭也是理所当然的事情。点击进...
Pia云是一家2018的开办的国人商家,原名叫哔哔云,目前整合到了魔方云平台上,商家主要销售VPS服务,采用KVM虚拟架构 ,机房有美国洛杉矶、中国香港和深圳地区,洛杉矶为crea机房,三网回程CN2 GIA,带20G防御,常看我测评的朋友应该知道,一般带防御去程都是骨干线路,香港的线路也是CN2直连大陆,目前商家重新开业,价格非常美丽,性价比较非常高,有需要的朋友可以关注一下。活动方案...