经验首页 前端设计 程序设计 Java相关 移动开发 数据库/运维 软件/图像 大数据/云计算 其他经验
当前位置:技术经验 » 数据库/运维 » Redis » 查看文章
Window server中安装Redis的超详细教程
来源:jb51  时间:2021/11/16 11:12:30  对本文有异议

1.下载Window版的安装包,选择下载msi版本安装即可。

官网不支持下载window版本,只能去github上下载:

Window版redis

按步骤安装完毕即可。

2.打开服务,会看到Redis服务已开启:

设置启动类型为自动.

这样每次机器重启,redis也将自动启动。 

3.安装可视化界面:Another.Redis.Desktop.Manager

这是一款免费的redis操作界面,可简单的查看redis数据库。

 3.设置云服务上的redis可进行远程连接:

为了后续的开发,应配置远程服务器上的redis可进行远程连接(可通过ip地址+端口号进行访问).

在安装目录下,找到redis.windows-service.conf配置文件

配置文件:

  1. # Redis configuration file example
  2. # Note on units: when memory size is needed, it is possible to specify
  3. # it in the usual form of 1k 5GB 4M and so forth:
  4. #
  5. # 1k => 1000 bytes
  6. # 1kb => 1024 bytes
  7. # 1m => 1000000 bytes
  8. # 1mb => 1024*1024 bytes
  9. # 1g => 1000000000 bytes
  10. # 1gb => 1024*1024*1024 bytes
  11. #
  12. # units are case insensitive so 1GB 1Gb 1gB are all the same.
  13. ################################## INCLUDES ###################################
  14. # Include one or more other config files here. This is useful if you
  15. # have a standard template that goes to all Redis servers but also need
  16. # to customize a few per-server settings. Include files can include
  17. # other files, so use this wisely.
  18. #
  19. # Notice option "include" won't be rewritten by command "CONFIG REWRITE"
  20. # from admin or Redis Sentinel. Since Redis always uses the last processed
  21. # line as value of a configuration directive, you'd better put includes
  22. # at the beginning of this file to avoid overwriting config change at runtime.
  23. #
  24. # If instead you are interested in using includes to override configuration
  25. # options, it is better to use include as the last line.
  26. #
  27. # include .\path\to\local.conf
  28. # include c:\path\to\other.conf
  29. ################################ GENERAL #####################################
  30. # On Windows, daemonize and pidfile are not supported.
  31. # However, you can run redis as a Windows service, and specify a logfile.
  32. # The logfile will contain the pid.
  33. # Accept connections on the specified port, default is 6379.
  34. # If port 0 is specified Redis will not listen on a TCP socket.
  35. port 6379
  36. # TCP listen() backlog.
  37. #
  38. # In high requests-per-second environments you need an high backlog in order
  39. # to avoid slow clients connections issues. Note that the Linux kernel
  40. # will silently truncate it to the value of /proc/sys/net/core/somaxconn so
  41. # make sure to raise both the value of somaxconn and tcp_max_syn_backlog
  42. # in order to get the desired effect.
  43. tcp-backlog 511
  44. # By default Redis listens for connections from all the network interfaces
  45. # available on the server. It is possible to listen to just one or multiple
  46. # interfaces using the "bind" configuration directive, followed by one or
  47. # more IP addresses.
  48. #
  49. # Examples:
  50. #
  51. # bind 192.168.1.100 10.0.0.1
  52. bind 0.0.0.0
  53. # Specify the path for the Unix socket that will be used to listen for
  54. # incoming connections. There is no default, so Redis will not listen
  55. # on a unix socket when not specified.
  56. #
  57. # unixsocket /tmp/redis.sock
  58. # unixsocketperm 700
  59. # Close the connection after a client is idle for N seconds (0 to disable)
  60. timeout 0
  61. # TCP keepalive.
  62. #
  63. # If non-zero, use SO_KEEPALIVE to send TCP ACKs to clients in absence
  64. # of communication. This is useful for two reasons:
  65. #
  66. # 1) Detect dead peers.
  67. # 2) Take the connection alive from the point of view of network
  68. # equipment in the middle.
  69. #
  70. # On Linux, the specified value (in seconds) is the period used to send ACKs.
  71. # Note that to close the connection the double of the time is needed.
  72. # On other kernels the period depends on the kernel configuration.
  73. #
  74. # A reasonable value for this option is 60 seconds.
  75. tcp-keepalive 0
  76. # Specify the server verbosity level.
  77. # This can be one of:
  78. # debug (a lot of information, useful for development/testing)
  79. # verbose (many rarely useful info, but not a mess like the debug level)
  80. # notice (moderately verbose, what you want in production probably)
  81. # warning (only very important / critical messages are logged)
  82. loglevel notice
  83. # Specify the log file name. Also 'stdout' can be used to force
  84. # Redis to log on the standard output.
  85. logfile "Logs/redis_log.txt"
  86. # To enable logging to the Windows EventLog, just set 'syslog-enabled' to
  87. # yes, and optionally update the other syslog parameters to suit your needs.
  88. # If Redis is installed and launched as a Windows Service, this will
  89. # automatically be enabled.
  90. syslog-enabled yes
  91. # Specify the source name of the events in the Windows Application log.
  92. syslog-ident redis
  93. # Set the number of databases. The default database is DB 0, you can select
  94. # a different one on a per-connection basis using SELECT <dbid> where
  95. # dbid is a number between 0 and 'databases'-1
  96. databases 16
  97. ################################ SNAPSHOTTING ################################
  98. #
  99. # Save the DB on disk:
  100. #
  101. # save <seconds> <changes>
  102. #
  103. # Will save the DB if both the given number of seconds and the given
  104. # number of write operations against the DB occurred.
  105. #
  106. # In the example below the behaviour will be to save:
  107. # after 900 sec (15 min) if at least 1 key changed
  108. # after 300 sec (5 min) if at least 10 keys changed
  109. # after 60 sec if at least 10000 keys changed
  110. #
  111. # Note: you can disable saving completely by commenting out all "save" lines.
  112. #
  113. # It is also possible to remove all the previously configured save
  114. # points by adding a save directive with a single empty string argument
  115. # like in the following example:
  116. #
  117. # save ""
  118. save 900 1
  119. save 300 10
  120. save 60 10000
  121. # By default Redis will stop accepting writes if RDB snapshots are enabled
  122. # (at least one save point) and the latest background save failed.
  123. # This will make the user aware (in a hard way) that data is not persisting
  124. # on disk properly, otherwise chances are that no one will notice and some
  125. # disaster will happen.
  126. #
  127. # If the background saving process will start working again Redis will
  128. # automatically allow writes again.
  129. #
  130. # However if you have setup your proper monitoring of the Redis server
  131. # and persistence, you may want to disable this feature so that Redis will
  132. # continue to work as usual even if there are problems with disk,
  133. # permissions, and so forth.
  134. stop-writes-on-bgsave-error yes
  135. # Compress string objects using LZF when dump .rdb databases?
  136. # For default that's set to 'yes' as it's almost always a win.
  137. # If you want to save some CPU in the saving child set it to 'no' but
  138. # the dataset will likely be bigger if you have compressible values or keys.
  139. rdbcompression yes
  140. # Since version 5 of RDB a CRC64 checksum is placed at the end of the file.
  141. # This makes the format more resistant to corruption but there is a performance
  142. # hit to pay (around 10%) when saving and loading RDB files, so you can disable it
  143. # for maximum performances.
  144. #
  145. # RDB files created with checksum disabled have a checksum of zero that will
  146. # tell the loading code to skip the check.
  147. rdbchecksum yes
  148. # The filename where to dump the DB
  149. dbfilename dump.rdb
  150. # The working directory.
  151. #
  152. # The DB will be written inside this directory, with the filename specified
  153. # above using the 'dbfilename' configuration directive.
  154. #
  155. # The Append Only File will also be created inside this directory.
  156. #
  157. # Note that you must specify a directory here, not a file name.
  158. dir ./
  159. ################################# REPLICATION #################################
  160. # Master-Slave replication. Use slaveof to make a Redis instance a copy of
  161. # another Redis server. A few things to understand ASAP about Redis replication.
  162. #
  163. # 1) Redis replication is asynchronous, but you can configure a master to
  164. # stop accepting writes if it appears to be not connected with at least
  165. # a given number of slaves.
  166. # 2) Redis slaves are able to perform a partial resynchronization with the
  167. # master if the replication link is lost for a relatively small amount of
  168. # time. You may want to configure the replication backlog size (see the next
  169. # sections of this file) with a sensible value depending on your needs.
  170. # 3) Replication is automatic and does not need user intervention. After a
  171. # network partition slaves automatically try to reconnect to masters
  172. # and resynchronize with them.
  173. #
  174. # slaveof <masterip> <masterport>
  175. # If the master is password protected (using the "requirepass" configuration
  176. # directive below) it is possible to tell the slave to authenticate before
  177. # starting the replication synchronization process, otherwise the master will
  178. # refuse the slave request.
  179. #
  180. # masterauth <master-password>
  181. # When a slave loses its connection with the master, or when the replication
  182. # is still in progress, the slave can act in two different ways:
  183. #
  184. # 1) if slave-serve-stale-data is set to 'yes' (the default) the slave will
  185. # still reply to client requests, possibly with out of date data, or the
  186. # data set may just be empty if this is the first synchronization.
  187. #
  188. # 2) if slave-serve-stale-data is set to 'no' the slave will reply with
  189. # an error "SYNC with master in progress" to all the kind of commands
  190. # but to INFO and SLAVEOF.
  191. #
  192. slave-serve-stale-data yes
  193. # You can configure a slave instance to accept writes or not. Writing against
  194. # a slave instance may be useful to store some ephemeral data (because data
  195. # written on a slave will be easily deleted after resync with the master) but
  196. # may also cause problems if clients are writing to it because of a
  197. # misconfiguration.
  198. #
  199. # Since Redis 2.6 by default slaves are read-only.
  200. #
  201. # Note: read only slaves are not designed to be exposed to untrusted clients
  202. # on the internet. It's just a protection layer against misuse of the instance.
  203. # Still a read only slave exports by default all the administrative commands
  204. # such as CONFIG, DEBUG, and so forth. To a limited extent you can improve
  205. # security of read only slaves using 'rename-command' to shadow all the
  206. # administrative / dangerous commands.
  207. slave-read-only yes
  208. # Replication SYNC strategy: disk or socket.
  209. #
  210. # -------------------------------------------------------
  211. # WARNING: DISKLESS REPLICATION IS EXPERIMENTAL CURRENTLY
  212. # -------------------------------------------------------
  213. #
  214. # New slaves and reconnecting slaves that are not able to continue the replication
  215. # process just receiving differences, need to do what is called a "full
  216. # synchronization". An RDB file is transmitted from the master to the slaves.
  217. # The transmission can happen in two different ways:
  218. #
  219. # 1) Disk-backed: The Redis master creates a new process that writes the RDB
  220. # file on disk. Later the file is transferred by the parent
  221. # process to the slaves incrementally.
  222. # 2) Diskless: The Redis master creates a new process that directly writes the
  223. # RDB file to slave sockets, without touching the disk at all.
  224. #
  225. # With disk-backed replication, while the RDB file is generated, more slaves
  226. # can be queued and served with the RDB file as soon as the current child producing
  227. # the RDB file finishes its work. With diskless replication instead once
  228. # the transfer starts, new slaves arriving will be queued and a new transfer
  229. # will start when the current one terminates.
  230. #
  231. # When diskless replication is used, the master waits a configurable amount of
  232. # time (in seconds) before starting the transfer in the hope that multiple slaves
  233. # will arrive and the transfer can be parallelized.
  234. #
  235. # With slow disks and fast (large bandwidth) networks, diskless replication
  236. # works better.
  237. repl-diskless-sync no
  238. # When diskless replication is enabled, it is possible to configure the delay
  239. # the server waits in order to spawn the child that transfers the RDB via socket
  240. # to the slaves.
  241. #
  242. # This is important since once the transfer starts, it is not possible to serve
  243. # new slaves arriving, that will be queued for the next RDB transfer, so the server
  244. # waits a delay in order to let more slaves arrive.
  245. #
  246. # The delay is specified in seconds, and by default is 5 seconds. To disable
  247. # it entirely just set it to 0 seconds and the transfer will start ASAP.
  248. repl-diskless-sync-delay 5
  249. # Slaves send PINGs to server in a predefined interval. It's possible to change
  250. # this interval with the repl_ping_slave_period option. The default value is 10
  251. # seconds.
  252. #
  253. # repl-ping-slave-period 10
  254. # The following option sets the replication timeout for:
  255. #
  256. # 1) Bulk transfer I/O during SYNC, from the point of view of slave.
  257. # 2) Master timeout from the point of view of slaves (data, pings).
  258. # 3) Slave timeout from the point of view of masters (REPLCONF ACK pings).
  259. #
  260. # It is important to make sure that this value is greater than the value
  261. # specified for repl-ping-slave-period otherwise a timeout will be detected
  262. # every time there is low traffic between the master and the slave.
  263. #
  264. # repl-timeout 60
  265. # Disable TCP_NODELAY on the slave socket after SYNC?
  266. #
  267. # If you select "yes" Redis will use a smaller number of TCP packets and
  268. # less bandwidth to send data to slaves. But this can add a delay for
  269. # the data to appear on the slave side, up to 40 milliseconds with
  270. # Linux kernels using a default configuration.
  271. #
  272. # If you select "no" the delay for data to appear on the slave side will
  273. # be reduced but more bandwidth will be used for replication.
  274. #
  275. # By default we optimize for low latency, but in very high traffic conditions
  276. # or when the master and slaves are many hops away, turning this to "yes" may
  277. # be a good idea.
  278. repl-disable-tcp-nodelay no
  279. # Set the replication backlog size. The backlog is a buffer that accumulates
  280. # slave data when slaves are disconnected for some time, so that when a slave
  281. # wants to reconnect again, often a full resync is not needed, but a partial
  282. # resync is enough, just passing the portion of data the slave missed while
  283. # disconnected.
  284. #
  285. # The bigger the replication backlog, the longer the time the slave can be
  286. # disconnected and later be able to perform a partial resynchronization.
  287. #
  288. # The backlog is only allocated once there is at least a slave connected.
  289. #
  290. # repl-backlog-size 1mb
  291. # After a master has no longer connected slaves for some time, the backlog
  292. # will be freed. The following option configures the amount of seconds that
  293. # need to elapse, starting from the time the last slave disconnected, for
  294. # the backlog buffer to be freed.
  295. #
  296. # A value of 0 means to never release the backlog.
  297. #
  298. # repl-backlog-ttl 3600
  299. # The slave priority is an integer number published by Redis in the INFO output.
  300. # It is used by Redis Sentinel in order to select a slave to promote into a
  301. # master if the master is no longer working correctly.
  302. #
  303. # A slave with a low priority number is considered better for promotion, so
  304. # for instance if there are three slaves with priority 10, 100, 25 Sentinel will
  305. # pick the one with priority 10, that is the lowest.
  306. #
  307. # However a special priority of 0 marks the slave as not able to perform the
  308. # role of master, so a slave with priority of 0 will never be selected by
  309. # Redis Sentinel for promotion.
  310. #
  311. # By default the priority is 100.
  312. slave-priority 100
  313. # It is possible for a master to stop accepting writes if there are less than
  314. # N slaves connected, having a lag less or equal than M seconds.
  315. #
  316. # The N slaves need to be in "online" state.
  317. #
  318. # The lag in seconds, that must be <= the specified value, is calculated from
  319. # the last ping received from the slave, that is usually sent every second.
  320. #
  321. # This option does not GUARANTEE that N replicas will accept the write, but
  322. # will limit the window of exposure for lost writes in case not enough slaves
  323. # are available, to the specified number of seconds.
  324. #
  325. # For example to require at least 3 slaves with a lag <= 10 seconds use:
  326. #
  327. # min-slaves-to-write 3
  328. # min-slaves-max-lag 10
  329. #
  330. # Setting one or the other to 0 disables the feature.
  331. #
  332. # By default min-slaves-to-write is set to 0 (feature disabled) and
  333. # min-slaves-max-lag is set to 10.
  334. ################################## SECURITY ###################################
  335. # Require clients to issue AUTH <PASSWORD> before processing any other
  336. # commands. This might be useful in environments in which you do not trust
  337. # others with access to the host running redis-server.
  338. #
  339. # This should stay commented out for backward compatibility and because most
  340. # people do not need auth (e.g. they run their own servers).
  341. #
  342. # Warning: since Redis is pretty fast an outside user can try up to
  343. # 150k passwords per second against a good box. This means that you should
  344. # use a very strong password otherwise it will be very easy to break.
  345. #
  346. requirepass 123456
  347. # Command renaming.
  348. #
  349. # It is possible to change the name of dangerous commands in a shared
  350. # environment. For instance the CONFIG command may be renamed into something
  351. # hard to guess so that it will still be available for internal-use tools
  352. # but not available for general clients.
  353. #
  354. # Example:
  355. #
  356. # rename-command CONFIG b840fc02d524045429941cc15f59e41cb7be6c52
  357. #
  358. # It is also possible to completely kill a command by renaming it into
  359. # an empty string:
  360. #
  361. # rename-command CONFIG ""
  362. #
  363. # Please note that changing the name of commands that are logged into the
  364. # AOF file or transmitted to slaves may cause problems.
  365. ################################### LIMITS ####################################
  366. # Set the max number of connected clients at the same time. By default
  367. # this limit is set to 10000 clients, however if the Redis server is not
  368. # able to configure the process file limit to allow for the specified limit
  369. # the max number of allowed clients is set to the current file limit
  370. # minus 32 (as Redis reserves a few file descriptors for internal uses).
  371. #
  372. # Once the limit is reached Redis will close all the new connections sending
  373. # an error 'max number of clients reached'.
  374. #
  375. # maxclients 10000
  376. # If Redis is to be used as an in-memory-only cache without any kind of
  377. # persistence, then the fork() mechanism used by the background AOF/RDB
  378. # persistence is unnecessary. As an optimization, all persistence can be
  379. # turned off in the Windows version of Redis. This will redirect heap
  380. # allocations to the system heap allocator, and disable commands that would
  381. # otherwise cause fork() operations: BGSAVE and BGREWRITEAOF.
  382. # This flag may not be combined with any of the other flags that configure
  383. # AOF and RDB operations.
  384. # persistence-available [(yes)|no]
  385. # Don't use more memory than the specified amount of bytes.
  386. # When the memory limit is reached Redis will try to remove keys
  387. # according to the eviction policy selected (see maxmemory-policy).
  388. #
  389. # If Redis can't remove keys according to the policy, or if the policy is
  390. # set to 'noeviction', Redis will start to reply with errors to commands
  391. # that would use more memory, like SET, LPUSH, and so on, and will continue
  392. # to reply to read-only commands like GET.
  393. #
  394. # This option is usually useful when using Redis as an LRU cache, or to set
  395. # a hard memory limit for an instance (using the 'noeviction' policy).
  396. #
  397. # WARNING: If you have slaves attached to an instance with maxmemory on,
  398. # the size of the output buffers needed to feed the slaves are subtracted
  399. # from the used memory count, so that network problems / resyncs will
  400. # not trigger a loop where keys are evicted, and in turn the output
  401. # buffer of slaves is full with DELs of keys evicted triggering the deletion
  402. # of more keys, and so forth until the database is completely emptied.
  403. #
  404. # In short... if you have slaves attached it is suggested that you set a lower
  405. # limit for maxmemory so that there is some free RAM on the system for slave
  406. # output buffers (but this is not needed if the policy is 'noeviction').
  407. #
  408. # WARNING: not setting maxmemory will cause Redis to terminate with an
  409. # out-of-memory exception if the heap limit is reached.
  410. #
  411. # NOTE: since Redis uses the system paging file to allocate the heap memory,
  412. # the Working Set memory usage showed by the Windows Task Manager or by other
  413. # tools such as ProcessExplorer will not always be accurate. For example, right
  414. # after a background save of the RDB or the AOF files, the working set value
  415. # may drop significantly. In order to check the correct amount of memory used
  416. # by the redis-server to store the data, use the INFO client command. The INFO
  417. # command shows only the memory used to store the redis data, not the extra
  418. # memory used by the Windows process for its own requirements. Th3 extra amount
  419. # of memory not reported by the INFO command can be calculated subtracting the
  420. # Peak Working Set reported by the Windows Task Manager and the used_memory_peak
  421. # reported by the INFO command.
  422. #
  423. maxmemory 100mb
  424. # MAXMEMORY POLICY: how Redis will select what to remove when maxmemory
  425. # is reached. You can select among five behaviors:
  426. #
  427. # volatile-lru -> remove the key with an expire set using an LRU algorithm
  428. # allkeys-lru -> remove any key according to the LRU algorithm
  429. # volatile-random -> remove a random key with an expire set
  430. # allkeys-random -> remove a random key, any key
  431. # volatile-ttl -> remove the key with the nearest expire time (minor TTL)
  432. # noeviction -> don't expire at all, just return an error on write operations
  433. #
  434. # Note: with any of the above policies, Redis will return an error on write
  435. # operations, when there are no suitable keys for eviction.
  436. #
  437. # At the date of writing these commands are: set setnx setex append
  438. # incr decr rpush lpush rpushx lpushx linsert lset rpoplpush sadd
  439. # sinter sinterstore sunion sunionstore sdiff sdiffstore zadd zincrby
  440. # zunionstore zinterstore hset hsetnx hmset hincrby incrby decrby
  441. # getset mset msetnx exec sort
  442. #
  443. # The default is:
  444. #
  445. # maxmemory-policy noeviction
  446. # LRU and minimal TTL algorithms are not precise algorithms but approximated
  447. # algorithms (in order to save memory), so you can select as well the sample
  448. # size to check. For instance for default Redis will check three keys and
  449. # pick the one that was used less recently, you can change the sample size
  450. # using the following configuration directive.
  451. #
  452. # maxmemory-samples 3
  453. ############################## APPEND ONLY MODE ###############################
  454. # By default Redis asynchronously dumps the dataset on disk. This mode is
  455. # good enough in many applications, but an issue with the Redis process or
  456. # a power outage may result into a few minutes of writes lost (depending on
  457. # the configured save points).
  458. #
  459. # The Append Only File is an alternative persistence mode that provides
  460. # much better durability. For instance using the default data fsync policy
  461. # (see later in the config file) Redis can lose just one second of writes in a
  462. # dramatic event like a server power outage, or a single write if something
  463. # wrong with the Redis process itself happens, but the operating system is
  464. # still running correctly.
  465. #
  466. # AOF and RDB persistence can be enabled at the same time without problems.
  467. # If the AOF is enabled on startup Redis will load the AOF, that is the file
  468. # with the better durability guarantees.
  469. #
  470. # Please check http://redis.io/topics/persistence for more information.
  471. appendonly no
  472. # The name of the append only file (default: "appendonly.aof")
  473. appendfilename "appendonly.aof"
  474. # The fsync() call tells the Operating System to actually write data on disk
  475. # instead of waiting for more data in the output buffer. Some OS will really flush
  476. # data on disk, some other OS will just try to do it ASAP.
  477. #
  478. # Redis supports three different modes:
  479. #
  480. # no: don't fsync, just let the OS flush the data when it wants. Faster.
  481. # always: fsync after every write to the append only log . Slow, Safest.
  482. # everysec: fsync only one time every second. Compromise.
  483. #
  484. # The default is "everysec", as that's usually the right compromise between
  485. # speed and data safety. It's up to you to understand if you can relax this to
  486. # "no" that will let the operating system flush the output buffer when
  487. # it wants, for better performances (but if you can live with the idea of
  488. # some data loss consider the default persistence mode that's snapshotting),
  489. # or on the contrary, use "always" that's very slow but a bit safer than
  490. # everysec.
  491. #
  492. # More details please check the following article:
  493. # http://antirez.com/post/redis-persistence-demystified.html
  494. #
  495. # If unsure, use "everysec".
  496. # appendfsync always
  497. appendfsync everysec
  498. # appendfsync no
  499. # When the AOF fsync policy is set to always or everysec, and a background
  500. # saving process (a background save or AOF log background rewriting) is
  501. # performing a lot of I/O against the disk, in some Linux configurations
  502. # Redis may block too long on the fsync() call. Note that there is no fix for
  503. # this currently, as even performing fsync in a different thread will block
  504. # our synchronous write(2) call.
  505. #
  506. # In order to mitigate this problem it's possible to use the following option
  507. # that will prevent fsync() from being called in the main process while a
  508. # BGSAVE or BGREWRITEAOF is in progress.
  509. #
  510. # This means that while another child is saving, the durability of Redis is
  511. # the same as "appendfsync none". In practical terms, this means that it is
  512. # possible to lose up to 30 seconds of log in the worst scenario (with the
  513. # default Linux settings).
  514. #
  515. # If you have latency problems turn this to "yes". Otherwise leave it as
  516. # "no" that is the safest pick from the point of view of durability.
  517. no-appendfsync-on-rewrite no
  518. # Automatic rewrite of the append only file.
  519. # Redis is able to automatically rewrite the log file implicitly calling
  520. # BGREWRITEAOF when the AOF log size grows by the specified percentage.
  521. #
  522. # This is how it works: Redis remembers the size of the AOF file after the
  523. # latest rewrite (if no rewrite has happened since the restart, the size of
  524. # the AOF at startup is used).
  525. #
  526. # This base size is compared to the current size. If the current size is
  527. # bigger than the specified percentage, the rewrite is triggered. Also
  528. # you need to specify a minimal size for the AOF file to be rewritten, this
  529. # is useful to avoid rewriting the AOF file even if the percentage increase
  530. # is reached but it is still pretty small.
  531. #
  532. # Specify a percentage of zero in order to disable the automatic AOF
  533. # rewrite feature.
  534. auto-aof-rewrite-percentage 100
  535. auto-aof-rewrite-min-size 64mb
  536. # An AOF file may be found to be truncated at the end during the Redis
  537. # startup process, when the AOF data gets loaded back into memory.
  538. # This may happen when the system where Redis is running
  539. # crashes, especially when an ext4 filesystem is mounted without the
  540. # data=ordered option (however this can't happen when Redis itself
  541. # crashes or aborts but the operating system still works correctly).
  542. #
  543. # Redis can either exit with an error when this happens, or load as much
  544. # data as possible (the default now) and start if the AOF file is found
  545. # to be truncated at the end. The following option controls this behavior.
  546. #
  547. # If aof-load-truncated is set to yes, a truncated AOF file is loaded and
  548. # the Redis server starts emitting a log to inform the user of the event.
  549. # Otherwise if the option is set to no, the server aborts with an error
  550. # and refuses to start. When the option is set to no, the user requires
  551. # to fix the AOF file using the "redis-check-aof" utility before to restart
  552. # the server.
  553. #
  554. # Note that if the AOF file will be found to be corrupted in the middle
  555. # the server will still exit with an error. This option only applies when
  556. # Redis will try to read more data from the AOF file but not enough bytes
  557. # will be found.
  558. aof-load-truncated yes
  559. ################################ LUA SCRIPTING ###############################
  560. # Max execution time of a Lua script in milliseconds.
  561. #
  562. # If the maximum execution time is reached Redis will log that a script is
  563. # still in execution after the maximum allowed time and will start to
  564. # reply to queries with an error.
  565. #
  566. # When a long running script exceeds the maximum execution time only the
  567. # SCRIPT KILL and SHUTDOWN NOSAVE commands are available. The first can be
  568. # used to stop a script that did not yet called write commands. The second
  569. # is the only way to shut down the server in the case a write command was
  570. # already issued by the script but the user doesn't want to wait for the natural
  571. # termination of the script.
  572. #
  573. # Set it to 0 or a negative value for unlimited execution without warnings.
  574. lua-time-limit 5000
  575. ################################ REDIS CLUSTER ###############################
  576. #
  577. # ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  578. # WARNING EXPERIMENTAL: Redis Cluster is considered to be stable code, however
  579. # in order to mark it as "mature" we need to wait for a non trivial percentage
  580. # of users to deploy it in production.
  581. # ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  582. #
  583. # Normal Redis instances can't be part of a Redis Cluster; only nodes that are
  584. # started as cluster nodes can. In order to start a Redis instance as a
  585. # cluster node enable the cluster support uncommenting the following:
  586. #
  587. # cluster-enabled yes
  588. # Every cluster node has a cluster configuration file. This file is not
  589. # intended to be edited by hand. It is created and updated by Redis nodes.
  590. # Every Redis Cluster node requires a different cluster configuration file.
  591. # Make sure that instances running in the same system do not have
  592. # overlapping cluster configuration file names.
  593. #
  594. # cluster-config-file nodes-6379.conf
  595. # Cluster node timeout is the amount of milliseconds a node must be unreachable
  596. # for it to be considered in failure state.
  597. # Most other internal time limits are multiple of the node timeout.
  598. #
  599. # cluster-node-timeout 15000
  600. # A slave of a failing master will avoid to start a failover if its data
  601. # looks too old.
  602. #
  603. # There is no simple way for a slave to actually have a exact measure of
  604. # its "data age", so the following two checks are performed:
  605. #
  606. # 1) If there are multiple slaves able to failover, they exchange messages
  607. # in order to try to give an advantage to the slave with the best
  608. # replication offset (more data from the master processed).
  609. # Slaves will try to get their rank by offset, and apply to the start
  610. # of the failover a delay proportional to their rank.
  611. #
  612. # 2) Every single slave computes the time of the last interaction with
  613. # its master. This can be the last ping or command received (if the master
  614. # is still in the "connected" state), or the time that elapsed since the
  615. # disconnection with the master (if the replication link is currently down).
  616. # If the last interaction is too old, the slave will not try to failover
  617. # at all.
  618. #
  619. # The point "2" can be tuned by user. Specifically a slave will not perform
  620. # the failover if, since the last interaction with the master, the time
  621. # elapsed is greater than:
  622. #
  623. # (node-timeout * slave-validity-factor) + repl-ping-slave-period
  624. #
  625. # So for example if node-timeout is 30 seconds, and the slave-validity-factor
  626. # is 10, and assuming a default repl-ping-slave-period of 10 seconds, the
  627. # slave will not try to failover if it was not able to talk with the master
  628. # for longer than 310 seconds.
  629. #
  630. # A large slave-validity-factor may allow slaves with too old data to failover
  631. # a master, while a too small value may prevent the cluster from being able to
  632. # elect a slave at all.
  633. #
  634. # For maximum availability, it is possible to set the slave-validity-factor
  635. # to a value of 0, which means, that slaves will always try to failover the
  636. # master regardless of the last time they interacted with the master.
  637. # (However they'll always try to apply a delay proportional to their
  638. # offset rank).
  639. #
  640. # Zero is the only value able to guarantee that when all the partitions heal
  641. # the cluster will always be able to continue.
  642. #
  643. # cluster-slave-validity-factor 10
  644. # Cluster slaves are able to migrate to orphaned masters, that are masters
  645. # that are left without working slaves. This improves the cluster ability
  646. # to resist to failures as otherwise an orphaned master can't be failed over
  647. # in case of failure if it has no working slaves.
  648. #
  649. # Slaves migrate to orphaned masters only if there are still at least a
  650. # given number of other working slaves for their old master. This number
  651. # is the "migration barrier". A migration barrier of 1 means that a slave
  652. # will migrate only if there is at least 1 other working slave for its master
  653. # and so forth. It usually reflects the number of slaves you want for every
  654. # master in your cluster.
  655. #
  656. # Default is 1 (slaves migrate only if their masters remain with at least
  657. # one slave). To disable migration just set it to a very large value.
  658. # A value of 0 can be set but is useful only for debugging and dangerous
  659. # in production.
  660. #
  661. # cluster-migration-barrier 1
  662. # By default Redis Cluster nodes stop accepting queries if they detect there
  663. # is at least an hash slot uncovered (no available node is serving it).
  664. # This way if the cluster is partially down (for example a range of hash slots
  665. # are no longer covered) all the cluster becomes, eventually, unavailable.
  666. # It automatically returns available as soon as all the slots are covered again.
  667. #
  668. # However sometimes you want the subset of the cluster which is working,
  669. # to continue to accept queries for the part of the key space that is still
  670. # covered. In order to do so, just set the cluster-require-full-coverage
  671. # option to no.
  672. #
  673. # cluster-require-full-coverage yes
  674. # In order to setup your cluster make sure to read the documentation
  675. # available at http://redis.io web site.
  676. ################################## SLOW LOG ###################################
  677. # The Redis Slow Log is a system to log queries that exceeded a specified
  678. # execution time. The execution time does not include the I/O operations
  679. # like talking with the client, sending the reply and so forth,
  680. # but just the time needed to actually execute the command (this is the only
  681. # stage of command execution where the thread is blocked and can not serve
  682. # other requests in the meantime).
  683. #
  684. # You can configure the slow log with two parameters: one tells Redis
  685. # what is the execution time, in microseconds, to exceed in order for the
  686. # command to get logged, and the other parameter is the length of the
  687. # slow log. When a new command is logged the oldest one is removed from the
  688. # queue of logged commands.
  689. # The following time is expressed in microseconds, so 1000000 is equivalent
  690. # to one second. Note that a negative number disables the slow log, while
  691. # a value of zero forces the logging of every command.
  692. slowlog-log-slower-than 10000
  693. # There is no limit to this length. Just be aware that it will consume memory.
  694. # You can reclaim memory used by the slow log with SLOWLOG RESET.
  695. slowlog-max-len 128
  696. ################################ LATENCY MONITOR ##############################
  697. # The Redis latency monitoring subsystem samples different operations
  698. # at runtime in order to collect data related to possible sources of
  699. # latency of a Redis instance.
  700. #
  701. # Via the LATENCY command this information is available to the user that can
  702. # print graphs and obtain reports.
  703. #
  704. # The system only logs operations that were performed in a time equal or
  705. # greater than the amount of milliseconds specified via the
  706. # latency-monitor-threshold configuration directive. When its value is set
  707. # to zero, the latency monitor is turned off.
  708. #
  709. # By default latency monitoring is disabled since it is mostly not needed
  710. # if you don't have latency issues, and collecting data has a performance
  711. # impact, that while very small, can be measured under big load. Latency
  712. # monitoring can easily be enabled at runtime using the command
  713. # "CONFIG SET latency-monitor-threshold <milliseconds>" if needed.
  714. latency-monitor-threshold 0
  715. ############################# Event notification ##############################
  716. # Redis can notify Pub/Sub clients about events happening in the key space.
  717. # This feature is documented at http://redis.io/topics/notifications
  718. #
  719. # For instance if keyspace events notification is enabled, and a client
  720. # performs a DEL operation on key "foo" stored in the Database 0, two
  721. # messages will be published via Pub/Sub:
  722. #
  723. # PUBLISH __keyspace@0__:foo del
  724. # PUBLISH __keyevent@0__:del foo
  725. #
  726. # It is possible to select the events that Redis will notify among a set
  727. # of classes. Every class is identified by a single character:
  728. #
  729. # K Keyspace events, published with __keyspace@<db>__ prefix.
  730. # E Keyevent events, published with __keyevent@<db>__ prefix.
  731. # g Generic commands (non-type specific) like DEL, EXPIRE, RENAME, ...
  732. # $ String commands
  733. # l List commands
  734. # s Set commands
  735. # h Hash commands
  736. # z Sorted set commands
  737. # x Expired events (events generated every time a key expires)
  738. # e Evicted events (events generated when a key is evicted for maxmemory)
  739. # A Alias for g$lshzxe, so that the "AKE" string means all the events.
  740. #
  741. # The "notify-keyspace-events" takes as argument a string that is composed
  742. # of zero or multiple characters. The empty string means that notifications
  743. # are disabled.
  744. #
  745. # Example: to enable list and generic events, from the point of view of the
  746. # event name, use:
  747. #
  748. # notify-keyspace-events Elg
  749. #
  750. # Example 2: to get the stream of the expired keys subscribing to channel
  751. # name __keyevent@0__:expired use:
  752. #
  753. # notify-keyspace-events Ex
  754. #
  755. # By default all notifications are disabled because most users don't need
  756. # this feature and the feature has some overhead. Note that if you don't
  757. # specify at least one of K or E, no events will be delivered.
  758. notify-keyspace-events ""
  759. ############################### ADVANCED CONFIG ###############################
  760. # Hashes are encoded using a memory efficient data structure when they have a
  761. # small number of entries, and the biggest entry does not exceed a given
  762. # threshold. These thresholds can be configured using the following directives.
  763. hash-max-ziplist-entries 512
  764. hash-max-ziplist-value 64
  765. # Similarly to hashes, small lists are also encoded in a special way in order
  766. # to save a lot of space. The special representation is only used when
  767. # you are under the following limits:
  768. list-max-ziplist-entries 512
  769. list-max-ziplist-value 64
  770. # Sets have a special encoding in just one case: when a set is composed
  771. # of just strings that happen to be integers in radix 10 in the range
  772. # of 64 bit signed integers.
  773. # The following configuration setting sets the limit in the size of the
  774. # set in order to use this special memory saving encoding.
  775. set-max-intset-entries 512
  776. # Similarly to hashes and lists, sorted sets are also specially encoded in
  777. # order to save a lot of space. This encoding is only used when the length and
  778. # elements of a sorted set are below the following limits:
  779. zset-max-ziplist-entries 128
  780. zset-max-ziplist-value 64
  781. # HyperLogLog sparse representation bytes limit. The limit includes the
  782. # 16 bytes header. When an HyperLogLog using the sparse representation crosses
  783. # this limit, it is converted into the dense representation.
  784. #
  785. # A value greater than 16000 is totally useless, since at that point the
  786. # dense representation is more memory efficient.
  787. #
  788. # The suggested value is ~ 3000 in order to have the benefits of
  789. # the space efficient encoding without slowing down too much PFADD,
  790. # which is O(N) with the sparse encoding. The value can be raised to
  791. # ~ 10000 when CPU is not a concern, but space is, and the data set is
  792. # composed of many HyperLogLogs with cardinality in the 0 - 15000 range.
  793. hll-sparse-max-bytes 3000
  794. # Active rehashing uses 1 millisecond every 100 milliseconds of CPU time in
  795. # order to help rehashing the main Redis hash table (the one mapping top-level
  796. # keys to values). The hash table implementation Redis uses (see dict.c)
  797. # performs a lazy rehashing: the more operation you run into a hash table
  798. # that is rehashing, the more rehashing "steps" are performed, so if the
  799. # server is idle the rehashing is never complete and some more memory is used
  800. # by the hash table.
  801. #
  802. # The default is to use this millisecond 10 times every second in order to
  803. # actively rehash the main dictionaries, freeing memory when possible.
  804. #
  805. # If unsure:
  806. # use "activerehashing no" if you have hard latency requirements and it is
  807. # not a good thing in your environment that Redis can reply from time to time
  808. # to queries with 2 milliseconds delay.
  809. #
  810. # use "activerehashing yes" if you don't have such hard requirements but
  811. # want to free memory asap when possible.
  812. activerehashing yes
  813. # The client output buffer limits can be used to force disconnection of clients
  814. # that are not reading data from the server fast enough for some reason (a
  815. # common reason is that a Pub/Sub client can't consume messages as fast as the
  816. # publisher can produce them).
  817. #
  818. # The limit can be set differently for the three different classes of clients:
  819. #
  820. # normal -> normal clients including MONITOR clients
  821. # slave -> slave clients
  822. # pubsub -> clients subscribed to at least one pubsub channel or pattern
  823. #
  824. # The syntax of every client-output-buffer-limit directive is the following:
  825. #
  826. # client-output-buffer-limit <class> <hard limit> <soft limit> <soft seconds>
  827. #
  828. # A client is immediately disconnected once the hard limit is reached, or if
  829. # the soft limit is reached and remains reached for the specified number of
  830. # seconds (continuously).
  831. # So for instance if the hard limit is 32 megabytes and the soft limit is
  832. # 16 megabytes / 10 seconds, the client will get disconnected immediately
  833. # if the size of the output buffers reach 32 megabytes, but will also get
  834. # disconnected if the client reaches 16 megabytes and continuously overcomes
  835. # the limit for 10 seconds.
  836. #
  837. # By default normal clients are not limited because they don't receive data
  838. # without asking (in a push way), but just after a request, so only
  839. # asynchronous clients may create a scenario where data is requested faster
  840. # than it can read.
  841. #
  842. # Instead there is a default limit for pubsub and slave clients, since
  843. # subscribers and slaves receive data in a push fashion.
  844. #
  845. # Both the hard or the soft limit can be disabled by setting them to zero.
  846. client-output-buffer-limit normal 0 0 0
  847. client-output-buffer-limit slave 256mb 64mb 60
  848. client-output-buffer-limit pubsub 32mb 8mb 60
  849. # Redis calls an internal function to perform many background tasks, like
  850. # closing connections of clients in timeot, purging expired keys that are
  851. # never requested, and so forth.
  852. #
  853. # Not all tasks are perforemd with the same frequency, but Redis checks for
  854. # tasks to perform according to the specified "hz" value.
  855. #
  856. # By default "hz" is set to 10. Raising the value will use more CPU when
  857. # Redis is idle, but at the same time will make Redis more responsive when
  858. # there are many keys expiring at the same time, and timeouts may be
  859. # handled with more precision.
  860. #
  861. # The range is between 1 and 500, however a value over 100 is usually not
  862. # a good idea. Most users should use the default of 10 and raise this up to
  863. # 100 only in environments where very low latency is required.
  864. hz 10
  865. # When a child rewrites the AOF file, if the following option is enabled
  866. # the file will be fsync-ed every 32 MB of data generated. This is useful
  867. # in order to commit the file to the disk more incrementally and avoid
  868. # big latency spikes.
  869. aof-rewrite-incremental-fsync yes
  870. ################################## INCLUDES ###################################
  871. # Include one or more other config files here. This is useful if you
  872. # have a standard template that goes to all Redis server but also need
  873. # to customize a few per-server settings. Include files can include
  874. # other files, so use this wisely.
  875. #
  876. # include /path/to/local.conf
  877. # include /path/to/other.conf

