redis_sentinel.conf.j2 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348
  1. # Example sentinel.conf
  2. bind {{ redis_sentinel_bind_interface }}
  3. # By default protected mode is disabled in sentinel mode. Sentinel is reachable
  4. # from interfaces different than localhost. Make sure the sentinel instance is
  5. # protected from the outside world via firewalling or other means.
  6. protected-mode no
  7. # port <sentinel-port>
  8. # The port that this sentinel instance will run on
  9. port {{ redis_sentinel_port }}
  10. # By default Redis Sentinel does not run as a daemon. Use 'yes' if you need it.
  11. # Note that Redis will write a pid file in /var/run/redis-sentinel.pid when
  12. # daemonized.
  13. daemonize no
  14. # When running daemonized, Redis Sentinel writes a pid file in
  15. # /var/run/redis-sentinel.pid by default. You can specify a custom pid file
  16. # location here.
  17. pidfile {{ redis_sentinel_pidfile }}
  18. # Specify the log file name. Also the empty string can be used to force
  19. # Sentinel to log on the standard output. Note that if you use standard
  20. # output for logging but daemonize, logs will be sent to /dev/null
  21. logfile {{ redis_sentinel_logfile }}
  22. # sentinel announce-ip <ip>
  23. # sentinel announce-port <port>
  24. #
  25. # The above two configuration directives are useful in environments where,
  26. # because of NAT, Sentinel is reachable from outside via a non-local address.
  27. #
  28. # When announce-ip is provided, the Sentinel will claim the specified IP address
  29. # in HELLO messages used to gossip its presence, instead of auto-detecting the
  30. # local address as it usually does.
  31. #
  32. # Similarly when announce-port is provided and is valid and non-zero, Sentinel
  33. # will announce the specified TCP port.
  34. #
  35. # The two options don't need to be used together, if only announce-ip is
  36. # provided, the Sentinel will announce the specified IP and the server port
  37. # as specified by the "port" option. If only announce-port is provided, the
  38. # Sentinel will announce the auto-detected local IP and the specified port.
  39. #
  40. # Example:
  41. #
  42. # sentinel announce-ip 1.2.3.4
  43. # dir <working-directory>
  44. # Every long running process should have a well-defined working directory.
  45. # For Redis Sentinel to chdir to /tmp at startup is the simplest thing
  46. # for the process to don't interfere with administrative tasks such as
  47. # unmounting filesystems.
  48. dir /tmp
  49. # sentinel monitor <master-name> <ip> <redis-port> <quorum>
  50. #
  51. # Tells Sentinel to monitor this master, and to consider it in O_DOWN
  52. # (Objectively Down) state only if at least <quorum> sentinels agree.
  53. #
  54. # Note that whatever is the ODOWN quorum, a Sentinel will require to
  55. # be elected by the majority of the known Sentinels in order to
  56. # start a failover, so no failover can be performed in minority.
  57. #
  58. # Replicas are auto-discovered, so you don't need to specify replicas in
  59. # any way. Sentinel itself will rewrite this configuration file adding
  60. # the replicas using additional configuration options.
  61. # Also note that the configuration file is rewritten when a
  62. # replica is promoted to master.
  63. #
  64. # Note: master name should not include special characters or spaces.
  65. # The valid charset is A-z 0-9 and the three characters ".-_".
  66. {% if ansible_fqdn != groups['redis_servers'][0] %}
  67. sentinel monitor mymaster {{ groups['redis_servers'][0] }} {{ redis_port }} 2
  68. {% else %}
  69. sentinel monitor mymaster 127.0.0.1 {{ redis_port }} 2
  70. {% endif %}
  71. # sentinel auth-pass <master-name> <password>
  72. #
  73. # Set the password to use to authenticate with the master and replicas.
  74. # Useful if there is a password set in the Redis instances to monitor.
  75. #
  76. # Note that the master password is also used for replicas, so it is not
  77. # possible to set a different password in masters and replicas instances
  78. # if you want to be able to monitor these instances with Sentinel.
  79. #
  80. # However you can have Redis instances without the authentication enabled
  81. # mixed with Redis instances requiring the authentication (as long as the
  82. # password set is the same for all the instances requiring the password) as
  83. # the AUTH command will have no effect in Redis instances with authentication
  84. # switched off.
  85. #
  86. # Example:
  87. #
  88. # sentinel auth-pass mymaster MySUPER--secret-0123passw0rd
  89. # sentinel auth-user <master-name> <username>
  90. #
  91. # This is useful in order to authenticate to instances having ACL capabilities,
  92. # that is, running Redis 6.0 or greater. When just auth-pass is provided the
  93. # Sentinel instance will authenticate to Redis using the old "AUTH <pass>"
  94. # method. When also an username is provided, it will use "AUTH <user> <pass>".
  95. # In the Redis servers side, the ACL to provide just minimal access to
  96. # Sentinel instances, should be configured along the following lines:
  97. #
  98. # user sentinel-user >somepassword +client +subscribe +publish \
  99. # +ping +info +multi +slaveof +config +client +exec on
  100. # sentinel down-after-milliseconds <master-name> <milliseconds>
  101. #
  102. # Number of milliseconds the master (or any attached replica or sentinel) should
  103. # be unreachable (as in, not acceptable reply to PING, continuously, for the
  104. # specified period) in order to consider it in S_DOWN state (Subjectively
  105. # Down).
  106. #
  107. # Default is 30 seconds.
  108. sentinel down-after-milliseconds mymaster {{ redis_sentinel_down_after_milliseconds }}
  109. # IMPORTANT NOTE: starting with Redis 6.2 ACL capability is supported for
  110. # Sentinel mode, please refer to the Redis website https://redis.io/topics/acl
  111. # for more details.
  112. # Sentinel's ACL users are defined in the following format:
  113. #
  114. # user <username> ... acl rules ...
  115. #
  116. # For example:
  117. #
  118. # user worker +@admin +@connection ~* on >ffa9203c493aa99
  119. #
  120. # For more information about ACL configuration please refer to the Redis
  121. # website at https://redis.io/topics/acl and redis server configuration
  122. # template redis.conf.
  123. # ACL LOG
  124. #
  125. # The ACL Log tracks failed commands and authentication events associated
  126. # with ACLs. The ACL Log is useful to troubleshoot failed commands blocked
  127. # by ACLs. The ACL Log is stored in memory. You can reclaim memory with
  128. # ACL LOG RESET. Define the maximum entry length of the ACL Log below.
  129. acllog-max-len 128
  130. # Using an external ACL file
  131. #
  132. # Instead of configuring users here in this file, it is possible to use
  133. # a stand-alone file just listing users. The two methods cannot be mixed:
  134. # if you configure users here and at the same time you activate the external
  135. # ACL file, the server will refuse to start.
  136. #
  137. # The format of the external ACL user file is exactly the same as the
  138. # format that is used inside redis.conf to describe users.
  139. #
  140. # aclfile /etc/redis/sentinel-users.acl
  141. # requirepass <password>
  142. #
  143. # You can configure Sentinel itself to require a password, however when doing
  144. # so Sentinel will try to authenticate with the same password to all the
  145. # other Sentinels. So you need to configure all your Sentinels in a given
  146. # group with the same "requirepass" password. Check the following documentation
  147. # for more info: https://redis.io/topics/sentinel
  148. #
  149. # IMPORTANT NOTE: starting with Redis 6.2 "requirepass" is a compatibility
  150. # layer on top of the ACL system. The option effect will be just setting
  151. # the password for the default user. Clients will still authenticate using
  152. # AUTH <password> as usually, or more explicitly with AUTH default <password>
  153. # if they follow the new protocol: both will work.
  154. #
  155. # New config files are advised to use separate authentication control for
  156. # incoming connections (via ACL), and for outgoing connections (via
  157. # sentinel-user and sentinel-pass)
  158. #
  159. # The requirepass is not compatible with aclfile option and the ACL LOAD
  160. # command, these will cause requirepass to be ignored.
  161. # sentinel sentinel-user <username>
  162. #
  163. # You can configure Sentinel to authenticate with other Sentinels with specific
  164. # user name.
  165. # sentinel sentinel-pass <password>
  166. #
  167. # The password for Sentinel to authenticate with other Sentinels. If sentinel-user
  168. # is not configured, Sentinel will use 'default' user with sentinel-pass to authenticate.
  169. # sentinel parallel-syncs <master-name> <numreplicas>
  170. #
  171. # How many replicas we can reconfigure to point to the new replica simultaneously
  172. # during the failover. Use a low number if you use the replicas to serve query
  173. # to avoid that all the replicas will be unreachable at about the same
  174. # time while performing the synchronization with the master.
  175. sentinel parallel-syncs mymaster 1
  176. # sentinel failover-timeout <master-name> <milliseconds>
  177. #
  178. # Specifies the failover timeout in milliseconds. It is used in many ways:
  179. #
  180. # - The time needed to re-start a failover after a previous failover was
  181. # already tried against the same master by a given Sentinel, is two
  182. # times the failover timeout.
  183. #
  184. # - The time needed for a replica replicating to a wrong master according
  185. # to a Sentinel current configuration, to be forced to replicate
  186. # with the right master, is exactly the failover timeout (counting since
  187. # the moment a Sentinel detected the misconfiguration).
  188. #
  189. # - The time needed to cancel a failover that is already in progress but
  190. # did not produced any configuration change (SLAVEOF NO ONE yet not
  191. # acknowledged by the promoted replica).
  192. #
  193. # - The maximum time a failover in progress waits for all the replicas to be
  194. # reconfigured as replicas of the new master. However even after this time
  195. # the replicas will be reconfigured by the Sentinels anyway, but not with
  196. # the exact parallel-syncs progression as specified.
  197. #
  198. # Default is 3 minutes.
  199. sentinel failover-timeout mymaster 180000
  200. # SCRIPTS EXECUTION
  201. #
  202. # sentinel notification-script and sentinel reconfig-script are used in order
  203. # to configure scripts that are called to notify the system administrator
  204. # or to reconfigure clients after a failover. The scripts are executed
  205. # with the following rules for error handling:
  206. #
  207. # If script exits with "1" the execution is retried later (up to a maximum
  208. # number of times currently set to 10).
  209. #
  210. # If script exits with "2" (or an higher value) the script execution is
  211. # not retried.
  212. #
  213. # If script terminates because it receives a signal the behavior is the same
  214. # as exit code 1.
  215. #
  216. # A script has a maximum running time of 60 seconds. After this limit is
  217. # reached the script is terminated with a SIGKILL and the execution retried.
  218. # NOTIFICATION SCRIPT
  219. #
  220. # sentinel notification-script <master-name> <script-path>
  221. #
  222. # Call the specified notification script for any sentinel event that is
  223. # generated in the WARNING level (for instance -sdown, -odown, and so forth).
  224. # This script should notify the system administrator via email, SMS, or any
  225. # other messaging system, that there is something wrong with the monitored
  226. # Redis systems.
  227. #
  228. # The script is called with just two arguments: the first is the event type
  229. # and the second the event description.
  230. #
  231. # The script must exist and be executable in order for sentinel to start if
  232. # this option is provided.
  233. #
  234. # Example:
  235. #
  236. # sentinel notification-script mymaster /var/redis/notify.sh
  237. # CLIENTS RECONFIGURATION SCRIPT
  238. #
  239. # sentinel client-reconfig-script <master-name> <script-path>
  240. #
  241. # When the master changed because of a failover a script can be called in
  242. # order to perform application-specific tasks to notify the clients that the
  243. # configuration has changed and the master is at a different address.
  244. #
  245. # The following arguments are passed to the script:
  246. #
  247. # <master-name> <role> <state> <from-ip> <from-port> <to-ip> <to-port>
  248. #
  249. # <state> is currently always "start"
  250. # <role> is either "leader" or "observer"
  251. #
  252. # The arguments from-ip, from-port, to-ip, to-port are used to communicate
  253. # the old address of the master and the new address of the elected replica
  254. # (now a master).
  255. #
  256. # This script should be resistant to multiple invocations.
  257. #
  258. # Example:
  259. #
  260. # sentinel client-reconfig-script mymaster /var/redis/reconfig.sh
  261. # SECURITY
  262. #
  263. # By default SENTINEL SET will not be able to change the notification-script
  264. # and client-reconfig-script at runtime. This avoids a trivial security issue
  265. # where clients can set the script to anything and trigger a failover in order
  266. # to get the program executed.
  267. sentinel deny-scripts-reconfig yes
  268. # REDIS COMMANDS RENAMING (DEPRECATED)
  269. #
  270. # WARNING: avoid using this option if possible, instead use ACLs.
  271. #
  272. # Sometimes the Redis server has certain commands, that are needed for Sentinel
  273. # to work correctly, renamed to unguessable strings. This is often the case
  274. # of CONFIG and SLAVEOF in the context of providers that provide Redis as
  275. # a service, and don't want the customers to reconfigure the instances outside
  276. # of the administration console.
  277. #
  278. # In such case it is possible to tell Sentinel to use different command names
  279. # instead of the normal ones. For example if the master "mymaster", and the
  280. # associated replicas, have "CONFIG" all renamed to "GUESSME", I could use:
  281. #
  282. # SENTINEL rename-command mymaster CONFIG GUESSME
  283. #
  284. # After such configuration is set, every time Sentinel would use CONFIG it will
  285. # use GUESSME instead. Note that there is no actual need to respect the command
  286. # case, so writing "config guessme" is the same in the example above.
  287. #
  288. # SENTINEL SET can also be used in order to perform this configuration at runtime.
  289. #
  290. # In order to set a command back to its original name (undo the renaming), it
  291. # is possible to just rename a command to itself:
  292. #
  293. # SENTINEL rename-command mymaster CONFIG CONFIG
  294. # HOSTNAMES SUPPORT
  295. #
  296. # Normally Sentinel uses only IP addresses and requires SENTINEL MONITOR
  297. # to specify an IP address. Also, it requires the Redis replica-announce-ip
  298. # keyword to specify only IP addresses.
  299. #
  300. # You may enable hostnames support by enabling resolve-hostnames. Note
  301. # that you must make sure your DNS is configured properly and that DNS
  302. # resolution does not introduce very long delays.
  303. #
  304. SENTINEL resolve-hostnames no
  305. # When resolve-hostnames is enabled, Sentinel still uses IP addresses
  306. # when exposing instances to users, configuration files, etc. If you want
  307. # to retain the hostnames when announced, enable announce-hostnames below.
  308. #
  309. SENTINEL announce-hostnames no
  310. # When master_reboot_down_after_period is set to 0, Sentinel does not fail over
  311. # when receiving a -LOADING response from a master. This was the only supported
  312. # behavior before version 7.0.
  313. #
  314. # Otherwise, Sentinel will use this value as the time (in ms) it is willing to
  315. # accept a -LOADING response after a master has been rebooted, before failing
  316. # over.
  317. SENTINEL master-reboot-down-after-period mymaster 0