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.8 #用于读取数据的负载均衡的虚拟ip 40. } 41. }
42. virtual_server 192.168.0.7 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.3 6379 { 49. weight 8 50. TCP_CHECK { 51. connect_timeout 10 52. nb_get_retry 3 53. delay_before_retry 3 54. connect_port 6379 55. } 56. } 57. }
58. virtual_server 192.168.0.8 6379 { 59. delay_loop 3 60. lb_algo wrr 61. lb_kind DR
62. persistence_timeout 30 63. protocol TCP
64. real_server 192.168.0.3 6379 { 65. weight 5 66. TCP_CHECK { 67. connect_timeout 10 68. nb_get_retry 3 69. delay_before_retry 3 70. connect_port 6379 71. } 72. }
73. real_server 192.168.0.4 6379 { 74. weight 5 75. TCP_CHECK {
76. connect_timeout 10 77. nb_get_retry 3 78. delay_before_retry 3 79. connect_port 6379 80. } 81. } 82. }
redis维护脚本redis.sh
[plain] view plaincopy 1. #!/usr/bin/env bash
2. /usr/local/bin/redis-cli -h 192.168.0.2 -p 6379 shutdown
3. /usr/local/bin/redis-cli -h 192.168.0.3 -p 6379 config set appendonly no
此脚本用在route2的notify_master,即当route2进入master时执行 设置redis的主从关系
设置redis的sentinel,配置文件
[plain] view plaincopy 1. # Example sentinel.conf 2.
3. # port
4. # The port that this sentinel instance will run on 5. port 26379 6.
7. # sentinel monitor
9. # Tells Sentinel to monitor this slave, and to consider it in O_DOWN 10. # (Objectively Down) state only if at least
12. # Note: master name should not include special characters or spaces. 13. # The valid charset is A-z 0-9 and the three characters \
14. sentinel monitor mymaster 192.168.0.2 6379 2 #此处的意思是需要两个哨兵来确认服务
是否挂掉 15.
16. # sentinel auth-pass
18. # Set the password to use to authenticate with the master and slaves.
19. # Useful if there is a password set in the Redis instances to monitor. 20. #
21. # Note that the master password is also used for slaves, so it is not 22. # possible to set a different password in masters and slaves instances 23. # if you want to be able to monitor these instances with Sentinel. 24. #
25. # However you can have Redis instances without the authentication enabled 26. # mixed with Redis instances requiring the authentication (as long as the 27. # password set is the same for all the instances requiring the password) as 28. # the AUTH command will have no effect in Redis instances with authentication 29. # switched off. 30. #
31. # Example: 32. #
33. # sentinel auth-pass mymaster MySUPER--secret-0123passw0rd 34.
35. # sentinel down-after-milliseconds
37. # Number of milliseconds the master (or any attached slave or sentinel) should 38. # be unreachable (as in, not acceptable reply to PING, continuously, for the 39. # specified period) in order to consider it in S_DOWN state (Subjectively 40. # Down). 41. #
42. # Default is 30 seconds.
43. sentinel down-after-milliseconds mymaster 5000 44.
45. # sentinel can-failover
47. # Specify if this Sentinel can start the failover for this master. 48. sentinel can-failover mymaster yes 49.
50. # sentinel parallel-syncs
52. # How many slaves we can reconfigure to point to the new slave simultaneously 53. # during the failover. Use a low number if you use the slaves to serve query 54. # to avoid that all the slaves will be unreachable at about the same 55. # time while performing the synchronization with the master. 56. sentinel parallel-syncs mymaster 1 57.
58. # sentinel failover-timeout
60. # Specifies the failover timeout in milliseconds. When this time has elapsed 61. # without any progress in the failover process, it is considered concluded by 62. # the sentinel even if not all the attached slaves were correctly configured
63. # to replicate with the new master (however a \ 64. # is sent to all the slaves before). 65. #
66. # Also when 25% of this time has elapsed without any advancement, and there 67. # is a leader switch (the sentinel did not started the failover but is now 68. # elected as leader), the sentinel will continue the failover doing a 69. # \ 70. #
71. # Default is 15 minutes.
72. sentinel failover-timeout mymaster 90000 73.
74. # SCRIPTS EXECUTION 75. #
76. # sentinel notification-script and sentinel reconfig-script are used in order 77. # to configure scripts that are called to notify the system administrator 78. # or to reconfigure clients after a failover. The scripts are executed 79. # with the following rules for error handling: 80. #
81. # If script exists with \ 82. # number of times currently set to 10). 83. #
84. # If script exists with \ 85. # not retried. 86. #
87. # If script terminates because it receives a signal the behavior is the same 88. # as exit code 1. 89. #
90. # A script has a maximum running time of 60 seconds. After this limit is 91. # reached the script is terminated with a SIGKILL and the execution retried. 92.
93. # NOTIFICATION SCRIPT 94. #
95. # sentinel notification-script
97. # Call the specified notification script for any sentienl event that is 98. # generated in the WARNING level (for instance -sdown, -odown, and so forth). 99. # This script should notify the system administrator via email, SMS, or any 100. # other messaging system, that there is something wrong with the monitored 101. # Redis systems. 102. #
103. # The script is called with just two arguments: the first is the event type 104. # and the second the event description. 105. #
106. # The script must exist and be executable in order for sentinel to start if
107. # this option is provided. 108. #
109. # Example: 110. #
111. # sentinel notification-script mymaster /var/redis/notify.sh 112.
113. # CLIENTS RECONFIGURATION SCRIPT 114. #
115. # sentinel client-reconfig-script
117. # When the failover starts, ends, or is aborted, a script can be called in 118. # order to perform application-specific tasks to notify the clients that the 119. # configuration has changed and the master is at a different address. 120. #
121. # The script is called in the following cases: 122. #
123. # Failover started (a slave is already promoted)
124. # Failover finished (all the additional slaves already reconfigured) 125. # Failover aborted (in that case the script was previously called when the 126. # failover started, and now gets called again with swapped 127. # addresses). 128. #
129. # The following arguments are passed to the script: 130. #
131. #
133. #
136. # The arguments from-ip, from-port, to-ip, to-port are used to communicate 137. # the old address of the master and the new address of the elected slave 138. # (now a master) in the case state is \ 139. #
140. # For abort instead the \ 141. # \ 142. # was aborted. 143. #
144. # This script should be resistant to multiple invocations. 145. #
146. # Example: 147. #
148. # sentinel client-reconfig-script mymaster /var/redis/reconfig.sh