(1)允许远程访问

  1. #1. 注释掉下面代码,或者改为 bind 0.0.0.0
  2. #bind 127.0.0.1
  3. #2. 关闭保护模式
  4. protected-mode no
  5. #3. 开启密码(开启密码后,上面的保护模式可以不用关闭,远程也可以连接)
  6. requirepass 123456

还需保证端口开放或者防火墙关闭

腾讯云开放6379端口:

 然后重启redis服务,在本地通过ip地址和port进行访问:可成功访问

(2). redis cluster配置

  1. # 一. 允许远程访问
  2. #1. 注释掉下面代码,或者改为 bind 0.0.0.0
  3. #bind 127.0.0.1
  4. #2. 关闭保护模式
  5. protected-mode no
  6. #二. 通用配置
  7. #1. 开启守护进程
  8. daemonize yes
  9. #2. 配置密码(必须设置相同的密码,不设masterauth的话宕机了不能自动恢复)
  10. requirepass 123456
  11. masterauth 123456
  12. #三.集群配置
  13. port 6384 #配置端口
  14. cluster-enabled yes #开启集群
  15. cluster-config-file nodes-6384.conf #集群节点配置文件
  16. pidfile /var/run/redis_6384.pid
  17. cluster-node-timeout 5000 #集群节点超时时间

(3). 数据持久化、缓存淘汰策略

  1. #一. RDB存储
  2. # 下面配置为默认配置,默认就是开启的,在一定的间隔时间中,检测key的变化情况,然后持久化数据
  3. save 900 1 #900s后至少1个key发生变化则进行存储
  4. save 300 10 #300s后至少10个key发生变化则进行存储
  5. save 60 10000 #60s后至少10000个key发生变化则进行存储
  6. #二. AOP存储
  7. #默认是关闭的,日志记录的方式,可以记录每一条命令的操作。可以每一次命令操作后,持久化数据,启用的话通常使用每隔一秒持久化一次的策略
  8. appendonly no(默认no --> appendonly yes (开启aof
  9. # appendfsync always #每一次操作都进行持久化
  10. appendfsync everysec #每隔一秒进行一次持久化
  11. # appendfsync no # 不进行持久化
  1. # - volatile-lru: 针对到期的键值,采取 LRU 策略;
  2. # - volatile-lfu: 针对到期的键值,采取 LFU 策略;
  3. # - volatile-random: 针对到期的键值,采取随机策略;
  4. # - allkeys-lru: 针对所有键值,采取 LRU 策略;
  5. # - allkeys-lfu: 针对所有键值,采取 LFU 策略;
  6. # - allkeys-random: 针对所有键值,采取随机策略;
  7. # - volatile-ttl: 删除最近到期的key(次要TTL)
  8. # - noeviction: 不清除任何内容,只是在写入操作时报错。
  9. #
  10. # LRU表示最近最少使用
  11. # LFU意味着最少使用
  12. #
  13. # LRU,LFU和volatile-ttl都是使用近似随机算法实现的。
  14. #
  15. # 默认值是:noeviction
  16. #
  17. # maxmemory-policy noeviction

常用配置汇总

  1. #修改daemonize为yes,即默认以后台程序方式运行
  2. daemonize yes
  3. #修改默认监听端口(一般用默认的)
  4. port 6379
  5. #修改生成默认日志文件位置,默认为""
  6. logfile ""
  7. #默认rdb存储方式的名称
  8. dbfilename dump.rdb
  9. #rdb文件存放位置,默认为当前目录
  10. dir ./
  11. #开启aof存储,默认为no
  12. appendonly no
  13. #aof存储持久化文件的名称
  14. appendfilename "appendonly.aof"
  15. #PID文件
  16. pidfile /home/apps/redis/redis.pid
  17. #保护模式
  18. protected-mode no
  19. #支持集群
  20. cluster-enabled yes
  21. #密码
  22. requirepass 123456
  23. #集群相关密码
  24. masterauth 123456
  25. #缓存淘汰策略(默认不清除)
  26. maxmemory-policy noeviction

到此这篇关于Window server中安装Redis的文章就介绍到这了,更多相关Window server安装Redis内容请搜索w3xue以前的文章或继续浏览下面的相关文章希望大家以后多多支持w3xue!

 友情链接:直通硅谷  点职佳  北美留学生论坛

本站QQ群:前端 618073944 | Java 606181507 | Python 626812652 | C/C++ 612253063 | 微信 634508462 | 苹果 692586424 | C#/.net 182808419 | PHP 305140648 | 运维 608723728

W3xue 的所有内容仅供测试,对任何法律问题及风险不承担任何责任。通过使用本站内容随之而来的风险与本站无关。
关于我们  |  意见建议  |  捐助我们  |  报错有奖  |  广告合作、友情链接(目前9元/月)请联系QQ:27243702 沸活量
皖ICP备17017327号-2 皖公网安备34020702000426号